ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
10

How can I run ROS2 nodes in a debugger (e.g. gdb)?

asked 2017-07-24 14:52:24 -0600

Is there something like the --prefix argument from rosrun in ros2 (see #q222530)?

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
16

answered 2017-07-28 10:27:35 -0600

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).

edit flag offensive delete link more

Comments

I don't want to create a new question for this but; how would that be written for lldb ? probably trivial but I couldn't get it to work.

klintan gravatar image klintan  ( 2019-09-11 20:04:45 -0600 )edit
8

answered 2021-04-28 09:01:24 -0600

JADC362 gravatar image

updated 2021-04-28 15:24:38 -0600

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...

edit flag offensive delete link more

Comments

Can you please update your answer to include the relevant information from the link that you posted? Link-only answers are discouraged as links change, go down, etc. and if/when that happens then your answer won't be of much utility

jayess gravatar image jayess  ( 2021-04-28 15:11:32 -0600 )edit
1

Sure. Updated :)

JADC362 gravatar image JADC362  ( 2021-04-28 15:25:45 -0600 )edit

Thank you for your great answer, but is there any similar way to debug composable nodes insight component containers? I'm really struggling to debug these nodes.

ffent gravatar image ffent  ( 2021-05-25 06:04:23 -0600 )edit
1

@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})'

HiroIshida gravatar image HiroIshida  ( 2021-10-06 13:22:51 -0600 )edit

How about in vscode? For nodes, I can use --prefix to add gdbserver 127.0.0.1:3000 to start a server on a particular node, but a similar --prefix doesn't exist for components or Composable nodes

jd2548 gravatar image jd2548  ( 2022-09-29 12:45:49 -0600 )edit
2

answered 2017-07-24 15:30:32 -0600

William gravatar image

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:

https://github.com/ros2/ros2cli

edit flag offensive delete link more

Comments

Thanks for the quick answer!

Andre Volk gravatar image Andre Volk  ( 2017-07-24 15:34:41 -0600 )edit
1

answered 2020-08-20 00:29:04 -0600

klintan gravatar image

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.

edit flag offensive delete link more

Question Tools

4 followers

Stats

Asked: 2017-07-24 14:52:24 -0600

Seen: 16,049 times

Last updated: Apr 28 '21