This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Make Process and subclass constructors protected
ClosedPublic

Authored by mgorny on Aug 5 2022, 11:08 AM.

Details

Summary

Make constructors of the Process and its subclasses class protected,
to prevent accidentally constructing Process on stack when it could be
afterwards accessed via a shared_ptr (since it uses
std::enable_shared_from_this<>).

The only place where a stack allocation was used were unittests,
and fixing them via declaring an explicit public constructor
in the respective mock classes is trivial.

Sponsored by: The FreeBSD Foundation

Diff Detail

Event Timeline

mgorny created this revision.Aug 5 2022, 11:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 5 2022, 11:08 AM
Herald added a subscriber: arichardson. · View Herald Transcript
mgorny requested review of this revision.Aug 5 2022, 11:08 AM
labath accepted this revision.Aug 8 2022, 6:10 AM
labath added inline comments.
lldb/include/lldb/Target/Process.h
478–487

Just move this to the existing protected section on line 2500 (boy is this class big). Too many sections makes it hard to find what's the visibility of something.

lldb/source/Plugins/Process/Windows/Common/ProcessWindows.h
38–39

same here

lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
51–52

and here

lldb/source/Plugins/Process/scripted/ScriptedProcess.h
52–53

and here

lldb/unittests/Expression/DWARFExpressionTest.cpp
331–333

huh, I did not expect this to be necessary. Inherited constructors are weird...

This revision is now accepted and ready to land.Aug 8 2022, 6:10 AM
mgorny added inline comments.Aug 8 2022, 6:28 AM
lldb/include/lldb/Target/Process.h
478–487

Will do. Wasn't sure whether this was desirable or not.

lldb/unittests/Expression/DWARFExpressionTest.cpp
331–333

Yes, they are. I've searched a bit and couldn't find a way to make using change their visibility.

mgorny marked 4 inline comments as done.Aug 8 2022, 6:33 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptAug 8 2022, 8:34 AM