Lldb

mohitmishra786/low-level-dev-skills/skills/debuggers/lldb

作者 mohitmishra786bdc58472fa9f無授權條款253 個星標收錄於 2026年10月9日更新於 2026年10月9日儲存庫3 個月前更新

LLDB debugger skill for C/C++/Swift/Objective-C programs. Use when debugging with LLDB on macOS, FreeBSD, or Linux-clang environments, mapping GDB mental models to LLDB commands, using LLDB in Xcode or VS Code, or debugging Swift/Objective-C. Activates on queries about LLDB commands, GDB to LLDB migration, Apple platform debugging, LLDB Python scripting, or IDE-integrated debugging with clang-built binaries.

AI 產生的概覽

指導 LLDB 除錯工作階段,並將 GDB 指令對應到 LLDB,適用於 C、C++、Swift 與 Objective-C 程式。

功能
此技能提供執行 LLDB 除錯工作階段的說明,包括啟動 LLDB、設定中斷點與監看點、檢視變數、記憶體與暫存器,以及管理執行緒。內容包含 GDB 到 LLDB 的指令對照表、Apple/macOS 相關內容(例如 Objective-C 物件列印與 image lookup)、VS Code CodeLLDB 啟動設定,以及 LLDB Python 指令碼範例。它也指向一個包含更完整 GDB-LLDB 指令對照的參考檔案。
適用情境
適用於使用 LLDB 除錯 C、C++、Swift 或 Objective-C 程式,尤其是在 macOS、FreeBSD 或採用 clang 的 Linux 環境。也適合將既有的 GDB 知識轉換為 LLDB 指令、除錯 Apple 平台程式碼,或在 Xcode 或 VS Code 中設定 LLDB。
執行需求
不隨附指令碼,僅為說明文件。使用所述工作流程需要 LLDB 除錯器與含除錯資訊的已編譯二進位檔;VS Code 部分假定已安裝 CodeLLDB 擴充套件。

LLDB

Purpose

Guide agents through LLDB sessions and map existing GDB knowledge to LLDB. Covers command differences, Apple specifics, Python scripting, and IDE integration.

Triggers

  • "I'm on macOS and need to debug a C++ program"
  • "How does LLDB differ from GDB?"
  • "How do I do [GDB command] in LLDB?"
  • "LLDB shows <unavailable> for variables"
  • "How do I use LLDB in VS Code?"
  • "How do I write an LLDB Python script?"

Workflow

1. Start LLDB

bash
lldb ./prog                         # load binarylldb ./prog -- arg1 arg2            # with argumentslldb -p 12345                       # attach to PIDlldb -c core.1234                   # load core dumplldb ./prog core.1234               # binary + core

2. GDB → LLDB command map

Source: https://lldb.llvm.org/use/map.html

GDBLLDBNotes
run [args]process launch [args] / r
continueprocess continue / c
nextthread step-over / n
stepthread step-in / s
nextithread step-inst-over / ni
stepithread step-inst / si
finishthread step-out / finish
break mainbreakpoint set -n main / b main
break file.c:42breakpoint set -f file.c -l 42 / b file.c:42
break *0x400abcbreakpoint set -a 0x400abc / b -a 0x400abc
watch xwatchpoint set variable x / wa s v x
print xframe variable x / p x
print/x xp/x x
info localsframe variable / fr v
info argsframe variable --arguments
backtracethread backtrace / bt
frame Nframe select N / f N
info threadsthread list
thread Nthread select N
thread apply all btthread backtrace all
x/10wx addrmemory read -s4 -fx -c10 addr / x/10xw addr
set var = 42expression var = 42 / expr var = 42
quitquit / q

3. Breakpoints

lldb
# By nameb mainbreakpoint set --name foobreakpoint set --name foo --condition 'x > 0'
# By file:lineb file.c:42breakpoint set --file file.c --line 42
# By addressb -a 0x100003f20
# By regexbreakpoint set --func-regex '^MyClass::'
# Listbreakpoint list / br l
# Deletebreakpoint delete 2
# Disable/enablebreakpoint disable 1breakpoint enable 1
# Commands on hitbreakpoint command add 1  > p x  > continue  > DONE

4. Inspect state

lldb
# Print variablep xframe variable xp *ptrp arr[0]
# Print expressionexpression x * 2 + 1expr (int)sqrt(9.0)
# All localsframe variablefr v -a          # include arguments
# Registersregister readregister read rip rsp
# Memorymemory read --size 4 --format x --count 10 0x7fff0000x/10xw 0x7fff0000          # GDB-compatible syntax
# Type infoimage lookup --type MyClasstype lookup MyClass

5. Watchpoints

lldb
watchpoint set variable x           # write watchpointwatchpoint set variable -w read x   # read watchpointwatchpoint set variable -w read_write xwatchpoint set expression -- &x     # by address
watchpoint listwatchpoint delete 1

6. Threads

lldb
thread listthread select 3thread backtrace allthread backtrace --count 5           # limit depth
# Per-thread steppingthread step-over                     # step this thread only

7. macOS / Apple specifics

lldb
# Symbol lookup in shared cacheimage lookup --address 0x18ab12345image lookup --name objc_msgSend
# Objective-C method breakpointb "-[NSArray objectAtIndex:]"b "+[NSString stringWithFormat:]"
# Inspect Objective-C objectpo myObject                          # print-object (calls -description)po [arr count]
# Show loaded librariesimage listimage list -b                        # brief (names only)

8. VS Code integration

Install the CodeLLDB extension. .vscode/launch.json:

json
{  "version": "0.2.0",  "configurations": [    {      "name": "Debug (lldb)",      "type": "lldb",      "request": "launch",      "program": "${workspaceFolder}/build/prog",      "args": [],      "cwd": "${workspaceFolder}",      "preLaunchTask": "build"    }  ]}

9. LLDB Python scripting

python
import lldb
def print_all_threads(debugger, command, result, internal_dict):    target = debugger.GetSelectedTarget()    process = target.GetProcess()    for thread in process:        print(f"Thread {thread.GetIndexID()}: {thread.GetName()}")        for frame in thread:            print(f"  {frame}")
def __lldb_init_module(debugger, internal_dict):    debugger.HandleCommand('command script add -f myscript.print_all_threads pthreads')

Load: command script import /path/to/myscript.py

For a full GDB↔LLDB command map, see references/gdb-lldb-map.md [blocked].

Related skills

  • Use skills/debuggers/gdb for GDB workflows
  • Use skills/debuggers/core-dumps for core dump analysis
  • Use skills/compilers/clang for building with debug info

來源與署名

來源:mohitmishra786/low-level-dev-skills位於skills/debuggers/lldb提交bdc5847

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架