[原创] Ubuntu开机启动程序崩溃解析

当把程序安装至Ubuntu的开机启动项后,发现程序崩溃无法启动且非必现,可通过如下操作进行解析.

流程

1.Ubuntu开机启动后,/var/log/apport.log将保留程序崩溃日志,如:

ERROR: apport (pid 3702) Mon May 18 10:43:13 2020: apport: report /var/crash/_opt_ros_kinetic_lib_test.0.crash already exists and unseen, doing nothing to avoid disk usage DoS

2.如有崩溃内容,将会把崩溃日志写入/var/crash/中,且名称为崩溃内容如:

/var/crash/_opt_ros_kinetic_lib_test.0.crash

解析

系统调试有两种方法,第一种为设置core大小,随后运行程序,产出崩溃内核,使用gdb 程序 core形式进行分析

第二种为解压系统产出的.crash,使用解压出来的CoreDump文件进行gdb调试,目标现场较多

步骤

1.将.crash解压缩至其他目录

2.使用gdb对解压缩出来的CoreDump进行分析

解压缩

首先创建问题目录,如~/coreFile

mkdir ~/coreDir

将.crash解压至coreDIr

apport-unpack /var/crash/_ros_kinetic_lib_test.0.crash ~/coreDir

完成后,将会在~/coreDir中产生:

-rw-r--r-- 1 root whoopsie         5 5月  18 13:44 Architecture
-rw-r--r-- 1 root whoopsie 227246080 5月  18 13:44 CoreDump
-rw-r--r-- 1 root whoopsie        24 5月  18 13:44 Date
-rw-r--r-- 1 root whoopsie        12 5月  18 13:44 DistroRelease
-rw-r--r-- 1 root whoopsie        77 5月  18 13:44 ExecutablePath
-rw-r--r-- 1 root whoopsie        10 5月  18 13:44 ExecutableTimestamp
-rw-r--r-- 1 root whoopsie         5 5月  18 13:44 ProblemType
-rw-r--r-- 1 root whoopsie       346 5月  18 13:44 ProcCmdline
-rw-r--r-- 1 root whoopsie        10 5月  18 13:44 ProcCwd
-rw-r--r-- 1 root whoopsie       317 5月  18 13:44 ProcEnviron
-rw-r--r-- 1 root whoopsie     30607 5月  18 13:44 ProcMaps
-rw-r--r-- 1 root whoopsie      1308 5月  18 13:44 ProcStatus
-rw-r--r-- 1 root whoopsie         2 5月  18 13:44 Signal
-rw-r--r-- 1 root whoopsie        30 5月  18 13:44 Uname

其中CoreDump为core日志.

分析

解压来可使用gdb进行调试,如

gdb /opt/ros/kinetic/lib/test/test ~/coreDir/CoreDump

其中/opr/ros/kinetic/lib/test/test为可执行程序, ~/coreDIr/CoreDump为解压.crash后产生的文件,进入gdb后运行bt,可查看崩溃地址

gdb /opt/ros/kinetic/lib/test/test ~/coreDir/CoreDump 
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 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 /opt/ros/kinetic/lib/test/test...(no debugging symbols found)...done.

warning: core file may not match specified executable file.
[New LWP 10383]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
bCore was generated by `/opt/ros/kinetic/lib/test/test f'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  _IO_new_proc_open (fp=fp@entry=0x7f45740008f0, command=command@entry=0x7f4574000b10 "cat /proc/meminfo", mode=<optimized out>, mode@entry=0x7f45bc9895b1 "r") at iopopen.c:213
213	iopopen.c: No such file or directory.
(gdb) bt
#0  _IO_new_proc_open (fp=fp@entry=0x7f45740008f0, command=command@entry=0x7f4574000b10 "cat /proc/meminfo", mode=<optimized out>, mode@entry=0x7f45bc9895b1 "r") at iopopen.c:213
#1  0x00007f45bd14d65c in _IO_new_popen (command=0x7f4574000b10 "cat /proc/meminfo", mode=0x7f45bc9895b1 "r") at iopopen.c:296
#2  0x00007f45bc971607 in geekplus::rsm::exec(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /opt/ros/kinetic/lib/libgeekplusbot_rsm_common.so
#3  0x00007f45bf4293a9 in * () from /opt/ros/kinetic/lib/libtest.so
#4  0x000000000042836f in boost::detail::thread_data<boost::function0<void> >::run() ()
#5  0x00007f45be11a5d5 in ?? () from /usr/lib/x86_64-linux-gnu/libboost_thread.so.1.58.0
#6  0x00007f45bdceb6ba in start_thread (arg=0x7f457bfff700) at pthread_create.c:333
#7  0x00007f45bd1e541d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109
(gdb) q

由日志分析克制,在'cat /proc/meminfo'中发生崩溃.修复Bug即可

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章