23 Commits

Author SHA1 Message Date
Dave Lee
b66d98afb9
[lldb][bytecode] Improvements to compiler generated Swift (#189425)
Following feedback from @benrimmington in
https://github.com/apple/swift-collections/pull/607, this changes the
following:

1. Uses `objectFormat()` compiler conditional instead of `os()` (see
"Cross-platform object file format support" in
[SE-0492](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0492-section-control.md#cross-platform-object-file-format-support))
2. Uses a raw identifier for the generated Swift symbol name, instead of
an escaped name (see
[SE-0451](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0451-escaped-identifiers.md))
2026-03-31 08:23:30 -07:00
Dave Lee
821c22a1be
[lldb][bytecode] Change compiler to require update return type decl (#188637)
To better ensure that bytecode `@update` implementations return a 0/1
value (see https://github.com/llvm/llvm-project/pull/181199), this
changes the Python -> formatter bytecode compiler to require that Python
`update` methods be declared to return `bool`.

A declaration like this will be a compiler error:

```py
def update(self):
    # implementation...
```
2026-03-26 14:39:18 -07:00
Dave Lee
95546c849e
[lldb] Fix value of sig_update in formatter_bytecode.py (#188292) 2026-03-24 17:41:13 +00:00
Dave Lee
d8e1f50780
[lldb][bytecode] Document invocation in compiler output (#187547)
Document compiler invocation in the compiler output, to aide subsequent
regeneration.
2026-03-20 10:30:38 -07:00
Dave Lee
05ae66851d
[lldb][bytecode] Swift output is conditional on >=6.3 (#187544)
The `@section` and `@used` attributes are available in Swift 6.3 and
later. See [SE-0492][1].

Prior to 6.3, these were available as `@_section` and `@_used`, however
those require enabling the `SymbolLinkageMarkers ` experimental feature.

[1]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0492-section-control.md
2026-03-19 17:49:39 +00:00
Dave Lee
23d8651de3
[lldb][bytecode] Remove tracking of stack temps in compiler (#187401)
The `num_temps` was introduced under the mistaken understanding of the
index values given to the `pick` op. I thought the `pick` index was from
the top of the stack, but it's from the bottom. The model of indexing
from the bottom of the stack has the benefit of simplifying the
compiler.
2026-03-19 10:10:47 -07:00
Dave Lee
d70ebc84ac
[lldb][bytecode] Compile pick ops using unsigned literal (#187376)
The `pick` op requires an unsigned integer index. Use the `u` suffix
when generating `pick` operations in the Python->formatter-bytecode
compiler.
2026-03-18 14:15:24 -07:00
Dave Lee
6903a58870
[lldb][bytecode] Add swift output to Python->bytecode compiler (#185773)
For swift projects using the compiler, having a swift output option will
make it easier to integrate bytecode formatters into the build.
2026-03-11 15:36:52 -07:00
Dave Lee
13b394312b
[lldb][bytecode] Add Python to formatter bytecode compiler (#113734)
A compiler from Python to the assembly syntax of the [lldb data
formatter
bytecode](https://discourse.llvm.org/t/a-bytecode-for-lldb-data-formatters/82696).

Assisted-by: claude
2026-03-09 13:48:24 -07:00
Dave Lee
9145a7484e
[lldb] Use "assemble" instead of "compile" in formatter_bytecode.py (#184714)
Replace "compile" with "assemble" in formatter_bytecode. This is in
preparation for the addition of a Python to formatter bytecode compiler.
It will be more clear to have one meaning for "compile".
2026-03-05 11:11:32 -08:00
Dave Lee
ece4b75932
[lldb] Add C source output mode to formatter_bytecode.py (#184242)
Add the ability to generate a C source file, which is in addition to the
existing functionality of generating binary.

An example of the generated source:

```c
#ifdef __APPLE__
#define FORMATTER_SECTION "__DATA_CONST,__lldbformatters"
#else
#define FORMATTER_SECTION ".lldbformatters"
#endif

__attribute__((used, section(FORMATTER_SECTION)))
unsigned char _Account_synthetic[] =
    // version
    "\x01"
    // remaining record size
    "\x15"
    // type name size
    "\x07"
    // type name
    "Account"
    // flags
    "\x00"
    // sig_get_num_children
    "\x02"
    // program size
    "\x02"
    // program
    "\x20\x01"
    // sig_get_child_at_index
    "\x04"
    // program size
    "\x06"
    // program
    "\x02\x20\x00\x23\x11\x60"
;
```
2026-03-03 15:48:30 -08:00
Dave Lee
a0fb4f6708
[lldb] Add BytecodeSection class to formatter_bytecode.py (#183876)
Changes `formatter_bytecode.compile_file` to return a `BytecodeSection`
value. The `BytecodeSection` holds the data that needs to be emitted to
an `__lldbformatters` section.

The `BytecodeSection` currently provides `write_binary`, but will be
updated in a follow up commit to include `write_source` which will allow
the data to be emitted as C source code, or Swift source code. This will
make it easier to integrate into build systems, as it's easier to get
data into a binary via source code, than as a raw binary file.
2026-02-28 14:31:26 -08:00
Dave Lee
fd9421cccd
[lldb] Fix sys.path manipulation failure in formatter_bytecode.py (#183868)
Fix bug in #183804.
2026-02-28 00:07:41 +00:00
Dave Lee
abbba22f45
[lldb] Add synthetic support to formatter_bytecode.py (#183804)
Updates formatter_bytecode.py to support compilation and disassembly for
synthetic formatters, in other words support for multiple functions
(signatures).

This includes a number of other changes:
* String parsing and encoding have bugs fixed
* CLI args are updated, primarily to support an output file
* Added uleb encoding/decoding support

This work is a prelude the ongoing work of a Python to formatter
bytecode compiler. The python compiler to emit assembly, and this module
(formatter_bytecode) will compile it into binary bytecode.
2026-02-27 14:20:19 -08:00
Dave Lee
0668d9939f
[lldb] Improve unittest invocation in formatter_bytecode.py (#183394) 2026-02-25 14:40:17 -08: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
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
9f98949c94 [lldb] Move the python module import workaround further up 2024-12-06 17:01:58 -08:00
Adrian Prantl
fffe8c6684 [lldb] Add a compiler/interpreter of LLDB data formatter bytecode to examples
This PR adds a proof-of-concept for a bytecode designed to ship and
run LLDB data formatters. More motivation and context can be found in
the formatter-bytecode.rst file and on discourse.

https://discourse.llvm.org/t/a-bytecode-for-lldb-data-formatters/82696

Relanding with a fix for a case-sensitive path.
2024-12-06 16:27:16 -08:00
Adrian Prantl
b504c8771f Revert "[lldb] Add a compiler/interpreter of LLDB data formatter bytecode to examples"
This reverts commit 60380cd27c6fa5ed6e39866c51b18a64bc4d566a.
2024-12-06 16:26:55 -08:00
Adrian Prantl
60380cd27c [lldb] Add a compiler/interpreter of LLDB data formatter bytecode to examples
This PR adds a proof-of-concept for a bytecode designed to ship and
run LLDB data formatters. More motivation and context can be found in
the formatter-bytecode.rst file and on discourse.

https://discourse.llvm.org/t/a-bytecode-for-lldb-data-formatters/82696

Relanding with a fix for a case-sensitive path.
2024-12-06 16:10:09 -08:00
Adrian Prantl
8ab76a47b2 Revert "[lldb] Add a compiler/interpreter of LLDB data formatter bytecode to examples"
This reverts commit 7e3da87ca896484a11ac09df297183147154ac91.

I managed to break the bots.
2024-12-06 15:34:12 -08:00
Adrian Prantl
0ee364d2a2
[lldb] Add a compiler/interpreter of LLDB data formatter bytecode to lldb/examples (#113398)
This PR adds a proof-of-concept for a bytecode designed to ship and run
LLDB data formatters. More motivation and context can be found in the
`formatter-bytecode.md` file and on discourse.

https://discourse.llvm.org/t/a-bytecode-for-lldb-data-formatters/82696
2024-12-06 15:11:21 -08:00