This implementation was found by Alejandro Duarte and Jeison Garcia.
This is a small tutorial on how to debug a ROS2 C++ node usign VSCode.
Once you have your C++ code correctly implemented (at least compile), the First thing to do is to compile the package exporting the symbols (allow the breakpoints where you want to stop the code):
cd
cd autoware
colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebInfo
source install/setup.bash
Second, we have to launch the GDB Server for debbuging the CPP Code. Here, we will use a localhost:port for creating the server. Choose any free port that you want.
ros2 run --prefix 'gdbserver localhost:3000' package_name executable_name
Third, we have to create a launch.json on VSCode. In other words, we will create a custom debugging configuration. In our case, create a GDB client and connect to the server.
1) Open VSCode on your workspace.
2) Go to your side bar, 'Run and Debug' section.
3) Add a new configuration (Select C++ enviroment or any other)
4) On your launch.json file, put the following information
Launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Debugger",
"request": "launch",
"type": "cppdbg",s
"miDebuggerServerAddress": "localhost:3000",
"cwd": "/",
"program": "[build-path-executable]"
}
]
}
Lastly, use the VSCode buttons and panels option to debug correctly your code.