[Lldb-commits] [lldb] [lldb][DWARF] Delay struct/class/union definition DIE searching when parsing declaration DIEs. (PR #90663)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Fri May 3 11:15:20 PDT 2024


clayborg wrote:

> > > > Is any of it testable?
> > > 
> > > 
> > > Good question. Though this is mostly meant to be "NFC" (with very large quotes), I can imagine us doing something like forcing the parsing of a specific type (`type lookup <something>` ?), and then checking that the module ast (`image dump ast`) does _not_ contain specific types -- as that's basically what we're trying to achieve.
> > 
> > 
> > Yea that could work. But if it's going to be very painful or fragile to test then don't let that hold back the PR
> 
> In terms of testing, since this only delays definition DIE searching not type completion, we need to construct a test so that lldb finds the declaration DIE first without trigger a type completion on it and somehow test the incomplete type. The first part is tricky. I'm not sure how to achieve it.

You should be able to make a test case with two files. One file contains the class definition and the other uses only a forward declaration. You could test by running the binary stopping only in the one with the forward declaration. So file 1 would be something like `foo.cpp` containing
```
struct Foo { 
  int value;
  Foo(int v): value(v) {}
};

Foo *CreateFoo() {
  return new Foo(1);
}

```
Then having `main.cpp` contain:
```
struct Foo; // Forward declare Foo
// Prototypes that don't need Foo definition
void Increment(Foo *); 
Foo *CreateFoo();

int main() {
  Foo *foo = CreateFoo();
  return 0; // Breakpoint 1 here
}
```
Then run to "Breakpoint 1 here" and then run `frame variable foo`. Foo won't need to be completed for this. But if you then run `frame variable *foo`, it should cause the type to be completed and show the instance variable correctly.


https://github.com/llvm/llvm-project/pull/90663


More information about the lldb-commits mailing list