First, we are going to create each example program in the ROS package in our workspace individually. Alternatively, we could copy the chapter4_tutorials package from GitHub at https://github.com/kbipin/Robot-Operating-System-Cookbook.
We can debug a ROS C/C++ node with the gdb debugger by using the location of the node executable and running the node executable inside gdb with the following command:
$ cd devel/lib/chapter4_tutorials $ gdb program1
roscore must be running before we start our node inside gdb since it will need the master server to be running. We have to use the catkin_make -DCMAKE_BUILD_TYPE=Debug command to build the ROS packages with the debug symbol.