/*********************************************************************
* 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)