1、查看是否打开了coredump
lybxin@Inspiron:~/MyRes/miscellany/test/01_coredump$ulimit -c #这里可以看到ulimit限制coredump的产生
0
lybxin@Inspiron:~/MyRes/miscellany/test/01_coredump$ulimit -c unlimited #取消限制
lybxin@Inspiron:~/MyRes/miscellany/test/01_coredump$ulimit -c
unlimited
2、coredump默认存储在与程序相同的目录里
3、core文件的命名规则
/proc/sys/kernel/core_uses_pid 1 表示使用procid命名,0表示不使用
/proc/sys/kernel/core_pattern 可以设置格式化的 core 文件保存位置或文件名
echo “/opt/corefile/core-%e-%p-%t” > /proc/sys/kernel/core_pattern
将会控制所产生的 core 文件会存放到 /corefile 目录下,产生的文件名为 core- 命令名 -pid- 时间戳
以下是参数列表 :
%p - insert pid into filename 添加 pid
%u - insert current uid into filename 添加当前 uid
%g - insert current gid into filename 添加当前 gid
%s - insert signal that caused the coredump into the filename 添加导致产生 core 的信号
%t - insert UNIX time that the coredump occurred into filename 添加 core 文件生成时的 unix 时间
%h - insert hostname where the coredump happened into filename 添加主机名
%e - insert coredumping executable name into filename 添加命令名
4、core_pattern内核解析函数
format_corename
5、Coredump调试
除了下面方法外,也可以在打开gdb后使用core-file core-xxx命令来吧core-xxx文件加载进去
lybxin@Inspiron:~/MyRes/miscellany/test/04_gdbtest$gdb -core=core
GNU gdb (Ubuntu7.11.1-0ubuntu1~16.04)7.11.1
Copyright(C)2016FreeSoftwareFoundation,Inc.
LicenseGPLv3+: 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".
[New LWP 6093]
Core was generated by `./testgdb.out'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00000000004005f4 in ?? ()
(gdb) bt
#0 0x00000000004005f4 in ?? ()
#1 0x000000000000000a in ?? ()
#2 0x0000000000000140 in ?? ()
#3 0x00007fff5297f7d0 in ?? ()
#4 0x0000000000000145 in ?? ()
#5 0x00007fff5297f6d0 in ?? ()
#6 0x000000000040065e in ?? ()
#7 0x00000000004007ac in ?? ()
#8 0x000000647ce2a7fa in ?? ()
#9 0x0000000000000000 in ?? ()
(gdb) file all.out
warning: core file may not match specified executable file.
Reading symbols from all.out...done.
(gdb) bt
#0 0x00000000004005f4 in test1 (p=320)
at /home/lybxin/MyRes/miscellany/test/04_gdbtest/testgdb.c:18
#1 0x000000000040065e in test2 (offset=100)
at /home/lybxin/MyRes/miscellany/test/04_gdbtest/testgdb.c:30
#2 0x00000000004006c3 in main (argc=1, argv=0x7fff5297f7d8)
at /home/lybxin/MyRes/miscellany/test/04_gdbtest/testgdb.c:46
(gdb)