$ gdb -c core.25819.1000.8.a.out.1706446582
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
Copyright (C) 2022 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 "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
[New LWP 25819]
Core was generated by `./a.out'.
Program terminated with signal SIGFPE, Arithmetic exception.
#0 0x000055f620b4c13b in ?? ()
(gdb) l
No symbol table is loaded. Use the "file" command.
加载core对应的编译后的程序文件,里面含有代码的调试信息, 此处为 a.out 程序
(gdb)file a.out
Reading symbols from a.out...
(gdb) l
3c=a/b;4return0;5}67 int calc(){
8 int a;9 int b;10a=13;11b=0;12 actual_calc(a, b);(gdb) bt
#0 0x000055f620b4c13b in actual_calc (a=13, b=0) at test.c:3#1 0x000055f620b4c171 in calc () at test.c:12#2 0x000055f620b4c18a in main () at test.c:17(gdb) p b
$1=0(gdb) p a/b
Division by zero
(gdb) f 1#1 0x000055f620b4c171 in calc () at test.c:1212 actual_calc(a, b);(gdb) l
7 int calc(){
8 int a;9 int b;10a=13;11b=0;12 actual_calc(a, b);13return0;14}1516 int main(){
(gdb) f 2#2 0x000055f620b4c18a in main () at test.c:1717 calc();(gdb) l
12 actual_calc(a, b);13return0;14}1516 int main(){
17 calc();18return0;19}20(gdb) q
注意上面加载core后, 默认堆栈在最顶端, 类似于执行了f 0的效果, 对应的就是当前出错位置, 直接执行 p a/b 得到 Division by zero, 也就是错误原因;