Create a core file condition
Use Ulimit-c to specify the core file size to enable the creation of the core file, such as: Ulimit-c Unlimited
Analyze the condition of the core file with GDB
The executable program compiles with the-G parameter, otherwise gdb cannot find the symbol information and cannot locate the problem.
For example, in the following two CPP files, Test.cpp will cause crash.
Test.cppvoid Testcrash () { int *p = 0; *p = 3; }
Main.cpp#include <stdio.h>void Testcrash (); int main () { testcrash (); Return0;}
The problem in the core file cannot be located at compile time, as follows-G is required.
g++-C- G test.cpp
g++-C main.cpp
g++ TEST.O Main.o-o Main
Files required to analyze core files
- Core files generated when the program runs crashing
- Executable file that produces the core file
Analyzing core files with GDB
Start GDB:
- GDB [executable file] [core file]
When you enter the GDB command line, you will be able to print out the relevant information that causes crash, or you can perform the following command to view it in detail.
GDB command line:
- BT: Stack information when the print program crashes, including the corresponding frame number that caused the crash, file name and line count
- frame [frame number]: Print out the line code
- Info locals: print local variable information
- print [local variable]: printing a local variable
- List: Print related code
- Quit: Exit GDB command line
Unix analyzes core dump files with GDB