How to set breakpoints and make it break when debugging core dump with gdb? When I use the command "gdb program core", the process halt at the crash point, how can I make the process break before halting there. If I cannot make it break, which commands I can use in gdb when debugging a core dump?
Asked
Active
Viewed 3,154 times
0
-
1When debugging a core, you are not running the program, hence no breakpoints. If you're asking how to debug GDB, please clarify. – Michael Foukarakis May 14 '15 at 08:40
-
Very similar: [c - gdb evaluate function in process core - Stack Overflow](https://stackoverflow.com/questions/8892597/gdb-evaluate-function-in-process-core) – user202729 Mar 10 '22 at 00:57
2 Answers
2
You can restart your program once loading the core if you want to trace the steps leading to the crash. Use 'start', this will take you to the first line in your program. Then set breakpoints between main() and the crash point. See sample below:
<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
$1 = (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>

narz
- 71
- 3
1
When you examine a core file you can for example list a stack trace or view executed function arguments:
gdb <program> <core>
(gdb) backtrace
(gdb) print <variable or *address>
If you would like to set breakpoints open a program with gdb without a core file so you can run it:
gdb <program>
(gdb) break <line>
(gdb) run

mpasko256
- 811
- 14
- 30