Skip to content

Instantly share code, notes, and snippets.

@JamesHagerman
Last active June 24, 2020 22:38
Show Gist options
  • Save JamesHagerman/c1902f5ba1fb5eb7925f93ec1e8e9905 to your computer and use it in GitHub Desktop.
Save JamesHagerman/c1902f5ba1fb5eb7925f93ec1e8e9905 to your computer and use it in GitHub Desktop.
My notes on debugging c/c++ binaries using gdb... the normal way

GDB and GEF notes

I should be using radare2 instead... but I'm on ARM and don't really want to install radare2

TODO: Install radare2! :D

Args and launching

Just run:

(gdb) run

Run with args from stdin from file

(gdb) run < in.txt

Set args in gdb:

(gdb) set args asdf
(gdb) show args

Commands

  • Show disassembly: disassemble main
  • Show code: list main
  • Show line: list 123
  • Set breakpoint at line: break 14
  • Set breakpoint at address: break *0x080000whatever00
  • Delete breakpoint: delete 1 (delete breakpoint number 1)
  • Show breakpoints: info break OR i b
  • Ignore breakpoint some amount of times: ignore 1 100 (ignore breakpoint 1 the first 100 times it's crossed)
  • Watch variable: `watch src/modules/src/crtp_commander_rpyt.c::
  • Show register: info register OR info register esp
  • Show address: x 0xffffd640
  • Show 10 bytes after address: x/10 0xfffd640
  • Show 16 strings after address: x/16s 0xffff6d40
  • List callstack/backtrace: backtrace

.gdbinit files

GDB will load any .gdbinit files it finds in the local directory. It probably finds them elsewhere as well.

The commands in these files will run when gdb starts to initialize your gdb session.

Some people build really insane init files for gdb...

BMP example

For the Black Magic Probe STM32 programming/debugging tool, this .gdbinit can be pretty useful:

target extended-remote /dev/cu.usbmodemBDEAA9F1
monitor swdp_scan
attach 1
set confirm off
set mem inaccessible-by-default off
define lc
load
continue
end
define lr
load
run
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment