0
$\begingroup$

Rosanswers logo

I am a developer of rmw_iceoryx, I ran into problems about segfault when executing ros2cli like ros2 topic echo /topic, bug I cannot find a way to debug this kind of problem, see this issue if you like.

I know it is about python and cpp debug and I tried using vscode python debug launcher to debug ros2cli python script, but failed to catch the segment exception.

So, does anybody has experence on debug ros2cli code that dynamiclly load rmw interface?

Thanks.


Originally posted by zhensheng on ROS Answers with karma: 33 on 2021-08-15

Post score: 1

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

I found this: https://wiki.python.org/moin/DebuggingWithGdb

I installed the Python debug package (Ubuntu 20.04):

$ sudo apt-get install python3-dbg

If you try to blindly follow the examples, it doesn't work if you just do:

$ gdb -ex r --args ros2 topic /echo
"/home/$USER/ros2_ws/install/ros2cli/bin/ros2": not in executable format: file format not recognized

So you have to run python3 with the actual entrypoint Python file (which you can see in the error message) as the first argument + the rest. You can also use which to find the Python file corresponding to ros2:

$ gdb -ex r --args python3 `which ros2` topic echo /topic

This seemed to run gdb correctly for me, but with the default RMW implementation there's no segfault, so I can't tell if it actually gives a stack trace, etc. It should, though, according to what I can see in the link above. Let us know if it works!


Originally posted by christophebedard with karma: 641 on 2021-08-21

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by moss on 2022-01-04:
Works like a charm, thanks for the hint!

$\endgroup$
0
$\begingroup$

Rosanswers logo

your method works on vscode too. Thank you very much!

the launch file in vscode is like

{
            "name": "zs: gdbrun ros2",
            "type": "cppdbg",
            "request": "launch",
            "program": "/usr/bin/python3",
            "args": [
                "/opt/ros/foxy/bin/ros2",
                "topic",
                "echo",
                "/tf_static"
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [
                {
                    "name": "RMW_IMPLEMENTATION",
                    // "value": "rmw_fastrtps_cpp"
                    // "value": "rmw_ecal_proto_cpp"
                    "value": "rmw_iceoryx_cpp"
                }
            ],
            "externalConsole": false,
            // "preLaunchTask": "source_ros2_ws",
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },

Originally posted by zhensheng with karma: 33 on 2022-01-13

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.