A GDB debugging tool designed for AI Agents
GDB CLI for AI
A GDB debugging tool designed for AI Agents (Claude Code, etc.). Uses a "thin client CLI + GDB built-in Python RPC Server" architecture, enabling stateful GDB debugging through Bash.
Features
- Core Dump Analysis: Load core dumps with symbols resident in memory for millisecond-level response
- Live Attach Debugging: Attach to running processes with non-stop mode support
- Structured JSON Output: All commands output JSON with automatic truncation/pagination and operation hints
- Security Mechanisms: Command whitelist, heartbeat timeout auto-cleanup, idempotency guarantees
- Database-Optimized: scheduler-locking, large object pagination, multi-thread truncation
Requirements
- Python: 3.6.8+
- GDB: 9.0+ with Python support enabled
- OS: Linux
Check GDB Python Support
# Check if GDB has Python support
gdb -nx -q -batch -ex "python print('OK')"
# If system GDB lacks Python, check GCC Toolset (RHEL/CentOS)
/opt/rh/gcc-toolset-13/root/usr/bin/gdb -nx -q -batch -ex "python print('OK')"
Installation
# Install from PyPI
pip install gdb-cli
# Or install from GitHub
pip install git+https://github.com/Cerdore/gdb-cli.git
# Or clone and install locally
git clone https://github.com/Cerdore/gdb-cli.git
cd gdb-cli
pip install -e .
Environment check
gdb-cli env-check
## Quick Start
### 1. Load Core Dump
```bash
gdb-cli load --binary ./my_program --core ./core.12345
Output:
{
"session_id": "f465d650",
"mode": "core",
"binary": "./my_program",
"core": "./core.12345",
"gdb_pid": 12345,
"status": "started"
}
If your system's default GDB doesn't have Python support, specify it with
--gdb-path:gdb-cli load --binary ./my_program --core ./core.12345 \ --gdb-path /opt/rh/gcc-toolset-13/root/usr/bin/gdb
2. Debugging Operations
All operations use --session / -s to specify the session ID:
SESSION="f465d650"
# List threads
gdb-cli threads -s $SESSION
# Get backtrace (default: current thread)
gdb-cli bt -s $SESSION
# Get backtrace for a specific thread
gdb-cli bt -s $SESSION --thread 3
# Evaluate C/C++ expressions
gdb-cli eval-cmd -s $SESSION "my_struct->field"
# Access array elements
gdb-cli eval-element -s $SESSION "my_array" --index 5
# View local variables
gdb-cli locals-cmd -s $SESSION
# Execute raw GDB commands
gdb-cli exec -s $SESSION "info registers"
# Check session status
gdb-cli status -s $SESSION
3. Session Management
# List all active sessions
gdb-cli sessions
# Stop a session
gdb-cli stop -s $SESSION
4. Live Attach Debugging
# Attach to a running process (default: scheduler-locking + non-stop)
gdb-cli attach --pid 9876
# Attach with symbol file
gdb-cli attach --pid 9876 --binary ./my_program
# Allow memory modification and function calls
gdb-cli attach --pid 9876 --allow-write --allow-call
Full Command Reference
load — Load Core Dump
gdb-cli load --binary --core [options]
--binary, -b Executable file path (required)
--core, -c Core dump file path (required)
--sysroot sysroot path (for cross-machine debugging)
--solib-prefix Shared library prefix
--source-dir Source code directory
--timeout Heartbeat timeout in seconds (default: 600)
--gdb-path GDB executable path (default: "gdb")
attach — Attach to Process
gdb-cli attach --pid [options]
--pid, -p Process PID (required)
--binary Executable file path (optional)
--scheduler-locking Enable scheduler-locking (default: true)
--non-stop Enable non-stop mode (default: true)
--timeout Heartbeat timeout in seconds (default: 600)
--allow-write Allow memory modification
--allow-call Allow function calls
threads — List Threads
gdb-cli threads -s <session> [options]
--range Thread range, e.g., "3-10"
--limit Maximum return count (default: 20)
--filter-state Filter by state ("running" / "stopped")
bt — Backtrace
gdb-cli bt -s <session> [options]
--thread, -t Specify thread ID
--limit Maximum frame count (default: 30)
--full Include local variables
--range Frame range, e.g., "5-15"
eval-cmd — Evaluate Expression
gdb-cli eval-cmd -s <session> <expr> [options]
--max-depth Recursion
Tools (5)
loadLoad a core dump for debuggingattachAttach to a running process for debuggingthreadsList threads for a specific sessionbtGet backtrace for a sessioneval-cmdEvaluate C/C++ expressionsConfiguration
{ "mcpServers": { "gdb-cli": { "command": "gdb-cli", "args": ["--server"] } } }