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/Programcgdb -ex=start --args programToDebug arg2 arg3cgdb -p 1234An empty command repeats the previous command
CGDB:
Esc): Browse code using VIM bindingsCTRL-wi): Enter GDB commandsProgram states:
startr or runc or continuek or killq or quitStepping:
s or stepn or nextfin or finishu [file:]123 or until [file:]123adv [file:]123 or advance [file:]123Breakpoints:
b [file:]123 or break [file:]123b [function]b [file:]123 if x >= 5i b or info breakdis 3 or disable 3en 3 or enable 3d 3 or delete 3"Watchpoints":
aw EXPRESSION or awatch EXPRESSIONrw EXPRESSION or rwatch EXPRESSIONwa EXPRESSION or watch EXPRESSIONaw *0x0000beefi watch or info watchpointsFrames:
f or framebt or backtracef digitThreads:
info threadsthread [thread number]thread apply [thread number] commandthread appl all btPrinting values:
p EXPRESSION or print EXPRESSIONp/FMT ...p/op/xp/dp/up/tp/fp/ip/cp/sp EXPRESSION@COUNTcall [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
CGDB specific settings can be configured by editing ~/.cgdb/cgdbrc:
:set tabstop=2
:set autosourcereload