Troubleshooting first step
If the code is not complex, you should definitely insert ROS_INFO print statements to determine the source of the crash.
Troubleshooting second step
If the code is very complex, make use of the following steps which can help to pinpoint exactly where the code crashes
1. Enable Core Dumps (current shell)#
ulimit -c unlimitedulimit -c # should print: unlimited2. Configure Core Dump Location#
echo '/tmp/core_%e.%p' | sudo tee /proc/sys/kernel/core_pattern3. Build With Debug Symbols#
catkin tools#
catkin config -DCMAKE_BUILD_TYPE=RelWithDebInfo #or Debugcatkin build4. Run ROS and Reproduce Crash#
5. Open Core Dump in GDB#
gdb <path_to_node_binary> <core_file>Example:
gdb ~/storage/ros_ws/devel/lib/ros_pkg/ros_node\ /tmp/core_hydra_front_end.123456. Inspect Crash in GDB#
Stack trace#
btbt full8. OR VSCode Core Dump Debugging instead of GDB#
.vscode/launch.json
{ "name": "Debug Core Dump", "type": "cppdbg", "request": "launch", "program": "/path/to/devel/lib/pkg/node", "coreDumpPath": "/tmp/core_node.12345", "MIMode": "gdb"}