关于core文件

/*********************************************************************
 * Author  : Samson
 * Date    : 04/18/2012
 * Test platform:
 *               GNU Linux version 2.6.29.4
 *               gcc version 4.4.0 20090506 (Red Hat 4.4.0-4) (GCC)
 * *******************************************************************/

GNU linux系统中core文件生效的的配置:

http://blog.csdn.net/yygydjkthh/article/details/6370829

core文件何时如何产生:

当处于调试状态的程序出错的时候,就会生成core.PID的core文件。

core文件的查看:

当需要进入core文件中查看出错的堆栈情况的时候,就在命令行中使用:gdb programname core.****

以下代码针对除数为0的一个出错程序testcorewitherro.c进行测试:

#include <stdio.h>
#include <signal.h>
#include <stdlib.h>

void test ()
{
    int *p1 = NULL;
    int m = 12 / 0;
    
    printf ("m is %d \n", m);
    return;    
}

int main()
{
    test ();
    printf ("SIGRTMIN is %d SIGRTMAX is %d\n", SIGRTMIN, SIGRTMAX);
    return 0;    
}


编译:

cc -g testcorewitherro.c

执行:

[root@UFO]# ./a.out

浮点数例外 (core dumped)

查看core文件中的出错堆栈信息(有二种方式):

第一种:

[root@UFO my-ipc-test]# gdb a.out core.17327
GNU gdb (GDB) Fedora (6.8.50.20090302-21.fc11)
Copyright (C) 2009 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 "i586-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...

warning: Can't read pathname for load map: 输入/输出错误.
Reading symbols from /lib/libc.so.6...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
Core was generated by `./a.out'.
Program terminated with signal 8, Arithmetic exception.
#0  0x08048472 in test () at testcorewitherro.c:8
8        int m = 12 / 0;
Missing separate debuginfos, use: debuginfo-install glibc-2.10.1-2.i686
(gdb) bt
#0  0x08048472 in test () at testcorewitherro.c:8
#1  0x0804849c in main () at testcorewitherro.c:16
(gdb)

第二种:[root@UFO my-ipc-test]# gdb --core core.17327
GNU gdb (GDB) Fedora (6.8.50.20090302-21.fc11)
Copyright (C) 2009 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 "i586-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Missing separate debuginfo for the main executable file
Try: yum --enablerepo='*-debuginfo' install /usr/lib/debug/.build-id/15/02a4e0271a108f91535403ff4dcbe7db11ae19
Core was generated by `./a.out'.
Program terminated with signal 8, Arithmetic exception.
#0  0x08048472 in ?? ()
(gdb) bt
#0  0x08048472 in ?? ()
#1  0x009c7ff4 in ?? ()
#2  0x009c61e0 in ?? ()
#3  0xbf92ab98 in ?? ()
#4  0x00870865 in ?? ()
#5  0x00857660 in ?? ()
#6  0x08049768 in ?? ()
#7  0x00000000 in ?? ()
(gdb) file a.out
Reading symbols from /home/samson/stevens network/IPC-test/my-ipc-test/a.out...done.
(gdb) bt
#0  0x08048472 in test () at testcorewitherro.c:8
#1  0x0804849c in main () at testcorewitherro.c:16
(gdb)


  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值