Useful Debugger Commands (PC version)
• To enable debugging on your program, compile with the -g option!
g++ -g file.cpp
• To run the debugger:
gdb a.exe
gdb a
• Setting a Breakpoint:
o Set a breakpoint at line 12:
break 12
b 12
o Set a breakpoint at line 12 of file.cpp. Only relevant once your program spans multiple
files:
break file.cpp:12
b file.cpp:12
o Set a breakpoint at the start of function f.
break f
b f
o Set a breakpoint at the start of main:
break main
b main
• Displaying variables
o Show the contents of a variable “x” whenever the program stops:
display x
d x
o Show the contents of the element at position “i” of string (or vector, or array) “s”
whenever the program stops:
display s[i]
d s[i]
o Show the contents of variable “x” right now (and not when the program stops again)
print x
• Moving Through The Program:
o Start the program at the beginning, stopping when we hit a breakpoint (or the end of the
program):
run
r
o Continue the program from its current position to the next breakpoint, or the end of the
program
continue
c
o Go to the next line of the current function (skipping over any function calls on the current
line)
next
n
o Go to the next line that will be executed (entering a function call if there is one on the
current line):
step
s
• Quitting the debugger:
quit
q