summaryrefslogtreecommitdiff
path: root/lldb/source/Core/FormatEntity.cpp
AgeCommit message (Collapse)Author
2025-09-04[lldb] Introduce ScriptedFrame affordance (#149622)Med Ismail Bennani
This patch introduces a new scripting affordance in lldb: `ScriptedFrame`. This allows user to produce mock stackframes in scripted threads and scripted processes from a python script. With this change, StackFrame can be synthetized from different sources: - Either from a dictionary containing a load address, and a frame index, which is the legacy way. - Or by creating a ScriptedFrame python object. One particularity of synthezising stackframes from the ScriptedFrame python object, is that these frame have an optional PC, meaning that they don't have a report a valid PC and they can act as shells that just contain static information, like the frame function name, the list of variables or registers, etc. It can also provide a symbol context. rdar://157260006 Signed-off-by: Med Ismail Bennani <ismail@bennani.ma> Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2025-09-03[lldb] Mark scripted frames as synthetic instead of artificial (#153117)Med Ismail Bennani
This patch changes the way frames created from scripted affordances like Scripted Threads are displayed. Currently, they're marked artificial which is used usually for compiler generated frames. This patch changes that behaviour by introducing a new synthetic StackFrame kind and moves 'artificial' to be a distinct StackFrame attribut. On top of making these frames less confusing, this allows us to know when a frame was created from a scripted affordance. rdar://155949703 Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2025-08-05[lldb] add TemplateRange and NameQualifiersRange to DemangledNameInfo (#150999)Charles Zablit
This patch adds 2 new attributes to `DemangledNameInfo`: `TemplateRange` and `NameQualifiersRange`. It also introduces the `function.name-qualifiers` entity formatter which allows tracking qualifiers between the name of a function and its arguments/template. This will be used downstream in Swift but may have applications in C++: https://github.com/swiftlang/llvm-project/pull/11068.
2025-07-12[lldb][Format] Fall back to old function.name-with-args if language frame ↵Michael Buch
format is emtpy (#148235) There is currently no way to prevent `${function.name-with-args}` from using the `plugin.cplusplus.display.function-name-format` setting. Even if the setting is set to an empty string. As a way to disable formatting by language plugin, this patch makes it so `plugin.cplusplus.display.function-name-format` falls back to the old way of printing `${function.name-with-args}`. Even if we didn't want to add a fallback, making the setting an empty string shouldn't really "succeed".
2025-06-24[lldb] Eliminate check for HasLoadedSections (NFC) (#145366)Jonas Devlieghere
We can omit the call to Target::HasLoadedSections as Address::HasLoadedSections already "does the right thing" and returns LLDB_INVALID_ADDRESS if no sections are loaded.
2025-06-05[lldb][Format] Add [inlined] marker to names of inlined frames (#142952)Michael Buch
This was removed in https://github.com/llvm/llvm-project/pull/135343 in favour of making it a format variable, which we do here. This follows the precedent of the `[opt]` and `[artificial]` markers. Before: ``` thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.2 * frame #0: 0x000000010000037c a.out`inlined1() at inline.cpp:4:3 frame #1: 0x000000010000037c a.out`regular() at inline.cpp:6:17 frame #2: 0x00000001000003b8 a.out`inlined2() at inline.cpp:7:43 frame #3: 0x00000001000003b4 a.out`main at inline.cpp:10:3 frame #4: 0x0000000186345be4 dyld`start + 7040 ``` After (note the `[inlined]` markers): ``` thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.2 * frame #0: 0x000000010000037c a.out`inlined1() at inline.cpp:4:3 [inlined] frame #1: 0x000000010000037c a.out`regular() at inline.cpp:6:17 frame #2: 0x00000001000003b8 a.out`inlined2() at inline.cpp:7:43 [inlined] frame #3: 0x00000001000003b4 a.out`main at inline.cpp:10:3 frame #4: 0x0000000186345be4 dyld`start + 7040 ``` rdar://152642178
2025-06-03[lldb] Fix data race in statusline format handling (#142489)Jonas Devlieghere
This fixes a data race between the main thread and the default event handler thread. The statusline format option value was protected by a mutex, but it was returned as a pointer, allowing one thread to access it while another was modifying it. Avoid the data race by returning format values by value instead of by pointer.
2025-05-28[Demangling] Refactor Demangler range tracking (#140762)Charles Zablit
This PR is a subset of the commits made in https://github.com/swiftlang/llvm-project/pull/10710. The most notable change is the addition of `PrefixRange` and `SuffixRange` which are a catch-all to track anything after or before a function's demangled name. In the case of Swift, this allows to add support for name highlighting without having to track the range of the scope and specifiers of a function (this will come in another PR).
2025-05-05[lldb] Support alternatives for scope format entries (#137751)Jonas Devlieghere
This PR implements support for specifying multiple alternatives for scope format entries. Scopes are used to enclose things that should only be printed when everything in the scope resolves. For example, the following scope only resolves if both `${line.file.basename}` and `${line.number}` resolve. ` ``` { at ${line.file.basename}:${line.number}} ``` However, the current implementation doesn't let you specify what to print when they don't resolve. This PR adds support for specifying multiple alternative scopes, which are evaluated left-to-right. For example: ``` { at ${line.file.basename}:${line.number}| in ${function.name}| <unknown location>} ``` This will resolve to: - ` at ${line.file.basename}:${line.number}` if the corresponding variables resolve. - Otherwise, this resolves to ` in ${function.name}` if `${function.name}` resolves. - Otherwise, this resolves to ` <unknown location>` which always resolves. This PR makes the `|` character a special character within a scope, but allows it to be escaped. I ended up with this approach because it fit quite nicely in the existing architecture of the format entries and by limiting the functionality to scopes, it sidesteps some complexity, like dealing with recursion.
2025-05-04[lldb] Remove unused local variables (NFC) (#138457)Kazu Hirata
2025-04-29Reland "[lldb][Format] Make function name frame-format variables work ↵Michael Buch
without debug-info" (#137757) This reverts commit da7099290cea7d11b83da01adda8afeb3bcd5362. Same as the original PR. The failing test-case was resolved in https://github.com/llvm/llvm-project/pull/137763
2025-04-29[lldb][Format] Add function.suffix frame-format variable (#137763)Michael Buch
This patch adds another frame-format variable (currently only implemented in the CPlusPlus language plugin) that represents the "suffix" of a function. The name is derived from the `DotSuffix` node of LLVM's Itanium demangler. For a function name such as `int foo() (.cold)`, the suffix would be `(.cold)`.
2025-04-29Revert "[lldb][Format] Make function name frame-format variables work ↵Michael Buch
without debug-info" (#137757) Reverts llvm/llvm-project#137408 This change broke `lldb/test/Shell/Unwind/split-machine-functions.test`. The test binary has a symbol named `_Z3foov.cold` and the test expects the backtrace to print the name of the cold part of the function like this: ``` # SPLIT: frame #1: {{.*}}`foo() (.cold) + ``` but now it gets ``` frame #1: 0x000055555555514f split-machine-functions.test.tmp`foo() + 12 ```
2025-04-28[lldb/Format] Make progress count show thousands separators (NFC) (#137446)Med Ismail Bennani
This patch changes the progress count formatting show thousands separator making it easier to read big numbers. Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2025-04-28[lldb][Format] Make function name frame-format variables work without ↵Michael Buch
debug-info (#137408) This patch makes the frame-format variables introduced in https://github.com/llvm/llvm-project/pull/131836 also work when no debug-info is available. Previously, we assumed `sc.function` was available, but without debug-info we might only have `sc.symbol`. We don't really need the `sc.function` apart from when formatting arguments. For the function arguments case I added a fallback that will just print the arguments we get from the demangler (which is what LLDB does for stacktraces with no debug-info anyway). Ideally we'd have a separate `FormatEntity::Entry::Type::FunctionArguments` that will just print the arguments from the demangler and have something like the following in the `plugin.cplusplus.display.function-name-format`: ``` { ${function.formatted-arguments} || ${function.arguments} } ``` I.e., when we can't format the arguments, print the ones from the demangler. But we currently don't have the `||` operator in the frame-format language yet.
2025-04-25[lldb][CPlusPlus] Add plugin.cplusplus.display.function-name-format setting ↵Michael Buch
(#131836) Adds the new `plugin.cplusplus.display.function-name-format` setting and makes the `${function.name-with-args}` query it for formatting the function name. One caveat is that the setting can't itself be set to `${function.name-with-args}` because that would cause infinite recursion and blow the stack. I added an XFAILed test-case for it and will address it in a follow-up patch. https://github.com/llvm/llvm-project/pull/131836
2025-04-25[lldb][Format] Introduce new frame-format variables for function parts (#131836)Michael Buch
Adds new frame-format variables and implements them in the CPlusPlusLanguage plugin. We use the `DemangledNameInfo` type to retrieve the necessary part of the demangled name. https://github.com/llvm/llvm-project/pull/131836
2025-04-22[lldb] Make the statusline separator configurable (#136611)Adrian Prantl
And use this functionality to replace the ASCII "|" with the same full-geight line-drawing character used in diagnostics rendering on a color terminal.
2025-04-14[lldb][Format][NFC] Remove unused FormatEntity::FormatCStringMichael Buch
One can use `FormatStringRef` instead anyway
2025-04-14[lldb][Format][NFC] Factor FunctionNameWithArgs case out into helper functionMichael Buch
2025-04-13[lldb][Format] Display only the inlined frame name in backtraces if ↵Michael Buch
available (#135343) When a frame is inlined, LLDB will display its name in backtraces as follows: ``` * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.3 * frame #0: 0x0000000100000398 a.out`func() [inlined] baz(x=10) at inline.cpp:1:42 frame #1: 0x0000000100000398 a.out`func() [inlined] bar() at inline.cpp:2:37 frame #2: 0x0000000100000398 a.out`func() at inline.cpp:4:15 frame #3: 0x00000001000003c0 a.out`main at inline.cpp:7:5 frame #4: 0x000000026eb29ab8 dyld`start + 6812 ``` The longer the names get the more confusing this gets because the first function name that appears is the parent frame. My assumption (which may need some more surveying) is that for the majority of cases we only care about the actual frame name (not the parent). So this patch removes all the special logic that prints the parent frame. Another quirk of the current format is that the inlined frame name does not abide by the `${function.name-XXX}` format variables. We always just print the raw demangled name. With this patch, we would format the inlined frame name according to the `frame-format` setting (see the test-cases). If we really want to have the `parentFrame [inlined] inlinedFrame` format, we could expose it through a new `frame-format` variable (e..g., `${function.inlined-at-name}` and let the user decide where to place things.
2025-04-13[lldb][Language] Change GetFunctionDisplayName to take SymbolContext by ↵Michael Buch
reference (#135536) Both the `CPlusPlusLanguage` plugins and the Swift language plugin already assume the `sc != nullptr`. And all `FormatEntity` callsites of `GetFunctionDisplayName` already check for nullptr before passing `sc`. This patch makes this pre-condition explicit by changing the parameter to `const SymbolContext &`. This will help with some upcoming changes in this area.
2025-04-10[lldb][FormatEntity][NFCI] Refactor FunctionNameWithArgs into helper ↵Michael Buch
functions and use LLVM style (#135031) I've always found this hard to read. Some upcoming changes make similar computations, so I thought it's a good time to factor out this logic into re-usable helpers and clean it up using LLVM's preferred early-return style.
2025-03-26[lldb] Implement a statusline in LLDB (#121860)Jonas Devlieghere
Add a statusline to command-line LLDB to display information about the current state of the debugger. The statusline is a dedicated area displayed at the bottom of the screen. The information displayed is configurable through a setting consisting of LLDB’s format strings. Enablement ---------- The statusline is enabled by default, but can be disabled with the following setting: ``` (lldb) settings set show-statusline false ``` Configuration ------------- The statusline is configurable through the `statusline-format` setting. The default configuration shows the target name, the current file, the stop reason and any ongoing progress events. ``` (lldb) settings show statusline-format statusline-format (format-string) = "${ansi.bg.blue}${ansi.fg.black}{${target.file.basename}}{ | ${line.file.basename}:${line.number}:${line.column}}{ | ${thread.stop-reason}}{ | {${progress.count} }${progress.message}}" ``` The statusline supersedes the current progress reporting implementation. Consequently, the following settings no longer have any effect (but continue to exist to not break anyone's `.lldbinit`): ``` show-progress -- Whether to show progress or not if the debugger's output is an interactive color-enabled terminal. show-progress-ansi-prefix -- When displaying progress in a color-enabled terminal, use the ANSI terminal code specified in this format immediately before the progress message. show-progress-ansi-suffix -- When displaying progress in a color-enabled terminal, use the ANSI terminal code specified in this format immediately after the progress message. ``` Format Strings -------------- LLDB's format strings are documented in the LLDB documentation and on the website: https://lldb.llvm.org/use/formatting.html#format-strings. The current implementation is relatively limited but various improvements have been discussed in the RFC. One such improvement is being to display a string when a format string is empty. Right now, when launching LLDB without a target, the statusline will be empty, which is expected, but looks rather odd. RFC --- The full RFC can be found on Discourse: https://discourse.llvm.org/t/rfc-lldb-statusline/83948
2025-02-06[lldb] s/GetAddressRange().GetBaseAddress()/GetAddress() (#125847)Pavel Labath
Three more cases where it's obvious that the code is looking for the address of the function entry point.
2025-01-20[lldb] Implement ${target.file} format variable (#123431)Jonas Devlieghere
Implements a format variable to print the basename and full path to the current target.
2025-01-14[lldb][NFC] Make the target's SectionLoadList private. (#113278)Greg Clayton
Lots of code around LLDB was directly accessing the target's section load list. This NFC patch makes the section load list private so the Target class can access it, but everyone else now uses accessor functions. This allows us to control the resolving of addresses and will allow for functionality in LLDB which can lazily resolve addresses in JIT plug-ins with a future patch.
2024-11-21[lldb] Fix incorrect nullptr check in DumpAddressAndContent (#117219)Jonas Devlieghere
When checking the section load list, the existing code assumed that a valid execution context guaranteed a valid target. This is a speculative fix for a crash report (without a reproducer). rdar://133969831
2024-10-24[lldb] Move ValueObject into its own library (NFC) (#113393)Jonas Devlieghere
ValueObject is part of lldbCore for historical reasons, but conceptually it deserves to be its own library. This does introduce a (link-time) circular dependency between lldbCore and lldbValueObject, which is unfortunate but probably unavoidable because so many things in LLDB rely on ValueObject. We already have cycles and these libraries are never built as dylibs so while this doesn't improve the situation, it also doesn't make things worse. The header includes were updated with the following command: ``` find . -type f -exec sed -i.bak "s%include \"lldb/Core/ValueObject%include \"lldb/ValueObject/ValueObject%" '{}' \; ```
2024-08-27[lldb] Turn lldb_private::Status into a value type. (#106163)Adrian Prantl
This patch removes all of the Set.* methods from Status. This cleanup is part of a series of patches that make it harder use the anti-pattern of keeping a long-lives Status object around and updating it while dropping any errors it contains on the floor. This patch is largely NFC, the more interesting next steps this enables is to: 1. remove Status.Clear() 2. assert that Status::operator=() never overwrites an error 3. remove Status::operator=() Note that step (2) will bring 90% of the benefits for users, and step (3) will dramatically clean up the error handling code in various places. In the end my goal is to convert all APIs that are of the form ` ResultTy DoFoo(Status& error) ` to ` llvm::Expected<ResultTy> DoFoo() ` How to read this patch? The interesting changes are in Status.h and Status.cpp, all other changes are mostly ` perl -pi -e 's/\.SetErrorString/ = Status::FromErrorString/g' $(git grep -l SetErrorString lldb/source) ` plus the occasional manual cleanup.
2024-07-09[lldb] Improve summary string handling of dollar chars (#98190)Dave Lee
This improves the handling of `$` (dollar) characters in summary strings in the following ways: 1. When a `$` is not followed by an open paren (`{`), it should be treated as a literal character and preserved in the output. Previously, the dollar would be consumed by the parser and not shown in the output. 2. When a `$` is the last character of a format string, this change eliminates the infinite loop lldb would enter into. rdar://131392446
2024-06-20Convert ValueObject::Dump() to return llvm::Error() (NFCish)Adrian Prantl
This change by itself has no measurable effect on the LLDB testsuite. I'm making it in preparation for threading through more errors in the Swift language plugin.
2024-05-16[lldb] Use operator==(StringRef, StringRef) instead of StringRef::equals ↵Kazu Hirata
(NFC) (#92476) Note that StringRef::equals has been deprecated in favor of operator==(StringRef, StringRef).
2024-05-15[lldb] Support custom LLVM formatting for variables (#91868)Dave Lee
Re-apply https://github.com/llvm/llvm-project/pull/81196, with a fix that handles the absence of llvm formatting: https://github.com/llvm/llvm-project/pull/91868/commits/3ba650e91eded3543764f37921dcce3b b47d425f
2024-04-30Revert "[lldb] Support custom LLVM formatting for variables (#81196)"Dave Lee
This reverts commit 7a8d15e919dde70118dbfa34e927be1705ded67d.
2024-04-30[lldb] Support custom LLVM formatting for variables (#81196)Dave Lee
Adds support for applying LLVM formatting to variables. The reason for this is to support cases such as the following. Let's say you have two separate bytes that you want to print as a combined hex value. Consider the following summary string: ``` ${var.byte1%x}${var.byte2%x} ``` The output of this will be: `0x120x34`. That is, a `0x` prefix is unconditionally applied to each byte. This is unlike printf formatting where you must include the `0x` yourself. Currently, there's no way to do this with summary strings, instead you'll need a summary provider in python or c++. This change introduces formatting support using LLVM's formatter system. This allows users to achieve the desired custom formatting using: ``` ${var.byte1:x-}${var.byte2:x-} ``` Here, each variable is suffixed with `:x-`. This is passed to the LLVM formatter as `{0:x-}`. For integer values, `x` declares the output as hex, and `-` declares that no `0x` prefix is to be used. Further, one could write: ``` ${var.byte1:x-2}${var.byte2:x-2} ``` Where the added `2` results in these bytes being written with a minimum of 2 digits. An alternative considered was to add a new format specifier that would print hex values without the `0x` prefix. The reason that approach was not taken is because in addition to forcing a `0x` prefix, hex values are also forced to use leading zeros. This approach lets the user have full control over formatting.
2024-03-21[lldb] Reland: Store SupportFile in FileEntry (NFC) (#85892)Jonas Devlieghere
This is another step towards supporting DWARF5 checksums and inline source code in LLDB. This is a reland of #85468 but without the functional change of storing the support file from the line table (yet).
2024-03-19Revert "[lldb] Store SupportFile in FileEntry (NFC)" (#85885)Jonas Devlieghere
Reverts llvm/llvm-project#85468 because @slackito reports this broke stepping in one of their tests [1] and this patch was meant to be NFC. [1] https://github.com/llvm/llvm-project/commit/d5a277d309e92b1d3e493da6036cffdf815105b1#commitcomment-139991120
2024-03-15[lldb] Store SupportFile in FileEntry (NFC) (#85468)Jonas Devlieghere
This is another step towards supporting DWARF5 checksums and inline source code in LLDB.
2024-03-08Change GetNumChildren()/CalculateNumChildren() methods return llvm::Expected ↵Adrian Prantl
(#84219) Change GetNumChildren()/CalculateNumChildren() methods return llvm::Expected This is an NFC change that does not yet add any error handling or change any code to return any errors. This is the second big change in the patch series started with https://github.com/llvm/llvm-project/pull/83501 A follow-up PR will wire up error handling.
2024-03-08Revert "Change GetNumChildren()/CalculateNumChildren() methods return ↵Florian Mayer
llvm::Expected (#84219)" This reverts commit 99118c809367d518ffe4de60c16da953744b68b9.
2024-03-08Change GetNumChildren()/CalculateNumChildren() methods return llvm::Expected ↵Adrian Prantl
(#84219) Change GetNumChildren()/CalculateNumChildren() methods return llvm::Expected This is an NFC change that does not yet add any error handling or change any code to return any errors. This is the second big change in the patch series started with https://github.com/llvm/llvm-project/pull/83501 A follow-up PR will wire up error handling.
2024-02-08[lldb] Refactor GetFormatFromCString to always check for partial matches ↵Dave Lee
(NFC) (#81018) Refactors logic in `ParseInternal` that was previously calling `GetFormatFromCString` twice, once with `partial_match_ok` set to false, and the second time set to true. With this change, lldb formats (ie `%@`, `%S`, etc) are checked first. If a format is not one of those, then `GetFormatFromCString` is called once, and now always checks for partial matches.
2024-01-18[lldb][Format] Fix missing inlined function names in frame formatting. (#78494)Zequan Wu
This fixes missing inlined function names when formatting frame and the `Block` in `SymbolContext` is a lexical block (e.g. `DW_TAG_lexical_block` in Dwarf).
2023-12-04[lldb] Additional pieces towards OpenBSD support (#74198)Brad Smith
2023-11-13[lldb-dap] Add an option to provide a format for stack frames (#71843)Walter Erquinigo
When this option gets enabled, descriptions of stack frames will be generated using the format provided in the launch configuration instead of simply calling `SBFrame::GetDisplayFunctionName`. This allows lldb-dap to show an output similar to the one in the CLI.
2023-05-22[lldb] Add support for negative integer to {SB,}StructuredDataMed Ismail Bennani
This patch refactors the `StructuredData::Integer` class to make it templated, makes it private and adds 2 public specialization for both `int64_t` & `uint64_t` with a public type aliases, respectively `SignedInteger` & `UnsignedInteger`. It adds new getter for signed and unsigned interger values to the `StructuredData::Object` base class and changes the implementation of `StructuredData::Array::GetItemAtIndexAsInteger` and `StructuredData::Dictionary::GetValueForKeyAsInteger` to support signed and unsigned integers. This patch also adds 2 new `Get{Signed,Unsigned}IntegerValue` to the `SBStructuredData` class and marks `GetIntegerValue` as deprecated. Finally, this patch audits all the caller of `StructuredData::Integer` or `StructuredData::GetIntegerValue` to use the proper type as well the various tests that uses `SBStructuredData.GetIntegerValue`. rdar://105575764 Differential Revision: https://reviews.llvm.org/D150485 Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-04-17[lldb] Change some pointers to refs in register printing codeDavid Spickett
No one was passing nullptr for these. Reviewed By: JDevlieghere Differential Revision: https://reviews.llvm.org/D148228
2023-02-07[NFC][TargetParser] Remove llvm/ADT/Triple.hArchibald Elliott
I also ran `git clang-format` to get the headers in the right order for the new location, which has changed the order of other headers in two files.
2022-12-19[lldb] Modernize sprintf in FormatEntity.cppPavel Labath
Avoid buffer overflows with large indexes, and spurious nul characters with small ones.