When LLDB's DWARF parser is parsing the member DIEs of a struct/class it
currently fully resolves the types of static member variables in a class before
adding the respective VarDecl to the record.
For record types fully resolving the type will also parse the member DIEs of the
respective class. The other way of resolving is just 'forward' resolving the type
which will try to load only the minimum amount of information about the type
(for records that would only be the name/kind of the type). Usually we always
resolve types on-demand so it's rarely useful to speculatively fully resolve
them on the first use.
This patch changes makes that we only 'forward' resolve the types of static
members. This solves the fact that LLDB unnecessarily loads debug information
to parse the type if it's maybe not needed later and it also avoids a crash where
the parsed type might in turn reference the surrounding class that is currently
The new test case demonstrates the crash that might happen. The crash happens
with the following steps:
- We parse class ToLayout and it's members.
- We parse the static class member and fully resolve its type (DependsOnParam2<ToLayout>).
- That type has a non-static class member DependsOnParam1<ToLayout> for which LLDB will try to calculate the size.
- The layout (and size)DependsOnParam1<ToLayout> turns depends on the ToLayout size/layout.
- Clang will calculate the record layout/size for ToLayout even though we are currently parsing it and it's missing it's non-static member.
The created is missing the offset for the yet unparsed non-static member. If we later try to
get the offset we end up hitting different asserts. Most common is the one in TypeSystemClang::DumpValue
where it checks that the record layout has offsets for the current FieldDecl.
assert(field_idx < record_layout.getFieldCount());