GDB Cheat Sheet

Configuration

  • Save history
1
set history save on

Args

1
gdb --args ./d8 --allow-natives-syntax jit.js --single-threaded

Print

history command

1
C-r (reverse-i-search)`':

address

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
  x/nfu addr

  n: How many units to print (default 1).

  f: Format character (like print)
      o - octal
      x - hexadecimal
      d - decimal
      u - unsigned decimal
      t - binary
      f - floating point
      a - address
      c - char
      s - string
      i - instruction

      u: Unit.
      b: Byte,
      h: Half-word (two bytes)
      w: Word (four bytes)
      g: Giant word (eight bytes))

print hex

1
p/x variable

show all functions

1
info functions [regexp]

show address info

1
info symbol addr

Kernel Debugging

1
2
3
4
5
6
7
8
9
(gdb) apropos lx
function lx_current -- Return current task
function lx_module -- Find module by name and return the module variable
function lx_per_cpu -- Return per-cpu variable
function lx_task_by_pid -- Find Linux task by PID and return the task_struct variable
function lx_thread_info -- Calculate Linux thread_info from task variable
lx-dmesg -- Print Linux kernel log buffer
lx-lsmod -- List currently loaded modules
lx-symbols -- (Re-)load symbols of Linux kernel and currently loaded modules

Radare2

analysis

CommandDescription
aaanalyze all
afllist functions
s sym.mainseek to function

inspecting

CommandDescription
pdbbasic block
pdffunction disassembly
afafunction arguments
afvfunction variables
afanalyze function

graph output

CommandDescription
agfvInteractive Ascii Art
agfdGraphviz dot