當把程序安裝至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即可