This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Don't recursively load types of static member variables in the DWARF AST parser
ClosedPublic

Authored by teemperor on Apr 9 2021, 5:01 AM.

Details

Summary

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
being parsed.

The new test case demonstrates the crash that might happen. The crash happens
with the following steps:

  1. We parse class ToLayout and it's members.
  2. We parse the static class member and fully resolve its type (DependsOnParam2<ToLayout>).
  3. That type has a non-static class member DependsOnParam1<ToLayout> for which LLDB will try to calculate the size.
  4. The layout (and size)DependsOnParam1<ToLayout> turns depends on the ToLayout size/layout.
  5. 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());

Fixed rdar://67910011

Diff Detail

Event Timeline

teemperor created this revision.Apr 9 2021, 5:01 AM
teemperor requested review of this revision.Apr 9 2021, 5:01 AM
teemperor updated this revision to Diff 336403.
  • Add missing test case.
teemperor edited the summary of this revision. (Show Details)Apr 9 2021, 10:16 AM
shafik accepted this revision.Apr 9 2021, 10:54 AM

LGTM

This revision is now accepted and ready to land.Apr 9 2021, 10:54 AM
This revision was landed with ongoing or failed builds.Apr 12 2021, 5:37 AM
This revision was automatically updated to reflect the committed changes.