coredump

 

 

root@ubuntu:~# ulimit -c unlimited
root@ubuntu:~# echo 1 > /proc/sys/kernel/core_uses_pid
root@ubuntu:~# mkdir /corefile
root@ubuntu:~# echo /corefile/core.%e.%p> /proc/sys/kernel/core_pattern
root@ubuntu:~# 

 

Segmentation fault
[root@centos7 user1]# ulimit -c unlimited
[root@centos7 user1]# echo 1 > /proc/sys/kernel/core_uses_pid
[root@centos7 user1]# mkdir /corefile
mkdir: cannot create directory ‘/corefile’: File exists
[root@centos7 user1]# echo /corefile/core.%e.%p> /proc/sys/kernel/core_pattern
[root@centos7 user1]# ls /corefile/
[root@centos7 user1]# gcc -g  -o test_main  test_main.c  dlmalloc.c 
test_main.c: In function ‘main’:
test_main.c:10:10: warning: assignment makes pointer from integer without a cast [enabled by default]
         p=create_mspace_with_base((void *)base,MALLOC_SIZE,0);
          ^
dlmalloc.c:2:9: warning: unknown option after ‘#pragma GCC diagnostic’ kind [-Wpragmas]
 #pragma GCC diagnostic ignored "-Wexpansion-to-defined"
         ^
[root@centos7 user1]# ./test_main 
base addr 0x316e0010 
dlmalloc addr (nil) 
Segmentation fault (core dumped)
[root@centos7 user1]# ls /corefile/
core.test_main.15488

 

gdb [exec_file] [core_file]

#or
gdb -c [core_file] [exec_file]   #-c指定转储的core文件

 

[root@centos7 user1]# gdb -c /corefile/core.test_main.15488  test_main
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-120.el7
Copyright (C) 2013 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 "aarch64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /root/programming/kernel/study/dlmalloc/user1/test_main...done.
[New LWP 15488]
Core was generated by `./test_main'.
Program terminated with signal 11, Segmentation fault.
#0  0x000000000040730c in destroy_mspace (msp=0x0) at dlmalloc.c:5309
5309          char* base = sp->base;
Missing separate debuginfos, use: debuginfo-install glibc-2.17-325.el7_9.aarch64
(gdb) bt
#0  0x000000000040730c in destroy_mspace (msp=0x0) at dlmalloc.c:5309
#1  0x0000000000400834 in main () at test_main.c:12
(gdb) q

 

上面的设置只是使能了core dump功能,缺省情况下,内核在coredump时所产生的core文件放在与该程序相同的目录中,并且文件名固定为core。很显然,如果有多个程序产生core文件,或者同一个程序多次崩溃,就会重复覆盖同一个core文件。

过修改kernel的参数,可以指定内核所生成的coredump文件的文件名。使用下面命令,可以实现coredump永久配置、存放路径以及生成coredump名称等。

mkdir -p /www/coredump/
chmod 777 /www/coredump/

/etc/profile
ulimit -c unlimited

/etc/security/limits.conf
*          soft     core   unlimited

echo "/www/coredump/core-%e-%p-%h-%t" > /proc/sys/kernel/core_pattern

 

 

 

 

 

 

posted on 2021-05-20 11:17  tycoon3  阅读(97)  评论(0编辑  收藏  举报

导航