GNU GDB Debugger Command Cheat Sheet logo

GNU GDB Debugger Command Cheat Sheet

Free

Quick reference for GDB debugging commands.

FreeFree tier
Type
Open Source
Company
GNU Project

About GNU GDB Debugger Command Cheat Sheet

GNU GDB (GNU Debugger) is a portable command-line debugger for Unix-like systems, supporting languages such as C, C++, Ada, and Fortran. This cheat sheet provides a quick reference for common GDB command-line arguments, breakpoints, watchpoints, stepping commands, and inspecting variables and stacks. It also covers attaching to running processes, debugging multi-threaded programs, and using the terminal user interface (TUI).

Key Features

Comprehensive command reference for GDB
GDB command line arguments and options
Breakpoints and watchpoints (including temporary and conditional)
Stepping and continuing execution
Examining stack frames and variables
Attaching to running processes by PID
Thread debugging with thread-specific breakpoints
Support for core file analysis
Terminal user interface (TUI) mode
Batch mode for automated debugging

Pros & Cons

Pros
  • Free and open source (GNU GDB)
  • Portable across multiple platforms
  • Rich set of debugging capabilities (breakpoints, stepping, variable inspection)
  • Supports multi-threaded and multi-process debugging
  • Integrates with IDEs and editors via GDB/MI interface
  • Text-based interface available even without GUI
Cons
  • Steep learning curve for beginners unfamiliar with command-line debuggers
  • Primarily command-line based, though TUI mode offers a simple curses interface
  • Requires knowledge of assembly and memory concepts for advanced debugging
  • Not suitable for developers who prefer entirely graphical debugging environments

Best For

Debugging C/C++ applicationsAnalyzing core dumps to diagnose crashesAttaching to running processes for real-time debuggingAutomating debugger setup with command filesLearning GDB commands for embedded systems development

FAQ

How do I start GDB with an executable?
Use the command: gdb name-of-executable
How can I attach GDB to a running process?
Use: gdb name-of-executable --pid=process-id or gdb name-of-executable process-id
How do I set a breakpoint at a function?
Use the command: break function-name or break ClassName::functionName
How can I view the program's command line arguments during debugging?
Use the command: info args or i args