coredump的生成以及gdb查看

coredump是记录了特点时间某一进程的内存状态,主要是内存的寄存器、堆栈、其他内存信息,本文件简述下coredump生成以及使用gdb查看的方式
一、默认不生成coredump
[root@linux mcheck]# ./main
p=0x14a39010
after free p one time
*** glibc detected *** ./main: double free or corruption (fasttop): 0x0000000014a39010 ***
======= Backtrace: =========
/lib64/libc.so.6[0x380fc7245f]
/lib64/libc.so.6(cfree+0x4b)[0x380fc728bb]
./main[0x4005ad]
/lib64/libc.so.6(__libc_start_main+0xf4)[0x380fc1d994]
./main[0x4004b9]
======= Memory map: ========
00400000-00401000 r-xp 00000000 08:02 210141200                          /home/lijiancheng/test/mcheck/main
00600000-00601000 rw-p 00000000 08:02 210141200                          /home/lijiancheng/test/mcheck/main
14a39000-14a5a000 rw-p 14a39000 00:00 0                                  [heap]
380f400000-380f41c000 r-xp 00000000 08:02 143884625                      /lib64/ld-2.5.so
380f61c000-380f61d000 r--p 0001c000 08:02 143884625                      /lib64/ld-2.5.so
380f61d000-380f61e000 rw-p 0001d000 08:02 143884625                      /lib64/ld-2.5.so
380fc00000-380fd4e000 r-xp 00000000 08:02 143884626                      /lib64/libc-2.5.so
380fd4e000-380ff4e000 ---p 0014e000 08:02 143884626                      /lib64/libc-2.5.so
380ff4e000-380ff52000 r--p 0014e000 08:02 143884626                      /lib64/libc-2.5.so
380ff52000-380ff53000 rw-p 00152000 08:02 143884626                      /lib64/libc-2.5.so
380ff53000-380ff58000 rw-p 380ff53000 00:00 0 
3811c00000-3811c0d000 r-xp 00000000 08:02 143884638                      /lib64/libgcc_s-4.1.2-20080825.so.1
3811c0d000-3811e0d000 ---p 0000d000 08:02 143884638                      /lib64/libgcc_s-4.1.2-20080825.so.1
3811e0d000-3811e0e000 rw-p 0000d000 08:02 143884638                      /lib64/libgcc_s-4.1.2-20080825.so.1
2b702636e000-2b7026371000 rw-p 2b702636e000 00:00 0 
2b702639c000-2b702639d000 rw-p 2b702639c000 00:00 0 
7fff15ef4000-7fff15f09000 rw-p 7ffffffe9000 00:00 0                      [stack]
7fff15ffd000-7fff16000000 r-xp 7fff15ffd000 00:00 0                      [vdso]
ffffffffff600000-ffffffffffe00000 ---p 00000000 00:00 0                  [vsyscall]
Aborted  未生成coredump
[root@linux mcheck]# ls -l
总计 28
-rwxr-xr-x 1 root root 7168 08-09 10:25 main
-rw-r--r-- 1 root root 1009 08-09 17:40 main.c
-rw-r--r-- 1 root root 1856 08-09 17:40 main.o
二、打开coredump生成开关,(一般在开机脚本或者配置中)

[root@linux mcheck]# ulimit -c unlimited


