37 Commits

Author SHA1 Message Date
jeffreytan81
d6ae568d58
Fix LLDB data formatter for llvm::Expected<T> with non-reference types (#179294)
This patch fixes LLDB data formatter support for llvm::Expected<T> with
the following changes:

llvm/utils/lldbDataFormatters.py: Fix ExpectedSynthProvider to handle
non-templated storage types (e.g., int, int*). Previously the formatter
only worked with templated storage types like std::reference_wrapper<T>.

cross-project-tests/lit.cfg.py:

Fix get_lldb_version_string() to use locally-built LLDB on non-Darwin
platforms instead of system LLDB
Fix minimum version from "1900" to "19.0.0" (typo in original code)
New test files: Added expected.cpp and expected.test to test the
formatter with Expected<int> and Expected<int*>.

---------

Co-authored-by: Jeffrey Tan <jeffreytan@fb.com>
2026-02-09 19:23:40 -08:00
Michael Buch
f73f43cf50
[llvm][formatters] Add LLDB formatter for llvm::PointerUnion (#175218)
We make use of the fact that the `PointerUnion` element is a
`PointerIntPair`, for which we have a synthetic provider already. We get
the `Int` portion of the pair (which is the index into the template
parameter pack of the union) to get the active type and the `Pointer`
portion of the pair to get the actual pointer value.

Before:
```
(lldb) (lldb) v -T z_float
(llvm::PointerUnion<Z *, float *>) z_float = {
  (llvm::pointer_union_detail::PointerUnionMembers<llvm::PointerUnion<Z *, float *>, llvm::PointerIntPair<void *, 1, int, llvm::pointer_union_detail::PointerUnionUIntTraits<Z *, float *> >, 0, Z *, float *>) llvm::pointer_union_detail::PointerUnionMembers<llvm::PointerUnion<Z *, float *>, llvm::PointerIntPair<void *, 1, int, llvm::pointer_union_detail::PointerUnionUIntTraits<Z *, float *>, llvm::PointerIntPairInfo<void *, 1, llvm::pointer_union_detail::PointerUnionUIntTraits<Z *, float *> > >, 0, Z *, float *> = {
    (llvm::pointer_union_detail::PointerUnionMembers<llvm::PointerUnion<Z *, float *>, llvm::PointerIntPair<void *, 1, int, llvm::pointer_union_detail::PointerUnionUIntTraits<Z *, float *> >, 1, float *>) llvm::pointer_union_detail::PointerUnionMembers<llvm::PointerUnion<Z *, float *>, llvm::PointerIntPair<void *, 1, int, llvm::pointer_union_detail::PointerUnionUIntTraits<Z *, float *>, llvm::PointerIntPairInfo<void *, 1, llvm::pointer_union_detail::PointerUnionUIntTraits<Z *, float *> > >, 1, float *> = {
      (llvm::pointer_union_detail::PointerUnionMembers<llvm::PointerUnion<Z *, float *>, llvm::PointerIntPair<void *, 1, int, llvm::pointer_union_detail::PointerUnionUIntTraits<Z *, float *> >, 2>) llvm::pointer_union_detail::PointerUnionMembers<llvm::PointerUnion<Z *, float *>, llvm::PointerIntPair<void *, 1, int, llvm::pointer_union_detail::PointerUnionUIntTraits<Z *, float *>, llvm::PointerIntPairInfo<void *, 1, llvm::pointer_union_detail::PointerUnionUIntTraits<Z *, float *> > >, 2> = {
        (llvm::PointerIntPair<void *, 1, int, llvm::pointer_union_detail::PointerUnionUIntTraits<Z *, float *> >) Val = {...}
      }
    }
  }
}
```

After:
```
(llvm::PointerUnion<Z *, float *>) z_float = {
  (float *) Pointer = 0x000000016fdfebb0
}
```
2026-01-12 15:20:03 +00:00
Michael Buch
0b9d07860a Reland "[llvm][formatters] Add LLDB data-formatter for llvm::PointerIntPair"
Reverts a4cc033408fe0a69aad6865ddc7e020d64098f20.

Relanding the original patch as-is, but changing the `__builtin_debugtrap`s to explicitly set breakpoints. Some bots failed to compile the tests when `__builtin_debugtrap` was used.

Also adding `REQUIRES: lldb-formats-compatibility` to the test because some build-bots run the tests with an LLDB version that doesn't support the `FindDirectNestedType` API.

Original commit message:

This patch revives the llvm::PointerIntPair LLDB data-formatter. The previous version was commented out because it relied on expression evaluation and was hence slow/brittle. The formatter in this PR doesn't rely on evaluating expressions.

Drive-by change:
* removes the llvm::PointerUnion formatter which was also commented out. A future version of it will look very different than it does now, so there's no point in keeping it because the diff won't be helpful in a review.
2026-01-07 18:10:46 +00:00
Michael Buch
a4cc033408
Revert "[llvm][formatters] Add LLDB data-formatter for llvm::PointerIntPair" (#174673)
Reverts llvm/llvm-project#173261

Some bots were failing with:
```
Step 6 (build-unified-tree) failure: build (failure)
...
2.874 [7103/10/382] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/CallingConvEmitter.cpp.o
2.875 [7102/10/383] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeEmitterGen.cpp.o
2.895 [7101/10/384] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenMapTable.cpp.o
2.896 [7100/10/385] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/CompressInstEmitter.cpp.o
2.898 [7099/10/386] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/CTagsEmitter.cpp.o
2.901 [7098/10/387] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/DAGISelEmitter.cpp.o
2.905 [7097/10/388] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/DAGISelMatcherEmitter.cpp.o
2.918 [7096/10/389] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/DAGISelMatcherGen.cpp.o
2.920 [7095/10/390] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/DecoderTree.cpp.o
2.932 [7094/10/391] Building CXX object projects/cross-project-tests/CMakeFiles/check-lldb-llvm-support-pointer-int-pair.dir/debuginfo-tests/llvm-prettyprinters/lldb/pointer-int-pair.cpp.o
FAILED: projects/cross-project-tests/CMakeFiles/check-lldb-llvm-support-pointer-int-pair.dir/debuginfo-tests/llvm-prettyprinters/lldb/pointer-int-pair.cpp.o 
/opt/ccache/bin/g++ -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GLIBCXX_USE_CXX11_ABI=1 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/buildbot/buildbot-root/abi-test/build/projects/cross-project-tests -I/home/buildbot/buildbot-root/abi-test/llvm/cross-project-tests -I/home/buildbot/buildbot-root/abi-test/build/include -I/home/buildbot/buildbot-root/abi-test/llvm/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-array-bounds -Wno-stringop-overread -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -UNDEBUG -g -O0 -std=c++17 -MD -MT projects/cross-project-tests/CMakeFiles/check-lldb-llvm-support-pointer-int-pair.dir/debuginfo-tests/llvm-prettyprinters/lldb/pointer-int-pair.cpp.o -MF projects/cross-project-tests/CMakeFiles/check-lldb-llvm-support-pointer-int-pair.dir/debuginfo-tests/llvm-prettyprinters/lldb/pointer-int-pair.cpp.o.d -o projects/cross-project-tests/CMakeFiles/check-lldb-llvm-support-pointer-int-pair.dir/debuginfo-tests/llvm-prettyprinters/lldb/pointer-int-pair.cpp.o -c /home/buildbot/buildbot-root/abi-test/llvm/cross-project-tests/debuginfo-tests/llvm-prettyprinters/lldb/pointer-int-pair.cpp
/home/buildbot/buildbot-root/abi-test/llvm/cross-project-tests/debuginfo-tests/llvm-prettyprinters/lldb/pointer-int-pair.cpp: In function ‘int main()’:
/home/buildbot/buildbot-root/abi-test/llvm/cross-project-tests/debuginfo-tests/llvm-prettyprinters/lldb/pointer-int-pair.cpp:25:3: error: ‘__builtin_debugtrap’ was not declared in this scope; did you mean ‘__builtin_trap’?
   25 |   __builtin_debugtrap();
      |   ^~~~~~~~~~~~~~~~~~~
      |   __builtin_trap
2.932 [7094/9/392] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/DAGISelMatcherOpt.cpp.o
2.933 [7094/8/393] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/DecoderTableEmitter.cpp.o
2.936 [7094/7/394] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/DecoderEmitter.cpp.o
2.937 [7094/6/395] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/DFAEmitter.cpp.o
2.944 [7094/5/396] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/DFAPacketizerEmitter.cpp.o
3.340 [7094/4/397] Building PPCGenTargetFeatures.inc...
3.450 [7094/3/398] Building ARMTargetParserDef.inc...
3.780 [7094/2/399] Building AArch64TargetParserDef.inc...
5.093 [7094/1/400] Building RISCVTargetParserDef.inc...
ninja: build stopped: subcommand failed.
```
2026-01-07 00:36:05 +00:00
Michael Buch
9471f530b7
[llvm][formatters] Add LLDB data-formatter for llvm::PointerIntPair (#173261)
Depends on:
* https://github.com/llvm/llvm-project/pull/173238

(only last commit relevant for review)

This patch revives the `llvm::PointerIntPair` LLDB data-formatter. The
previous version was commented out because it relied on expression
evaluation and was hence slow/brittle. The formatter in this PR doesn't
rely on evaluating expressions.

Drive-by change:
* removes the `llvm::PointerUnion` formatter which was also commented
out. A future version of it will look very different than it does now,
so there's no point in keeping it because the diff won't be helpful in a
review.
2026-01-06 23:28:40 +00:00
Ebuka Ezike
9ef60ff7ff
[llvm][utils] Improve the StringRef summary provider (#162298)
- check the length of data before casting as `char[N]` because the will
cause lldb to allocate `N` bytes of memory.

---------

Co-authored-by: Dave Lee <davelee.com@gmail.com>
2025-10-24 12:07:12 +01:00
Dave Lee
933d8723b0
[llvm][utils] Improve the StringRef summary formatter (#151594)
Improve the `StringRef` summary formatter in the following ways:
* inherit adherence to the `target.max-string-summary-length` setting
* support non-printable bytes (such as null bytes, and any other binary data)

With the previous implementation, some non-printable bytes would raise a
Python exception.
2025-08-21 13:42:49 -07:00
Dave Lee
eba0c57411
[llvm][utils] Add summary formatter for SmallBitVector (#150542)
Originally implemented in https://github.com/swiftlang/swift/pull/29014.

I've made a couple changes:
1. Use the target's address size, not lldb
2. Replaced the loop with a format string
2025-07-28 10:38:51 -07:00
Dave Lee
cbc2ef0e89
[llvm][utils] Add synthetic provider for llvm::DenseSet (#143631)
Add a synthetic child provider for `DenseSet`, which is a wrapper around
`DenseMap`. This provider leverages the existing `DenseMap` provider,
reshaping its dictionary structured children into a set.
2025-06-12 10:13:30 -07:00
Aaron Puchert
1c04ebbbb5
Remove debugger pretty printers for llvm::Optional (#135235)
Since 2916b99182752b1aece8cc4479d8d6a20b5e02da this is just an alias to
std::optional, and by now it has been removed entirely.
2025-04-14 14:11:55 +02:00
Dave Lee
398f3b368a
[lldb] Add synthetic formatter for llvm::Expected (#118758)
Adds a synthetic formatter for `llvm::Expected<T>`. The synthetic value
will have a single child, either `value` or `error`.
2024-12-05 19:31:20 -08:00
Alexander Richardson
db9811cd13
Make lldbDataFormatters.py compatible with Python 3.8 (#82518)
I just tried to load this into LLDB built against Python 3.8.5 and got
the following error: `TypeError: 'type' object is not subscriptable`. I
could fix this by wrapping the annotations in quotes but since Python
3.7 this syntax can be enabled with `from __future__ import
annotations`.
2024-02-21 11:53:01 -08:00
Dave Lee
45d1cca339
[llvm][utils] Fix SmallString summary provider (#78527)
Fixes `SmallString` summary provider, which was incorrectly producing the empty string. 
Initially I thought the strings I was debugging were empty for unknown reasons, but 
that was not the case.
2024-01-18 10:35:18 -08:00
Dave Lee
a4b82f7f9b
[lldb] Allow lldbDataFormatters.py to be used by other names (NFC) (#65528)
Instead of hard-coding the name `lldbDataFormatters`, use `__name__` to
get the module's name.

This allows the formatters to be loaded from any path, with any
filename.
2023-09-06 13:39:45 -07:00
Michael Buch
bb90a5cf20 [llvm][utils] Fix SmallVector formatter when type is a pointer
Previously types such as `SmallVector<clang::Attr, 4> *` would
trigger the assertion inside the `SmallVector` formatter:
```
assert self.type_size != 0
```
This happens because `the_type.GetTemplateArgumentType(0)` returns
`None` (since `the_type` is a pointer to the `SmallVector`).

This patch dereferences `the_type` if it's a pointer type. We do this
for references already.

Differential Revision: https://reviews.llvm.org/D157961
2023-08-15 23:09:59 +01:00
Dave Lee
b8580ef717 [llvm][utils] Use literal type name for non-template data formatters (NFC)
These don't need to be regex.
2023-07-20 19:33:47 -07:00
Dave Lee
78c9122ac9 [llvm][utils] Add DenseMap data formatters
Add summary and synthetic data formatters for `llvm::DenseMap`.

This implementation avoids expression evaluation by using a heuristic. However, as
heuristics go, there is a corner case: A single deleted entry (a single "tombstone"),
will result in a child value with an invalid key but a valid value.

Instead of calling `getEmptyKey()` and `getTombstoneKey()` to determine which buckets
are empty, and which contain real key-values, the heuristic scans all buckets to
identify keys that exist only once. These singleton keys are considered valid.

The empty key will always exist multiple times. However the tombstone key may exist
zero, one, or many times. The heuristic has no problems when there are zero or many
tombstones, but when there is exactly one deleted entry (one tombstone), then the
heuristic will incorrectly identify it as valid.

Differential Revision: https://reviews.llvm.org/D137028
2023-07-19 13:21:49 -07:00
Dave Lee
f0acfaf924 [llvm][utils] Disable lldb formatters for PointerIntPair and PointerUnion
These synthetic providers use expression evaluation and fail in some cases.

Examples:

```
llvm::PointerIntPair<llvm::PointerUnion<const Type *, const ExtQuals *>,
                     Qualifiers::FastWidth> Value;
```

and

```
typedef llvm::PointerUnion<const ValueDecl *, const Expr *, TypeInfoLValue,
                           DynamicAllocLValue>
        PtrTy;
```

Original contribution: D117779

rdar://110791233
rdar://112195543

Differential Revision: https://reviews.llvm.org/D155219
2023-07-13 15:51:25 -07:00
Tobias Hieta
b71edfaa4e
[NFC][Py Reformat] Reformat python files in llvm
This is the first commit in a series that will reformat
all the python files in the LLVM repository.

Reformatting is done with `black`.

See more information here:

https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style

Reviewed By: jhenderson, JDevlieghere, MatzeB

Differential Revision: https://reviews.llvm.org/D150545
2023-05-17 10:48:52 +02:00
Dave Lee
987d5e6c6c [llvm][utils] Make lldb data formatters show both summaries and children
When a type has a summary and synthetic child provider, the children are shown
only if `--expand`/`-e` is given.

This updates `lldbDataFormatters.py` to expand children of types that have both
a summary and synthetic children.

Differential Revision: https://reviews.llvm.org/D132095
2022-08-22 18:08:53 -07:00
Dave Lee
826bdf51ff [lldb] Fix llvm::Optional summary provider
Differential Revision: https://reviews.llvm.org/D122041
2022-03-21 10:03:16 -07:00
Sergej Jaskiewicz
773467c812 [LLDB] Add formatters for PointerIntPair, PointerUnion
Also, add summaries for `SmallVector` and `ArrayRef`,
and fix the `StringRef` summary provider so it doesn't
ignore the `Length` field.

Differential Revision: https://reviews.llvm.org/D117779
2022-01-27 12:54:16 +03:00
Dave Lee
50a6aa6c0f [llvm][utils] Fix handling of llvm::None 2021-03-29 17:43:53 -07:00
Dave Lee
a01a406bba [llvm][utils] Fix innocuous off by one in lldb formatters
num_children is "last_index" + 1, thus
    num_children + 1 = "last_index" + 2

this worked anyway because the index of `$$dereference$$` would work as long as
it was past the last index.
2021-02-26 08:10:41 -08:00
Dave Lee
8d1b6afcea [llvm][utils] Rename lldb dict variables to internal_dict
Most lldb scripts use `internal_dict`. Also, `dict` is a builtin constructor,
it's good habit to avoid using it as a variable name.
2021-02-26 07:46:54 -08:00
Dave Lee
408456f53e [llvm][utils] Support dereferencing llvm::Optional lldb formatter
Add deref support to `llvm::Optional` in `lldbDataFormatters.py`.

This creates a synthetic provider that adds dereference support, but otherwise proxies all access to the underlying value.

With this change, an optional value can be displayed by running `v *someOptional`, and its contents can be accessed with the arrow `operator->`, for example `v someOpt->HasThing`. This matches expressions usable from expression evaluation.

See also D97165 and D97524.

Differential Revision: https://reviews.llvm.org/D97525
2021-02-26 07:43:33 -08:00
Adrian Prantl
a206ca40b5 Bring llvm::Optional data formatter back in sync with the implementation. 2020-08-26 15:10:39 -07:00
Adrian Prantl
828fb0c51a Fix a null dereference in the LLDB data formatters. 2020-02-25 16:43:55 -08:00
Adrian Prantl
43c8b19546 Add LLDB dataformatters for llvm::StringRef and lldb_private::ConstString
These data formatters make the string value appear in Xcode's
variables view (and on the command line) without having to expand the
data structure.

Differential Revision: https://reviews.llvm.org/D66354

llvm-svn: 369175
2019-08-16 23:47:57 +00:00
Davide Italiano
4f88388c0b [utils] Add a lldb data formatter for llvm::SmallString.
Result:

(lldb) p val
(llvm::SmallString<32>) $31 = "patatino"

llvm-svn: 359157
2019-04-25 00:03:02 +00:00
Justin Bogner
628ea14557 [utils] Update SmallVector lldb formatter for r337514
SmallVector was changed to store a begin and a size rather than a
begin and an end a while back. Update the formatter to look at the
correct members.

llvm-svn: 346252
2018-11-06 18:52:30 +00:00
Vedant Kumar
0970e2e34f [utils] Fix the llvm::Optional data formatter
The llvm::Optional data formatter needs to look through the `Storage`
container if it's present.

Before:

   220    if (Op && Op->getOp() != dwarf::DW_OP_LLVM_fragment)
-> 221      HasComplexExpression = true;
   222
   223    // If the register can only be described by a complex expression (i.e.,
   224    // multiple subregisters) it doesn't safely compose with another complex
Target 0: (llc) stopped.
(lldb) p Op
(llvm::Optional<llvm::DIExpression::ExprOperand>) $0 = None

After:

(lldb) p Op
(llvm::Optional<llvm::DIExpression::ExprOperand>) $0 =
(llvm::DIExpression::ExprOperand) storage = {
  Op = 0x000000010603d460
}

llvm-svn: 337752
2018-07-23 21:59:06 +00:00
Justin Bogner
3e18de2dbb utils: Teach lldbDataFormatters about llvm::Optional
llvm-svn: 229956
2015-02-20 02:55:22 +00:00
Justin Bogner
8e5f548b81 utils: Teach lldbDataFormatters how to format ArrayRefs
llvm-svn: 217567
2014-09-11 01:47:38 +00:00
Justin Bogner
dc30fbf7b6 utils: Teach lldbDataFormatters to load automatically
Add an __lldb_init_module function so that importing the
lldbDataFormatters script automatically adds the formatters.

llvm-svn: 209712
2014-05-28 05:45:17 +00:00
Benjamin Kramer
91b014cd66 Simplify the SmallVector pretty printer for LLDB a bit and make it work with reference types.
llvm-svn: 167674
2012-11-10 09:45:32 +00:00
Benjamin Kramer
50b78ec043 Add an LLDB data formatter script for llvm::SmallVector, maybe this is helpful to someone else.
This lets lldb give sane output for SmallVectors, e.g.
Before:
(lldb) p sv
(llvm::SmallVector<int, 10>) $0 = {
  (llvm::SmallVectorImpl<int>) llvm::SmallVectorImpl<int> = {
    (llvm::SmallVectorTemplateBase<int>) llvm::SmallVectorTemplateBase<int> = {
      (llvm::SmallVectorTemplateCommon<int>) llvm::SmallVectorTemplateCommon<int> = {
        (llvm::SmallVectorBase) llvm::SmallVectorBase = {
          (void *) BeginX = 0x00007fff5fbff960
...
}

After:
(lldb) p sv
(llvm::SmallVector<int, 10>) $0 = {
  (int) [0] = 42
  (int) [1] = 23
...
}

The script is still a bit rough so expect crashes for vectors of complex types.
Synthetic children are _not_ available in xcode 4.2, newer LLDBs should work though.

llvm-svn: 148308
2012-01-17 14:52:12 +00:00