https://gist.github.com/JADC362/a4425c2d05cdaadaaa71b697b674425f
Compile the code with the correct flag so you can add breakpoints in VSCode
colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebInfo
Launch GDB server, with the correct package name and executable
ros2 run --prefix 'gdbserver localhost:3000' package_name executable_name
Add the following Launch.json file
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Debugger",
"request": "launch",
"type": "cppdbg",
"miDebuggerServerAddress": "localhost:3000",
"cwd": "/",
"program": "[build-path-executable]"
}
]
}
Where
- name - Custom name of your debugger configuration
- request - In this case we want to launch the client
- type - cppdbg for c++ debugging
- miDebuggerServerAddress - path_server:port
- cwd - Where to find all the required files. We use root because ROS, the package, and other required files are distributed along the entire PC.
- program - Change
[build-path-executable]
by your executable build file. You can find this path on the console when you launch the server.