25 Commits
Author SHA1 Message Date
Dave Lee 637f9d7122 [lldb] Fix compile Python f-strings to improved @fmt (#232997)
Updates the `@fmt` selector, by adding support for Python f-strings to
the Python to bytecode compiler, and updating the evaluation of `@fmt`
by improved interfacing with `llvm::formatv`.

Changes to `@fmt`:

* Consume the arguments, leaving only the resulting string on the stack.
Previously, the arguments were left on the stack, unlike what the docs
describe and what the interpreter does.
* In version 2 formatters, replacements are automatically indexed.
Explicit indexes,such as `{0}`, are an error. This makes the stack
effect of `@fmt` clear from the format string: the number of arguments
is the number of replacements, and each argument is used once, in stack
order. Arguments can be reordered or reused with the stack operations.
* In version 2 formatters, layouts and options (`{,8}`, `{:x}`) are
accepted, but are currently ignored. They are treated as best effort
hints, so that support for them can be added later without changing the
ABI.
* In version 2 formatters, the format string is checked by LLDB before
it reaches `formatv`, which is given only literal text, escaped braces,
and `{}`. Format strings come from the binary being debugged, and
`formatv` asserts on malformed input. Layouts with a very large width,
such as `{,4000000000}`, would also build a very large string, even in
release builds.

Version 1 formatters are unchanged, except for consuming their
arguments.

Changes to formatter_bytecode.py:

* f-strings are compiled to `@fmt`. Conversions (`{x!r}`) and format
specs (`{x:>8}`) are not supported, and are a compile error.
* String literals, including f-strings, escape quotes and backslashes
when emitting assembly.
* The interpreter's `@fmt` matches the C++ interpreter. It now passes
arguments in stack order, supports `{}`, and follows the `formatv` rules
for braces (`{{` is a literal `{`, and a lone `}` is a literal).

Assisted-by: claude
2026-10-20 22:47:20 +00:00
Dave Lee fd2f5ff2ea [lldb] Introduce formatter bytecode version 2 ABI (#228589)
First this changes how "self" is represented. Previously, self was the
combined stack values after conclusion of `@init` and `@update`. With
this change, self is represented as a Dictionary (see #225955). The self
dictionary is passed to each method. This will aide
`formatter_bytecode.Compiler`, allowing the stack space to be used only
for computation and local variables.

While making calling convention changes, I updated the builtin selector
signatures to use `Integer` instead of `Int`/`UInt` (see #220665)

Assisted-by: claude
2026-10-06 17:35:57 +00:00
Dave Lee e9c7db29f1 [lldb] Add three more formatter bytecode selectors (#224773) 2026-10-05 18:04:47 +00:00
Dave Lee 143eb3cae4 [lldb] Add dictionary data type to formatter bytecode (#225955)
Add a dictionary data type to formatter bytecode.

This addition will help in two ways:
1. A subsequent change will use dictionaries to model "self" ("this")
2. Many formatters internal use a dictionary as an implementation
detail, and this will allow such formatters to be compiled/ported to
formatter bytecode

Assisted-by: claude
2026-10-02 21:23:16 +00:00
Dave Lee d53a3f7552 [lldb] Add null opcode to formatter bytecode (#224443)
This allows formatters to produce a null ValueObject, which can be
needed for
`@get_child_index` or `@get_child_at_index`.
2026-09-29 10:22:24 -07:00
Dave Lee 83728c8a9f [lldb] Add APSInt representation to formatter bytecode (#220665)
Adopt a single representation for integers in the formatter bytecode
interpreter. This simplifies code generation, where the (now deprecated)
distinction of `uint64_t` and `int64_t` types could make conditionals
and other operations more complicated, by having to have code paths for
signed and unsigned.

Depends on https://github.com/llvm/llvm-project/pull/218801

Assisted-by: claude
2026-09-08 20:18:49 -07:00
Dave Lee 11542f5bf4 [lldb][test] Reinforce formatter bytecode unit tests (#211042)
rdar://176903081

Assisted-by: claude
2026-07-22 14:55:39 -07:00
Alexis Engelke 3aec6a40bb [Support] Remove virtual functions from formatv (#207516)
Currently, formatv erases types using a base class and calls the virtual
function format() to format the objects. To avoid these vtables,
refactor formatv to instead store function_refs to a functor (struct
with overloaded operator()). This saves ~5kiB in vtables.

Additionally, add a static assertion that a formatter is present instead
of relying on errors due to missing templates. This requires a little
change to MLIR's tgfmt to use a different name -- previously, the
substitution failure on ArrayRef<> would cause the variadic function to
be skipped, but a static assertion failure is not a substitution error.

Also, simplify the code in FormatVariadicDetails to use if constexpr
instead of template overloads with enable_if, making the code shorter
and easier to read.
2026-07-05 08:45:49 +02:00
Dave Lee d09ffba14f [lldb][bytecode] Add GetParent and Clone selectors (#197312)
`GetParent` and `Clone` are needed to implement a `std::optional<T>`
data formatter for libc++.
2026-05-18 21:50:48 -07:00
Sergei Barannikov 6a02dc584b [lldb] Remove unused argument of DataExtractor constructor (NFC) (#191876)
`AddressSize` parameter is not used by `DataExtractor` and will be
removed in the future. See #190519 for more context.

This also removes two of the four related methods:
```
DataExtractor::GetAsLLVM()
DataExtractor::GetAsLLVMDWARF() - removed as unused
DWARFDataExtractor::GetAsLLVM() - removed as redundant, it hid the equivalent method of DataExtractor
DWARFDataExtractor::GetAsLLVMDWARF()
```

That is, now we have:
```
DataExtractor::GetAsLLVM()
DWARFDataExtractor::GetAsLLVMDWARF()
```
2026-04-20 23:51:03 +03:00
Jason Molenda fb36a54ef6 [lldb] Rename formatv verbose log call, misc log cleanups [NFC] (#186951)
lldb had three preprocessor defines for logging,

LLDB_LOG  - formatv style argument
LLDB_LOGF - printf style argument
LLDB_LOGV - formatv style argument, only when verbose enabled

If you weren't looking at Log.h and the definition of these three, and
wanted to log something with formatv, it was easy to use LLDB_LOGV by
accident. We just had a situation where an important log statement
wasn't logging and it turned out to be this. This is fragile if you
aren't looking at the header directly, so I'd like to make this more
explicit. My proposal:

LLDB_LOG  - formatv style argument
LLDB_LOG_VERBOSE - formatv style argument, only when verbose enabled 
LLDB_LOGF - printf style argument
LLDB_LOGF_VERBOSE - printf style argument, only when verbose enabled

The new fouth one is to remove several places where we do `if (log &&
log->GetVerbose()) LLDB_LOGF (...)` in the sources today, and make both
styles consistent.

This PR implements that change, mechanically changing all LLDB_LOGV's to
LLDB_LOG_VERBOSE.

It also updates many of the `if (log && log->GetVerbose()) LLDB_LOGF`'s.
Some uses of this conditional expression do extra calculations in
addition to logging, and so those were left as-is so we're not doing
throwaway work when running without verbose logging.

There were many instances throughout lldb where callers are still doing
`if (log) LLDB_LOG*(...)`, a remnant of when all calls were to the `Log`
object's `Printf()` method, and you had to check if your local Log*
pointer was non-nullptr before calling the method. I removed those,
again keeping ones where work for logging is done in the block of code.

The code changes are all mechanical and uninteresting, but the question
of whether this naming change is widely agreed on is maybe worth
discussing.
2026-03-18 16:31:33 -07:00
Dave Lee 4baab258b8 [lldb] Add Get(Non)SyntheticValue formatter bytecodes (#174839)
`GetSyntheticValue` in synthetic providers which need to operate on raw
root values, but will often want to use the synthetic value of children,
or nested children.
2026-02-12 10:07:17 -08:00
Dave Lee 52bcdc6ad1 [lldb] Implement bytecode based SyntheticChildren (#179832)
Initial implementation of a [bytecode][1] synthetic provider. This is a follow up to
https://github.com/llvm/llvm-project/pull/114333 which implemented the bytecode
interpreter, support for summary formatters, and more.

rdar://169727764

[1]: https://lldb.llvm.org/resources/formatterbytecode.html
2026-02-11 09:43:59 -08:00
Dave Lee 5587993548 [lldb] Move FormatterBytecode.{h,def} to include/ (#179355)
To allow other headers to reference types declared in `FormatterBytecode.h`.
2026-02-03 08:18:50 -08:00
Dave Lee b026317b59 [lldb] Match #undef to preceding #define (NFC) (#174821) 2026-01-07 13:50:27 -08:00
Charles Zablit b3d130279f [lldb] Upgrade GetIndexOfChildWithName to use llvm::Expected (#136693)
This patch replaces the use of `UINT32_MAX` as the error return value of
`GetIndexOfChildWithName` with `llvm::Expected`.


# Tasks to do in another PR

1. Replace `CalculateNumChildrenIgnoringErrors` with
`CalculateNumChildren`. See [this
comment](https://github.com/llvm/llvm-project/pull/136693#discussion_r2056319358).
2. Update `lldb_private::formatters::ExtractIndexFromString` to use
`llvm::Expected`. See [this
comment](https://github.com/llvm/llvm-project/pull/136693#discussion_r2054217536).
3. Create a new class which carries both user and internal errors. See
[this
comment](https://github.com/llvm/llvm-project/pull/136693#discussion_r2056439608).
2025-04-30 11:44:19 +01:00
Adrian Prantl ee1adc5aab [lldb] Add a return opcode to the formatter bytecode (#121602)
In LLVM we love our early exists and this opcode allows for simpler code
generation.
2025-01-03 15:26:40 -08:00
Adrian Prantl 2470cfab63 [lldb] Disallow left shifts of negative values in the interpreter (#119620)
This trips UBSAN and probably isn't partiuclarly useful either.
2024-12-11 14:16:23 -08:00
Adrian Prantl c00a708fc9 [lldb] Eliminate dead code (NFC) 2024-12-10 17:09:44 -08:00
Adrian Prantl 1593f36935 [lldb] Add explicit type conversion 2024-12-10 17:01:51 -08:00
Adrian Prantl 87659a17d0 Reland: [lldb] Implement a formatter bytecode interpreter in C++
Compared to the python version, this also does type checking and error
handling, so it's slightly longer, however, it's still comfortably
under 500 lines.

Relanding with more explicit type conversions.
2024-12-10 16:37:53 -08:00
Sylvestre Ledru a2fb70523a Revert "[lldb] Add cast to fix compile error on 32-bit platforms"
This reverts commit f6012a209d.

Revert "[lldb] Add cast to fix compile error on 32-but platforms"

This reverts commit d300337e93.

Revert "[lldb] Improve log message to include missing strings"

This reverts commit 0be3348485.

Revert "[lldb] Add comment"

This reverts commit e2bb47443d.

Revert "[lldb] Implement a formatter bytecode interpreter in C++"

This reverts commit 9a9c1d4a61.
2024-12-11 00:00:44 +01:00
Adrian Prantl f6012a209d [lldb] Add cast to fix compile error on 32-bit platforms 2024-12-10 10:28:14 -08:00
Adrian Prantl d300337e93 [lldb] Add cast to fix compile error on 32-but platforms 2024-12-10 10:00:54 -08:00
Adrian Prantl 9a9c1d4a61 [lldb] Implement a formatter bytecode interpreter in C++
Compared to the python version, this also does type checking and error
handling, so it's slightly longer, however, it's still comfortably
under 500 lines.
2024-12-10 09:36:38 -08:00