gdb command: Before using gdb, the compiler need to add parameters -g g ++ (generate debug symbol table)
1, gdb filename // debugging an executable file
-> quit (q) quit debugging
2, pause mechanism (① break, ② monitoring point, ③ capture points), said here only breakpoint.
break function names (b)
break line number
break Path: line number (demo_11_15 / swap.cpp: 5)
Path break: function name (demo_11_15 / swap.cpp: swap)
info breakpoints (ib) // View all breakpoints
Note: In the gdb without stopping, the new code is compiled, can be perceived gdb code changes when run (r)
delete breakpoint number or function name (see the first breakpoint before you can use ib) // delete one or more breakpoints
clear // clear breakpoints at the next instruction to be executed gdb, can be used when the delete usage similar.
// disable the breakpoint disable breakpoint
enable the breakpoint // Enable breakpoint
Note: The following diagram type is type (① break, ② monitoring point, ③ capture point), disp for the status of a breakpoint (keep, del, dis), Enb as is enabled.
3, the implementation of the program
run (r) // execute the program. Or re-run
step (s) // single step (entering function).
next (n) // single step (not enter function).
continue (c) // continue until the next breakpoint or end.
In the latter continue n // n breakpoints do not stop, stopping to n + 1 at the breakpoint (the loop is executed n cycles Italy).
finsh (fin) // End execution of the current function
until (u) // After completing the current cycle. Until the next is a special case of FIG. You can also back until now line number, function name
4, conditional breakpoints
break main if i> 5 // perform a loop i> 5 when stopped.
break main if i == 10
cond 1 i == 3 // normal set conditional breakpoints, breakpoint 1, with the proviso i == 3
cond 1 // resume normal breakpoint breakpoint 1
. . . . Complex supplemented later on.
5, watchpoints
Watch each time i // i will break live changes.
watch expressions
6, variable
print variable (p) // print out the value of the variable.
p / xi // print hex value i also similar p / ci and p / si // print ascii characters and string
info locals // print all the local variables of the current stack frame
set $ i = 0 pw [$ i ++] // When w program array allows the array index i as. i is a convenient variable (convenience variable) gdb provided
p * $ i // print the value of $ i,