This is an archive of the discontinued LLVM Phabricator instance.

[CodeView] Improve debbuging of virtual base class member variables
ClosedPublic

Authored by bwyma on Apr 30 2018, 9:43 AM.

Details

Summary

Right now the virtual base pointer offset for virtual bases is not implemented and hard-coded to zero in CodeViewDebug.cpp. This patch passes the offset from clang to CodeView where it can be emitted. The crux of the patch looks like this:

-      // FIXME: Emit VBPtrOffset when the frontend provides it.
-      unsigned VBPtrOffset = 0;
+      unsigned VBPtrOffset = I->getVBPtrOffset();

The rest of the source changes support embedding this single field in the IR and reading/writing it to bitcode.

Inheritance is currently encoded in the IR as a DIDerivedType which is currently reused for several other purposes. Four tests which have bitcode files containing a DIDerivedType needed to have the bitcode file updated. Three of these bitcode files were not marked in subversion as a binary file, so I also set the mime-type accordingly.

The diglobalvariable.ll file did not appear to get updated to match changes made to diglobalvariable.bc when DIGlobalVariableExpression was added. Since I had to regenerate the bitcode file anyways I also updated the ".ll" file accordingly.

Diff Detail

Event Timeline

bwyma created this revision.Apr 30 2018, 9:43 AM
bwyma edited the summary of this revision. (Show Details)Apr 30 2018, 9:49 AM
rnk added a project: debug-info.
rnk added a subscriber: dblaikie.Apr 30 2018, 10:22 AM
rnk added inline comments.
llvm/include/llvm/IR/DebugInfoMetadata.h
794–795

vbptroffset is pretty esoteric. It seems really unfortunate to have to widen the very popular DIDerivedType constructor to take this obscure parameter. Pointer and reference types are some of the most common kinds of DIDerivedType nodes, so taking an address space is less objectionable, even though it is specialized towards one kind of derived type node.

I'd recommend encoding this information in the extraData field, similar to how we encode bit offsets for bitfields, or making a new DIInheritanceType node. @aprantl, @dblaikie WDYT?

aprantl added inline comments.Apr 30 2018, 10:56 AM
llvm/include/llvm/IR/DebugInfoMetadata.h
794

please drop the \brief.

794–795

Seems reasonable; avoiding making DIDerivedType larger for all languages and platforms would be a good thing.

Document a comment I received via email from David to keep everything in one place:

Bitcode files shouldn't generally need updating - because bitcode should be backwards compatible (& indeed usually the only reason bitcode files are checked in is to test and ensure that backwards compatibility guarantee is met)

bwyma added inline comments.Apr 30 2018, 11:28 AM
llvm/include/llvm/IR/DebugInfoMetadata.h
794–795

Although I believe DIInheritedType is a better solution, changing DW_TAG_inheritance from DIDerivedType to DIInheritedType is a substantial change which I would recommend making independently from this fix. Furthermore, your valid argument regarding the esoteric nature of the field will be just as valid for DIInheritedType as it is for DIDerivedType, so I think in either case the field should be moved to extraData. As a result, for the purposes of this patch I propose moving this field to the extraData field of DIDerivedType. Is this sufficient?

rnk added inline comments.Apr 30 2018, 11:51 AM
llvm/include/llvm/IR/DebugInfoMetadata.h
794–795

Yep, sounds good to me.

bwyma added inline comments.Apr 30 2018, 11:56 AM
llvm/include/llvm/IR/DebugInfoMetadata.h
794

please drop the \brief.

I have no personal attachment to this tag and I would be happy to remove it, but it matches the surrounding code and seems to be permitted by the coding standard. Can you explain why it should be removed?

aprantl added inline comments.Apr 30 2018, 12:12 PM
llvm/include/llvm/IR/DebugInfoMetadata.h
794

Sure! A few years ago we started enabling autobrief mode in LLVM's Doxygen configuration, which makes the use of \brief in the source code redundant. It's a distraction when reading the source code, so we shouldn't add it in new code and probably also remove it from existing code.

rnk added inline comments.Apr 30 2018, 12:29 PM
llvm/include/llvm/IR/DebugInfoMetadata.h
794

Given that I've seen you raise this comment a few times, I think it's probably worth doing a large pass to remove \brief across LLVM. Otherwise people will continue to copy it in an effort to fit in with existing code, and then we'll spend time on it during review.

dexonsmith added inline comments.Apr 30 2018, 1:04 PM
llvm/include/llvm/IR/DebugInfoMetadata.h
794–795

SGTM too.

aprantl added inline comments.Apr 30 2018, 2:30 PM
llvm/include/llvm/IR/DebugInfoMetadata.h
794

I think it's probably worth doing a large pass to remove \brief across LLVM.

Done! -> https://reviews.llvm.org/D46290

bwyma updated this revision to Diff 145220.May 4 2018, 10:20 AM

The virtual base pointer offset is now encoded in the extraData field of DIDerivedType.

bwyma marked 2 inline comments as done.May 4 2018, 10:22 AM
rnk accepted this revision.May 8 2018, 5:29 PM

lgtm, thanks!

This revision is now accepted and ready to land.May 8 2018, 5:29 PM
bwyma updated this revision to Diff 146687.May 14 2018, 2:17 PM

In the test inheritance.ll I updated the 'variables' attribute to 'retainedNodes' to reflect the changes recently committed in rL331841.

bwyma closed this revision.May 15 2018, 4:18 AM

Changes committed in rL332296.