1, the method of generating core dump file:
$ ulimit-c//check for 0
If the 0
$ ulimit-c Unlimited
This will generate a core.xxxx file in the current directory after the program crashes
2. Debug Core dump File
After generating the core.xxx file
$ gdb./Application Core.xxxx
You'll be back on the scene to the moment your program crashes.
(GDB) bt//This command will list the stack information when the program crashes, one layer will have the label #0 #1 #2 ...
If you want to see a layer of information, you need to switch the current stack, in general, when the program stops, the topmost stack is the current stack, if you want to look at the bottom layer of the stack of details, the first thing to do is to switch to the stack you want to see
(GDB) F N//n is the label of the stack you want to switch, and you can use the ' P variable ' to view the value of the variable to find out why the exception occurred
Info args
Prints the parameter name of the current function and its value.
Info locals
Prints out all local variables and their values in the current function.
Info catch
Prints exception handling information in the current function.
3, GDB Debugging command
L Lists the context code for the function that is now running to the line of code
B Set Breakpoints
R starts running the program
s single step debugging, enter function
N Single step, do not enter the next layer of functions
n K (a number) this is equivalent to the input K N, which is the K-step.
C continue to run the program (usually run to the breakpoint, followed by a few steps, enter C continue to go down a breakpoint run)
[Enter] Enter the last command by default
Finish performs the current function returned to the call to his function, such as stepping if into a function, but you want to quit the function
U (until) set up the program until you exit the current loop body, and enter u to automatically perform the full part of the loop
Break if var=12//Set a conditional breakpoint, set a breakpoint on 34 lines when Var equals 12 watch I!= 10//Monitor A certain condition, then set a breakpoint, if I is not equal to 10, set the breakpoint
Break func//Set a breakpoint for a function
Break Filename:n//Set a breakpoint on the nth line of a file
Info breakpoints shows all the breakpoint information
Delete N//Remove breakpoint with label n
Delete Deletes all breakpoints
Clear N//clearly all the breakpoints above n
p VAR print variable var value
When you print a string, there is a length limit, you want to print a full long string, and you can use the command set print element 0.
p/x var Displays the value of Var in 16
X 16 System
D 10 System
T binary system
c Display variables by character format
f by floating-point numbers
Print *a@10//If A is an array, this displays the value of the 10 elements of the data
Print var=10//Modify the value of a run-time variable
Whatis var//Display the type of a variable
PType var//More detailed display of the variable var type, will print out the structure definition of Var
4, compile time to add the-G option, you can track the program
5, GDB Debugger when the value of the printing variable will appear <value optimized out> situation, can be compiled in GCC when adding-o0 parameters, meaning is not to compile optimization, debugging time will be smooth, running flow will not jump to jump, When you publish the project, remember not to use the-o0 parameter entry, GCC default compile or add-o2 optimization compile will increase the speed of program running