LLDB调试服务器

LLDB MCP服务器是一个基于模型上下文协议(MCP)的调试服务器,通过40种专用工具向AI助手提供LLDB调试能力,支持C/C++应用的AI驱动交互式调试。

  • by FYTJ
  • Python
  • 本地部署
  • 4 星标
  • 更新于
在 GitHub 查看 FYTJ/lldb-mcp-server

使用说明

LLDB MCP服务器

语言: 英语 | 中文

概述

LLDB MCP Server是一个基于 模型上下文协议(MCP)。它通过40个专用工具向Claude Code和Claude Desktop等AI助手展示LLDB调试功能,实现了C/C++应用程序的AI驱动交互式调试。

核心架构: 多会话设计,其中每个调试会话都是隔离的 SBDebugger, SBTarget,以及 SBProcess 实例,支持并发调试工作流。

使用案例:

  • 使用Claude Code/Claude Desktop进行人工智能辅助调试
  • 自动调试脚本和工作流
  • 崩溃分析和安全漏洞检测
  • 远程调试和核心转储分析

关键能力:

  • 🔧 40调试工具:会话管理、断点、执行控制、内存操作、安全分析等
  • 🔄 多会话支持:同时运行多个独立的调试会话
  • 📊 事件驱动架构:状态更改、断点命中、stdout/stderr的非阻塞事件收集
  • 🛡️ 安全分析:碰撞可利用性分类和危险功能检测
  • 📝 会话录制:自动记录所有命令并输出时间戳
  • 💻 跨平台:支持macOS(英特尔和苹果Silicon)、Linux(Ubuntu、Fedora、Arch)和Windows(实验版)

文档

  • 特性 -40种工具和详细功能的完整列表
  • 配置 -Claude Code、Claude Desktop、Cursor和Codex的详细配置
  • 使用指南 -使用示例、Claude Code Skill集成和测试程序
  • 故障排除 -所有平台的常见问题和解决方案
  • Linux安装 -详细的Linux安装指南
  • Windows安装 -详细的Windows安装指南

先决条件

系统要求

  • 操作系统:macOS(英特尔或苹果Silicon)、Linux(Ubuntu 22.04+、Fedora 38+、Arch Linux)或Windows(10+)
  • LLDB 使用Python绑定(建议使用14+、18+版本)
  • Python 3.10+

平台特定要求

macOS:

Linux:

  • 包管理器:apt(Ubuntu/Debian)、dnf(Fedora/RHEL)或pacman(Arch)
  • LLDB:通过安装 sudo apt install lldb-18 python3-lldb-18 (Ubuntu)或同等版本

窗户:

  • 巧克力 (推荐)或另一个包含Python绑定的LLVM/LDB发行版
  • LLVM/LLDB:通过安装 choco install -y llvm python

快速开始

1.安装依赖项

macOS

# Install Homebrew LLVM (includes LLDB)
brew install llvm

# Install uv (provides uvx command)
curl -LsSf https://astral.sh/uv/install.sh | sh

# Add Homebrew LLVM to PATH (add to ~/.zshrc)
export PATH="$(brew --prefix llvm)/bin:$PATH"

# Reload shell configuration
source ~/.zshrc
hash -r

# Verify LLDB installation
which lldb
lldb --version

Linux(Ubuntu/Debian)

# Install LLDB with Python bindings
sudo apt update
sudo apt install lldb-19 python3-lldb-19

# Install uv (provides uvx command)
curl -LsSf https://astral.sh/uv/install.sh | sh

# Find LLDB Python path
lldb-19 -P
# Example output: /usr/lib/llvm-19/lib/python3.12/site-packages

# Verify Python 3.12 is available (required for LLDB-19 bindings)
which python3.12
python3.12 --version

# Test LLDB Python bindings
python3.12 -c "import sys; sys.path.insert(0, '$(/usr/bin/lldb-19 -P)'); import lldb; print('LLDB Python bindings OK')"

⚠️ 关键-Linux Python版本匹配:

  • LLDB Python绑定是为特定Python版本编译的 (例如LLDB-19→ Python 3.12)
  • uvx 默认为系统的默认Python (通常来自linuxbrew的3.14)
  • 你必须强制uvx使用匹配的Python版本 和 --python /usr/bin/python3.12
  • 始终设置 LLDB_PYTHON_PATH 输出 lldb-19 -P
  • Python版本不匹配的原因 cannot import name '_lldb' 错误

对于其他Linux发行版(Fedora、Arch等),请参阅 Linux安装指南.

窗户(巧克力)

# Install LLVM (includes LLDB) and Python
choco install -y llvm python

# Verify LLDB and Python
lldb --version
python --version

# Verify LLDB Python bindings
python -c "import lldb; print('LLDB Python bindings OK')"

