gdb Quick Reference

From Wikistix
Jump to: navigation, search

Running

command abbreviation action
step s step to next source line, possibly into functions
next n step over any functions to next source line
finish fin step out of the current stack frame/function
stepi step to next instruction, stepping into subroutine calls
nexti step to next instruction, stepping over subroutine calls

Examining state

command abbreviation action
info registers i r Dump out common registers

Breakpoints

command abbreviation action
info breakpoints i b display breakpoints
delete <n> d <n> delete breakpoint numbered <n>
breakpoint <n> b <n> breakpoint at <n>, which may be a symbol, line number or address

Dumping output to a file

(gdb) set pagination off
(gdb) set logging file /tmp/ls.malloc.log
(gdb) set logging overwrite
(gdb) set logging redirect on
(gdb) set logging on
Redirecting output to /tmp/ls.malloc.log.

Examples

Dump stack on function call

Dump thread stack each and every time a specific function is called, writing to a log.

ksh$ gdb /bin/ls
GNU gdb (GDB) 7.7.1
...
(gdb) b malloc
Breakpoint 1 at 0x401360
(gdb) commands
Type commands for breakpoint(s) 1, one per line.
End with a line saying just "end".
>bt
>c
>end
(gdb) set pagination off
(gdb) set logging file /tmp/ls.malloc.log
(gdb) set logging overwrite
(gdb) set logging redirect on
(gdb) set logging on
Redirecting output to /tmp/ls.malloc.log.
(gdb) run
...
(gdb) quit
ksh$ head -10 /tmp/ls.malloc.log
Starting program: /bin/ls

Breakpoint 1, 0x00007f7ff70b2b4a in malloc () from /lib/libc.so.12
#0  0x00007f7ff70b2b4a in malloc () from /lib/libc.so.12
#1  0x00007f7ff70f4871 in __setlocale () from /lib/libc.so.12
#2  0x00000000004023fa in ls_main ()
#3  0x0000000000401715 in ___start ()
#4  0x00007f7ff7ffa000 in ?? ()
#5  0x0000000000000001 in ?? ()
#6  0x00007f7ffffffca0 in ?? ()
#7  0x0000000000000000 in ?? ()

See Also

External


Misinformation found herein copyright Paul Ripke (aka “stix”) stixpjr@gmail.com.