ros-industrial / ros_qtc_plugin

ROS Qt Creator Plug-in (https://ros-qtc-plugin.readthedocs.io)
396 stars 213 forks source link

How to debug a ROS2 node launched with a launch.py file #484

Closed martinakos closed 1 year ago

martinakos commented 1 year ago

I'm trying to debug a ROS2 C++ node that crashes with a Segmentation fault. I've installed QtCreator 10.0.2 with the corresponding ROSProjectManager plugin. I set the build system to Colcon and passed specific colcon and cmake arguments in the build step. It builds successfully within QtCreator using RelWithDebInfo and Debug build types. I set a breakpoint in the first line of my node and I select Attach to Unstarted Application and select my node. A window saying waiting for process to start appears. I untick Continue on attach. Then from a terminal I run a launch.py launch file that starts a few nodes including the one I want to debug. However, the node I want to debug crashes without the debugger attaching and the waiting to attach window closes. In my terminal I see this message:

*** UNEXPECTED STATE TRANSITION: Debugger::Internal::DebuggerEngine(0x498c080, name = "GdbEngine") "State changed from EngineRunRequested(3) to EngineShutdownRequested(14)"

Is this the correct procedure to debug a C++ node started externally with a launch file? if it is what could be the reason it doesn't attach to the C++ node?

martinakos commented 1 year ago

I realised of the problem. ptrace was set to 1, both in my docker container (where I have ROS2) and in the host. I changed it to 0 and now I can attach to the node.