Skip to content

Instantly share code, notes, and snippets.

@puilp0502
Created January 21, 2020 18:41
Show Gist options
  • Save puilp0502/584498a1260f091326c3e5111fd47055 to your computer and use it in GitHub Desktop.
Save puilp0502/584498a1260f091326c3e5111fd47055 to your computer and use it in GitHub Desktop.
GDB Cheatsheet

GDB Cheatsheet

Data Inspection

p/f expr: evaluate & Print expr, where

  • f is the display format,

  • expr is the expression to evaluate. e.g. to see the contents of eax register: p/x $eax

    Available display format: x, d, u, o, t (binary), a (address), c, f, s, z (zero-pad hex)

x/nfu addr: eXamine memory, where

  • n is the repeat count,
  • f is the display format,
  • u is the unit size,
  • addr is the memory address to examine. e.g. to see 16 instructions from current PC: x/16i $pc

display/fmt expr: automatically display expr, where

  • expr is the expression to watch.

i display: show currently set automatic display expressions.

undisplay dnum: disable automatic display, where

  • dnum is the display number. (Can be specified in range)

Execution

c: Continue until next breakpoint

s: Step to different line
n: step to Next line (does not stop on function invocation)

si: Step to different Instruction
ni: step to Next Instruction, excluding function invocation

u location: continue Until specified location e.g. to execute until address 0x7C00: u *0x7c00 (note the star prefix)

Breakpoints

break location: set a breakpoint at the given location.
break: set a breakpoint at the next instruction

tbreak: same as break, but cleared once encountered.
hbreak: same as break, but hardware-assisted.

watch [-l|-location] expr: set a watchpoint for an expr. GDB will break when the expression expr is written into by the program and its value changes. If location is specified, GDB will break when memory location specified by expr changes.

rwatch: same as watch, but breaks on read.
awatch: same as watch, but breaks on access(read/write).
For more info, refer to the official document.

i break: show breakpoints/watchpoints.
i watch: show watchpoints.

clear location: delete breakpoints at location.
d breakpoints: delete breakpoints/watchpoints specified by breakpoints.

Misc

layout asm: TUI-based assembly view

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment