ROS交流群
ROS Group 产品服务
Product Service 开源代码库
Github 官网
Official website 技术交流
Technological exchanges 激光雷达
LIDAR ROS教程
ROS Tourials 深度学习
Deep Learning 机器视觉
Computer Vision
ROS Group 产品服务
Product Service 开源代码库
Github 官网
Official website 技术交流
Technological exchanges 激光雷达
LIDAR ROS教程
ROS Tourials 深度学习
Deep Learning 机器视觉
Computer Vision
如何调试崩溃的程序
-
在程序开发中经常会遇到这样的问题,对于C或C++的程序有时程序崩溃不能获得有效的调试信息
Segmentation fault
Core dump
这样的程序如何进行调试呢?
我们可以利用gdb去调试崩溃程序。首先开启core dump文件。在开启之后,当程序崩溃的时候操作系统会自动的把崩溃信息存储到core文件里面。
在终端输入ulimit -c unlimited
这样就打开core dump 功能了。
下面是一个崩溃的实际例子
randoms@nowhere:~/ramdisk$ /home/randoms/Documents/ros/workspace/devel/lib/orb_slam2/mono /home/randoms/Documents/ros/workspace/src/ORB_SLAM2/Examples/ROS/orb_slam2/Data/ORBvoc.bin /home/randoms/Documents/ros/workspace/src/ORB_SLAM2/Examples/ROS/orb_slam2/Data/setting4.yaml /camera/image_raw:=/camera_node/image_raw /Pose2D:=/xqserial_server/Pose2D > orb.log mono: ../nptl/pthread_mutex_lock.c:350: __pthread_mutex_lock_full: Assertion `(-(e)) != 3 || !robust' failed. Aborted (core dumped) randoms@nowhere:~/ramdisk$ ls 2.bag core KeyFrameTrajectory.txt orb.log
可以看到在程序崩溃后创建了一个core文件,在终端输入下面的指令开始调试
randoms@nowhere:~/ramdisk$ gdb /home/randoms/Documents/ros/workspace/devel/lib/orb_slam2/mono core
gdb
的指令格式是gdb EXE_FILE_PATH CORE_FILE_PATH
等待载入完成
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1 Copyright (C) 2014 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from /home/randoms/Documents/ros/workspace/devel/lib/orb_slam2/mono...(no debugging symbols found)...done. [New LWP 14392] [New LWP 14370] [New LWP 14365] [New LWP 14367] [New LWP 14371] [New LWP 14388] [New LWP 14376] [New LWP 14391] [New LWP 14407] [New LWP 14406] [New LWP 14408] [New LWP 14377] [New LWP 14411] [New LWP 14410] [New LWP 14369] [New LWP 14387] [New LWP 14409] [New LWP 14412] [New LWP 14390] [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Core was generated by `/home/randoms/Documents/ros/workspace/devel/lib/orb_slam2/mono /home/randoms/Do'. Program terminated with signal SIGABRT, Aborted. #0 0x00007fe6ca6ecc37 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56 56 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
gdb在终端中输入
bt
可以显示出崩溃时的堆栈信息
#0 0x00007fe6ca6ecc37 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56 #1 0x00007fe6ca6f0028 in __GI_abort () at abort.c:89 #2 0x00007fe6ca6e5bf6 in __assert_fail_base ( fmt=0x7fe6ca8363b8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x7fe6c9bb6a25 "(-(e)) != 3 || !robust", file=file@entry=0x7fe6c9bb6a08 "../nptl/pthread_mutex_lock.c", line=line@entry=350, function=function@entry=0x7fe6c9bb6b20 <__PRETTY_FUNCTION__.8695> "__pthread_mutex_lock_full") at assert.c:92 #3 0x00007fe6ca6e5ca2 in __GI___assert_fail ( assertion=assertion@entry=0x7fe6c9bb6a25 "(-(e)) != 3 || !robust", file=file@entry=0x7fe6c9bb6a08 "../nptl/pthread_mutex_lock.c", line=line@entry=350, function=function@entry=0x7fe6c9bb6b20 <__PRETTY_FUNCTION__.8695> "__pthread_mutex_lock_full") at assert.c:101 #4 0x00007fe6c9ba9ce1 in __pthread_mutex_lock_full (mutex=0x9643740) at ../nptl/pthread_mutex_lock.c:350 #5 0x00007fe6cb03403a in __gthread_mutex_lock (__mutex=0x9643740) at /usr/include/x86_64-linux-gnu/c++/4.8/bits/gthr-default.h:748 #6 lock (this=0x9643740) at /usr/include/c++/4.8/mutex:134 #7 lock (this=0x7fe694ed5a10) at /usr/include/c++/4.8/mutex:511 #8 unique_lock (__m=..., this=0x7fe694ed5a10) ---Type <return> to continue, or q <return> to quit--- at /usr/include/c++/4.8/mutex:443 #9 ORB_SLAM2::MapPoint::isBad (this=0x96434c0) at /home/randoms/Documents/ros/workspace/src/ORB_SLAM2/src/MapPoint.cc:272 #10 0x00007fe6cb03c957 in ORB_SLAM2::KeyFrame::RemoveBadPoints (this=0xa33f510) at /home/randoms/Documents/ros/workspace/src/ORB_SLAM2/src/KeyFrame.cc:1155 #11 0x00007fe6caff8b5a in ORB_SLAM2::Tracking::GC (this=0x711d310) at /home/randoms/Documents/ros/workspace/src/ORB_SLAM2/src/Tracking.cc:311 #12 0x00007fe6cb0baef2 in ORB_SLAM2::GC::Run (this=0x7157fe0) at /home/randoms/Documents/ros/workspace/src/ORB_SLAM2/src/GC.cc:37 #13 0x00007fe6cad42a60 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6 #14 0x00007fe6c9bac184 in start_thread (arg=0x7fe694ed6700) at pthread_create.c:312 #15 0x00007fe6ca7b037d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111
这样我们就可以定位到具体在哪一个语句崩溃的。可以看出这次的崩溃是一个锁的问题。在
MapPoint.cc
文件里面。