gdb调试ROS节点有两种方法,分别是调试coredump文件,一种是在线调试。
调试coredump文件
首先,要确认允许coredump文件,方法是在shell终端中执行命令
ulimit -c N
其中N为任意大于0的整数,表示允许生成的coredump文件大小的上限,通常N设置为unlimited,即不做大小限制,确保生成任意大小的coredump文件。
其次,运行导致coredump的程序。
最后,执行命令
gdb problem_program coredump_file
进入coredump分析环境,务必记住coredump文件必须和程序是匹配的,即coredump文件必须是运行problem_program崩溃时生成的。想要查看backtrace, 可以在gdb环境中输入where命令。
在线调试
首先,配置gdb调用。在launch文件中,找到该ROS节点的启动选项中添加launch-prefix="xterm -e gdb --args" 如
<launch>
<node pkg="my_pkg" type="my_pkg_node" name="my_pkg_name" launch-prefix="xterm -e gdb --args"/>
</node>
</launch>
然后,通过roslaunch 启动节点。如果不出意外,ROS节点启动失败,并会得到一个错误输出如下,
RLException: Roslaunch got a 'No such file or directory' error while attempting to run:
xterm -e gdb --args /home/.../ros_ws/devel/lib/my_pkg/my_pkg_node __name:=my_pkg_node __log:=/home/ubuntu/.ros/log/1b9a3f72-9eb6-11ec-a17d-bdfa0cb3ef94/my_pkg_node-3.log
Please make sure that all the executables in this command exist and have
executable permission. This is often caused by a bad launch-prefix.
The traceback for the exception was written to the log file
出现这种情况,一般可以通过安装xterm解决,方法为执行如下命令:
sudo apt-get install xterm