rr-mcp
用于编排多进程的MCP(模型上下文协议)服务器 rr 调试会话。
概述
rr-mcp使AI代理(如Claude)能够使用rr的记录和回放功能调试多进程应用程序。它提供:
- 48个专业调试工具 具有丰富的描述和使用背景
- 动态MCP资源 暴露实时会话状态(
rr://sessions/{id}) - 并发重播会话 用于同时调试不同进程
- 完全反向执行 --在两个方向上前进、继续和完成
- 多流程支持 --调试执行进程(
pid)或者没有执行子系统的分叉(fork_pid) - 条件断点和临时断点、观察点和捕捉点(投掷/捕捉/系统调用/信号)
对rr调试不熟悉? 看 RR_DEBUGING_GUIDE.md 了解概念、工作流程和最佳实践。
需求
- Linux(rr仅在Linux上运行)
- Python 3.11+
- rr 已安装并位于PATH中
- 要调试的rr记录
安装
克劳德代码
claude mcp add rr-mcp -- uvx rr-mcp其他MCP客户端
任何支持stdio服务器的MCP客户端都可以运行 uvx rr-mcp (或 pipx run rr-mcp).
从源代码安装
为了发展 (建议-更改后不需要重新安装):
git clone https://github.com/jnjaeschke/rr-mcp && cd rr-mcp
uv sync # Install dependencies
# Configure Claude Code to run from source
claude mcp add rr-mcp -- uv run --directory /absolute/path/to/rr-mcp rr-mcp用于生产用途:
git clone https://github.com/jnjaeschke/rr-mcp && cd rr-mcp
uv tool install .
# Configure Claude Code
claude mcp add rr-mcp -- rr-mcp对于其他MCP客户端,请使用相应的命令(uv run ... 发展或 rr-mcp 用于生产)。
用法
安装后,当您启动MCP客户端时,服务器会自动加载。通过询问以下问题来验证它是否正常工作:
“列出可用的rr跟踪”
克劳德将使用 traces_list 在您的 _RR_TRACE_DIR (默认为 ~/.local/share/rr).
MCP资源
rr://guide--调试指南,包括工作流程、工具选择建议和常见陷阱rr://traces--可用录制的动态列表rr://sessions/{id}--当前会话状态(位置、地点)rr://sessions/{id}/backtrace--会话的实时通话堆栈
工具
48个调试工具按类别组织。每个工具都包含丰富的描述,包括使用上下文、参数文档、返回值格式规范和工作流程指导。
跟踪管理(3个工具)
| 工具 | 说明 |
|---|---|
traces_list | 列出系统上所有可用的rr记录 |
trace_info | 获取有关跟踪的元数据(创建时间、二进制文件等) |
trace_processes | 在跟踪中列出带有PID和exec信息的进程 |
会话生命周期(3个工具)
| 工具 | 说明 |
|---|---|
session_create | 为特定进程创建重播会话。支持 pid (执行流程)和 fork_pid (分叉时没有高管子女) |
session_list | 列出所有活动的重播会话 |
session_close | 结束会话并释放其资源 |
执行控制(14个工具)
| 工具 | 说明 |
|---|---|
continue / reverse_continue | 向前/向后运行,直到断点、信号或结束 |
step / reverse_step | 按源代码行逐步转换为函数 |
next / reverse_next | 按源代码行,按函数 |
finish / reverse_finish | 运行到当前功能的结束/开始 |
stepi / reverse_stepi | 根据机器指令,进入通话 |
nexti / reverse_nexti | 通过机器指令、电话进行逐步操作 |
run_to_event | 跳转到特定的rr事件编号 |
interrupt | 停止正在运行的程序 |
断点和观察点(7个工具)
| 工具 | 说明 |
|---|---|
breakpoint_set | 按函数、文件、行或地址设置断点。支持条件(condition)以及临时断点。挂起的断点会自动为卸载的代码启用 |
breakpoint_delete | 按数字删除断点 |
breakpoint_list | 列出所有断点及其状态 |
breakpoint_enable / breakpoint_disable | 打开/关闭断点 |
watchpoint_set | 内存中断写入、读取或访问表达式 |
catch | C的捕获点++ throw/catch、系统调用(可选按名称过滤)和信号 |
检查(14个工具)
| 工具 | 说明 |
|---|---|
backtrace | 带可选功能的调用堆栈 full 模式(包括每帧的局部值) |
print | 在当前上下文中计算表达式 |
locals | 当前帧中的局部变量 |
args | 跨堆栈帧的函数参数 |
frame_select | 切换到其他堆栈帧 |
registers | CPU寄存器(gp_only 将过滤器标记为通用寄存器) |
examine_memory | 格式化内存转储(如GDB x 命令) |
when | 当前rr事件和滴答位置 |
threads_list / thread_select | 列出线程并在线程之间切换 |
checkpoint_create | 保存执行位置,以便稍后立即返回 |
checkpoint_restore | 跳转回已保存的检查点 |
checkpoint_delete / checkpoint_list | 管理检查点 |
信号处理和内存搜索(2个工具)
| 工具 | 说明 |
|---|---|
handle_signal | 配置GDB如何处理信号(停止、通过、打印) |
find_in_memory | 在内存范围内搜索字节模式 |
源代码和高级(5个工具)
| 工具 | 说明 |
|---|---|
source_list | 用上下文线显示位置周围的源代码 |
source_path | 将文件名解析为其完整路径 |
source_files | 列出程序中的所有源文件 |
info | GDB info 子命令(proc映射、共享库、符号、类型、信号) |
gdb_raw | 执行任意GDB命令(escape舱口) |
所有工具都包含克劳德可见的详细描述。请参阅中的工具定义 src/rr_mcp/server.py.
示例会话
Agent: Let me list the available traces.
[calls traces_list]
Agent: I see firefox-0. Let me check what processes are in it.
[calls trace_processes with trace="firefox-0"]
Agent: The main process is PID 12345, and there's a content process
PID 12350 that crashed with SIGSEGV. Let me debug the content
process — it forked without exec, so I need fork_pid.
[calls session_create with trace="firefox-0", fork_pid=12350]
Agent: Let me see where we are and get the crash backtrace.
[calls backtrace with session_id="abc123"]
Agent: Frame #3 in HandleEvent dereferences a null mWidget pointer.
Let me see the source code around that line.
[calls source_list with location="HandleEvent.cpp:142"]
Agent: I'll set a watchpoint on mWidget to find where it was set to null,
then reverse-continue to catch the moment it happened.
[calls watchpoint_set with expression="this->mWidget", access_type="write"]
[calls reverse_continue]
Agent: The watchpoint triggered at event 84021 in Widget::Destroy().
Let me check who called this.
[calls backtrace]
Agent: I'll save this position as a checkpoint so I can return here later,
then continue investigating the caller.
[calls checkpoint_create]发展
# Install dev dependencies
uv sync --all-extras
# Run tests (parallel execution with pytest-xdist)
uv run pytest -n auto
# Run tests (sequential)
uv run pytest
# Run linter
uv run ruff check src/ tests/
# Run type checker
uv run mypy src/许可证
麻省理工学院