# Install lldb-mcp-server
pip install -U lldb-mcp-server
lldb-mcp-server --help

如果 import lldb 失败,请参阅 Windows安装指南 如何设置 LLDB_PYTHON_PATH.

2.配置MCP

选择您的IDE并按照配置说明进行操作:

克劳德代码

macOS-全局配置(推荐):

英特尔(x86_64):

claude mcp add-json --scope user lldb-debugger '{
  "type": "stdio",
  "command": "uvx",
  "args": ["--python", "/usr/local/opt/python@3.13/bin/python3.13", "lldb-mcp-server"],
  "env": {
    "LLDB_MCP_ALLOW_LAUNCH": "1",
    "LLDB_MCP_ALLOW_ATTACH": "1",
    "PYTHONPATH": "/usr/local/opt/llvm/lib/python3.13/site-packages"
  }
}'

苹果硅(arm64):

claude mcp add-json --scope user lldb-debugger '{
  "type": "stdio",
  "command": "uvx",
  "args": ["--python", "/opt/homebrew/opt/python@3.13/bin/python3.13", "lldb-mcp-server"],
  "env": {
    "LLDB_MCP_ALLOW_LAUNCH": "1",
    "LLDB_MCP_ALLOW_ATTACH": "1",
    "PYTHONPATH": "/opt/homebrew/opt/llvm/lib/python3.13/site-packages"
  }
}'

Linux:

# First, get your LLDB Python path
LLDB_PATH=$(/usr/bin/lldb-19 -P)
echo "LLDB Python path: $LLDB_PATH"

# Then add MCP server configuration
claude mcp add-json --scope user lldb-debugger '{
  "type": "stdio",
  "command": "uvx",
  "args": ["--python", "/usr/bin/python3.12", "-q", "lldb-mcp-server", "--transport", "stdio"],
  "env": {
    "LLDB_MCP_ALLOW_LAUNCH": "1",
    "LLDB_MCP_ALLOW_ATTACH": "1",
    "LLDB_PYTHON_PATH": "'"$LLDB_PATH"'"
  }
}'

重要提示:

  • 替换 /usr/bin/python3.12 如果不同,请使用系统的Python 3.12路径
  • 这 --python 参数必须与编译LLDB的Python版本匹配
  • 检查LLDB的Python版本: lldb-19 -P | grep python3.
  • 如果您有LLDB-18,请使用 lldb-18 -P 并相应地调整Python版本

克劳德桌面版

macOS: 编辑 ~/Library/Application Support/Claude/claude_desktop_config.json

Linux: 编辑 ~/.config/claude/claude_desktop_config.json

看 配置指南 查看详细的配置示例。

光标IDE

创建 .cursor/mcp.json 在您的项目根目录中或 ~/.cursor/mcp.json 用于全局配置。

看 配置指南 针对特定平台的示例。

食品法典委员会(OpenAI)

使用 codex mcp add 命令或编辑 ~/.codex/config.toml.

看 配置指南 详细说明。

3.开始使用

所有平台: 无需手动安装!当您使用配置MCP服务器时 uvx,它会自动安装和管理软件包。

只需配置IDE并启动Claude Code或重新启动Claude Desktop。

用法示例

基本调试

User: "Debug the program at /path/to/my/app"

Claude automatically:
1. Creates a debugging session
2. Loads the binary
3. Sets breakpoints
4. Launches the process
5. Analyzes execution

碰撞分析

User: "This program crashed, help me analyze the cause"

Claude will:
1. Analyze the crash event
2. Show crash stack trace
3. Check register state
4. Detect dangerous functions
5. Provide repair suggestions

有关更多示例,请参阅 使用指南.

环境变量

变量 目的 默认值
LLDB_MCP_ALLOW_LAUNCH=1 允许启动新进程 已禁用
LLDB_MCP_ALLOW_ATTACH=1 允许附加到现有进程 已禁用
LLDB_PYTHON_PATH 覆盖LLDB Python模块路径 自动检测

故障排除

macOS: No module named lldb

# Verify LLDB is from Homebrew
which lldb

# Add to PATH
echo 'export PATH="$(brew --prefix llvm)/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
hash -r

Linux: cannot import name '_lldb'

当uvx使用与LLDB编译时不同的Python版本时,会发生此错误。

# Check LLDB's Python version
lldb-19 -P
# Example: /usr/lib/llvm-19/lib/python3.12/site-packages (Python 3.12)

# Check uvx's default Python
uvx --python-preference system python --version
# If this shows 3.14, but LLDB needs 3.12, that's the problem

# Solution: Force uvx to use matching Python version
# Update your MCP config to include: "--python", "/usr/bin/python3.12"
# See Linux configuration section above for complete example

有关更多问题和解决方案,请参阅 故障排除指南.

许可证

此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。

链接