aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands
AgeCommit message (Collapse)AuthorFilesLines
2025-09-16[clang] Initialize the file system explicitly (#158381)Jan Svoboda1-1/+3
This PR is a part of the effort to make the VFS used in the compiler more explicit and consistent. Instead of creating the VFS deep within the compiler (in `CompilerInstance::createFileManager()`), clients are now required to explicitly call `CompilerInstance::createVirtualFileSystem()` and provide the base VFS from the outside. This PR also helps in breaking up the dependency cycle where creating a properly configured `DiagnosticsEngine` requires a properly configured VFS, but creating properly configuring a VFS requires the `DiagnosticsEngine`. Both `CompilerInstance::create{FileManager,Diagnostics}()` now just use the VFS already in `CompilerInstance` instead of taking one as a parameter, making the VFS consistent across the instance sub-object.
2025-09-15[lldb][TypeSystem] Enable colored AST dump (#86159)Michael Buch1-3/+6
This patch causes the various AST dump commands (`target modules dump ast`/`target dump typesystem`) to be color-highlighted. I added a `bool show_color` parameter to `SymbolFile::DumpClangAST` and `TypeSystem::Dump`. In `TypeSystemClang` I temporarily sets the `getShowColors` flag on the owned Clang AST (using an RAII helper) for the duration of the AST dump. We use `Debugger::GetUseColors` to decide whether to color the AST dump.
2025-09-10[lldb] Pass execution context to CompilerType::GetByteSize - in ↵Dave Lee1-3/+4
CommandObjectMemoryRead (NFC) (#157750) Some type systems require an execution context be available when working with types (ex: Swift). This fixes `memory read --type` to support such type systems, by passing in an execution context to `GetByteSize()`, instead of passing null. rdar://158968545
2025-09-05[lldb] Add more command option mnemonics (#156987)Jonas Devlieghere1-60/+64
Add a few more command option mnemonics.
2025-09-04[lldb] Correct style of error messages (#156774)Jonas Devlieghere11-49/+49
The LLVM Style Guide says the following about error and warning messages [1]: > [T]o match error message styles commonly produced by other tools, > start the first sentence with a lowercase letter, and finish the last > sentence without a period, if it would end in one otherwise. I often provide this feedback during code review, but we still have a bunch of places where we have inconsistent error message, which bothers me as a user. This PR identifies a handful of those places and updates the messages to be consistent. [1] https://llvm.org/docs/CodingStandards.html#error-and-warning-messages
2025-09-04[lldb] Reflow descriptions in source/Commands/Options.td (#156981)Jonas Devlieghere1-91/+73
Reflow command descriptions butchered by clang-format.
2025-09-04[lldb] Add more command option mnemonics (#155705)Jonas Devlieghere1-129/+152
Add a bunch of mnemonics to the command options now that they're highlighted in the help output. This uncovered two issues: - We had an instance where we weren't applying the ANSI formatting. - We had a place where we were now incorrectly computing the column width. Both are fixed by this PR.
2025-09-02[lldb] Format source/Commands/Options.td (#156517)Jonas Devlieghere1-1147/+2005
Format the command options tablegen file, which was created before clang-format added support for tablegen. Small changes lead to lots of reformatting changes which makes the diffs hard to review.
2025-08-29[lldb] Adjust ProtocolServer connection defaults. (#155714)John Harrison1-8/+7
This adjusts the ProtocolServer command to default to create a new connection listening on `localhost:0` and adds a new `ServerMetadata` details to `~/.lldb/mcp/lldb-<pid>.json` to record information about the current MCP server. This can be consumed by the lldb-mcp binary to establish a connection from an LLM client. --------- Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
2025-08-29[lldb] Fix some spelling and grammatical issues in Commands/Options.td (#156121)Jonas Devlieghere1-34/+59
Fixes whitespace, spelling and grammatical issues in the command options. I also formatted the affected options with clang-format and reflowed the description where necessary.
2025-08-29[lldb] Add a simplified syntax for underlying command options (NFC) (#155694)Jonas Devlieghere1-17/+14
This PR updates the tablegen emitter for command options to support a simplified syntax to underline the mnemonic. Previously, you had to write `${ansi.underline}<L>${ansi.normal}`, where `<L>` is the mnemonic. This really hurt the readability of the description. With this PR, you can write `${<L>}` instead.
2025-08-28Stateful variable-location annotations in Disassembler::PrintInstructions() ↵Abdullah Mohammad Amin3-0/+11
(follow-up to #147460) (#152887) **Context** Follow-up to [#147460](https://github.com/llvm/llvm-project/pull/147460), which added the ability to surface register-resident variable locations. This PR moves the annotation logic out of `Instruction::Dump()` and into `Disassembler::PrintInstructions()`, and adds lightweight state tracking so we only print changes at range starts and when variables go out of scope. --- ## What this does While iterating the instructions for a function, we maintain a “live variable map” keyed by `lldb::user_id_t` (the `Variable`’s ID) to remember each variable’s last emitted location string. For each instruction: - **New (or newly visible) variable** → print `name = <location>` once at the start of its DWARF location range, cache it. - **Location changed** (e.g., DWARF range switched to a different register/const) → print the updated mapping. - **Out of scope** (was tracked previously but not found for the current PC) → print `name = <undef>` and drop it. This produces **concise, stateful annotations** that highlight variable lifetime transitions without spamming every line. --- ## Why in `PrintInstructions()`? - Keeps `Instruction` stateless and avoids changing the `Instruction::Dump()` virtual API. - Makes it straightforward to diff state across instructions (`prev → current`) inside the single driver loop. --- ## How it works (high-level) 1. For the current PC, get in-scope variables via `StackFrame::GetInScopeVariableList(/*get_parent=*/true)`. 2. For each `Variable`, query `DWARFExpressionList::GetExpressionEntryAtAddress(func_load_addr, current_pc)` (added in #144238). 3. If the entry exists, call `DumpLocation(..., eDescriptionLevelBrief, abi)` to get a short, ABI-aware location string (e.g., `DW_OP_reg3 RBX → RBX`). 4. Compare against the last emitted location in the live map: - If not present → emit `name = <location>` and record it. - If different → emit updated mapping and record it. 5. After processing current in-scope variables, compute the set difference vs. the previous map and emit `name = <undef>` for any that disappeared. Internally: - We respect file↔load address translation already provided by `DWARFExpressionList`. - We reuse the ABI to map LLVM register numbers to arch register names. --- ## Example output (x86_64, simplified) ``` -> 0x55c6f5f6a140 <+0>: cmpl $0x2, %edi ; argc = RDI, argv = RSI 0x55c6f5f6a143 <+3>: jl 0x55c6f5f6a176 ; <+54> at d_original_example.c:6:3 0x55c6f5f6a145 <+5>: pushq %r15 0x55c6f5f6a147 <+7>: pushq %r14 0x55c6f5f6a149 <+9>: pushq %rbx 0x55c6f5f6a14a <+10>: movq %rsi, %rbx 0x55c6f5f6a14d <+13>: movl %edi, %r14d 0x55c6f5f6a150 <+16>: movl $0x1, %r15d ; argc = R14 0x55c6f5f6a156 <+22>: nopw %cs:(%rax,%rax) ; i = R15, argv = RBX 0x55c6f5f6a160 <+32>: movq (%rbx,%r15,8), %rdi 0x55c6f5f6a164 <+36>: callq 0x55c6f5f6a030 ; symbol stub for: puts 0x55c6f5f6a169 <+41>: incq %r15 0x55c6f5f6a16c <+44>: cmpq %r15, %r14 0x55c6f5f6a16f <+47>: jne 0x55c6f5f6a160 ; <+32> at d_original_example.c:5:10 0x55c6f5f6a171 <+49>: popq %rbx ; i = <undef> 0x55c6f5f6a172 <+50>: popq %r14 ; argv = RSI 0x55c6f5f6a174 <+52>: popq %r15 ; argc = RDI 0x55c6f5f6a176 <+54>: xorl %eax, %eax 0x55c6f5f6a178 <+56>: retq ``` Only transitions are shown: the start of a location, changes, and end-of-lifetime. --- ## Scope & limitations (by design) - Handles **simple locations** first (registers, const-in-register cases surfaced by `DumpLocation`). - **Memory/composite locations** are out of scope for this PR. - Annotations appear **only at range boundaries** (start/change/end) to minimize noise. - Output is **target-independent**; register names come from the target ABI. ## Implementation notes - All annotation printing now happens in `Disassembler::PrintInstructions()`. - Uses `std::unordered_map<lldb::user_id_t, std::string>` as the live map. - No persistent state across calls; the map is rebuilt while walking instruction by instruction. - **No changes** to the `Instruction` interface. --- ## Requested feedback - Placement and wording of the `<undef>` marker. - Whether we should optionally gate this behind a setting (currently always on when disassembling with an `ExecutionContext`). - Preference for immediate inclusion of tests vs. follow-up patch. --- Thanks for reviewing! Happy to adjust behavior/format based on feedback. --------- Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com> Co-authored-by: Adrian Prantl <adrian.prantl@gmail.com>
2025-08-27[lldb] Fix a typo in --one-shot description (NFC) (#155637)Dave Lee1-1/+1
2025-08-26[lldb] Underline short option letters as mnemonics (#153695)Jonas Devlieghere4-15/+35
Whenever an option would use something other than the first letter of the long option as the short option, Jim would capitalized the letter we picked as a mnemonic. This has often been mistaken for a typo and Jim wondered if we should stop doing this. During the discussion, David mentioned how this reminds him of the underline in menu bars when holding down alt. I suggested we do something similar in LLDB by underlying the letter in the description. https://discourse.llvm.org/t/should-we-remove-the-capital-letter-in-option-helps/87816
2025-08-21[lldb] Add flag to "settings show" to include default values (#153233)Dave Lee2-5/+47
Adds a `--defaults`/`-d` flag to `settings show`. This mode will _optionally_ show a setting's default value. In other words, this does not always print a default value for every setting. A default value is not shown when the current value _is_ the default. Note: some setting types do not print empty or invalid values. For these setting types, if the default value is empty or invalid, the same elision logic is applied to printing the default value.
2025-08-19Revert "[lldb] Fix error : unknown error while starting lldb's C/C++ repl ↵Shubham Sandeep Rastogi1-6/+0
(#153560)" This reverts commit 00ffd8b8aa4e8cd3a2fee654d55995918886e874. The change breaks lldb greendragon tests Namely, TestClangREPL.py
2025-08-19[lldb] Fix error : unknown error while starting lldb's C/C++ repl (#153560)Anutosh Bhat1-0/+6
Fixes https://github.com/llvm/llvm-project/issues/153157 The proposed solution has been discussed here (https://github.com/llvm/llvm-project/issues/153157#issue-3313379242) This is what we would be seeing now ``` base) anutosh491@Anutoshs-MacBook-Air bin % ./lldb /Users/anutosh491/work/xeus-cpp/a.out (lldb) target create "/Users/anutosh491/work/xeus-cpp/a.out" Current executable set to '/Users/anutosh491/work/xeus-cpp/a.out' (arm64). (lldb) b main Breakpoint 1: where = a.out`main, address = 0x0000000100003f90 (lldb) r Process 71227 launched: '/Users/anutosh491/work/xeus-cpp/a.out' (arm64) Process 71227 stopped * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 frame #0: 0x0000000100003f90 a.out`main a.out`main: -> 0x100003f90 <+0>: sub sp, sp, #0x10 0x100003f94 <+4>: str wzr, [sp, #0xc] 0x100003f98 <+8>: str w0, [sp, #0x8] 0x100003f9c <+12>: str x1, [sp] (lldb) expression --repl -l c -- 1> 1 + 1 (int) $0 = 2 2> 2 + 2 (int) $1 = 4 ``` ``` base) anutosh491@Anutoshs-MacBook-Air bin % ./lldb /Users/anutosh491/work/xeus-cpp/a.out (lldb) target create "/Users/anutosh491/work/xeus-cpp/a.out" Current executable set to '/Users/anutosh491/work/xeus-cpp/a.out' (arm64). (lldb) b main Breakpoint 1: where = a.out`main, address = 0x0000000100003f90 (lldb) r Process 71355 launched: '/Users/anutosh491/work/xeus-cpp/a.out' (arm64) Process 71355 stopped * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 frame #0: 0x0000000100003f90 a.out`main a.out`main: -> 0x100003f90 <+0>: sub sp, sp, #0x10 0x100003f94 <+4>: str wzr, [sp, #0xc] 0x100003f98 <+8>: str w0, [sp, #0x8] 0x100003f9c <+12>: str x1, [sp] (lldb) expression --repl -l c -- 3 + 3 Warning: trailing input is ignored in --repl mode 1> 1 + 1 (int) $0 = 2 ```
2025-08-15Revert "[lldb] Fallback to expression eval when Dump of variable fails in ↵Dave Lee1-29/+18
dwim-print" (#153824) Reverts llvm/llvm-project#151374 Superseded by https://github.com/llvm/llvm-project/pull/152417
2025-08-15[lldb] Print ValueObject when GetObjectDescription fails (#152417)Dave Lee2-5/+5
This fixes a few bugs, effectively through a fallback to `p` when `po` fails. The motivating bug this fixes is when an error within the compiler causes `po` to fail. Previously when that happened, only its value (typically an object's address) was printed – and problematically, no compiler diagnostics were shown. With this change, compiler diagnostics are shown, _and_ the object is fully printed (ie `p`). Another bug this fixes is when `po` is used on a type that doesn't provide an object description (such as a struct). Again, the normal `ValueObject` printing is used. Additionally, this also improves how lldb handles an object description method that fails in some way. Now an error will be shown (it wasn't before), and the value will be printed normally.
2025-08-11[lldb][NFC] Fix `help breakpoint set` typo. (#152981)b109021181-1/+1
2025-07-31[lldb] Add support for displaying `__float128` variables (#98369)beetrees1-0/+2
2025-07-31[lldb] Fallback to expression eval when Dump of variable fails in dwim-print ↵Dave Lee1-18/+29
(#151374) Previously, when dwim-print finds a frame variables, it returns immediately after calling `Dump`, even if `Dump` returns an error. This is most likely to happen when evaluating an object description, ie `po`. This changes dwim-print to continue on to expression evaluation when `Dump`ing a variable returns an error . This is to allow for diagnostics that match `expression`.
2025-07-28[lldb][NFC] Use IterationAction for ModuleList::ForEach callbacks (#150930)Michael Buch1-1/+1
2025-07-25[lldb] Use std::make_shared where possible (NFC) (#150714)Jonas Devlieghere2-9/+9
This is a continuation of 68fd102, which did the same thing but only for StopInfo. Using make_shared is both safer and more efficient: - With make_shared, the object and the control block are allocated together, which is more efficient. - With make_shared, the enable_shared_from_this base class is properly linked to the control block before the constructor finishes, so shared_from_this() will be safe to use (though still not recommended during construction).
2025-07-18[LLDB] Fix Memory64 BaseRVA, move all non-stack memory to Mem64. (#146777)Jacob Lalonde1-1/+2
### Context Over a year ago, I landed support for 64b Memory ranges in Minidump (#95312). In this patch we added the Memory64 list stream, which is effectively a Linked List on disk. The layout is a sixteen byte header and then however many Memory descriptors. ### The Bug This is a classic off-by one error, where I added 8 bytes instead of 16 for the header. This caused the first region to start 8 bytes before the correct RVA, thus shifting all memory reads by 8 bytes. We are correctly writing all the regions to disk correctly, with no physical corruption but the RVA is defined wrong, meaning we were incorrectly reading memory ![image](https://github.com/user-attachments/assets/049ef55d-856c-4f3c-9376-aeaa3fe8c0e1) ### Why wasn't this caught? One problem we've had is forcing Minidump to actually use the 64b mode, it would be a massive waste of resources to have a test that actually wrote >4.2gb of IO to validate the 64b regions, and so almost all validation has been manual. As a weakness of manual testing, this issue is psuedo non-deterministic, as what regions end up in 64b or 32b is handled greedily and iterated in the order it's laid out in /proc/pid/maps. We often validated 64b was written correctly by hexdumping the Minidump itself, which was not corrupted (other than the BaseRVA) ![image](https://github.com/user-attachments/assets/b599e3be-2d59-47e2-8a2d-75f182bb0b1d) ### Why is this showing up now? During internal usage, we had a bug report that the Minidump wasn't displaying values. I was unable to repro the issue, but during my investigation I saw the variables were in the 64b regions which resulted in me identifying the bug. ### How do we prevent future regressions? To prevent regressions, and honestly to save my sanity for figuring out where 8 bytes magically came from, I've added a new API to SBSaveCoreOptions. ```SBSaveCoreOptions::GetMemoryRegionsToSave()``` The ability to get the memory regions that we intend to include in the Coredump. I added this so we can compare what we intended to include versus what was actually included. Traditionally we've always had issues comparing regions because Minidump includes `/proc/pid/maps` and it can be difficult to know what memoryregion read failure was a genuine error or just a page that wasn't meant to be included. We are also leveraging this API to choose the memory regions to be generated, as well as for testing what regions should be bytewise 1:1. After much debate with @clayborg, I've moved all non-stack memory to the Memory64 List. This list doesn't incur us any meaningful overhead and Greg originally suggested doing this in the original 64b PR. This also means we're exercising the 64b path every single time we save a Minidump, preventing regressions on this feature from slipping through testing in the future. Snippet produced by [minidump.py](https://github.com/clayborg/scripts) ``` MINIDUMP_MEMORY_LIST: NumberOfMemoryRanges = 0x00000002 MemoryRanges[0] = [0x00007f61085ff9f0 - 0x00007f6108601000) @ 0x0003f655 MemoryRanges[1] = [0x00007ffe47e50910 - 0x00007ffe47e52000) @ 0x00040c65 MINIDUMP_MEMORY64_LIST: NumberOfMemoryRanges = 0x000000000000002e BaseRva = 0x0000000000042669 MemoryRanges[0] = [0x00005584162d8000 - 0x00005584162d9000) MemoryRanges[1] = [0x00005584162d9000 - 0x00005584162db000) MemoryRanges[2] = [0x00005584162db000 - 0x00005584162dd000) MemoryRanges[3] = [0x00005584162dd000 - 0x00005584162ff000) MemoryRanges[4] = [0x00007f6100000000 - 0x00007f6100021000) MemoryRanges[5] = [0x00007f6108800000 - 0x00007f6108828000) MemoryRanges[6] = [0x00007f6108828000 - 0x00007f610899d000) MemoryRanges[7] = [0x00007f610899d000 - 0x00007f61089f9000) MemoryRanges[8] = [0x00007f61089f9000 - 0x00007f6108a08000) MemoryRanges[9] = [0x00007f6108bf5000 - 0x00007f6108bf7000) ``` ### Misc As a part of this fix I had to look at LLDB logs a lot, you'll notice I added `0x` to many of the PRIx64 `LLDB_LOGF`. This is so the user (or I) can directly copy paste the address in the logs instead of adding the hex prefix themselves. Added some SBSaveCore tests for the new GetMemoryAPI, and Docstrings. CC: @DavidSpickett, @da-viper @labath because we've been working together on save-core plugins, review it optional and I didn't tag you but figured you'd want to know
2025-07-16[lldb] Print children-count warning for dwim-print and expr (#149088)Michael Buch2-0/+5
When dumping variables, LLDB will print a one-time warning about truncating children (when the children count exceeds the default `target.max-children-count`). But we only do this for `frame variable`. So if we use `dwim-print` or `expression`, the output gets truncated but we don't print a warning. But because we store the fact that we truncated some output on the `CommandInterpreter`, we fire the warning next time we use `frame variable`. E.g.,: ``` (lldb) p arr (int[1000]) { [0] = -5 [1] = 0 [2] = 0 <-- snipped --> [253] = 0 [254] = 0 [255] = 0 ... } (lldb) v someLocal (int) someLocal = 10 *** Some of the displayed variables have more members than the debugger will show by default. To show all of them, you can either use the --show-all-children option to frame variable or raise the limit by changing the target.max-children-count setting. ``` This patch prints the warning for `dwim-print` and `expression`. I only added a test for the `target.max-children-count` for now because it seems the `target.max-children-depth` warning is broken (I can't get it to fire).
2025-07-15[lldb] Add completions for plugin list/enable/disable (#147775)David Peixotto2-0/+32
This commit adds completion support for the plugin commands. It will try to complete partial namespaces to the full namespace string. If the completion input is already a full namespace string then it will add all the matching plugins in that namespace as completions. This lets the user complete to the namespace first and then tab-complete to the next level if desired. ``` (lldb) plugin list a<tab> Available completions: abi architecture (lldb) plugin list ab<tab> (lldb) plugin list abi<tab> (lldb) plugin list abi.<tab> Available completions: abi.SysV-arm64 abi.ABIMacOSX_arm64 abi.SysV-arm ... ```
2025-07-10[lldb] Support specifying a language for breakpoint conditions (#147603)Jonas Devlieghere2-1/+22
LLDB breakpoint conditions take an expression that's evaluated using the language of the code where the breakpoint is located. Users have asked to have an option to tell it to evaluate the expression in a specific language. This is feature is especially helpful for Swift, for example for a condition based on the value in memory at an offset from a register. Such a condition is pretty difficult to write in Swift, but easy in C. This PR adds a new argument (-Y) to specify the language of the condition expression. We can't reuse the current -L option, since you might want to break on only Swift symbols, but run a C expression there as per the example above. rdar://146119507
2025-07-09[lldb] Change breakpoint interfaces for error handling (#146972)Jonas Devlieghere2-7/+26
This RP changes some Breakpoint-related interfaces to return errors. On its own these improvements are small, but they encourage better error handling going forward. There are a bunch of other candidates, but these were the functions that I touched while working on #146602.
2025-07-07Defer loading all DWOs by default when dumping separate_debug-info (#146166)qxy112-4/+17
### Summary Currently `target modules dump separate separate-debug-info` automatically loads up all DWO files, even if deferred loading is enabled through debug_names. Then, as expected all DWO files (assuming there is no error loading it), get marked as "loaded". This change adds the option `--force-load-all-debug-info` or `-f` for short to force loading all debug_info up, if it hasn't been loaded yet. Otherwise, it will change default behavior to not load all debug info so that the correct DWO files will show up for each modules as "loaded" or not "loaded", which could be helpful in cases where we want to know which particular DWO files were loaded. ### Testing #### Unit Tests Added additional unit tests `test_dwos_load_json_with_debug_names_default` and `test_dwos_load_json_with_debug_names_force_load_all` to test both default behavior and loading with the new flag `--force-load-all-debug-info`, and changed expected behavior in `test_dwos_loaded_symbols_on_demand`. ``` bin/lldb-dotest -p TestDumpDwo ~/llvm-project/lldb/test/API/commands/target/dump-separate-debug-info/dwo ``` #### Manual Testing Compiled a simple binary w/ `--gsplit-dwarf --gpubnames` and loaded it up: ``` (lldb) target create "./a.out" Current executable set to '/home/qxy11/hello-world/a.out' (x86_64). (lldb) help target modules dump separate-debug-info List the separate debug info symbol files for one or more target modules. Syntax: target modules dump separate-debug-info <cmd-options> [<filename> [<filename> [...]]] Command Options Usage: target modules dump separate-debug-info [-efj] [<filename> [<filename> [...]]] -e ( --errors-only ) Filter to show only debug info files with errors. -f ( --force-load-all-debug-info ) Load all debug info files. -j ( --json ) Output the details in JSON format. This command takes options and free-form arguments. If your arguments resemble option specifiers (i.e., they start with a - or --), you must use ' -- ' between the end of the command options and the beginning of the arguments. (lldb) target modules dump separate-debug-info --j [ { "separate-debug-info-files": [ { ... "dwo_name": "main.dwo", "loaded": false }, { ... "dwo_name": "foo.dwo", "loaded": false }, { ... "dwo_name": "bar.dwo", "loaded": false } ], } ] (lldb) b main Breakpoint 1: where = a.out`main + 15 at main.cc:3:12, address = 0x00000000000011ff (lldb) target modules dump separate-debug-info --j [ { "separate-debug-info-files": [ { ... "dwo_name": "main.dwo", "loaded": true, "resolved_dwo_path": "/home/qxy11/hello-world/main.dwo" }, { ... "dwo_name": "foo.dwo", "loaded": false }, { ... "dwo_name": "bar.dwo", "loaded": false } ], } ] (lldb) b foo Breakpoint 2: where = a.out`foo(int) + 11 at foo.cc:12:11, address = 0x000000000000121b (lldb) target modules dump separate-debug-info --j [ { "separate-debug-info-files": [ { ... "dwo_name": "main.dwo", "loaded": true, "resolved_dwo_path": "/home/qxy11/hello-world/main.dwo" }, { ... "dwo_name": "foo.dwo", "loaded": true, "resolved_dwo_path": "/home/qxy11/hello-world/foo.dwo" }, { ... "dwo_name": "bar.dwo", "loaded": false } ], } ] (lldb) b bar Breakpoint 3: where = a.out`bar(int) + 11 at bar.cc:10:9, address = 0x000000000000126b (lldb) target modules dump separate-debug-info --j [ { "separate-debug-info-files": [ { ... "dwo_name": "main.dwo", "loaded": true, "resolved_dwo_path": "/home/qxy11/hello-world/main.dwo" }, { ... "dwo_name": "foo.dwo", "loaded": true, "resolved_dwo_path": "/home/qxy11/hello-world/foo.dwo" }, { ... "dwo_name": "bar.dwo", "loaded": true, "resolved_dwo_path": "/home/qxy11/hello-world/bar.dwo" } ], } ] ```
2025-07-03[lldb][Commands][NFC] image lookup: remove unused local variable (#146554)Michael Buch1-4/+1
The `current_module` pointer here was never set, but we check it when looping over the `target_modules` list. Presumably the intention was to avoid calling `LookupInModule` if we already found the type in the current module. This patch removes this `current_module`. If we decide the output below is not what the user should see, we can revisit the implementation. Current output: ``` (lldb) im loo -vt Foo --all Best match found in /Users/jonas/Git/llvm-worktrees/llvm-project/a.out: id = {0x00000037}, name = "Foo", byte-size = 1, decl = foo.cpp:1, compiler_type = "struct Foo { }" 1 match found in /Users/jonas/Git/llvm-worktrees/llvm-project/a.out: id = {0x00000037}, name = "Foo", byte-size = 1, decl = foo.cpp:1, compiler_type = "struct Foo { }" ``` which seems fine. Note, there can be multiple matches *within* the current module, so if we did the naive thing of skipping the `current_module` when printing with `--all`, then we would miss some matches.
2025-07-02[lldb][mcp] Fix unix domain socket protocol server addresses (#146603)Alexandre Perez1-3/+7
When starting an MCP protocol server that uses unix sockets as the transport, a local `'[0.0.0.0]:0'` file is used instead of the supplied socket path, e.g: ``` (lldb) protocol-server start MCP accept:///tmp/some/path.sock MCP server started with connection listeners: unix-connect://[0.0.0.0]:0 (lldb) shell ls '[*' [0.0.0.0]:0 ``` This change makes it so that the URI path is used if the socket protocol is `ProtocolUnixDomain`: ``` (lldb) protocol-server start MCP accept:///tmp/some/path.sock MCP server started with connection listeners: unix-connect:///tmp/some/path.sock ```
2025-06-26Fix a bug in the breakpoint ID verifier in CommandObjectBreakpoint. (#145994)jimingham1-2/+3
It was assuming that for any location M.N, N was always less than the number of breakpoint locations. But if you rebuild the target and rerun multiple times, when the section backing one of the locations is no longer valid, we remove the location, but we don't reuse the ID. So you can have a breakpoint that only has location 1.3. The num_locations check would say that was an invalid location.
2025-06-26Default transcript dumping in "statistics dump" to false (#145436)qxy112-9/+21
### Summary Currently, if the setting `interpreter.save-transcript` is enabled, whenever we call "statistics dump", it'll default to reporting a huge list of transcripts which can be a bit noisy. This is because the current check `GetIncludeTranscript` returns `!GetSummaryOnly()` by default if no specific transcript-setting option is given in the statistics dump command (ie. `statistics dump --transcripts=false` or `statistics dump --transcripts=true`). Then when `interpreter.save-transcript` is enabled, this saves a list of transcripts, and the transcript list ends up getting logged by default. These changes default the option to log transcripts in the `statistics dump` command to "false". This can still be enabled via the `--transcripts` option if users want to see a transcript. Since `interpreter.save-transcript` is false by default, the main delta is that if `interpreter.save-transcript` is true and summary mode is false, we now disable saving the transcript. This also adds a warning to 'statistics dump --transcript=true' when interpreter.save-transcript is disabled, which should help users understand why transcript data is empty. ### Testing #### Manual testing Tested with `settings set interpreter.save-transcript true` enabled at startup on a toy hello-world program: ``` (lldb) settings set interpreter.save-transcript true (lldb) target create "/home/qxy11/hello-world/a.out" Current executable set to '/home/qxy11/hello-world/a.out' (x86_64). (lldb) statistics dump { /* no transcript */ } (lldb) statistics dump --transcript=true { "transcript": [ { "command": "statistics dump", "commandArguments": "", "commandName": "statistics dump", "durationInSeconds": 0.0019650000000000002, "error": "", "output": "{... }, { "command": "statistics dump --transcript=true", "commandArguments": "--transcript=true", "commandName": "statistics dump", "timestampInEpochSeconds": 1750720021 } ] } ``` Without `settings set interpreter.save-transcript true`: ``` (lldb) target create "/home/qxy11/hello-world/a.out" Current executable set to '/home/qxy11/hello-world/a.out' (x86_64). (lldb) statistics dump { /* no transcript */ } (lldb) statistics dump --transcript=true { /* no transcript */ } warning: transcript requested but none was saved. Enable with 'settings set interpreter.save-transcript true' ``` #### Unit tests Changed unit tests to account for new expected default behavior to `false`, and added a couple new tests around expected behavior with `--transcript=true`. ``` lldb-dotest -p TestStats ~/llvm-sand/external/llvm-project/lldb/test/API/commands/statistics/basic/ ```
2025-06-25[lldb] Make MCP server instance global (#145616)Jonas Devlieghere1-42/+9
Rather than having one MCP server per debugger, make the MCP server global and pass a debugger id along with tool invocations that require one. This PR also adds a second tool to list the available debuggers with their targets so the model can decide which debugger instance to use.
2025-06-23[lldb] add plugin names to process save-core error output. (#143126)Ebuka Ezike1-1/+23
continuation of [#142684](https://github.com/llvm/llvm-project/pull/142684) to show plugin names. From issue [#14258](https://github.com/llvm/llvm-project/issues/142581)
2025-06-20[lldb] Fix ASCII art in CommandObjectProtocolServer (NFC)Jonas Devlieghere2-4/+2
2025-06-20[lldb] Add Model Context Protocol (MCP) support to LLDB (#143628)Jonas Devlieghere3-0/+202
This PR adds an MCP (Model Context Protocol ) server to LLDB. For motivation and background, please refer to the corresponding RFC: https://discourse.llvm.org/t/rfc-adding-mcp-support-to-lldb/86798 I implemented this as a new kind of plugin. The idea is that we could support multiple protocol servers (e.g. if we want to support DAP from within LLDB). This also introduces a corresponding top-level command (`protocol-server`) with two subcommands to `start` and `stop` the server. ``` (lldb) protocol-server start MCP tcp://localhost:1234 MCP server started with connection listeners: connection://[::1]:1234, connection://[127.0.0.1]:1234 ``` The MCP sever supports one tool (`lldb_command`) which executes a command, but can easily be extended with more commands.
2025-06-13[lldb] CommandObjectMemoryFind: Improve expression evaluation error messages ↵Michael Buch1-2/+6
(#144036) We now bubble up the expression evaluation diagnostics to the user and also distinguish between "expression failed to parse/run" versus other ways in which expressions didn't complete (e.g., setup errors, etc.). Before: ``` (lldb) memory find -e "" 0x16fdfedc0 0x16fdfede0 error: expression evaluation failed. pass a string instead (lldb) memory find -e "invalid" 0x16fdfedc0 0x16fdfede0 error: expression evaluation failed. pass a string instead ``` After: ``` (lldb) memory find -e "" 0x16fdfedc0 0x16fdfede0 error: Expression evaluation failed: error: No result returned from expression. Exit status: 1 (lldb) memory find -e "invalid" 0x16fdfedc0 0x16fdfede0 error: Expression evaluation failed: error: <user expression 0>:1:1: use of undeclared identifier 'invalid' 1 | invalid | ^~~~~~~ ```
2025-06-12[lldb][Commands] Fix memory find for Swift expressions (#143860)Michael Buch1-3/+10
(depends on https://github.com/llvm/llvm-project/pull/143686) There were two issues previously preventing `memory find -e` expressions to succeed when stopped in Swift frames: 1. We weren't getting the dynamic type of the result `ValueObject`. For Swift this would fail when we tried to produce a scalar value out of it because the static VO wasn't sufficient to get to the integer value. Hence we add a call to `GetQualifiedRepresentationIfAvailable` (which is what we do for expressions in `OptionArgParser::ToAddress` too). 2. We weren't passing an `ExecutionContextScope` to `GetByteSize`, which Swift relied on to get the size of the result type. My plan is to add an API test for this on the Apple `swiftlang/llvm-project` fork. I considered an alternative where we use `OptionArgParser::ToAddress` for `memory find -e` expressions, but it got a bit icky when trying to figure out how many bytes we should copy out of the result into the `DataBufferHeap` (currently we rely on the size of the result variable type). This gets even trickier when we were to pass an expression that was actually a hex digit or a number into `ToAddress`. rdar://152113525
2025-06-12[lldb][Commands][NFC] Extract memory find expression evaluation into helpers ↵Michael Buch1-43/+58
(#143686) This patch factors out the `-e` option logic into two helper functions. The `EvaluateExpression` helper might seem redundant but I'll be adding to it in a follow-up patch to fix an issue when running `memory find -e` for Swift targets. Also adds test coverage for the error cases that were previously untested. rdar://152113525
2025-06-10[lldb] Fix `target stop-hook add` help outputJonas Devlieghere1-3/+3
The help output for `target stop-hook add` references non-existing option `--one-line-command`. The correct option is `--one-liner`: ``` -o <one-line-command> ( --one-liner <one-line-command> ) Add a command for the stop hook. Can be specified more than once, and commands will be run in the order they appear. ``` This commit fixes the help text. rdar://152730660
2025-06-09Add commands to list/enable/disable plugins (#134418)David Peixotto3-1/+296
This commit adds three new commands for managing plugins. The `list` command will show which plugins are currently registered and their enabled state. The `enable` and `disable` commands can be used to enable or disable plugins. A disabled plugin will not show up to the PluginManager when it iterates over available plugins of a particular type. The purpose of these commands is to provide more visibility into registered plugins and allow users to disable plugins for experimental perf reasons. There are a few limitations to the current implementation 1. Only SystemRuntime and InstrumentationRuntime plugins are currently supported. We can easily extend the existing implementation to support more types. The scope was limited to these plugins to keep the PR size manageable. 2. Only "statically" know plugin types are supported (i.e. those managed by the PluginManager and not from `plugin load`). It is possibly we could support dynamic plugins as well, but I have not looked into it yet.
2025-06-04[lldb] Remove an unused local variable (NFC) (#142882)Kazu Hirata1-1/+0
Note that CommandArgumentEntry is an alias for: std::vector<CommandArgumentData>
2025-06-04[lldb] Do not accept invalid `process save-core` plugins (#142684)Ebuka Ezike1-1/+1
Fixes #142581
2025-06-04[lldb/cmake] Implicitly pass arguments to llvm_add_library (#142583)Pavel Labath1-3/+2
If we're not touching them, we don't need to do anything special to pass them along -- with one important caveat: due to how cmake arguments work, the implicitly passed arguments need to be specified before arguments that we handle. This isn't particularly nice, but the alternative is enumerating all arguments that can be used by llvm_add_library and the macros it calls (it also relies on implicit passing of some arguments to llvm_process_sources).
2025-06-02[lldb] Add filter option to AST dump command (#142164)Michael Buch1-5/+19
Depends on https://github.com/llvm/llvm-project/pull/142163 This patch makes the `-ast-dump-filter` Clang option available to the `target modules dump ast` command. This allows us to selectively dump parts of the AST by name. The AST can quickly grow way too large to skim on the console. This will aid in debugging AST related issues. Example: ``` (lldb) target modules dump ast --filter func Dumping clang ast for 48 modules. Dumping func: FunctionDecl 0xc4b785008 <<invalid sloc>> <invalid sloc> func 'void (int)' extern |-ParmVarDecl 0xc4b7853d8 <<invalid sloc>> <invalid sloc> x 'int' `-AsmLabelAttr 0xc4b785358 <<invalid sloc>> Implicit "_Z4funcIiEvT_" Dumping func<int>: FunctionDecl 0xc4b7850b8 <<invalid sloc>> <invalid sloc> func<int> 'void (int)' implicit_instantiation extern |-TemplateArgument type 'int' | `-BuiltinType 0xc4b85b110 'int' `-ParmVarDecl 0xc4b7853d8 <<invalid sloc>> <invalid sloc> x 'int' ``` The majority of this patch is adjust the `Dump` API. The main change in behaviour is in `TypeSystemClang::Dump`, where we now use the `ASTPrinter` for dumping the `TranslationUnitDecl`. This is where the `-ast-dump-filter` functionality lives in Clang.
2025-06-02[lldb] Refactor away UB in SBValue::GetLoadAddress (#141799)Pavel Labath1-14/+11
The problem was in calling GetLoadAddress on a value in the error state, where `ValueObject::GetLoadAddress` could end up accessing the uninitialized "address type" by-ref return value from `GetAddressOf`. This probably happened because each function expected the other to initialize it. We can guarantee initialization by turning this into a proper return value. I've added a test, but it only (reliably) crashes if lldb is built with ubsan.
2025-05-30[lldb][lldb-dap] Use the default disassembly flavour if none is provided. ↵Ebuka Ezike1-1/+0
(#141424) This is the currently the default for `SBTarget::ReadInstructions(SBAddress, uint32_t)`. But not for others, to make it consistent used the user assigned instruction flavour.
2025-05-28[lldb][Formatters] Add --pointer-match-depth option to `type summary add` ↵Zequan Wu2-8/+23
command. (#138209) Currently, the type `T`'s summary formatter will be matched for `T`, `T*`, `T**` and so on. This is unexpected in many data formatters. Such unhandled cases could cause the data formatter to crash. An example would be the lldb's built-in data formatter for `std::optional`: ``` $ cat main.cpp #include <optional> int main() { std::optional<int> o_null; auto po_null = &o_null; auto ppo_null = &po_null; auto pppo_null = &ppo_null; return 0; } $ clang++ -g main.cpp && lldb -o "b 8" -o "r" -o "v pppo_null" [lldb crash] ``` This change adds an options `--pointer-match-depth` to `type summary add` command to allow users to specify how many layer of pointers can be dereferenced at most when matching a summary formatter of type `T`, as Jim suggested [here](https://github.com/llvm/llvm-project/pull/124048/#issuecomment-2611164133). By default, this option has value 1 which means summary formatter for `T` could also be used for `T*` but not `T**` nor beyond. This option is no-op when `--skip-pointers` is set as well. I didn't add such option for `type synthetic add`, `type format add`, `type filter add`, because it useful for those command. Instead, they all have the pointer match depth of 1. When printing a type `T*`, lldb never print the children of `T` even if there is a synthetic formatter registered for `T`.