Debug ros node with GDB

April 29, 2021 · View on GitHub

Abstract

Debug the ros node with GDB. Some error (such as segment fault) is difficult to find. The GDB is a good choice to debug it.

Simple steps to use GDB to debug ros node

  • Step 1: compile the ros package
    $ catkin_make -DCMAKE_BUILD_TYPE=Debug
    
  • Step 2: run the ros node you want to debug with specified format ros node
    $ rosrun --prefix 'gdb -ex run --args'  package   node  
    
    or (launch)
    $ <node pkg="package" type="node" name="node_name" output="screen" launch-prefix="gdb -ex run --args" >/>  
    
    or (python)
    launch-prefix="xterm -e python -m pdb "
    

additional commands for GDB debugging

commandsfunctions
btshow location of error, e.g. segment fault
info filesshow the detail information of the debugged file
info varshow all the global and static variables
info localshow all the local variables
MoreLink, book