- Startup
gdb -help | print startup help, show switches |
gdb object | normal debug |
gdb object core | core debug (must specify core file) |
gdb object pid | attach to running process |
gdb | use file command to load object |
- Help
(gdb) help | list command classes |
(gdb) help running | list commands in one command class |
(gdb) help run | bottom-level help for a command "run" |
(gdb) help info | list info commands (running program state) |
(gdb) help info line | help for a particular info command |
(gdb) help show | list show commands (gdb state) |
(gdb) help show commands | specific help for a show command |
- Breakpoints
(gdb) break funcname | set a breakpoint on a function |
(gdb) break linenum | set a breakpoint on a line number |
(gdb) break filename:funcname | set breakpoint at file and function |
(gdb) break filename:linenum | set breakpoint at file and line |
(gdb) info breakpoints | show breakpoints |
(gdb) delete breakpointnum | delete a breakpoint by number |
(gdb) delete | delete all breakpoints |
(gdb) clear | delete breakpoints at current line |
(gdb) clear funcname | delete breakpoints at function |
(gdb) clear linenum | delete breakpoints at line |
(gdb) disable breakpointnum | turn a breakpoint off, but don't remove it |
(gdb) enable breakpointnum | turn disabled breakpoint back on |
(gdb) tbreak funcname\linenum | set a temporary breakpoint |
(gdb) commands break-no … end | set gdb commands with breakpoint |
(gdb) ignore break-no count | ignore bpt N-1 times before activation |
(gdb) condition break-no expression | break only if condition is true |
(gdb) condition 2 i == 20 | example: break on breakpoint 2 if i equals 20 |
(gdb) watch expression | set software watchpoint on variable |
(gdb) info watchpoints | show current watchpoints |
- Running the program
(gdb) run | run the program with current arguments |
(gdb) run args redirection | run with args and redirection |
(gdb) set args args… | set arguments for run |
(gdb) show args | show current arguments to run |
(gdb) cont | continue the program |
(gdb) step | single step the program; step into functions |
(gdb) step count | single step count times |
(gdb) next | step but step over functions |
(gdb) next count | next count times |
(gdb) CTRL-C | actually SIGINT, stop execution of current program |
(gdb) attach process-id | attach to running program |
(gdb) detach | detach from running program |
(gdb) finish | finish current function's execution |
(gdb) kill | kill current executing program |
- Stack backtrace
(gdb) bt | print stack backtrace |
(gdb) frame | show current execution position |
(gdb) up | move up stack trace (towards main) |
(gdb) down | move down stack trace (away from main) |
(gdb) info locals | print automatic variables in frame |
(gdb) info args | print function parameters |