An MCP (Model Context Protocol) server that provides AI assistants with programmatic access to GDB debugging sessions. This allows AI models to interact with debuggers in the same way IDEs like VS Code and CLion do, using the GDB/MI (Machine Interface) protocol.
- Full GDB Control: Start sessions, execute commands, control program execution
- Thread Analysis: Inspect threads, get backtraces, analyze thread states
- Breakpoint Management: Set conditional breakpoints, temporary breakpoints
- Variable Inspection: Evaluate expressions, inspect variables and registers
- Core Dump Analysis: Load and analyze core dumps with custom initialization
- Flexible Initialization: Run GDB scripts or commands on startup
This server uses the GDB/MI (Machine Interface) protocol, which is the same interface used by professional IDEs. It provides:
- Structured, machine-parseable output
- Full access to GDB's debugging capabilities
- Reliable command execution and response handling
- Python 3.10 or higher
- GDB installed and available in PATH
# Install pipx if needed
python3 -m pip install --user pipx
python3 -m pipx ensurepath
# Install gdb-mcp-server
cd /path/to/gdb-mcp
pipx install .For alternative installation methods (virtual environment, manual setup), see INSTALL.md.
Add this to your Claude Desktop configuration file:
Location:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
Configuration:
{
"mcpServers": {
"gdb": {
"command": "gdb-mcp-server"
}
}
}For other installation methods and MCP clients, see INSTALL.md.
The GDB MCP Server supports the following environment variables:
Specify the path to the GDB executable to use. This is useful when:
- You have multiple GDB versions installed
- GDB is installed in a non-standard location
- You want to use a custom or patched GDB build
Default: gdb (resolved via system PATH)
Example:
export GDB_PATH=/usr/local/bin/gdb-13.2
gdb-mcp-serverNote: The gdb_path parameter in the gdb_start_session tool overrides this environment variable if both are specified.
Set the logging level for the server.
Default: INFO
Options: DEBUG, INFO, WARNING, ERROR, CRITICAL
Example:
export GDB_MCP_LOG_LEVEL=DEBUG
gdb-mcp-serverThe GDB MCP Server provides 22 tools for controlling GDB debugging sessions:
Session Management:
gdb_start_session- Start a new GDB session with optional initializationgdb_execute_command- Execute GDB commands (CLI or MI format)gdb_call_function- Call a function in the target process (dedicated tool for separate permissioning)gdb_get_status- Get current session statusgdb_stop_session- Stop the current session
Thread & Frame Navigation:
gdb_get_threads- List all threadsgdb_select_thread- Select a specific threadgdb_get_backtrace- Get stack trace for a threadgdb_select_frame- Select a specific stack framegdb_get_frame_info- Get information about the current frame
Breakpoint Management:
gdb_set_breakpoint- Set breakpoints with optional conditionsgdb_list_breakpoints- List all breakpoints with structured datagdb_delete_breakpoint- Delete a breakpoint by numbergdb_enable_breakpoint- Enable a breakpointgdb_disable_breakpoint- Disable a breakpoint
Execution Control:
gdb_continue- Continue executiongdb_step- Step into functionsgdb_next- Step over functionsgdb_interrupt- Pause a running program
Data Inspection:
gdb_evaluate_expression- Evaluate expressionsgdb_get_variables- Get local variablesgdb_get_registers- Get CPU registers
For detailed documentation of each tool including parameters, return values, and examples, see TOOLS.md.
User: "Load the core dump at /tmp/core.12345, set the sysroot to /opt/sysroot, and tell me how many threads there were when it crashed."
AI Actions:
- Start session with init commands:
{
"init_commands": [
"file /path/to/executable",
"core-file /tmp/core.12345",
"set sysroot /opt/sysroot"
]
}- Get threads:
gdb_get_threads - Report: "There were 8 threads when the program crashed."
User: "Set a breakpoint at process_data but only when the count variable is greater than 100, then continue execution."
AI Actions:
- Set conditional breakpoint:
{
"location": "process_data",
"condition": "count > 100"
}- Continue execution:
gdb_continue - When hit, inspect state
For more detailed usage examples and workflows, see examples/USAGE_GUIDE.md and examples/README.md.
Create a .gdb file with your setup commands:
# setup.gdb
file /path/to/myprogram
core-file /path/to/core
# Set up symbol paths
set sysroot /opt/sysroot
set solib-search-path /opt/libs:/usr/local/lib
# Convenience settings
set print pretty on
set print array on
set pagination offThen use it:
{
"init_commands": ["source setup.gdb"]
}You can also use GDB's Python API:
# init.py
import gdb
gdb.execute("file /path/to/program")
gdb.execute("core-file /path/to/core")
# Custom analysisUse with:
{
"init_commands": ["source init.py"]
}While this server primarily works with core dumps and executables, you can attach to running processes:
{
"init_commands": [
"attach 12345" // PID of running process
]
}Note: This requires appropriate permissions (usually root or same user).
GDB Not Found
which gdb
gdb --versionTimeout Errors / Commands Not Responding
The program is likely still running! When a program is running, GDB is busy and won't respond to other commands.
Solution: Use gdb_interrupt to pause the running program, then other commands will work.
Program States:
- Not started: Use
gdb_execute_commandwith "run" or "start" - Running: Program is executing - use
gdb_interruptto pause it - Paused (at breakpoint): Use
gdb_continue,gdb_step,gdb_next, inspect variables - Finished: Program has exited - restart with "run" if needed
Missing Debug Symbols
Always check the warnings field in gdb_start_session response! Compile your programs with the -g flag.
For detailed troubleshooting, installation issues, and more solutions, see INSTALL.md.
-
GDB/MI Protocol: The server communicates with GDB using the Machine Interface (MI) protocol, the same interface used by IDEs.
-
pygdbmi Library: We use the excellent
pygdbmilibrary to handle the low-level protocol details and response parsing. -
MCP Integration: The server exposes GDB functionality as MCP tools, allowing AI assistants to:
- Understand the available debugging operations
- Execute commands with proper parameters
- Interpret structured responses
-
Session Management: A single GDB session is maintained per server instance, allowing stateful debugging across multiple tool calls.
Contributions welcome! Areas for improvement:
- Additional GDB commands (e.g., watchpoints, memory inspection)
- Better error handling and recovery
- Enhanced output formatting
MIT