- info locals
- trace
- generate-core-file
- gdb /path/to/core/file
- /proc/sys/kernel/core_ https://www.kernel.org/doc/Documentation/sysctl/kernel.txt
http://pfigue.github.io/blog/2012/12/28/where-is-my-core-dump-archlinux/
Where is my core dump?
Motivation
I was debugging a process. Such process was crashing and dumping the core. I wanted to load that core into gdb to debug the program, but I was unable to find the core in my filesystem (Arch Linux installation).
Kernel Configuration
In /proc/sys/kernel/ we can find, among others, core_pattern, core_pipe_limit andcore_uses_pid:
- core_pattern indicates the filename for the core dump. It has several formatters, like %E and %p to include the directory of the executable or its PID. If it begins with a | (pipe). that means that the dump should be piped to the command provided right after it, for example a command to automatically report crashes to Ubuntu, Mozilla, etc.
- core_pipe_limit When piping the dump to a program, the kernel should keep the information in /proc/<pid>/ for a while, till the program captures the information and exits. If somehow the process doesn’t exit, the next core-dumps will be blocked. This attribute controls how many core-dumps can be piped in parallel.
- core_uses_pid If dumping a file instead piping the dump to a program, this flag, when it is 1, will make sure that the file name will contain the PID of the process that crashed. Either because %p is present in core_pattern or appending “.” to the core filename.
So, probably you want to be sure that /proc/sys/kernel/core_pattern is dumping a file instead of piping to a program. Also, you probably want to know where the file is going to land (i.e. directory):
# echo "core" > /proc/sys/kernel/core_pattern
# echo "1" > /proc/sys/kernel/core_uses_pid
以上是临时性的配置,要持久化的话写入/etc/sysctl.conf
kernel.core_uses_pid = 1
#sysctl -p 使生效
Shell Configuration
Not only the kernel config., but also the ulimit of the shell can interfere if it restricts the ability to write a coredump.
$ ulimit -c
will show the current limit.
0 means no core dumps.
unlimited means that core dumps of all sizes can be written:
$ ulimit -c unlimited
That will change the limit for the current shell. The changed limits are inherited by subshells, so you can use sudo and the sudoed command will use the new limits.
Note that ulimit is a shell builtin, not a command.
References
http://www.akadia.com/services/ora_enable_core.html
http://blog.sina.com.cn/s/blog_8fa7dd410100xzhj.html
//---------------------------------------------------------------
1. core文件的简单介绍
//---------------------------------------------------------------
在一个程序崩溃时,它一般会在指定目录下生成一个core文件。core文件仅仅是一个内存映象(同时加上调试信息),主要是用来调试的。
//---------------------------------------------------------------
2. 开启或关闭core文件的生成
//---------------------------------------------------------------
用以下命令来阻止系统生成core文件:
ulimit -c 0
下面的命令可以检查生成core文件的选项是否打开:
ulimit -a
该命令将显示所有的用户定制,其中选项-a代表“all”。
也可以修改系统文件来调整core选项
在/etc/profile通常会有这样一句话来禁止产生core文件,通常这种设置是合理的:
# No core files by default
ulimit -S -c 0 > /dev/null 2>&1
但是在开发过程中有时为了调试问题,还是需要在特定的用户环境下打开core文件产生的设置
在用户的~/.bash_profile里加上ulimit -c unlimited来让特定的用户可以产生core文件
如果ulimit -c 0 则也是禁止产生core文件,而ulimit -c 1024则限制产生的core文件的大小不能超过1024kb
//---------------------------------------------------------------
3. 设置Core Dump的核心转储文件目录和命名规则
//---------------------------------------------------------------
/proc/sys/kernel/core_uses_pid可以控制产生的core文件的文件名中是否添加pid作为扩展,如果添加则文件内容为1,否则为0
/proc/sys/kernel/core_pattern可以设置格式化的core文件保存位置或文件名,比如原来文件内容是core-%e
可以这样修改:
echo "/corefile/core-%e-%p-%t" > 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文件
//---------------------------------------------------------------
在core文件所在目录下键入:
gdb -c core
它会启动GNU的调试器,来调试core文件,并且会显示生成此core文件的程序名,中止此程序的信号等等
如果你已经知道是由什么程序生成此core文件的,比如MyServer崩溃了生成core.12345,那么用此指令调试:
gdb -c core MyServer
以下怎么办就该去学习gdb的使用了
//---------------------------------------------------------------
5. 一个小方法来测试产生core文件
//---------------------------------------------------------------
直接输入指令:
kill -s SIGSEGV $$