Currently, the type `T`'s summary formatter will be matched for `T`,
`T*`, `T**` and so on. This is unexpected in many data formatters. Such
unhandled cases could cause the data formatter to crash. An example
would be the lldb's built-in data formatter for `std::optional`:
```
$ cat main.cpp
#include <optional>
int main() {
std::optional<int> o_null;
auto po_null = &o_null;
auto ppo_null = &po_null;
auto pppo_null = &ppo_null;
return 0;
}
$ clang++ -g main.cpp && lldb -o "b 8" -o "r" -o "v pppo_null"
[lldb crash]
```
This change adds an options `--pointer-match-depth` to `type summary
add` command to allow users to specify how many layer of pointers can be
dereferenced at most when matching a summary formatter of type `T`, as
Jim suggested
[here](https://github.com/llvm/llvm-project/pull/124048/#issuecomment-2611164133).
By default, this option has value 1 which means summary formatter for
`T` could also be used for `T*` but not `T**` nor beyond. This option is
no-op when `--skip-pointers` is set as well.
I didn't add such option for `type synthetic add`, `type format add`,
`type filter add`, because it useful for those command. Instead, they
all have the pointer match depth of 1. When printing a type `T*`, lldb
never print the children of `T` even if there is a synthetic formatter
registered for `T`.
33 lines
488 B
C++
33 lines
488 B
C++
struct Int {
|
|
int i;
|
|
};
|
|
typedef Int Foo;
|
|
typedef Int *FooP;
|
|
typedef Foo Bar;
|
|
typedef Foo *BarP;
|
|
|
|
int main() {
|
|
Int i = {42};
|
|
Int *i_p = &i;
|
|
Int **i_pp = &i_p;
|
|
Int ***i_ppp = &i_pp;
|
|
|
|
Foo f = i;
|
|
Foo *f_p = &f;
|
|
Foo **f_pp = &f_p;
|
|
Foo ***f_ppp = &f_pp;
|
|
|
|
FooP fp = f_p;
|
|
FooP *fp_p = &fp;
|
|
FooP **fp_pp = &fp_p;
|
|
|
|
Bar b = i;
|
|
Bar *b_p = &b;
|
|
Bar **b_pp = &b_p;
|
|
|
|
BarP bp = b_p;
|
|
BarP *bp_p = &bp;
|
|
BarP **bp_pp = &bp_p;
|
|
return 0; // Set break point at this line.
|
|
}
|