Generally, debugging C/CPP is either incredibly slow or tedious. Plain GDB is incredibly strong and, in principle, fast, but actually using it is horrible. CGDB, a terminal-based front-end, actually shows the fucking code, so that's a (necessary) upgrade. You still need to enter GDB commands, hence this page as a quick start.
Resources:
Launching the debugger:
cgdb ./Path/To/Program
cgdb -ex=start --args programToDebug arg2 arg3
cgdb -p 1234
An empty command repeats the previous command
CGDB:
Esc
): Browse code using VIM bindingsCTRL-w
i
): Enter GDB commandsProgram states:
start
r
or run
c
or continue
k
or kill
q
or quit
Stepping:
s
or step
n
or next
fin
or finish
u [file:]123
or until [file:]123
adv [file:]123
or advance [file:]123
Breakpoints:
b [file:]123
or break [file:]123
b [function]
b [file:]123 if x >= 5
i b
or info break
dis 3
or disable 3
en 3
or enable 3
d 3
or delete 3
"Watchpoints":
aw EXPRESSION
or awatch EXPRESSION
rw EXPRESSION
or rwatch EXPRESSION
wa EXPRESSION
or watch EXPRESSION
aw *0x0000beef
i w
or info w
Frames:
f
or frame
bt
or backtrace
f digit
Threads:
info threads
thread [thread number]
thread apply [thread number] command
thread appl all bt
Printing values:
p EXPRESSION
or print EXPRESSION
p/FMT ...
p/o
p/x
p/d
p/u
p/t
p/f
p/i
p/c
p/s
p EXPRESSION@COUNT
call [NameOfFunction]([ARG1], ...)
Reload files using lo
or load
.
To remove the copyright dump on startup, edit/create the file
~/.config/gdb/gdbearlyinit
and add the line:
set startup-quietly on
To make gdb settings persistent, edit/create the file
~/.config/gdb/gdbinit
.
Here is my current config:
set print pretty on
set pagination off
set confirm off
set history size 1000
set history save on
set history filename ~/.config/gdb/history
set disassembly-flavor intel