First, the compiler generates an executable file
If you want to execute an executable file with a debugger, you must add -g option when compiled with gcc.
After adding the -g option, gcc compiler is going to do the following additional actions:
1. Create a symbol table, symbol table contains a list of variable names used in the program.
2. Turn off all the optimization mechanism, so that during program execution in strict accordance with the original C code.
Two, the ulimit -C Unlimited allows core-files
Three, gdb a.out or to enter gdb then file a.out enter debug
Four, r / run starts running program
Five, l / list display multiple lines of source code
1. List displayed from the last position, by default, display 10 rows.
2. List n display lines 10 to the center of the behavior of the n
3. List functionname displaying 10 lines of code to function as a center functionname
4. List - shows the code just before the source code printed
5. The SET listsize n- number of lines displayed
6. The Show listsize number of lines displayed in the current settings are displayed
Six, b / break Set breakpoints will stop when the program runs to the breakpoint
1. BREAK location : setting a breakpoint, the change of position may be a line, a function name or address of the location in the position of other structures.
2. info Breakpoint : View breakpoint information.
3. the Delete Breakpoints breakpoint number : remove the breakpoint.
Seven, display / disp view a tracking variables, each stop will display its value
You can also use disable, enable, delete, info command to view and modify its state, and usage of the same breakpoint
Eight, the s / step executes a statement if the statement is a function call, the process proceeds to execute the function in which the first statement
Nine, n / next executes the next statement if the statement is a function call, will not enter the internal execution functions (ie, not a step by step debugging function inside the statement)
Ten, p / print print internal variable values
Eleven, c / continue and continue the program until the next breakpoint is encountered
Twelve, SET var name = value dynamically changing values of variables in the program run
XIII, monitor variable values change watch
Fourteen, backtrace / bt see the stack usage information
Fifteen, f / frame view information about a stack frame
f n View n th stack information.
Sixteen, k / kill to terminate the program being debugged
Seventeen: q / quit quit gdb environment