Unix core文件查看方法

Unix core文件查看方法

在Unix系統下,應用程序崩潰,(函數出錯時寫入errno)一般會產生core文件,如何根據core文件查找問題的所在,並做相應的分析和調試,是非常重要的,本文對此做簡單介紹。

例如,一個程序cmm_test_tool在運行的時候發生了錯誤,並生成了一個core文件,如下:

-rw-r–r– 1 root cmm_test_tool.c
-rw-r–r– 1 root cmm_test_tool.o
-rwxr-xr-x 1 root cmm_test_tool
-rw——- 1 root core.19344
-rw——- 1 root core.19351
-rw-r–r– 1 root cmm_test_tool.cfg
-rw-r–r– 1 root cmm_test_tool.res
-rw-r–r– 1 root cmm_test_tool.log
[root@AUTOTEST_SIM2 mam2cm]#

就可以利用命令gdb進行查找,參數一是應用程序的名稱,參數二是core文件,運行
gdb cmm_test_tool core.19344結果如下:

[root@AUTOTEST_SIM2 mam2cm]# gdb cmm_test_tool core.19344
GNU gdb Red Hat Linux (5.2.1-4)
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type “show copying” to see the conditions.
There is absolutely no warranty for GDB. Type “show warranty” for details.
This GDB was configured as “i386-redhat-linux”…
Core was generated by `./cmm_test_tool’.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /lib/i686/libpthread.so.0…done.
Loaded symbols for /lib/i686/libpthread.so.0
Reading symbols from /lib/i686/libm.so.6…done.
Loaded symbols for /lib/i686/libm.so.6
Reading symbols from /usr/lib/libz.so.1…done.
Loaded symbols for /usr/lib/libz.so.1
Reading symbols from /usr/lib/libstdc++.so.5…done.
Loaded symbols for /usr/lib/libstdc++.so.5
Reading symbols from /lib/i686/libc.so.6…done.
Loaded symbols for /lib/i686/libc.so.6
Reading symbols from /lib/libgcc_s.so.1…done.
Loaded symbols for /lib/libgcc_s.so.1
Reading symbols from /lib/ld-linux.so.2…done.
Loaded symbols for /lib/ld-linux.so.2
Reading symbols from /lib/libnss_files.so.2…done.
Loaded symbols for /lib/libnss_files.so.2
#0 0×4202cec1 in __strtoul_internal () from /lib/i686/libc.so.6
(gdb)

進入gdb提示符,輸入where,找到錯誤發生的位置和堆棧,如下:

(gdb) where
#0 0×4202cec1 in __strtoul_internal () from /lib/i686/libc.so.6
#1 0×4202d4e7 in strtoul () from /lib/i686/libc.so.6
#2 0×0804b4da in GetMaxIDFromDB (get_type=2, max_id=0×806fd20) at cmm_test_tool.c:788
#3 0×0804b9d7 in ConstrctVODProgram (vod_program=0×40345bdc) at cmm_test_tool.c:946
#4 0×0804a2f4 in TVRequestThread (arg=0×0) at cmm_test_tool.c:372
#5 0×40021941 in pthread_start_thread () from /lib/i686/libpthread.so.0
(gdb)

至此,可以看出文件出錯的位置是函數 GetMaxIDFromDB ,兩個參數分別是2和0×806fd20,這個函數位於源代碼的788行,基於此,我們就可以有針對性的找到問題的根源,並加以解決。

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