可以看到上面并没有给出具体的代码&行号,因为需要添加-g编译选项。为此重新编译、运行,此时的coredumnp文件就提供了全面的信息:
~/examples/cpp/core_dump % gdb ./a.out core
GNU gdb (GDB) 7.7
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <HTTP: gpl.html licenses gnu.org>
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-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<HTTP: bugs gdb software www.gnu.org />.
Find the GDB manual and other documentation resources online at:
<HTTP: gdb software www.gnu.org documentation />.
For help, type "help".
Type "apropos word" to search for commands related to "word"…
Reading symbols from ./a.out…done.
[New LWP 9758]
warning: Could not load shared library symbols for linux-gate.so.1.
Do you need "set solib-search-path" or "set sysroot"
Core was generated by `./a.out'.
Program terminated with signal SIGFPE, Arithmetic exception.
#0 0x08048415 in core_dump () at main.c:7
7 printf("(%d, %d)\n", i, 100 / i);
(gdb) where
#0 0x08048415 in core_dump () at main.c:7
#1 0x0804844b in main () at main.c:14
(gdb)
补充:
当然,并不是所有的异常都会生成coredump文件,有些环境缺省设置coredump文件是0字节,为此需要ulimit -c 1024(文件大小)。