Skip to content

Instantly share code, notes, and snippets.

@tin-z
Last active October 30, 2023 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tin-z/366bdec4c2bdbd3edf5ed68cc49a0cd8 to your computer and use it in GitHub Desktop.
Save tin-z/366bdec4c2bdbd3edf5ed68cc49a0cd8 to your computer and use it in GitHub Desktop.
GDB extra tips memo

GDB extra tips memo

GUI settings

  • Display specific information after hitting breakpoints
display/[length]<data-or-instruction>[format]
# e.g. display/10i $rip
  • Disable 'confirm' messagges
set confirm off
  • Disable the output after hitting breakpoints
set pagination off
  • Enable breakpoint pending on future shared library load
set breakpoint pending on
  • Sets the maximum amount of frames displayed by the backtrace command
set backtrace limit <#limit-number>
  • Changing Disassembly Syntax
set disassembly-flavor <intel|att>

Inspect memory/register

  • Show memory map of the debugged process
info files map
  • Show registers
info r [register-name| ...]
  • Search for instructions/string/etc
# search for 'xchg rsp, rax' instructions
find <start-addr>, <stop-addr>, '\x85','\xc0'

# search for 'xchg <register>, <register>' instructions
find <start-addr>, <stop-addr>, '\x48', '\x87'

Actions

  • Hardware break On Write-Only Access
watch [casting-to-access-size] <address>
  • Hardware break On Read-Only Access
rwatch [casting-to-for-access-size] <address>
  • Hardware break On Read-and-write
awatch [casting-to-for-access-size] <address>
  • Hardware Break On Execute
hbreak <symbol|*address>
  • Execute one machine instruction, but if it is a function call, proceed until the function returns
nexti [#repeat-number]
  • disable c++ name demangle
set print asm-demangle on

Tracing

  • trace instructions executed
# set tracing points
set $start_pc=<trace-from-address>
set $end_pc=<trace-to-address>

# disable pagination
set pagination off

# log output to gdb.txt file instead of standard output
set logging on
set logging redirect on

# Warning: 'set logging on', an alias for the command 'set logging enabled', is deprecated. Use 'set logging enabled on'.

# run until $start_pc address hit
tbreak *$start_pc
run

# for each breakpoint hit print the instruction
display/i $pc

# start loop
set $while_true=1
while $while_true
  si
  if $pc == $end_pc
    printf "Breakpoint reached\n"
    set $while_true=0
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment