Fristle - Closed Source Debugging With GDB
Fristle - Closed Source Debugging With GDB
Launching GDB gdb$ set The default is on, which continue Any time GDB is stopped, this
gdb programfile Start GDB ready to logging overwrites the existing will continue normal
launch and debug overwrite log file. execution.
programfile off
GDB: Environment
gdb --args Start GDB as above gdb$ set Turns on logging.
program arg1 but supplying logging on gdb$ show env
arg2 command line Display the debuggee's current enviro‐
gdb$ echo With logging on, this will
arguments to the nment variables.
comment\n add a comment to the
target process.
logfile. gdb$ set env varname= value
gdb -p pid Attach GDB to a
Set an environment variable.
running target GDB: Execution
gdb$ unset env varname
process.
Displaying the Call Stack
Selecting the Start of Debugging Delete an environment variable.
gdb$ bt Show the list of stack frames
gdb$ start Run the debuggee gdb$ show args
(BackTrace).
and break at main() Display the command-line arguments of the
gdb$ bt Show the list of stack frames
(if it exists). debuggee process.
full with the local variables of each.
gdb$ attach pid Attach GDB to a gdb$ set args arg1 arg2
gdb$ Show saved stack pointer, call
running target Set the command-line arguments to the
info address, etc. for the selected
process. debuggee process.
frame stack frame.
(gdb) attach (Mac OS X only) gdb$ shell command
Wait for a process to gdb$ Select stack frame number
--waitfor
frame number (and crashed GDB Run shell commands (useful commands
process-name launch and immedi‐
6.3.50 on OS X). may include "ps -e", etc.)
ately attach to it. number
gdb$ pwd | cd
Adding a shim Controlling Execution
Step-into (one or count instru‐ These two commands can can show or
gdb$ set exec- The dynamic library si
ction forward). change the working directory of GDB
wrapper env file libfoo
.so will be [count]
(useful for logging, etc.).
'LD_PRELO‐ loaded into the ni Step-over (one or count instru‐
AD=libfoo.so' address space of the [count] ction, stepping over function
GDB: Breakpoints
debuggee. calls).
Logging Managing Breakpoints
return Immediately return from the
gdb$ set The default logfile is current function, optionally gdb$ set breakpoint pending on
[value]
logging file gdb.txt but you can setting the return value. Bypasses the warning about breakpoints in
filename use this to change it. finish Stop after finishing execution of modules that aren't loaded yet.
the current function. gdb$ break function
gdb$ break *0x00001234 Multithreaded Debugging GDB will not detach at a fork() and will also
Sets a breakpoint at address 0x00001234. gdb$ info threads attach to the child process (both will be
debugged).
gdb$ break 0x00001234 if symbo‐ List the threads of the target process.
gdb$ show detach-on-fork
l== somevalue* gdb$ thread threadID
Display the current setting value.
This is an example of the conditional Attach GDB to the thread threadID.
breakpoint syntax. gdb$ info inferiors
gdb$ set non-stop on
gdb$ catch syscall name List all processes under GDB's control. (On
Only the debugged thread is halted in GDB,
Mac OS X: info files)
Stop when the syscall name is called. Omit the rest continue to run non-stop (unless
name to stop on every syscall. Instead of they are blocking on the thread being
name, you can also specify a syscall by GDB: Memory
debugged).
number. Memory Images
gdb$ set scheduler-locking on
gdb$ catch load gdb program -c dumpfile
Only the debugged thread will run when the
(not in Mac OS X) Stop when the debuggee debuggee is resumed. Debug program using a memory dump file,
loads any dynamic library. Also: catch imagefile.
gdb$ set scheduler-locking step
unload. gdb$ generate-core-file
Only the debugged thread will step when
gdb$ info break
being step-debugged. (not in Mac OS X) Dump the debuggee
List all breakpoints and watchpoints. process memory to disk.
gdb$ show scheduler-locking
gdb$ clear [ breakpointid] Reading Disassembly and Memory
Display the current setting value.
Deletes one or all existing breakpoints. gdb$ set disassembly-flavor
Without this cheat sheet, the user would be intel
Multiprocess Debugging
forced to guess what is being cleared.
gdb$ set follow-fork-mode child Use the modern syntax for x86-64
gdb$ disable [ breakpointid] assembly. This is not the default.
GDB will detach at a fork() and attach to the
Disables one or all breakpoints. gdb$ set disassemble-next-line
new process.
on
gdb$ set follow-fork-mode parent
Managing Watchpoints (Data Breakpoin‐ Disassemble the next instruction every time
(Default) GDB will not detach at a fork().
ts) GDB stops. You want to turn this on.
gdb$ show follow-fork-mode
gdb$ watch *0x12345678 [mask gdb$ x/4i 0x00001234
0xffffff00] Display the current setting value.
Disassemble (eXamine) the first 4 instru‐
Break on any change to the 24 most signif‐ gdb$ set follow-exec-mode new ctions at address 0x00001234.
icant bits of a 32-bit value at address GDB will detach at an exec() and attach to gdb$ x/32i $rip
0x12345678. the new process.
Disassemble the first 32 instructions
gdb$ awatch *0x12345678 gdb$ set follow-exec-mode same starting at the current instruction ($RIP on
Like watch, but also stops on any write or (Default) GDB will not detach at an exec(). x86-64).
read accesses to the given address.
gdb$ show follow-exec-mode gdb$ x/32i $rip-16
gdb$ rwatch *0x12345678
Display the current setting value. Same command, but attempting to disass‐
Like watch, but only stops on read emble both forward and backward from the
gdb$ set detach-on-fork off
accesses. current instruction.
gdb$ info address symbolname
Displays the symbol name (if any), gdb$ handle signal [keywords...]
executable segment, and executable (Untested) might bypass exception-based
module associated with the given address. anti-debugging
gdb$ x/1s 0x00001234 gdb$ catch syscall ptrace
Display one null-terminated string at (Untested) Use this breakpoint to return 0
address 0x00001234. (set $rax = 0; continue), should bypass
gdb$ x/8xb 0x00001234 ptrace() checking by the debuggee.