
GDB MCP Server

2025.04.07
0
Python程序调试AI辅助开发开发效率
GDB-MCP是一个基于MCP Python SDK开发的服务器,旨在使大型语言模型(LLMs)能够与GDB交互,进行程序调试和分析。该工具通过生成式AI接口,使LLMs能够执行复杂的调试任务。
View on GitHub
Overview
基本能力
产品定位
GDB-MCP是一个为开发者和AI模型设计的调试工具,它通过MCP协议提供GDB的调试功能,使得AI可以辅助进行程序调试和分析。
核心功能
- 会话管理:启动和管理多个GDB会话,加载程序和核心转储,附加到运行中的进程。
- 调试命令:设置带条件的断点,单步执行代码(step, next, finish),继续执行,获取回溯,打印变量值,反汇编代码,列出可用函数,检查寄存器。
- 高级功能:多会话支持,工作目录配置,程序参数处理,核心转储分析,符号检查。
适用场景
- AI辅助的程序调试和分析。
- 开发者通过AI模型快速定位和解决程序中的问题。
- 教学和培训中,AI辅助理解程序执行流程和调试技巧。
工具列表
GDB_COMMANDS = [
gdb_start,
gdb_load,
gdb_run,
gdb_command,
gdb_attach,
gdb_load_core,
gdb_set_breakpoint,
gdb_continue,
gdb_step,
gdb_next,
gdb_finish,
gdb_backtrace,
gdb_print,
gdb_disassemble,
gdb_info_registers,
gdb_info_functions,
gdb_list_sessions,
gdb_terminate,
]
常见问题解答
info functions
和disassemble
命令暂时不可用,原因是GDB Machine Interface (MI)输出解析问题。这些问题将在未来的更新中修复。
使用教程
使用依赖
- 确保已安装Python3和Poetry。
安装教程
- 克隆仓库:
git clone https://github.com/smadi0x86/gdb-mcp.git
cd gdb-mcp
- 使用Poetry安装依赖:
poetry install
- 以开发模式安装包:
poetry install
调试方式
- 启动GDB MCP服务器:
python3 gdb-mcp.py
- 服务器将在stdio上运行,准备接受命令。
LLM客户端配置
对于Claude Desktop
在claude_desktop_config.json
中添加以下配置:
{
"mcpServers": {
"gdb": {
"command": "python3",
"args": ["/home/your-username/dev/personal/gdb-mcp/gdb-mcp.py"]
}
}
}
对于VS Code Copilot
在VS Code设置中添加以下配置:
{
"mcp": {
"inputs": [],
"servers": {
"gdb": {
"command": "python3",
"args": ["/home/your-username/dev/personal/gdb-mcp/gdb-mcp.py"]
}
}
}
}
测试示例程序
- 编译带有调试符号的示例程序:
gcc -g example.c -o example
- 使用以下提示与LLM客户端交互:
I have a binary at /path/to/example that I need to analyze. I don't have access to the source code. Please help me understand and debug this program using GDB.
1. Start a GDB session and load the binary
2. Use info functions to discover what functions are available
3. For each interesting function:
- Disassemble it to understand its behavior
- Set breakpoints at key instructions
- Run the program and examine variables at breakpoints
4. When the program crashes or exhibits unexpected behavior:
- Get a backtrace
- Examine registers and variables
- Help me understand what might be causing the issue
For each step:
- Explain what we're doing and why
- Show me the disassembly or variable values
- Help me interpret what we're seeing
- Suggest next steps based on our findings