Docsity

GDB CHeatSheet for beginners, Cheat Sheet of Digital Logic Design and Programming

Toggle sidebar
bg1
Basics
help <cmd> Displays information about @cmd usage in GDB
run / r Executes program in GDB
start Starts executing program and stops at entry point (main)
next / n [N] Continues execution till next @N source line
print / p <expr> Evaluates expression and prints result
list / l [N] Lists the source code. If line given, lists ±10 lines from line @N
quit / q Exit GDB
TUI
Ctrl + x, a Switch between GDB terminal and TUI
Ctrl + l Refreshes TUI
layout Select TUI layouts. Layouts: src, reg, asm
layout split Splits current display screen
info registers Shows the contents of registers
disassemble Displays assembly instructions
nexti /ni [N] Execute N assembly instructions
step / s Step inside function
finish / fin Exit out of function
x[FMT] ADDRESS
Displays content of @ADDRESS based on given @FMT.
FMT: (N)(format)(size)
i.e. x/9xw 0x800000
continue / c Continue program execution till next breakpoint.
until / u [loc] Executes code until @loc. Useful when trying to exit loops
Breakpoints
break <lockspec> Adds breakpoint to specified location
info breakpoints Displays information about all current breakpoints.
delete breakpoints [b]
Deletes all given breakpoints. If none given, deletes all
breakpoints
watch <expr>
Breakpoint halting execution of program whenever variable is
modified.
info watchpoints Displays information about all watchpoints.
Prints
display/[FMT] [address/expr]
Whenever program halts, GDB prints the value of the display
variables
info display Shows active displays
undisp [#num] Deletes the display @num
dprintf <locspec> <fmt> <args>
Mix of breakpoint and printf. Gives the same effect of adding
printf to your code.
info locals Displays value of local variables in current scope.
info args Displays value of function argument.
Backtrace
backtrace or bt Prints the callstack
bt full Same as bt but with more details
frame / f [num] Goes to frame #num
up [count] Goes #count frames up
down [count] Goes #count frames down
pf3

Partial preview of the text

Download GDB CHeatSheet for beginners and more Cheat Sheet Digital Logic Design and Programming in PDF only on Docsity!

Basics

help Displays information about @cmd usage in GDB run / r Executes program in GDB start Starts executing program and stops at entry point (main) next / n [N] Continues execution till next @N source line print / p Evaluates expression and prints result list / l [N] Lists the source code. If line given, lists ±10 lines from line @N quit / q Exit GDB

TUI

Ctrl + x, a Switch between GDB terminal and TUI Ctrl + l Refreshes TUI layout Select TUI layouts. Layouts: src, reg, asm layout split Splits current display screen info registers Shows the contents of registers disassemble Displays assembly instructions nexti /ni [N] Execute N assembly instructions step / s Step inside function finish / fin Exit out of function

x[FMT] ADDRESS

Displays content of @ADDRESS based on given @FMT. FMT: (N)(format)(size) i.e. x/9xw 0x continue / c Continue program execution till next breakpoint. until / u [loc] Executes code until @loc. Useful when trying to exit loops

Breakpoints

break Adds breakpoint to specified location info breakpoints Displays information about all current breakpoints.

delete breakpoints [b]

Deletes all given breakpoints. If none given, deletes all breakpoints

watch

Breakpoint halting execution of program whenever variable is modified. info watchpoints Displays information about all watchpoints.

Prints

display/[FMT] [address/expr]

Whenever program halts, GDB prints the value of the display variables info display Shows active displays undisp [#num] Deletes the display @num

dprintf

Mix of breakpoint and printf. Gives the same effect of adding printf to your code. info locals Displays value of local variables in current scope. info args Displays value of function argument.

Backtrace

backtrace or bt Prints the callstack bt full Same as bt but with more details frame / f [num] Goes to frame #num up [count] Goes #count frames up down [count] Goes #count frames down

Misc

call Same as print but also applicable to call void functions. finish Continues execution till end of function ret Returns value of expression

skip /

When using step, skips going into @function or functions listed in @file info skip Displays details about the specified skips save breakpoints Saves all current breakpoints to @filename source breakpoints Loads breakpoint information from filename