GDB CLI MCP Server

Local setup required. This server has to be cloned and prepared on your machine before you register it in Claude Code.
1

Set the server up locally

Run this once to clone and prepare the server before adding it to Claude Code.

Run in terminal
pip install gdb-cli
2

Register it in Claude Code

After the local setup is done, run this command to point Claude Code at the built server.

Run in terminal
claude mcp add gdb-cli -- node "<FULL_PATH_TO_GDB_CLI>/dist/index.js"

Replace <FULL_PATH_TO_GDB_CLI>/dist/index.js with the actual folder you prepared in step 1.

README.md

A GDB debugging tool designed for AI Agents

GDB CLI for AI

English | 中文

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 debugging
attachAttach to a running process for debugging
threadsList threads for a specific session
btGet backtrace for a session
eval-cmdEvaluate C/C++ expressions

Configuration

claude_desktop_config.json
{ "mcpServers": { "gdb-cli": { "command": "gdb-cli", "args": ["--server"] } } }

Try it

Load the core dump at ./core.12345 for the binary ./my_program and list the active threads.
Attach to the running process with PID 9876 and provide a backtrace of the current thread.
Evaluate the expression 'my_struct->field' for the current debugging session.
List all active GDB debugging sessions and stop the session with ID f465d650.

Frequently Asked Questions

What are the key features of GDB CLI?

Core dump analysis with symbols resident in memory. Live attach debugging for running processes with non-stop mode. Structured JSON output for all commands. Security mechanisms including command whitelisting and heartbeat timeouts. Database-optimized operations with large object pagination.

What can I use GDB CLI for?

Automated post-mortem analysis of application crashes using core dumps. Live debugging of production processes by AI agents. Remote C/C++ expression evaluation during complex bug investigations. Managing multiple concurrent debugging sessions via CLI.

How do I install GDB CLI?

Install GDB CLI by running: pip install gdb-cli

What MCP clients work with GDB CLI?

GDB CLI works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep GDB CLI docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Need the old visual installer? Open Conare IDE.
Open Conare