UP | HOME

Debugging in ROS and C++

Debugging

  • Using gdb can greatly help you track down issues in your program
    • Among other features, it enables you to step through the code, examine variables, and break on certain lines
  • use ros2 run --prefix "gdb --args" package node to launch the node in gdb
  • Commands that may be useful are
    • tui enable to view a graphical interface with easier commands
    • run start running the program. Abbreviated with r
    • continue continue running a paused program. Abbreviated with c
    • break file:line or break function to put a breakpoint at a line or a function. Abbreviated with b
    • next go to the next line, skipping over functions. Abbreviated with n
    • step go to the next line, jumping into functions. Abbreviated with s
    • print display the value of a variable or memory address
  • To use gdb most effectively, the code must be compiled with Debugging symbols enabled
    • Use the Debug build type in CMake. See CMake Notes for how to set debugging mode
  • This tutorial helps you launch nodes the debugger

Author: Matthew Elwin