Help

OptionDescription
helpList gdb command topics.
help topic-classesList gdb command within class.
help commandCommand description.
eg help show to list the show commands
apropos search-wordSearch for commands and command topics containing search-word.
info args
i args
List program command line arguments
info breakpointsList breakpoints
info breakList breakpoint numbers.
info break breakpoint-numberList info about specific breakpoint.
info watchpointsList breakpoints
info registersList registers in use
info threadsList threads in use
info setList set-able option

Break and Watch

OptionDescription
break funtion-name
break line-number
break ClassName::functionName
Suspend program at specified function of line number.
break +offset
break -offset
Set a breakpoint specified number of lines forward or back from the position at which execution stopped.
break filename:functionDon’t specify path, just the file name and function name.
break filename:line-numberDon’t specify path, just the file name and line number.
break Directory/Path/filename.cpp:62
break *addressSuspend processing at an instruction address. Used when you do not have source.
break line-number⠀if conditionWhere condition is an expression. i.e. x > 5
Suspend when boolean expression is true.
break line⠀thread thread-numberBreak in thread at specified line number. Use info threads to display thread numbers.
tbreakTemporary break. Break once only. Break is then removed. See “break” above for options.
watch conditionSuspend processing when condition is met. i.e. x > 5
clear
clear function
clear line-number
Delete breakpoints as identified by command option.
Delete all breakpoints in function
Delete breakpoints at a given line
delete
d
Delete all breakpoints, watchpoints, or catchpoints.
delete breakpoint-number
delete range
Delete the breakpoints, watchpoints, or catchpoints of the breakpoint ranges specified as arguments.
disable breakpoint-number-or-range
enable breakpoint-number-or-range
Does not delete breakpoints. Just enables/disables them.
Show breakpoints: info break
i.e. disable 2-9
enable breakpoint-number onceEnables once
continue
c
Continue executing until next break point/watchpoint.
continue numberContinue but ignore current breakpoint number times.
Useful for breakpoints within a loop.
finishContinue to end of function.

Line Execution

OptionDescription
step
s
step number-of-steps-to-perform
Step to next line of code. Will step into a function.
next
n
next number
Execute next line of code. Will not enter functions.
until
until line-number
Continue processing until you reach a specified line number.
Also: function name, address, filename:function or filename:line-number.
info signals
info handle
handle SIGNAL-NAME option
Perform the following option when signal received: nostop, stop, print, noprint, pass/noignore or nopass/ignore
whereShows current line number and which function you are in.

Stack

OptionDescription
backtrace
bt
bt inner-function-nesting-depth
bt -outer-function-nesting-depth
Show trace of where you are currently. Which functions you are in. Prints stack backtrace.
backtrace fullPrint values of local variables.
frame
frame number
f number
Show current stack frame (function where you are stopped)
Select frame number. (can also user up/down to navigate frames)
up
down
up number
down number
Move up a single frame (element in the call stack)
Move down a single frame
Move up/down the specified number of frames in the stack.
info frameList address, language, address of arguments/local variables and which registers were saved in frame.
info args
info locals
info catch
Info arguments of selected frame, local variables and exception handlers.

Source Code

OptionDescription
list
l
list line-number
list function
list -
list start#,end#
list filename:function
List source code.
set listsize count
show listsize
Number of lines listed when list command given.
directory directory-name
dir directory-name
show directories
Add specified directory to front of source code path.
directoryClear sourcepath when nothing specified.

Machine Language

OptionDescription
info line
info line number
Displays the start and end position in object code for the current line in source.
Display position in object code for a specified line in source.
disassemble 0xstart 0xendDisplays machine code for positions in object code specified (can use start and end hex memory values given by the info line command.
stepi
si
nexti
ni
step/next assembly/processor instruction.
x 0xaddress
x/nfu 0xaddress
Examine the contents of memory.
Examine the contents of memory and specify formatting.
  • n: number of display items to print
  • f: specify the format for the output
  • u: specify the size of the data unit (eg. byte, word, …)
Example: x/4dw var

Examine Variables

OptionDescription
print variable-name
p variable-name
p file-name::variable-name
p 'file-name'::variable-name
Print value stored in variable.
p *array-variable@lengthPrint first # values of array specified by length. Good for pointers to dynamically allocated memory.
p/x variablePrint as integer variable in hex.
p/d variablePrint variable as a signed integer.
p/u variablePrint variable as a un-signed integer.
p/o variablePrint variable as a octal.
p/t variable
x/b address
x/b &variable
Print as integer value in binary. (1 byte/8bits)
p/c variablePrint integer as character.
p/f variablePrint variable as floating point number.
p/a variablePrint as a hex address.
x/w address
x/4b &variable
Print binary representation of 4 bytes (1 32 bit word) of memory pointed to by address.
ptype variable
ptype data-type
Prints type definition of the variable or declared variable type. Helpful for viewing class or struct definitions while debugging.

GDB Modes

OptionDescription
set gdb-option valueSet a GDB option
set logging on
set logging off
show logging
set logging file log-file
Turn on/off logging. Default name of file is gdb.txt
set print array on
set print array off
show print array
Default is off. Convient readable format for arrays turned on/off.
set print array-indexes on
set print array-indexes off
show print array-indexes
Default off. Print index of array elements.
set print pretty on
set print pretty off
show print pretty
Format printing of C structures.
set print union on
set print union off
show print union
Default is on. Print C unions.
set print demangle on
set print demangle off
show print demangle
Default on. Controls printing of C++ names.

Start and Stop

OptionDescription
run
r
run command-line-arguments
run <infile> outfile
Start program execution from the beginning of the program.
The command break main will get you started. Also allows basic I/O redirection.
continue
c
Continue execution to next break point.
killStop program execution.
quit
q
Exit GDB debugger.

Sources:

Related:

Tags:
Programming Languages - Communicate instructions between humans and computers