问题
This question already has an answer here:
- How do I analyze a program's core dump file with GDB when it has command-line parameters? 9 answers
What are all the things I will need to check while analyzing core dump file? Please tell me from scratch.
回答1:
You just need a binary (with debugging symbols included) that is identical to the one that generated the core. Then you can run gdb path/to/the/binary path/to/the/core
to debug it.
When it starts up, you can use bt
(for backtrace) to get a stack trace from the time of the crash. In the backtrace, each function invocation is given a number. You can use frame number
(replacing number with the corresponding number in the stack trace) to select a particular stack frame. You can then use list
to see code around that function, and info locals
to see the local variables. You can also use print name_of_variable
(replacing "name_of_variable" with a variable name) to see its value.
Typing help
within GDB will give you a prompt that will let you see additional commands.
回答2:
Steps to debug coredump using GDB:
Some generic help:
gdb start GDB, with no debugging les
gdb program begin debugging program
gdb program core debug coredump core produced by program
gdb --help describe command line options
1- First of all find the directory where the corefile is generated.
2- Then use ls -ltr
command in the directory to find the latest generated corefile.
3- To load the corefile use
gdb binary path of corefile
This will load the corefile.
4- Then you can get the information using bt
command.
For detailed backtrace use bt full
.
5- To print the variables use print variable-name
or p variable-name
6- To get any help on GDB, use the help
option or use apropos search-topic
7- Use frame frame-number
to go to the desired frame number.
8- Use up n
and down n
commands to select frame n frames up and select frame n frames down respectively.
9- To stop GDB, use quit
or q
.
来源:https://stackoverflow.com/questions/5115613/core-dump-file-analysis