This is an archive of the discontinued LLVM Phabricator instance.

DWARF: Implement DW_AT_signature lookup for type unit support
ClosedPublic

Authored by labath on May 22 2019, 4:32 AM.

Details

Summary

This patch implements the main feature of type units. When completing a
type, if we encounter a DW_AT_signature attribute, we use it's value to
lookup the complete definition of the type in the relevant type unit.

To enable this lookup, we build up a map of all type units in a symbol
file when parsing the units. Then we consult this map when resolving the
DW_AT_signature attribute.

I include add a couple of tests which exercise the type lookup feature,
including one that ensure we do something reasonable in case we fail to
lookup the type.

A lot of the ideas in this patch have been taken from D32167 and D61505.

Diff Detail

Repository
rL LLVM

Event Timeline

labath created this revision.May 22 2019, 4:32 AM
aprantl added inline comments.May 22 2019, 9:22 AM
source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
255 ↗(On Diff #200703)

Not your code, but it would be easier to follow the logic if we pulled these cases up front:

  if (type_ptr == DIE_IS_BEING_PARSED)
     return type_sp;
  if (type_ptr)
      return type_ptr->shared_from_this();
...
258 ↗(On Diff #200703)

if (type_sp = ParseTypeFromDWARF(sc, signature_die, log, type_is_new_ptr))

clayborg requested changes to this revision.May 22 2019, 10:11 AM

Just fix the return when we have a DW_AT_signature and this is good to go.

source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
267 ↗(On Diff #200703)

We should return before the } on line 267, not on line 265. If we have a DW_AT_signature and we fail to parse a type we won't do any better below when there is no type info right?

source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
74 ↗(On Diff #200703)

llvm::DenseMap?

This revision now requires changes to proceed.May 22 2019, 10:11 AM
JDevlieghere added inline comments.May 22 2019, 4:49 PM
source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
261 ↗(On Diff #200703)

Same here: if (clang::DeclContext *decl_ctx ....

labath updated this revision to Diff 200934.May 23 2019, 5:10 AM
labath marked 7 inline comments as done.
  • implement the sugested changes (except the DenseMap part)
  • fix a bug where we would enter an infinite recursion in case the type in the type unit ended up referring back to itself (and add a test). I do this by setting the DIE_IS_BEING_PARSED flag before doing the DW_AT_signature check (instead of at the beginning of each of the DW_TAG switch cases). This part changes the behavior slightly, because two of the switch cases did not set the DIE_IS_BEING_PARSED flag, but I believe this is actually for the better. In the DW_TAG_ptr_to_member case, I believe this is a bug, and could cause us to recurse infinitely in case of self-referring member pointer types (but I did not try to verify that). For the "default" case, this means that we will print the "unhandled type" warning only once for each DIE, which also sounds like a good thing.
labath added inline comments.May 23 2019, 5:12 AM
source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
255 ↗(On Diff #200703)

Done in r361471.

source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
74 ↗(On Diff #200703)

A sorted vector is the recommended approach for sets and maps with an insert-then-query pattern. Also, a DenseMap would blow up if one of the type signatures happened to be 0xfff...f.

clayborg accepted this revision.May 23 2019, 7:15 AM
This revision is now accepted and ready to land.May 23 2019, 7:15 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2019, 1:11 AM