0% found this document useful (0 votes)
10 views2 pages

Debugger sheet for gdb

This document provides a list of useful commands for debugging in the PC version of gdb. It includes instructions on enabling debugging, setting breakpoints, displaying variable contents, navigating through the program, and quitting the debugger. Each command is presented with its corresponding syntax for ease of use.

Uploaded by

lachanhday
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Debugger sheet for gdb

This document provides a list of useful commands for debugging in the PC version of gdb. It includes instructions on enabling debugging, setting breakpoints, displaying variable contents, navigating through the program, and quitting the debugger. Each command is presented with its corresponding syntax for ease of use.

Uploaded by

lachanhday
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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

You might also like