LLDB CLI 技能
使用此 CLI 工具运行结构化的 LLDB 调试工作流,并输出 JSON 格式结果。
能力
- 从可执行文件路径创建调试目标
- 启动进程或通过 PID/进程名附加
- 管理断点(设置/列出/删除/启用/禁用)
- 检查线程、帧、局部变量和回溯
- 在当前帧中评估表达式
- 读取/查找进程内存
- 加载核心转储
- 交互式 REPL,具有持久会话状态
- 为 AI/编辑器客户端提供的正式 stdio Debug Adapter 协议服务器
快速命令
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 协议
当 AI 客户端需要真正的调试适配器生命周期,而不是分别调用单独的 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 的异步中断。如果代理需要在调试对象运行时更改断点,适配器会首先中断并等待停止状态,然后再修改 LLDB 断点;如果目标没有及时停止,请在显式的 pause/stopped 周期后重试。
对于在调试器内部启动时停止或着色器 JIT 断点处停止的 GUI 应用程序,launch 和 attach 接受非标准布尔参数 autoContinueInternalBreakpoints。仅当这些内部停止对任务来说是噪声时才启用它;适配器在自动继续之前会发出 output 事件。对于特定目标的噪声,建议通过内联 stopRules 或外部 stopRuleProfile/--profile JSON 文件使用结构化停止规则。规则可以按 reason、module、function 和/或 regex 进行匹配,然后要么 stop(带有清晰的 cliAnythingStop.origin 元数据),要么自动 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
代理使用说明
- 对于所有自动化流程,建议使用
--json。 - 默认情况下,非 REPL 的单独调用共享一个持久会话守护进程。
- 使用
--session-file PATH或CLI_ANYTHING_LLDB_SESSION_FILE为任务固定显式会话。 - 完成后运行
cli-anything-lldb --json session close,以便分离附加的进程并清理启动的调试对象。 - 当人类般的交互式 shell 更方便时使用 REPL,而不是因为持久性需要。
- 未解决的 CLI 断点默认会失败;仅当预期未来会加载模块/符号时传递
--allow-pending。 - DAP 未解决的断点使用协议语义:在解决之前为
verified: false。 - DAP
continue对于长时间运行的 GUI 进程是非阻塞的,DAPpause使用异步中断。 - 在活动 continue 期间的 DAP 断点更改会首先中断并等待停止状态后再修改 LLDB。
- 使用 DAP 停止规则配置文件处理特定应用程序的内部陷阱;配置文件更改后重启并重新附加/重新启动。
memory find使用分块扫描,每次调用上限为 1 MiB。- 在进程或核心命令之前调用
target create。 - 期望结构化错误:
{"error": "...", "type": "..."}