Boost Your Terminal Debugging: From Raw GDB to TUI, CGDB, Emacs and gdbgui
This guide walks through practical ways to make GDB debugging more efficient in the terminal, covering raw command‑line usage, the built‑in TUI mode, CGDB, Emacs GDB integration, and the browser‑based gdbgui, with configuration snippets and key bindings for each tool.
When debugging crashes on production servers, the basic GDB command line is often the only tool available, but its dense syntax can be cumbersome. The article starts by recommending a simple cheat sheet for common commands such as bt, info locals, up/down, and print, and explains how to load a core file on a remote machine for quick inspection.
GDB TUI – Adding a Textual UI
Running gdb -tui hello launches GDB’s built‑in Text User Interface, which splits the screen into a source‑code window and a GDB console. Window navigation mimics Emacs (e.g., C‑x o) and layout commands like layout split let you view registers and disassembly. The update command refreshes the source view after stack‑frame changes.
.gdbinit and PEDA – Extending the Command Line
Placing configuration scripts in ~/.gdbinit can load Python‑based plugins such as PEDA, which enrich the prompt (changing (gdb) to gdb‑peda$) and automatically display registers, stack, and variable information. The author notes that while powerful, PEDA can interfere with TUI layout, so it may be disabled for a cleaner experience.
CGDB – Vim‑Style Interface
CGDB provides a split view similar to TUI but with Vim‑style key bindings. The source window (CGDB mode) and the GDB console (GDB mode) can be toggled with ESC and i. Navigation uses hjkl, paging with c‑f / c‑b, and o lists source files. Function keys are mapped to common GDB commands (F5 run, F6 continue, F7 finish, F8 next, F10 step). A sample ~/.cgdb/cgdbrc config shows how to set case‑insensitive search, tab width, vertical split, and a custom F9 shortcut for until.
Emacs GDB – Full‑Featured IDE‑Like Debugging
Emacs’s GDB mode (invoked via M‑x gdb) offers a multi‑window layout with separate panes for the console, locals, source, output, stack, and breakpoints. The article lists essential Emacs key bindings for window management ( C‑x o, C‑x 2/3, C‑x 0/1) and debugging commands ( gud‑run, gud‑cont, gud‑step, etc.). Custom Emacs Lisp snippets configure ALT‑arrow window navigation, function‑key shortcuts, enable gdb‑many‑windows, and add mouse support for scrolling and clicking.
gdbgui – Browser‑Based Graphical Front End
For users who prefer a mouse‑driven UI, gdbgui (installable via pip) runs a local web server (e.g., gdbgui --host 0.0.0.0 hello) exposing source code, GDB console, variable watch, stack, memory, and breakpoint panels in a modern browser. It supports Windows, visualizes data structures, and allows click‑to‑toggle breakpoints.
Putting It All Together
The author recommends a workflow: start with raw GDB or TUI for quick checks, switch to CGDB for Vim‑centric users, move to Emacs for complex sessions requiring many windows, and fall back to gdbgui when a graphical interface is desired. Each tool can be customized with short configuration snippets, and the choice depends on personal preference and the complexity of the debugging task.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
