This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Delete the SharingPtr class
ClosedPublic

Authored by labath on Feb 6 2020, 11:51 AM.

Details

Summary

The only use of this class was to implement the SharedCluster of ValueObjects.
However, the same functionality can be implemented using a regular
std::shared_ptr, and its little-known "sub-object pointer" feature, where the
pointer can point to one thing, but actually delete something else when it goes
out of scope.

This patch reimplements SharedCluster using this feature --
SharedClusterPointer::GetObject now returns a std::shared_pointer which points
to the ValueObject, but actually owns the whole cluster. The only change I
needed to make here is that now the SharedCluster object needs to be created
before the root ValueObject. This means that all private ValueObject
constructors get a ClusterManager argument, and their static Create functions do
the create-a-manager-and-pass-it-to-value-object dance.

Event Timeline

labath created this revision.Feb 6 2020, 11:51 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 6 2020, 11:51 AM
Herald added subscribers: jfb, mgorny. · View Herald Transcript
labath updated this revision to Diff 242974.Feb 6 2020, 12:01 PM

Remove the leftover mutex unlock in the ClusterManager destructor. Doing any
operation on the object while it is being destroyed is not safe, and the mutex
will not help there.

JDevlieghere accepted this revision.Feb 6 2020, 12:26 PM

Very nice!

This revision is now accepted and ready to land.Feb 6 2020, 12:26 PM

I think the ValueObjectRegisterSet::CreateChildAtIndex was wrong originally. It doesn't make it's children by passing itself in as the parent of the child, but just makes an independent ValueObject. You can fix that in your version by passing the ValueObjectRegisterSet's manager.

lldb/source/Core/ValueObjectRegister.cpp
96

Is this right? You are making a child of the ValueObjectRegisterContext, so it should use the manager of its parent, shouldn't it?

We were probably getting away with this because ValueObjectRegisterSet's children don't really need their parent to construct their values? But still, this is not how ValueObject children should work...

labath added a comment.Feb 6 2020, 1:53 PM

Actually, it looks like we were getting away with that because the whole ValueObjectRegisterContext (*not* RegisterSet) class is unused. In fact the whole concept of having the entire register context as a "value" seems fairly odd to me. Can we just delete it?

Actually, it looks like we were getting away with that because the whole ValueObjectRegisterContext (*not* RegisterSet) class is unused. In fact the whole concept of having the entire register context as a "value" seems fairly odd to me. Can we just delete it?

Oh, interesting. I have no idea what that is for. Looks like it was part of the initial checkin of lldb -> llvm.org, and except for formal changes hasn't actually been touched since then. Seems like if we haven't used it by now, it's fine to get rid of it.

This revision was automatically updated to reflect the committed changes.
lldb/source/Expression/IRInterpreter.cpp