This is an archive of the discontinued LLVM Phabricator instance.

Make getUnitForOffset a DWARFUnit method instead of a DWARFContext method.
ClosedPublic

Authored by friss on Sep 11 2014, 5:07 AM.

Details

Summary

This commit moves the Unit lookup code from the DWARFContext into
a static member of the DWARFUnit. Using a CRTP, each Unit embeds
a reference to the vector of all Units extracted from the same
section. This vector is qureried in getUnitForOffset in order to
be able to extract DIEs referenced from a foreign Unit (this happens
with LTO type uniquing for example). This works whatever the Unit's
origin: .debug_info, .debug_types or their dwo variants.

The DWARFContext API is left untouched by forwarding it lookup code
to the DWARFUnit static member.

This code will be exercised/tested in a followup patch that makes
dwarfdump emit the name for DW_AT_abstract_origin and DW_AT_specification
attributes.

Note that this commit contains a fixed version of the unit lookup code
that hasn't been approved yet.

Diff Detail

Event Timeline

friss updated this revision to Diff 13582.Sep 11 2014, 5:07 AM
friss retitled this revision from to Make getUnitForOffset a DWARFUnit method instead of a DWARFContext method..
friss added reviewers: dblaikie, samsonov, echristo, aprantl.
friss updated this object.
friss added a subscriber: Unknown Object (MLST).
dblaikie added inline comments.Sep 11 2014, 9:20 AM
lib/DebugInfo/DWARFContext.cpp
394

You shouldn't need to specify UnitType here, should you? Template argument deduction should fire on the first parameter. (similarly at the other call site)

lib/DebugInfo/DWARFUnit.h
217

You shouldn't need to specify UnitType here, should you? Template argument deduction should fire on the first parameter.

232

This doesn't necessarily have to be moved to the DWARFUnit - it could remain in the DWARFContext - though perhaps there's a circular referencing problem that makes this more convenient/possible here rather than where it was originally?

234

This looks like it's also changing the semantics based on one of your other code reviews - it'd be good to keep these things separate. (similarly I see the getOffset -> getNextUnitOffset change in the UnitOffsetComparator above)

friss added inline comments.Sep 11 2014, 10:03 AM
lib/DebugInfo/DWARFContext.cpp
394

No, type deduction doesn't seem to work here. Just a guess: the implicit conversion from SmallVector to SmallVectorImpl might be an issue?

lib/DebugInfo/DWARFUnit.h
217

As said above, it doesn't work.

232

Honestly, when I moved it to a header, I just thought that something comparing Units is better suited in the DWARFUnit class. Now that you mention it there is actually a circular include issue that prevents it from being in the DWARFContext header.

234

Yes, I mentioned it it the revision log. I needed a working patch to test it out, but if you agree that this is what you want I can easily respin it with the same semantic as before.

samsonov edited edge metadata.Sep 11 2014, 12:21 PM

This doesn't seem right to me. DWARFUnit shouldn't know or keep track of another units in the same section.

Oh, I see that this was suggested in http://reviews.llvm.org/D5264, which I lost track of. Let me catch up with that thread.

samsonov added inline comments.Sep 11 2014, 1:21 PM
lib/DebugInfo/DWARFUnit.h
218

See my suggestion in D5264 review thread. You can introduce a new template class DWARFUnitSection<T>,
which would be a wrapper around SmallVector<std::unique_ptr<T>>, and have
DWARFCompileUnit hold a reference to DWARFUnitSection<DWARFCompileUnit>,
and DWARFTypeUnit hold a reference to DWARFUnitSection<DWARFTypeUnit>.

Then instead of introducing Unit::getUnitForOffset(), you can have an (abstract) DWARFUnit::getSection(), and
DWARFUnitSection::getUnitForOffset().

friss updated this revision to Diff 13635.Sep 12 2014, 7:53 AM
friss edited edge metadata.

Rewrite the patch according to Alexey's comments.

This patch introduces the DWARFUnitSection abstraction that is a collection
of units with a generic base class allowing to query for the Unit containing
a certain offset.

This patch should induce no functional change.

dblaikie accepted this revision.Sep 12 2014, 9:16 AM
dblaikie edited edge metadata.

Looks good to me once the two minor comments are addressed.

Thanks for your patience!

lib/DebugInfo/DWARFUnit.h
65

Missing override

66

drop the '*' - SmallVector's iterators shouldn't be assumed to be pointers (we could one day have a checked iterator implementation with assertions, etc)

This revision is now accepted and ready to land.Sep 12 2014, 9:16 AM
samsonov accepted this revision.Sep 12 2014, 9:44 AM
samsonov edited edge metadata.

LGTM. I'd rather not make DWARFUnitSection inherit from SmallVector - unit section is not a vector, vector is just a way we represent a set of units, and I'm not sure we want to expose all SmallVector accessors to DWARFUnitSection users. This change is fine for now, though. We will be able to implement correct accessors and/or introduce DWARFUnitSection::parse() function later as needed.

Thanks!

friss added a comment.Sep 12 2014, 9:48 AM

Yeah, I did the minimal patch. Having it inherit from SmallVector allows to keep most of the other code (mostly in the Context) untouched. You'd have to implement a bunch of proxy methods to make the Context happy while not inheriting from the Vector, but it's doable as a later step if it's the road we want to go.

Sure. Please outline this in the commit message and proceed.

In D5310#14, @samsonov wrote:

LGTM. I'd rather not make DWARFUnitSection inherit from SmallVector - unit section is not a vector, vector is just a way we represent a set of units, and I'm not sure we want to expose all SmallVector accessors to DWARFUnitSection users.

'spose I should've noticed that, though I didn't. Agreed with your sentiments. :/

The derived template can have a bunch of accessors without exposing them to the other clients.

friss closed this revision.Sep 15 2014, 2:29 AM

Closed by r217747 and its companion fix commit r217751