gdb ref
2022-12-11 ยท 2 min read
run and immediately break at main
#
(gdb) start
(gdb) help start
Start the debugged program stopping at the beginning of the main procedure.
You may specify arguments to give it.
Args may include "*", or "[...]"; they are expanded using the
shell that will start the program (specified by the "$SHELL" environment
variable). Input and output redirection with ">", "<", or ">>"
are also allowed.
hexdump memory view #
define xxd
dump binary memory dump.bin $arg0 $arg0+$arg1
shell xxd dump.bin
end
(gdb) xxd buf.data_ptr 256
00000000: 9c55 5555 0500 0000 785a 65e9 81fc 4510 .UUU....xZe...E.
00000010: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000020: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000030: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000040: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000050: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000060: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000070: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000080: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000090: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
rust syntax #
(gdb) p 0x55585380 as *mut u8
TUI mode #
Tired of pressing l
(list)? Can't tell wtf is going on? Try TUI mode!
(gdb) tui enable
TUI Commands: https://sourceware.org/gdb/current/onlinedocs/gdb.html/TUI-Commands.html
TUI keybindings not working #
gdb
's TUI mode has some keybindings (ex: <CTRL-X a>
to open TUI, <Ctrl-X l>
to clear screen).
However, if you're like me and have vi
mode enabled in your ~/.inputrc
, then these keybinds won't work unless you're in emacs mode. Fortunately there's a keybind to switch modes:
vi mode (normal) -> emacs mode: <Ctrl-e>
emacs mode -> vi mode: <Ctrl-Alt-j>
TUI Keybindings: https://sourceware.org/gdb/current/onlinedocs/gdb.html/TUI-Keys.html
stdout filling screen with junk #
Repaint the TUI:
(gdb) <CTRL-l>