core dump

9 篇文章 0 订阅

详细内容见man文档:

man 5 core。http://man7.org/linux/man-pages/man5/core.5.html

man ulimit

把上面的man文档看一遍就差不多了。


我遇到的问题是,没能成功生成coredump文件。

解决办法:使用ulimit 改变core文件大小限制。

$ ulimit -S -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) 24110
max locked memory       (kbytes, -l) 64
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) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 1024
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited


上面显示core file size 为0个block。把它改大点就能生成coredump文件了。

$ ulimit -S -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) 24110
max locked memory       (kbytes, -l) 64
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) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 1024
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited


这样问题就解决了。

注意这样只对当前终端有效。

设置好core 文件大小之后,可以调试一个core dump文件练练手。可以使用gdb 进行调试。

例子:

代码

main.c

int main()
{
	char *p = "helloworld";
	p[0] = 'h';

	return 0;
}

gcc -Wall -g main.c -o main

./main

会产生coredump文件,core.8151

gdb main core.8151  注意用gdb调试要带上原来的可执行文件,后面加上coredump文件。

$ gdb main core.8151 
GNU gdb (GDB) Fedora (7.4.50.20120120-50.fc17)
Copyright (C) 2012 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 "i686-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/huntinux/work/linker_loader/coredump/main...done.
[New LWP 8151]
Core was generated by `./main'.
Program terminated with signal 11, Segmentation fault.
#0  0x080483e0 in main () at main.c:4
4		p[0] = 'h';
Missing separate debuginfos, use: debuginfo-install glibc-2.15-57.fc17.i686
(gdb) l
1	int main()
2	{
3		char *p = "helloworld";
4		p[0] = 'h';
5	
6		return 0;
7	}
(gdb) b 4
Breakpoint 1 at 0x80483dd: file main.c, line 4.
(gdb) r
Starting program: /home/huntinux/work/linker_loader/coredump/main 

Breakpoint 1, main () at main.c:4
4		p[0] = 'h';
(gdb) s

Program received signal SIGSEGV, Segmentation fault.
0x080483e0 in main () at main.c:4
4		p[0] = 'h';





参考: http://prefetch.net/blog/index.php/2012/01/19/using-the-automated-bug-reporting-tool-abrt-to-generate-core-dumps-when-a-linux-process-fails/

             http://man7.org/linux/man-pages/man5/core.5.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值