Gdb quick start

Intro This paper will introduce you how to quickly use gdb GDB Commands 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....

February 20, 2024 · 2 min · 271 words · Croak