From aldeid
Jump to: navigation, search
This page is still a draft. Thank you for your understanding.


Launch gdb

$ gdb --args executable-name arg1 arg2


Description Command
Create a sotfware breakpoint

Create breakpoint at address 0x40489c:

(gdb) break *0x40489c

Stop at main:

(gdb) b main  
Create a hardware breakpoint
(gdb) hbreak *0x0804b2a4
If gdb claims that "No hardware breakpoint support in the target", you have to first start the program (e.g. set a sofware breakpoint and run the program first).
Clear a breakpoint (gdb) clear
Clear all breakpoints (gdb) delete
List breakpoints (gdb) info breakpoints


Description Command
Run the program (gdb) run
Run with arguments:
(gdb) run arg1 "arg2" ...
(gdb) run $(python -c 'print "A"*200')
Run the program and break at entry point: (gdb) start
Run with arguments and break at entry point: (gdb) start arg1 "arg2" ...
Continue running until just after function in the selected stack frame returns. (gdb) finish
Restart (gdb) kill
Run (gdb) run
Step out
(gdb) step
(gdb) next
(gdb) u (use when no debugging information available)
Step in
(gdb) stepi
(gdb) nexti
Run until next breakpoint (gdb) continue


Description Command
Disassemble instructions (gdb) disas 0x40489c,+50
Examine memory: x/FMT ADDRESS.
expression for the memory address to examine.
repeat count followed by a format letter and a size letter.
Format letters are
  • o (octal)
  • x (hex)
  • d (decimal)
  • u (unsigned decimal)
  • t (binary)
  • f (float)
  • a (address)
  • i (instruction)
  • c (char)
  • s (string)
  • T (OSType)
  • A (floating point values in hex)
Size letters are
  • b (byte)
  • h (halfword)
  • w (word)
  • g (giant, 8 bytes).

Show 12 instructions:

(gdb) x /12i $pc
=> 0x47431b:	cmp    $0xfffffffffffff000,%rax
   0x474321:	ja     0x474348
   0x474323:	test   %rax,%rax
   0x474326:	js     0x474346
   0x474328:	test   %r8d,%r8d
   0x47432b:	je     0x474346
   0x47432d:	cmp    $0x3,%r8d
   0x474331:	ja     0x474346
   0x474333:	mov    $0xffffffffffffffc0,%rax
   0x47433a:	movl   $0x0,%fs:(%rax)
   0x474341:	mov    -0x48(%rsp),%rax
   0x474346:	repz retq 
Show execution stack (shows how a function is called from the beginning) (gdb) backtrace


Description Command
Show register value

Show value of RSP

(gdb) info reg rsp 

Show all registers:

(gdb) info reg

Format register R3 (ARM) in ASCII:

(gdb) p/c $r3
$10 = 116 't'
Modify value of register (R1 in the example)
(gdb) set $r1=65
Show stack
(gdb) x/32x $esp
0xbffff5d0:	0xbffff5e0	0xbffff842	0xbffff65c	0x0012fa74
0xbffff5e0:	0x90909090	0x90909090	0x90909090	0x90909090
0xbffff5f0:	0x90909090	0x90909090	0x90909090	0x90909090
0xbffff600:	0x90909090	0x90909090	0x31909090	0x01ec83c0
0xbffff610:	0x68240488	0x62697274	0x69642e68	0x2f6e6873
0xbffff620:	0x68666873	0xec836962	0x2404c601	0x50e6892f
0xbffff630:	0x890bb056	0x31e189f3	0xb080cdd2	0xcddb3101
0xbffff640:	0x41414180	0x41414141	0x41414141	0x41414141


Description Command
Show arguments
(gdb) show args
Show file information (e.g. entry point)
(gdb) info files


(gdb) info files
Symbols from "/data/01f47d58806a8264cd4b2b97b9dabb4a".
Local exec file:
	`/data/01f47d58806a8264cd4b2b97b9dabb4a', file type elf32-i386.
	Entry point: 0x8048380
	0x08048154 - 0x08048167 is .interp
	0x08048168 - 0x08048188 is .note.ABI-tag
	0x08048188 - 0x080481ac is
	0x080481ac - 0x080481cc is .gnu.hash
	0x080481cc - 0x0804823c is .dynsym
	0x0804823c - 0x08048291 is .dynstr
	0x08048292 - 0x080482a0 is .gnu.version
	0x080482a0 - 0x080482c0 is .gnu.version_r
	0x080482c0 - 0x080482c8 is .rel.dyn
	0x080482c8 - 0x080482f0 is .rel.plt
	0x080482f0 - 0x0804831e is .init
	0x08048320 - 0x08048380 is .plt
	0x08048380 - 0x080485ec is .text
	0x080485ec - 0x08048606 is .fini
	0x08048620 - 0x080486cb is .rodata
	0x080486cb - 0x080486e8 is text
	0x080486e8 - 0x0804871c is .eh_frame_hdr
	0x0804871c - 0x080487dc is .eh_frame
	0x08049f14 - 0x08049f1c is .ctors
	0x08049f1c - 0x08049f24 is .dtors
	0x08049f24 - 0x08049f28 is .jcr
	0x08049f28 - 0x08049ff0 is .dynamic
	0x08049ff0 - 0x08049ff4 is .got
	0x08049ff4 - 0x0804a014 is .got.plt
	0x0804a014 - 0x0804a01c is .data
	0x0804a020 - 0x0804a060 is .bss
Change disassembly style to intel
(gdb) set disassembly-flavor intel
Show Assembly panel
(gdb) layout asm
Show registers panel
(gdb) layout regs
(gdb) quit