Page MenuHomePhabricator

[lldb/cpluspluslanguage] Add constructor substitutor
ClosedPublic

Authored by labath on Nov 26 2019, 8:48 AM.

Details

Summary

This patch adds code which will substitute references to the full object
constructors/destructors with their base object versions.

Like all substitutions in this category, this operation is not really
sound, but doing this in a more precise way allows us to get rid of a
much larger hack -- matching function according to their demangled
names, which effectively does the same thing, but also much more.

This is a (very late) follow-up to D54074.

Background: clang has an optimization which can eliminate full object
structors completely, if they are found to be equivalent to their base
object versions. It does this because it assumes they can be regenerated
on demand in the compile unit that needs them (e.g., because they are
declared inline). However, this doesn't work for the debugging scenario,
where we don't have the structor bodies available -- we pretend all
constructors are defined out-of-line as far as clang is concerned. This
causes clang to emit references to the (nonexisting) full object
structors during expression evaluation.

Fun fact: This is not a problem on darwin, because the relevant
optimization is disabled to work around a linker bug.

Diff Detail

Event Timeline

labath created this revision.Nov 26 2019, 8:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 26 2019, 8:48 AM
shafik added a subscriber: shafik.Dec 3 2019, 10:53 AM
shafik added inline comments.
lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
327

trySubstitute has a return value but it is not used in the code below.

352

this->First - Written feels awkward, I feel like given the names they should be reversed :-(

labath updated this revision to Diff 232148.Dec 4 2019, 8:34 AM
labath marked 3 inline comments as done.

Remove unused return value

labath added a comment.Dec 4 2019, 8:35 AM

Thanks for taking a look at this.

lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
327

Yeah, I couldn't make up my mind on what to do here. Having no indication of success from this function seems weird, but OTOH the callers don't actually need to actually vary their behavior based on the result. I've now just removed the return value...

352

Yeah, it's a bit weird, but I'm not sure what to do about it.. do you have any specific suggestion? std::distance(Written, First) ? adding a member function like currentParserPos() to wrap the First?

shafik accepted this revision.Dec 4 2019, 9:23 AM
shafik added inline comments.
lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
352

Yes, I think currentParserPos() would be helpful, it would at least clarify the intent and it makes it more obvious it is doing the correct thing.

This revision is now accepted and ready to land.Dec 4 2019, 9:23 AM
labath marked 3 inline comments as done.Dec 5 2019, 3:43 AM
labath added inline comments.
lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
352

I'll do that. Thanks.

This revision was automatically updated to reflect the committed changes.
labath marked an inline comment as done.