mcpField
C
cli-anything-lldb

cli-anything-lldb

github.com/hkuds开发57.6k413 次安装5 周前更新
代码仓库

关于 cli-anything-lldb

面向 Agent 和编辑器客户端的 LLDB 调试 CLI 技能,提供结构化调试命令。它结合 JSON 输出、持久会话和 stdio Debug Adapter Protocol 服务端。

主要功能

  1. 01通过 JSON 控制目标和进程
  2. 02断点与线程检查
  3. 03帧、表达式和内存工具
  4. 04加载 Core dump
  5. 05支持持久状态的交互式 REPL
  6. 06stdio Debug Adapter Protocol 服务端

适用场景

  1. 01自动化调试可执行文件
  2. 02附加到运行中的进程
  3. 03检查崩溃和 Core dump
  4. 04通过 DAP 连接 AI 客户端

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/hkuds/cli-anything --skill cli-anything-lldb

安装后在 Claude Code 中输入/cli-anything-lldb确认已加载。

详细介绍

LLDB CLI 技能

使用此 CLI 以 JSON 输出运行结构化的 LLDB 调试工作流。

功能

  • 从可执行文件路径创建调试目标
  • 启动进程或通过 pid/name 附加
  • 管理断点(设置/列出/删除/启用/禁用)
  • 检查线程、帧、局部变量和回溯
  • 在当前帧中求值表达式
  • 读取/查找进程内存
  • 加载核心转储
  • 具有持久会话状态的交互式 REPL
  • 面向 AI/编辑器客户端的正式 stdio Debug Adapter Protocol 服务

快速命令

cli-anything-lldb --json target create --exe /path/to/exe
cli-anything-lldb --json process launch --arg foo --arg bar
cli-anything-lldb --json breakpoint set --function main
cli-anything-lldb --json breakpoint set --function PluginEntry --allow-pending
cli-anything-lldb --json process continue
cli-anything-lldb --json process interrupt
cli-anything-lldb --json thread backtrace --limit 20
cli-anything-lldb --json frame locals
cli-anything-lldb --json expr "myVar"
cli-anything-lldb --json memory read --address 0x1000 --size 64
cli-anything-lldb --json session close

Debug Adapter Protocol

当 AI 客户端需要真正的调试适配器生命周期,而不是通过 shell 调用单独的 CLI 命令时,请使用 DAP 入口点:

cli-anything-lldb-dap
cli-anything-lldb-dap --profile /path/to/stop-rules.json

或:

cli-anything-lldb dap
cli-anything-lldb dap --profile /path/to/stop-rules.json

DAP 服务使用 stdio Content-Length 帧通信,并且必须独占 stdout。不要在其周围向 stdout 打印日志。支持的请求包括 initialize、launch、attach、configurationDone、setBreakpoints、setFunctionBreakpoints、threads、stackTrace、scopes、variables、setVariable、evaluate、continue、pause、next、stepIn、stepOut、source、loadedSources、readMemory、modules、exceptionInfo、disassemble 和 disconnect。

DAP 变量可以为结构体/类/数组暴露子引用。仅在停止时使用 setVariable;LLDB 可能会拒绝对被优化掉或只读的值进行写入。

对于长时间运行的 GUI 被调试程序,从客户端角度看,DAP continue 是非阻塞的:适配器先发送响应和 continued 事件,然后在后台线程上等待 LLDB。DAP pause 使用 LLDB 异步中断。如果 Agent 需要在我们程序运行时更改断点,适配器会先中断并等待进入停止状态,然后再修改 LLDB 断点;如果目标未能及时停止,请在显式 pause/stopped 周期后重试。

对于在调试器内部启动断点或着色器 JIT 断点处停止的 GUI 应用,launch 和 attach 接受非标准布尔参数 autoContinueInternalBreakpoints。仅当这些内部停止对任务而言是噪声时才启用它;适配器在自动继续之前会发出 output 事件。对于特定目标的噪声,优先通过内联 stopRules 或外部 stopRuleProfile/--profile JSON 文件使用结构化停止规则。规则可以按 reason、module、function 和/或 regex 匹配,然后要么以清晰的 cliAnythingStop.origin 元数据 stop,要么自动 continue。对于诸如 C4D 之类的应用,请使用配置文件,使其 NVIDIA 着色器 JIT/启动陷阱位于通用适配器之外。

DAP stopped 事件包含 body.cliAnythingStop.origin:manualPause 表示客户端暂停请求,internalTrap 表示匹配到内部规则,debuggee 表示普通程序停止。现有的 cli-anything-lldb-dap 进程不会热加载新代码或配置文件内容;在期望新规则生效之前,请重启适配器并重新附加或重新启动。

命令组

target
cli-anything-lldb --json target create --exe /path/to/exe [--arch x86_64]
cli-anything-lldb --json target info
process
cli-anything-lldb --json process launch [--arg ARG ...] [--env KEY=VALUE ...] [--cwd DIR] [--stop-at-entry]
cli-anything-lldb --json process attach --pid 1234
cli-anything-lldb --json process attach --name myapp --wait-for
cli-anything-lldb --json process continue
cli-anything-lldb --json process interrupt
cli-anything-lldb --json process detach
cli-anything-lldb --json process info
breakpoint
cli-anything-lldb --json breakpoint set --function main
cli-anything-lldb --json breakpoint set --file main.c --line 42 --condition "i > 10"
cli-anything-lldb --json breakpoint set --function LateLoadedSymbol --allow-pending
cli-anything-lldb --json breakpoint list
cli-anything-lldb --json breakpoint delete --id 1
cli-anything-lldb --json breakpoint enable --id 1
cli-anything-lldb --json breakpoint disable --id 1
thread / frame / step
cli-anything-lldb --json thread list
cli-anything-lldb --json thread select --id 11111
cli-anything-lldb --json thread backtrace --limit 50
cli-anything-lldb --json frame select --index 0
cli-anything-lldb --json frame info
cli-anything-lldb --json frame locals
cli-anything-lldb --json step over
cli-anything-lldb --json step into
cli-anything-lldb --json step out
expr / memory / core
cli-anything-lldb --json expr "argc"
cli-anything-lldb --json memory read --address 0x1000 --size 128
cli-anything-lldb --json memory find "needle" --start 0x1000 --size 4096
cli-anything-lldb --json core load --path /path/to/core

Agent 使用说明

  • 对于所有自动化流程,优先使用 --json。
  • 默认情况下,非 REPL 的独立调用会共享一个持久会话守护进程。
  • 使用 --session-file PATH 或 CLI_ANYTHING_LLDB_SESSION_FILE 为任务固定一个显式会话。
  • 完成后运行 cli-anything-lldb --json session close,以便分离已附加的进程并清理已启动的调试对象。
  • 当类人交互式 shell 更方便时使用 REPL,而不是因为持久化需要它。
  • 未解析的 CLI 断点默认会失败;仅当预期未来会加载模块/符号时才传递 --allow-pending。
  • DAP 未解析的断点使用协议语义:在解析前为 verified: false。
  • 对于长时间运行的 GUI 进程,DAP continue 是非阻塞的,而 DAP pause 使用异步中断。
  • 在 active continue 期间的 DAP 断点更改会先中断并等待停止状态,然后再修改 LLDB。
  • 对于应用特定的内部陷阱,使用 DAP 停止规则配置文件;配置文件更改后重新启动并重新附加/重新启动。
  • memory find 使用分块扫描,每次调用上限为 1 MiB。
  • 在进程或核心命令之前调用 target create。
  • 预期结构化错误:{"error": "...", "type": "..."}

评论

支持 Markdown