How can I run ROS2 nodes in a debugger (e.g. gdb)?
Is there something like the --prefix
argument from rosrun in ros2 (see #q222530)?
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
Is there something like the --prefix
argument from rosrun in ros2 (see #q222530)?
The --prefix
argument is now working with ros2 run
. So you can use it in the same way as known from rosrun, e.g.:
ros2 run --prefix 'gdb -ex run --args' package_name executable_name
(see #q222530 for more examples).
At the moment this feature is only available on ROS2 installations, which were built from the development sources (master branch).
Hi, I find a method to debug a C++ node usign VSCode on ROS2 Foxy (Ubuntu).
1) Compile your C++ package with the symbols:
colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebInfo
2) Run the GDB Server in a localhost:port
ros2 run --prefix 'gdbserver localhost:3000' package_name executable_name
3) Open VSCode on your workspace, open the debug section (side bar) and create new launch.json configuration file for debugging. Configure as follow:
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Debugger",
"request": "launch",
"type": "cppdbg",
"miDebuggerServerAddress": "localhost:3000",
"cwd": "/",
"program": "[build-path-executable]"
}
]
}
Change [build-path-executable] by your executable build file. You can find this path on the console when you launch the server.
4) Run the debugger and use VSCode to debug your code.
Here is a more detail explanation https://gist.github.com/JADC362/a4425...
@flent I guess you can attach gdb process to existing process of the component conatiner.
like gdb --pid $(ps -ef|grep your_container_name|awk NR==1'{print $2})'
There is not an option like that. You can just run the binary directly from its location in gdb <install_prefix>/lib/<package_name>/<executable_name>
. You can open an issue or pull request on ros2 run
to make this case better:
Had some issues getting gdb
running on Mac, so had to use LLDB instead:
Make sure to build with debugging symbols.
colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebInfo
Further you can start your node by referencing the executables directly (in this case my packages is called arke_base
):
lldb -f arke_base/install/arke_base/lib/arke_base/arke_hardware_interface_node -- --ros-args --params-file arke_base/config/arke_diff_drive_controller.yaml
The command also shows arguments added, in this case a config file.
Asked: 2017-07-24 14:52:24 -0500
Seen: 12,832 times
Last updated: Apr 28 '21
ROS2 one action client calling multiple servers
trying to install Ros2 on Ubuntu 20.04, but it doesn't work
how to organize data transfer between nodes on multiple PCs on ROS2
Waiting for TransformListener with ROS2 and Python?
[ROS2] How to set QoS policy for topic in cpp script
I am getting an error using Ros2 Iron and micro-ROS on RP2040
Using ROS2 for autonomous driving
ROS2 Bag - DB3 CDR Deserialization
Why image not recieved using ROS2 functions in the node?
[ROS2] asyncio await with timeout a service call in a callback