GDB
-g
command line argument - compiler keeps copy of source code for use by debuggerlayout src
- turn on TUI modeset style enable off
- turns off syntax highlightingquit
- quit gdbrun
- explicitly runs program, program runs to completion if program does not halt due to errors.
run Hello 123 < file.in
break <function name | line number | [file:line](file:line) number>
- create a breakpointcontinue
- continue execution after pauseinfo breakpoints
- see list of breakpoints setupdelete <id num>
- delete breakpoint with given idenable <id num>
- enables breakpointdisable <id num>
- disables breakpoint with idnext
- executes one statement in current context, src window will show line of code to be executed next
step
- like next, but steps into contextsrefresh
- refresh screenlist
- useful if you are not using TUI mode - shows some number of surrounding statements
set listsize [count]
focus
- brings to focus a specific window, e.g. focus cmd
- brings focus to gdb command windowprint <variable>
- prints some variable
arr@num
to display num number of array elementsdisplay/undisplay/enable display/disable display
- tell GDB to display the value of a particular variable, expressions, address, etc.
undisplay
- stop displaying valueStack Navigation and Going in Reverse
backtrace
- displays one line for the stack frames in current call stack - provide summary info of how you got to this point in the programup/down
- navigate up/down call stackrecord, reverse-next, reverse-step
record
after you execute - basically where to start recording fromreverse-next
, reverse-step
- like next, step, but in reversefinish
- executes all of the function calls and stops once the current stack frame is poppedMore Features, Reference Sheet
set var
- set variable during debugging, e.g. set var name=value
layout
- lists different options availablefocus
- put cmd window in focusdinheight
- change winheight, first argument is window, second argument can be: number of lines for window, +count if we want to increase number of lines for window, -count if we want to decrease number of lines for windowset style
- configure how gdb styles stuffset logging
- can help log results of gdb
set logging file [filename]
- set file to which all output should be loggedset logging enabled on
Command | Abbreviation | Description |
---|---|---|
run | r | Runs the selected program until the next Breakpoint or Watch |
break | b | Sets a breakpoint at a line or function (Current line by default) |
watch | wa | Sets a watchpoint |
next | n | Steps through next line of code (Does not enter function call) |
step | s | Steps into next line of code (Enters function call if any) |
continue | c | Run from current point to next Breakpoint or Watch |
info breakpoints | i b | List out all breakpoints and watchpoints |
delete | d | Delete breakpoint or watchpoint with given id |
p | Prints out the value of the given variable | |
whatis | what | Prints out the type of the given variable |
display | disp | Print out the value of a variable at each step |
undisplay | undisp | Undo a "display" command |
up | up | Move up the call stack |
down | do | Move down the call stack |
backtrace | bt | Print a trace of the current call stack |
finish | fin | Run to the end of the current function call |
record | record | Begin recording additional information to enable reverse debugging (must be called after run) |
reverse-next | rn | Steps backward through code (Does not enter function call) |
reverse-step | rs | Steps backward through code (Enters function call if any) |
set var | set var | Modify the value stored in a variable during execution |
oh yeah you can set up breakpoints in vscode as well lmao