Intro
This paper will introduce you how to quickly use gdb
Debug program
Debug program with gdb is very simple, just follow below steps
- Build your program with debug info
gcc {your options} -o0 -g3 -ggdb
- Start gdb
# without args
gdb {program}
# with args
gdb --args {program} {args...}
- Add breakpoints
(gdb) b {filename}:{line}
# for example
(gdb) b test.cc:20
# the gdb will auto find file by filename and program debug info
# if gdb can't find file, add file search dir
(gdb) dir {filepath}
- Run program and debug
# In gdb command line
(gdb) run
# when program reach one breakpoint, you can print symbol
(gdb) print {symbol name}
# even with object's function, such as
(gdb) print list.size()
Debug coredump file
Core file can help us analysis program coredump reason. (TODO)
Advance Usage
Display
- Display memory
# show 100 elements in a uint8_t array
(gdb) p /x buf
(gdb) x /100b buf
0x7e1c30: 0xcd 0xdc 0x03 0x00 0x00 0x5e 0xf7 0x57
0x7e1c38: 0xaf 0x27 0x05 0x0d 0x00 0x02 0x00 0x01
0x7e1c40: 0x11 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x7e1c48: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x7e1c50: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x7e1c58: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x7e1c60: 0x00 0x00 0x01 0x01 0x00 0x00 0x06 0x00
0x7e1c68: 0x02 0xff 0xff 0xff 0xff 0x00 0x00 0x15
0x7e1c70: 0x8d 0xe6 0x18 0x00 0x00 0x00 0x00 0x00
0x7e1c78: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x7e1c80: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x7e1c88: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x7e1c90: 0x00 0x00 0x00 0x00