GCC如何产生core dump

先决条件

1.安装apport(automatically generate crash reports for debugging)

2.修改/etc/security/limits.conf文件,使允许core dump,或者用ulimit -c unlimited设置core dump文件的大小为unlimited

3.C/C++的编译开关-g(产生调试符号)

######运行编译好的程序testc(我的程序)

kimi@kimi-desktop:~/testc/bin/Debug$ ./testc

######下面一行显示了core dumped表示成功,core文件在/var/crash或者在当前目录

段错误 (core dumped)

kimi@kimi-desktop:~/testc/bin/Debug$ ls

######果然在当前目录

core testc

######gdb一下

kimi@kimi-desktop:~/testc/bin/Debug$ gdb testc core

GNU gdb 6.8-debian

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 "i486-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/tls/i686/cmov/libm.so.6...done.

Loaded symbols for /lib/tls/i686/cmov/libm.so.6

Reading symbols from /lib/libgcc_s.so.1...done.

Loaded symbols for /lib/libgcc_s.so.1

Reading symbols from /lib/tls/i686/cmov/libc.so.6...done.

Loaded symbols for /lib/tls/i686/cmov/libc.so.6

Reading symbols from /lib/ld-linux.so.2...done.

Loaded symbols for /lib/ld-linux.so.2

Core was generated by `./testc'.

######程序是由于段错误退出的

Program terminated with signal 11, Segmentation fault.

[New process 13072]

######段错误的地方在dummy_function - main.c的第5行

#0 0x080483a4 in dummy_function () at /home/kimi/testc/main.c:5

5 *ptr = 0x00;

######打印一下调用堆栈

(gdb) bt

#0 0x080483a4 in dummy_function () at /home/kimi/testc/main.c:5

#1 0x080483bc in main () at /home/kimi/testc/main.c:12

(gdb)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值