26 Commits

Author SHA1 Message Date
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