LLDB 命令列技能
使用此命令列來執行結構化的 LLDB 偵錯工作流程,並輸出 JSON。
能力
- 從可執行檔案路徑建立偵錯目標
- 啟動程序或依 PID/名稱附加程序
- 管理中斷點(設定/列出/刪除/啟用/停用)
- 檢查執行緒、堆疊框架、區域變數與回溯追蹤
- 在當前框架中評估表達式
- 讀取/搜尋處理程序記憶體
- 載入核心傾印
- 具有持久化會話狀態的互動式 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 用戶端需要真正的偵錯配接器生命週期,而不是分別執行個別 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 循環之後重試。
對於因偵錯器內部啟動或 shader-JIT 中斷點而停止的 GUI 應用程式,launch 和 attach 接受非標準的布林參數 autoContinueInternalBreakpoints。僅在這些內部停止對任務來說是噪音時才啟用它;配接器會在自動繼續之前發出 output 事件。對於目標特定的噪音,建議透過內聯 stopRules 或外部 stopRuleProfile/--profile JSON 檔案使用結構化停止規則。規則可以根據 reason、module、function 和/或 regex 進行匹配,然後 stop(附帶清楚的 cliAnythingStop.origin 元資料)或自動 continue。對於像 C4D 這樣的應用程式,請使用設定檔,以便其 NVIDIA shader-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。 - 對於長時間執行的 GUI 處理程序,DAP
continue是非阻塞的,DAPpause使用非同步中斷。 - 在活動的 continue 期間更改 DAP 中斷點時,會先中斷並等待暫停狀態,然後才修改 LLDB。
- 使用 DAP 停止規則設定檔來處理應用程式特定的內部陷阱;更改設定檔後,重新啟動並重新附加/重新啟動。
memory find使用分段掃描,每次調用上限為 1 MiB。- 在執行 process 或 core 指令之前,請先呼叫
target create。 - 預期結構化錯誤:
{"error": "...", "type": "..."}