1. Change core file size
[user@forever ~]$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 8192
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size
(512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 8192
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
[user@forever ~]$ ulimit -c
unlimited
[user@forever ~]$ ulimit -a
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 8192
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size
(512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 8192
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
2. Generate core dump file
Example code:
1 #include
<iostream>
2
3 using
namespace std;
4
5 int
main(void)
6 {
7 char *ptr = (char*)malloc(1000);
8
9 free(ptr);
10 free(ptr);
11
12 return 0;
13 }
[user@forever cpp]$ g++ -g
test2.cpp -o test2
[user@forever cpp]$ ./test2
*** glibc detected *** ./test2: double free or
corruption (top): 0x095af008 ***
======= Backtrace: =========
/lib/libc.so.6[0x83e595]
/lib/libc.so.6(cfree+0x59)[0x83e9d9]
./test2(__gxx_personality_v0+0x198)[0x804862c]
/lib/libc.so.6(__libc_start_main+0xdc)[0x7eae9c]
./test2(__gxx_personality_v0+0x3d)[0x80484d1]
======= Memory map: ========
00732000-00733000 r-xp 00732000 00:00 0 [vdso]
0076f000-0077a000 r-xp 00000000 08:02 255748 /lib/libgcc_s-4.1.2-20080825.so.1
0077a000-0077b000 rwxp 0000a000 08:02 255748 /lib/libgcc_s-4.1.2-20080825.so.1
007b2000-007cc000 r-xp 00000000 08:02 256073 /lib/ld-2.5.so
007cc000-007cd000 r-xp 00019000 08:02 256073 /lib/ld-2.5.so
007cd000-007ce000 rwxp 0001a000 08:02 256073 /lib/ld-2.5.so
007d5000-00914000 r-xp 00000000 08:02 256637 /lib/libc-2.5.so
00914000-00916000 r-xp 0013f000 08:02 256637 /lib/libc-2.5.so
00916000-00917000 rwxp 00141000 08:02 256637 /lib/libc-2.5.so
00917000-0091a000 rwxp 00917000 00:00 0
00922000-00947000 r-xp 00000000 08:02 256638 /lib/libm-2.5.so
00947000-00948000 r-xp 00024000 08:02 256638 /lib/libm-2.5.so
00948000-00949000 rwxp 00025000 08:02 256638 /lib/libm-2.5.so
06f3c000-0701c000 r-xp 00000000 08:02 296348 /usr/lib/libstdc++.so.6.0.8
0701c000-07020000 r-xp 000df000 08:02 296348 /usr/lib/libstdc++.so.6.0.8
07020000-07021000 rwxp 000e3000 08:02 296348 /usr/lib/libstdc++.so.6.0.8
07021000-07027000 rwxp 07021000 00:00 0
08048000-08049000 r-xp 00000000 08:03 1436238 /home/user/cpp/test2
08049000-0804a000 rw-p 00000000 08:03 1436238 /home/user/cpp/test2
095af000-095d0000 rw-p 095af000 00:00 0 [heap]
b7f6e000-b7f70000 rw-p b7f6e000 00:00 0
bfad9000-bfaee000 rw-p bffea000 00:00 0 [stack]
Aborted (core dumped)
3. Debug core dump file
[user@forever cpp]$ gdb
test2 core.6094
GNU gdb Fedora (6.8-37.el5)
Copyright (C) 2008 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
"i386-redhat-linux-gnu"...
warning: Can't read pathname for load map: Input/output
error.
Reading symbols from
/usr/lib/libstdc++.so.6...done.
Loaded symbols for /usr/lib/libstdc++.so.6
Reading symbols from
/lib/libm.so.6...done.
Loaded symbols for /lib/libm.so.6
Reading symbols from
/lib/libgcc_s.so.1...done.
Loaded symbols for /lib/libgcc_s.so.1
Reading symbols from
/lib/libc.so.6...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from
/lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
Core was generated by `./test2'.
Program terminated with signal 6, Aborted.
[New process 6094]
#0 0x00732402
in __kernel_vsyscall ()
(gdb) bt
#0 0x00732402
in __kernel_vsyscall ()
#1 0x007fddf0
in raise () from /lib/libc.so.6
#2 0x007ff701
in abort () from /lib/libc.so.6
#3 0x0083628b
in __libc_message () from /lib/libc.so.6
#4 0x0083e595
in _int_free () from /lib/libc.so.6
#5 0x0083e9d9
in free () from /lib/libc.so.6
#6
0x0804862c in main () at test2.cpp:10
(gdb) q
原文链接: https://www.cnblogs.com/zhtwe/archive/2011/08/29/core_dump.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/31378
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!