三、生成coredump
[root@linux mcheck]# ./main
p=0x4ce6010
after free p one time
*** glibc detected *** ./main: double free or corruption (fasttop): 0x0000000004ce6010 ***
======= Backtrace: =========
/lib64/libc.so.6[0x380fc7245f]
/lib64/libc.so.6(cfree+0x4b)[0x380fc728bb]
./main[0x4005ad]
/lib64/libc.so.6(__libc_start_main+0xf4)[0x380fc1d994]
./main[0x4004b9]
======= Memory map: ========
00400000-00401000 r-xp 00000000 08:02 210141200                          /home/lijiancheng/test/mcheck/main
00600000-00601000 rw-p 00000000 08:02 210141200                          /home/lijiancheng/test/mcheck/main
04ce6000-04d07000 rw-p 04ce6000 00:00 0                                  [heap]
380f400000-380f41c000 r-xp 00000000 08:02 143884625                      /lib64/ld-2.5.so
380f61c000-380f61d000 r--p 0001c000 08:02 143884625                      /lib64/ld-2.5.so
380f61d000-380f61e000 rw-p 0001d000 08:02 143884625                      /lib64/ld-2.5.so
380fc00000-380fd4e000 r-xp 00000000 08:02 143884626                      /lib64/libc-2.5.so
380fd4e000-380ff4e000 ---p 0014e000 08:02 143884626                      /lib64/libc-2.5.so
380ff4e000-380ff52000 r--p 0014e000 08:02 143884626                      /lib64/libc-2.5.so
380ff52000-380ff53000 rw-p 00152000 08:02 143884626                      /lib64/libc-2.5.so
380ff53000-380ff58000 rw-p 380ff53000 00:00 0 
3811c00000-3811c0d000 r-xp 00000000 08:02 143884638                      /lib64/libgcc_s-4.1.2-20080825.so.1
3811c0d000-3811e0d000 ---p 0000d000 08:02 143884638                      /lib64/libgcc_s-4.1.2-20080825.so.1
3811e0d000-3811e0e000 rw-p 0000d000 08:02 143884638                      /lib64/libgcc_s-4.1.2-20080825.so.1
2b244007f000-2b2440082000 rw-p 2b244007f000 00:00 0 
2b24400ad000-2b24400ae000 rw-p 2b24400ad000 00:00 0 
7ffffd090000-7ffffd0a5000 rw-p 7ffffffe9000 00:00 0                      [stack]
7ffffd1fd000-7ffffd200000 r-xp 7ffffd1fd000 00:00 0                      [vdso]
ffffffffff600000-ffffffffffe00000 ---p 00000000 00:00 0                  [vsyscall]
Aborted (core dumped) 此时显示coredump已经生成了
[root@linux mcheck]# ls -l
total 140
-rw------- 1 root root 315392 Sep  3 09:43 core.25298   生成的coredump文件
-rwxr-xr-x 1 root root   7168 Aug  9 10:25 main
-rw-r--r-- 1 root root   1009 Aug  9 17:40 main.c
-rw-r--r-- 1 root root   1856 Aug  9 17:40 main.o
四、可以用gdb对coredump进行查看
[root@linux mcheck]# gdb ./main ./core.25298 
GNU gdb (GDB) Red Hat Enterprise Linux (7.0.1-37.el5)
Copyright (C) 2009 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-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/lijiancheng/test/mcheck/main...(no debugging symbols found)...done.
[New Thread 25298]
Reading symbols from /lib64/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib64/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Reading symbols from /lib64/libgcc_s.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libgcc_s.so.1


warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffffd1fd000
Core was generated by `./main'.
Program terminated with signal 6, Aborted.
#0  0x000000380fc30265 in raise () from /lib64/libc.so.6
(gdb) bt
#0  0x000000380fc30265 in raise () from /lib64/libc.so.6
#1  0x000000380fc31d10 in abort () from /lib64/libc.so.6
#2  0x000000380fc6a99b in __libc_message () from /lib64/libc.so.6
#3  0x000000380fc7245f in _int_free () from /lib64/libc.so.6
#4  0x000000380fc728bb in free () from /lib64/libc.so.6
#5  0x00000000004005ad in main ()
(gdb) info registers
rax            0x0      0
rbx            0x7ffffd0a1ae0   140737438685920
rcx            0xffffffffffffffff       -1
rdx            0x6      6
rsi            0x62d2   25298
rdi            0x62d2   25298
rbp            0x2b24400ad6e0   0x2b24400ad6e0
rsp            0x7ffffd0a1a38   0x7ffffd0a1a38
r8             0x80     128
r9             0x101010101010101        72340172838076673
r10            0x8      8
r11            0x246    582
r12            0x4      4
r13            0x7ffffd0a1d60   140737438686560
r14            0x7ffffd0a1c00   140737438686208
r15            0x380fd22b28     240783600424
rip            0x380fc30265     0x380fc30265 <raise+53>
eflags         0x246    [ PF ZF IF ]
cs             0x33     51
ss             0x2b     43
ds             0x0      0
es             0x0      0
fs             0x0      0
gs             0x0      0
fctrl          0x37f    895
fstat          0x0      0
ftag           0xffff   65535
fiseg          0x0      0
fioff          0x0      0
foseg          0x0      0
fooff          0x0      0
fop            0x0      0
mxcsr          0x1f80   [ IM DM ZM OM UM PM ]
(gdb) quit

你可能感兴趣的:(gdb,调试,coredump)