使用gdb调试core dump时如何设置断点使其中断?

How to set breakpoints and make it break when debugging core dump with gdb?

gdb调试core dump时如何设置断点使其中断? 当我使用命令 "gdb program core" 时,进程在崩溃点停止, 我怎样才能在停止之前让这个过程中断。 如果我不能让它中断,调试核心转储时我可以在 gdb 中使用哪些命令?

当您检查核心文件时,您可以列出堆栈跟踪或查看执行的函数参数:

gdb <program> <core>
(gdb) backtrace
(gdb) print <variable or *address>

如果您想设置断点,请使用 gdb 打开一个没有核心文件的程序,这样您就可以 运行 它:

gdb <program>
(gdb) break <line>
(gdb) run

如果您想跟踪导致崩溃的步骤,您可以在加载核心后重新启动程序。使用 'start',这会将您带到程序的第一行。然后在 main() 和崩溃点之间设置断点。 请参阅下面的示例:

<pre> 
[narz@dev101 src]$ gdb -n -quiet myprogram core.12046
Reading symbols from </my/path/>...done.
[New Thread 12046]
Reading symbols from /usr/lib64/libstdc++.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib64/libstdc++.so.6
Reading symbols from /lib64/libm.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib64/libm.so.6
Reading symbols from /lib64/libgcc_s.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libgcc_s.so.1
Reading symbols from /lib64/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib64/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Core was generated by `./myprogram'.
Program terminated with signal 11, Segmentation fault.
#0  0x0000000000400658 in main () at stack.cpp:6
6               int b=*x;
(gdb) p x
 = (int *) 0x0
(gdb) l
1       #include <iostream>
2
3       int main(void)
4       {
5               int* x=NULL;
6               int b=*x;
7               return 0;
8       }
(gdb) start
No core file now.
Temporary breakpoint 1 at 0x40064c: file stack.cpp, line 5.
Starting program: /u03/narz/projects/xxxxx/xxxxx/src/myprogram

Temporary breakpoint 1, main () at stack.cpp:5
5               int* x=NULL;
(gdb)

</pre>