Author: jdevlieghere Date: Tue Mar 5 16:05:55 2019 New Revision: 355458 URL: http://llvm.org/viewvc/llvm-project?rev=355458&view=rev Log: [SBAPI] Don't check IsValid in constructor
When running the test suite with the instrumentation macros, I noticed two lldb-mi tests regressed. The issue was the copy constructor of SBLineEntry. Without the macros the returned value would be elided, but with the macros the copy constructor was called. The latter using ::IsValid to determine whether the underlying opaque pointer should be set. This is likely a remnant of when ::IsValid would only check the validity of the smart pointer. In SBLineEntry however, it actually forwards to LineEntry::IsValid(). So what happened here was that because of the macros the copy constructor was called. The opaque pointer was valid but the LineEntry didn't consider itself valid. So the copied-to object ended up default initialized. This patch replaces all checks for IsValid in copy (assignment) constructors with checks for the opaque pointer itself. Differential revision: https://reviews.llvm.org/D58946 Added: lldb/trunk/source/API/Utils.h Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj lldb/trunk/source/API/SBAddress.cpp lldb/trunk/source/API/SBAttachInfo.cpp lldb/trunk/source/API/SBCommandReturnObject.cpp lldb/trunk/source/API/SBDeclaration.cpp lldb/trunk/source/API/SBError.cpp lldb/trunk/source/API/SBExpressionOptions.cpp lldb/trunk/source/API/SBFileSpec.cpp lldb/trunk/source/API/SBFileSpecList.cpp lldb/trunk/source/API/SBFrame.cpp lldb/trunk/source/API/SBLineEntry.cpp lldb/trunk/source/API/SBMemoryRegionInfo.cpp lldb/trunk/source/API/SBModuleSpec.cpp lldb/trunk/source/API/SBProcessInfo.cpp lldb/trunk/source/API/SBStringList.cpp lldb/trunk/source/API/SBSymbolContext.cpp lldb/trunk/source/API/SBSymbolContextList.cpp lldb/trunk/source/API/SBThread.cpp lldb/trunk/source/API/SBTypeEnumMember.cpp lldb/trunk/source/API/SBTypeSummary.cpp Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=355458&r1=355457&r2=355458&view=diff ============================================================================== --- lldb/trunk/lldb.xcodeproj/project.pbxproj (original) +++ lldb/trunk/lldb.xcodeproj/project.pbxproj Tue Mar 5 16:05:55 2019 @@ -3238,6 +3238,7 @@ 9A4633DA11F65D8600955CE1 /* UserSettingsController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UserSettingsController.h; path = include/lldb/Core/UserSettingsController.h; sourceTree = "<group>"; }; 4C00833F1B9F9BA900D5CF24 /* UtilityFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UtilityFunction.cpp; path = source/Expression/UtilityFunction.cpp; sourceTree = "<group>"; }; 4C00833D1B9F9B8400D5CF24 /* UtilityFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UtilityFunction.h; path = include/lldb/Expression/UtilityFunction.h; sourceTree = "<group>"; }; + DD54302F222F190D00C1F021 /* Utils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Utils.h; path = source/API/Utils.h; sourceTree = "<group>"; }; 2654A6921E552F4600DA1013 /* VASPrintf.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = VASPrintf.h; path = include/lldb/Utility/VASPrintf.h; sourceTree = "<group>"; }; 2654A68F1E552ED500DA1013 /* VASprintf.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = VASprintf.cpp; path = source/Utility/VASprintf.cpp; sourceTree = "<group>"; }; 9A3D43C41F3150D200EB767C /* VASprintfTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = VASprintfTest.cpp; sourceTree = "<group>"; }; @@ -4442,6 +4443,7 @@ 23059A0F1958B319007B8189 /* SBUnixSignals.cpp */, 9A19A6A51163BB7E00E0D453 /* SBValue.h */, 9A19A6AD1163BB9800E0D453 /* SBValue.cpp */, + DD54302F222F190D00C1F021 /* Utils.h */, 9A357582116CFDEE00E8ED2F /* SBValueList.h */, 9A35758D116CFE0F00E8ED2F /* SBValueList.cpp */, 94235B9A1A8D5FD800EB2EED /* SBVariablesOptions.h */, Modified: lldb/trunk/source/API/SBAddress.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBAddress.cpp?rev=355458&r1=355457&r2=355458&view=diff ============================================================================== --- lldb/trunk/source/API/SBAddress.cpp (original) +++ lldb/trunk/source/API/SBAddress.cpp Tue Mar 5 16:05:55 2019 @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "lldb/API/SBAddress.h" +#include "Utils.h" #include "lldb/API/SBProcess.h" #include "lldb/API/SBSection.h" #include "lldb/API/SBStream.h" @@ -25,12 +26,11 @@ SBAddress::SBAddress() : m_opaque_up(new SBAddress::SBAddress(const Address *lldb_object_ptr) : m_opaque_up(new Address()) { if (lldb_object_ptr) - ref() = *lldb_object_ptr; + m_opaque_up = llvm::make_unique<Address>(*lldb_object_ptr); } SBAddress::SBAddress(const SBAddress &rhs) : m_opaque_up(new Address()) { - if (rhs.IsValid()) - ref() = rhs.ref(); + m_opaque_up = clone(rhs.m_opaque_up); } SBAddress::SBAddress(lldb::SBSection section, lldb::addr_t offset) @@ -45,12 +45,8 @@ SBAddress::SBAddress(lldb::addr_t load_a SBAddress::~SBAddress() {} const SBAddress &SBAddress::operator=(const SBAddress &rhs) { - if (this != &rhs) { - if (rhs.IsValid()) - ref() = rhs.ref(); - else - m_opaque_up.reset(new Address()); - } + if (this != &rhs) + m_opaque_up = clone(rhs.m_opaque_up); return *this; } Modified: lldb/trunk/source/API/SBAttachInfo.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBAttachInfo.cpp?rev=355458&r1=355457&r2=355458&view=diff ============================================================================== --- lldb/trunk/source/API/SBAttachInfo.cpp (original) +++ lldb/trunk/source/API/SBAttachInfo.cpp Tue Mar 5 16:05:55 2019 @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "lldb/API/SBAttachInfo.h" - +#include "Utils.h" #include "lldb/API/SBFileSpec.h" #include "lldb/API/SBListener.h" #include "lldb/Target/Process.h" @@ -39,7 +39,7 @@ SBAttachInfo::SBAttachInfo(const char *p SBAttachInfo::SBAttachInfo(const SBAttachInfo &rhs) : m_opaque_sp(new ProcessAttachInfo()) { - *m_opaque_sp = *rhs.m_opaque_sp; + m_opaque_sp = clone(rhs.m_opaque_sp); } SBAttachInfo::~SBAttachInfo() {} @@ -48,7 +48,7 @@ lldb_private::ProcessAttachInfo &SBAttac SBAttachInfo &SBAttachInfo::operator=(const SBAttachInfo &rhs) { if (this != &rhs) - *m_opaque_sp = *rhs.m_opaque_sp; + m_opaque_sp = clone(rhs.m_opaque_sp); return *this; } Modified: lldb/trunk/source/API/SBCommandReturnObject.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBCommandReturnObject.cpp?rev=355458&r1=355457&r2=355458&view=diff ============================================================================== --- lldb/trunk/source/API/SBCommandReturnObject.cpp (original) +++ lldb/trunk/source/API/SBCommandReturnObject.cpp Tue Mar 5 16:05:55 2019 @@ -7,9 +7,9 @@ //===----------------------------------------------------------------------===// #include "lldb/API/SBCommandReturnObject.h" +#include "Utils.h" #include "lldb/API/SBError.h" #include "lldb/API/SBStream.h" - #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Utility/ConstString.h" #include "lldb/Utility/Log.h" @@ -23,8 +23,7 @@ SBCommandReturnObject::SBCommandReturnOb SBCommandReturnObject::SBCommandReturnObject(const SBCommandReturnObject &rhs) : m_opaque_up() { - if (rhs.m_opaque_up) - m_opaque_up.reset(new CommandReturnObject(*rhs.m_opaque_up)); + m_opaque_up = clone(rhs.m_opaque_up); } SBCommandReturnObject::SBCommandReturnObject(CommandReturnObject *ptr) @@ -38,12 +37,8 @@ CommandReturnObject *SBCommandReturnObje const SBCommandReturnObject &SBCommandReturnObject:: operator=(const SBCommandReturnObject &rhs) { - if (this != &rhs) { - if (rhs.m_opaque_up) - m_opaque_up.reset(new CommandReturnObject(*rhs.m_opaque_up)); - else - m_opaque_up.reset(); - } + if (this != &rhs) + m_opaque_up = clone(rhs.m_opaque_up); return *this; } Modified: lldb/trunk/source/API/SBDeclaration.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBDeclaration.cpp?rev=355458&r1=355457&r2=355458&view=diff ============================================================================== --- lldb/trunk/source/API/SBDeclaration.cpp (original) +++ lldb/trunk/source/API/SBDeclaration.cpp Tue Mar 5 16:05:55 2019 @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "lldb/API/SBDeclaration.h" +#include "Utils.h" #include "lldb/API/SBStream.h" #include "lldb/Host/PosixApi.h" #include "lldb/Symbol/Declaration.h" @@ -21,23 +22,18 @@ using namespace lldb_private; SBDeclaration::SBDeclaration() : m_opaque_up() {} SBDeclaration::SBDeclaration(const SBDeclaration &rhs) : m_opaque_up() { - if (rhs.IsValid()) - ref() = rhs.ref(); + m_opaque_up = clone(rhs.m_opaque_up); } SBDeclaration::SBDeclaration(const lldb_private::Declaration *lldb_object_ptr) : m_opaque_up() { if (lldb_object_ptr) - ref() = *lldb_object_ptr; + m_opaque_up = llvm::make_unique<Declaration>(*lldb_object_ptr); } const SBDeclaration &SBDeclaration::operator=(const SBDeclaration &rhs) { - if (this != &rhs) { - if (rhs.IsValid()) - ref() = rhs.ref(); - else - m_opaque_up.reset(); - } + if (this != &rhs) + m_opaque_up = clone(rhs.m_opaque_up); return *this; } Modified: lldb/trunk/source/API/SBError.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBError.cpp?rev=355458&r1=355457&r2=355458&view=diff ============================================================================== --- lldb/trunk/source/API/SBError.cpp (original) +++ lldb/trunk/source/API/SBError.cpp Tue Mar 5 16:05:55 2019 @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "lldb/API/SBError.h" +#include "Utils.h" #include "lldb/API/SBStream.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/Status.h" @@ -19,21 +20,14 @@ using namespace lldb_private; SBError::SBError() : m_opaque_up() {} SBError::SBError(const SBError &rhs) : m_opaque_up() { - if (rhs.IsValid()) - m_opaque_up.reset(new Status(*rhs)); + m_opaque_up = clone(rhs.m_opaque_up); } SBError::~SBError() {} const SBError &SBError::operator=(const SBError &rhs) { - if (rhs.IsValid()) { - if (m_opaque_up) - *m_opaque_up = *rhs; - else - m_opaque_up.reset(new Status(*rhs)); - } else - m_opaque_up.reset(); - + if (this != &rhs) + m_opaque_up = clone(rhs.m_opaque_up); return *this; } Modified: lldb/trunk/source/API/SBExpressionOptions.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBExpressionOptions.cpp?rev=355458&r1=355457&r2=355458&view=diff ============================================================================== --- lldb/trunk/source/API/SBExpressionOptions.cpp (original) +++ lldb/trunk/source/API/SBExpressionOptions.cpp Tue Mar 5 16:05:55 2019 @@ -8,8 +8,8 @@ //===----------------------------------------------------------------------===// #include "lldb/API/SBExpressionOptions.h" +#include "Utils.h" #include "lldb/API/SBStream.h" - #include "lldb/Target/Target.h" using namespace lldb; @@ -18,16 +18,15 @@ using namespace lldb_private; SBExpressionOptions::SBExpressionOptions() : m_opaque_up(new EvaluateExpressionOptions()) {} -SBExpressionOptions::SBExpressionOptions(const SBExpressionOptions &rhs) { - m_opaque_up.reset(new EvaluateExpressionOptions()); - *(m_opaque_up.get()) = rhs.ref(); +SBExpressionOptions::SBExpressionOptions(const SBExpressionOptions &rhs) + : m_opaque_up() { + m_opaque_up = clone(rhs.m_opaque_up); } const SBExpressionOptions &SBExpressionOptions:: operator=(const SBExpressionOptions &rhs) { - if (this != &rhs) { - this->ref() = rhs.ref(); - } + if (this != &rhs) + m_opaque_up = clone(rhs.m_opaque_up); return *this; } Modified: lldb/trunk/source/API/SBFileSpec.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFileSpec.cpp?rev=355458&r1=355457&r2=355458&view=diff ============================================================================== --- lldb/trunk/source/API/SBFileSpec.cpp (original) +++ lldb/trunk/source/API/SBFileSpec.cpp Tue Mar 5 16:05:55 2019 @@ -9,6 +9,7 @@ #include <inttypes.h> #include <limits.h> +#include "Utils.h" #include "lldb/API/SBFileSpec.h" #include "lldb/API/SBStream.h" #include "lldb/Host/FileSystem.h" @@ -24,8 +25,9 @@ using namespace lldb_private; SBFileSpec::SBFileSpec() : m_opaque_up(new lldb_private::FileSpec()) {} -SBFileSpec::SBFileSpec(const SBFileSpec &rhs) - : m_opaque_up(new lldb_private::FileSpec(*rhs.m_opaque_up)) {} +SBFileSpec::SBFileSpec(const SBFileSpec &rhs) : m_opaque_up() { + m_opaque_up = clone(rhs.m_opaque_up); +} SBFileSpec::SBFileSpec(const lldb_private::FileSpec &fspec) : m_opaque_up(new lldb_private::FileSpec(fspec)) {} @@ -45,7 +47,7 @@ SBFileSpec::~SBFileSpec() {} const SBFileSpec &SBFileSpec::operator=(const SBFileSpec &rhs) { if (this != &rhs) - *m_opaque_up = *rhs.m_opaque_up; + m_opaque_up = clone(rhs.m_opaque_up); return *this; } Modified: lldb/trunk/source/API/SBFileSpecList.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFileSpecList.cpp?rev=355458&r1=355457&r2=355458&view=diff ============================================================================== --- lldb/trunk/source/API/SBFileSpecList.cpp (original) +++ lldb/trunk/source/API/SBFileSpecList.cpp Tue Mar 5 16:05:55 2019 @@ -8,6 +8,7 @@ #include <limits.h> +#include "Utils.h" #include "lldb/API/SBFileSpec.h" #include "lldb/API/SBFileSpecList.h" #include "lldb/API/SBStream.h" @@ -25,8 +26,7 @@ SBFileSpecList::SBFileSpecList() : m_opa SBFileSpecList::SBFileSpecList(const SBFileSpecList &rhs) : m_opaque_up() { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); - if (rhs.m_opaque_up) - m_opaque_up.reset(new FileSpecList(*(rhs.get()))); + m_opaque_up = clone(rhs.m_opaque_up); if (log) { log->Printf("SBFileSpecList::SBFileSpecList (const SBFileSpecList " @@ -39,9 +39,8 @@ SBFileSpecList::SBFileSpecList(const SBF SBFileSpecList::~SBFileSpecList() {} const SBFileSpecList &SBFileSpecList::operator=(const SBFileSpecList &rhs) { - if (this != &rhs) { - m_opaque_up.reset(new lldb_private::FileSpecList(*(rhs.get()))); - } + if (this != &rhs) + m_opaque_up = clone(rhs.m_opaque_up); return *this; } Modified: lldb/trunk/source/API/SBFrame.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFrame.cpp?rev=355458&r1=355457&r2=355458&view=diff ============================================================================== --- lldb/trunk/source/API/SBFrame.cpp (original) +++ lldb/trunk/source/API/SBFrame.cpp Tue Mar 5 16:05:55 2019 @@ -15,6 +15,7 @@ #include "lldb/lldb-types.h" #include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h" +#include "Utils.h" #include "lldb/Core/Address.h" #include "lldb/Core/StreamFile.h" #include "lldb/Core/ValueObjectRegister.h" @@ -68,14 +69,15 @@ SBFrame::SBFrame(const StackFrameSP &lld } } -SBFrame::SBFrame(const SBFrame &rhs) - : m_opaque_sp(new ExecutionContextRef(*rhs.m_opaque_sp)) {} +SBFrame::SBFrame(const SBFrame &rhs) : m_opaque_sp() { + m_opaque_sp = clone(rhs.m_opaque_sp); +} SBFrame::~SBFrame() = default; const SBFrame &SBFrame::operator=(const SBFrame &rhs) { if (this != &rhs) - *m_opaque_sp = *rhs.m_opaque_sp; + m_opaque_sp = clone(rhs.m_opaque_sp); return *this; } Modified: lldb/trunk/source/API/SBLineEntry.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBLineEntry.cpp?rev=355458&r1=355457&r2=355458&view=diff ============================================================================== --- lldb/trunk/source/API/SBLineEntry.cpp (original) +++ lldb/trunk/source/API/SBLineEntry.cpp Tue Mar 5 16:05:55 2019 @@ -6,43 +6,39 @@ // //===----------------------------------------------------------------------===// -#include <limits.h> - #include "lldb/API/SBLineEntry.h" +#include "Utils.h" #include "lldb/API/SBStream.h" #include "lldb/Host/PosixApi.h" #include "lldb/Symbol/LineEntry.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/StreamString.h" +#include <limits.h> + using namespace lldb; using namespace lldb_private; SBLineEntry::SBLineEntry() : m_opaque_up() {} SBLineEntry::SBLineEntry(const SBLineEntry &rhs) : m_opaque_up() { - if (rhs.IsValid()) - ref() = rhs.ref(); + m_opaque_up = clone(rhs.m_opaque_up); } SBLineEntry::SBLineEntry(const lldb_private::LineEntry *lldb_object_ptr) : m_opaque_up() { if (lldb_object_ptr) - ref() = *lldb_object_ptr; + m_opaque_up = llvm::make_unique<LineEntry>(*lldb_object_ptr); } const SBLineEntry &SBLineEntry::operator=(const SBLineEntry &rhs) { - if (this != &rhs) { - if (rhs.IsValid()) - ref() = rhs.ref(); - else - m_opaque_up.reset(); - } + if (this != &rhs) + m_opaque_up = clone(rhs.m_opaque_up); return *this; } void SBLineEntry::SetLineEntry(const lldb_private::LineEntry &lldb_object_ref) { - ref() = lldb_object_ref; + m_opaque_up = llvm::make_unique<LineEntry>(lldb_object_ref); } SBLineEntry::~SBLineEntry() {} Modified: lldb/trunk/source/API/SBMemoryRegionInfo.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBMemoryRegionInfo.cpp?rev=355458&r1=355457&r2=355458&view=diff ============================================================================== --- lldb/trunk/source/API/SBMemoryRegionInfo.cpp (original) +++ lldb/trunk/source/API/SBMemoryRegionInfo.cpp Tue Mar 5 16:05:55 2019 @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "lldb/API/SBMemoryRegionInfo.h" +#include "Utils.h" #include "lldb/API/SBDefines.h" #include "lldb/API/SBError.h" #include "lldb/API/SBStream.h" @@ -26,15 +27,14 @@ SBMemoryRegionInfo::SBMemoryRegionInfo(c } SBMemoryRegionInfo::SBMemoryRegionInfo(const SBMemoryRegionInfo &rhs) - : m_opaque_up(new MemoryRegionInfo()) { - ref() = rhs.ref(); + : m_opaque_up() { + m_opaque_up = clone(rhs.m_opaque_up); } const SBMemoryRegionInfo &SBMemoryRegionInfo:: operator=(const SBMemoryRegionInfo &rhs) { - if (this != &rhs) { - ref() = rhs.ref(); - } + if (this != &rhs) + m_opaque_up = clone(rhs.m_opaque_up); return *this; } Modified: lldb/trunk/source/API/SBModuleSpec.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBModuleSpec.cpp?rev=355458&r1=355457&r2=355458&view=diff ============================================================================== --- lldb/trunk/source/API/SBModuleSpec.cpp (original) +++ lldb/trunk/source/API/SBModuleSpec.cpp Tue Mar 5 16:05:55 2019 @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "lldb/API/SBModuleSpec.h" +#include "Utils.h" #include "lldb/API/SBStream.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" @@ -19,12 +20,13 @@ using namespace lldb_private; SBModuleSpec::SBModuleSpec() : m_opaque_up(new lldb_private::ModuleSpec()) {} -SBModuleSpec::SBModuleSpec(const SBModuleSpec &rhs) - : m_opaque_up(new lldb_private::ModuleSpec(*rhs.m_opaque_up)) {} +SBModuleSpec::SBModuleSpec(const SBModuleSpec &rhs) : m_opaque_up() { + m_opaque_up = clone(rhs.m_opaque_up); +} const SBModuleSpec &SBModuleSpec::operator=(const SBModuleSpec &rhs) { if (this != &rhs) - *m_opaque_up = *(rhs.m_opaque_up); + m_opaque_up = clone(rhs.m_opaque_up); return *this; } Modified: lldb/trunk/source/API/SBProcessInfo.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBProcessInfo.cpp?rev=355458&r1=355457&r2=355458&view=diff ============================================================================== --- lldb/trunk/source/API/SBProcessInfo.cpp (original) +++ lldb/trunk/source/API/SBProcessInfo.cpp Tue Mar 5 16:05:55 2019 @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "lldb/API/SBProcessInfo.h" - +#include "Utils.h" #include "lldb/API/SBFileSpec.h" #include "lldb/Utility/ProcessInfo.h" @@ -17,20 +17,14 @@ using namespace lldb_private; SBProcessInfo::SBProcessInfo() : m_opaque_up() {} SBProcessInfo::SBProcessInfo(const SBProcessInfo &rhs) : m_opaque_up() { - if (rhs.IsValid()) { - ref() = *rhs.m_opaque_up; - } + m_opaque_up = clone(rhs.m_opaque_up); } SBProcessInfo::~SBProcessInfo() {} SBProcessInfo &SBProcessInfo::operator=(const SBProcessInfo &rhs) { - if (this != &rhs) { - if (rhs.IsValid()) - ref() = *rhs.m_opaque_up; - else - m_opaque_up.reset(); - } + if (this != &rhs) + m_opaque_up = clone(rhs.m_opaque_up); return *this; } Modified: lldb/trunk/source/API/SBStringList.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBStringList.cpp?rev=355458&r1=355457&r2=355458&view=diff ============================================================================== --- lldb/trunk/source/API/SBStringList.cpp (original) +++ lldb/trunk/source/API/SBStringList.cpp Tue Mar 5 16:05:55 2019 @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "lldb/API/SBStringList.h" - +#include "Utils.h" #include "lldb/Utility/StringList.h" using namespace lldb; @@ -18,21 +18,16 @@ SBStringList::SBStringList() : m_opaque_ SBStringList::SBStringList(const lldb_private::StringList *lldb_strings_ptr) : m_opaque_up() { if (lldb_strings_ptr) - m_opaque_up.reset(new lldb_private::StringList(*lldb_strings_ptr)); + m_opaque_up = llvm::make_unique<StringList>(*lldb_strings_ptr); } SBStringList::SBStringList(const SBStringList &rhs) : m_opaque_up() { - if (rhs.IsValid()) - m_opaque_up.reset(new lldb_private::StringList(*rhs)); + m_opaque_up = clone(rhs.m_opaque_up); } const SBStringList &SBStringList::operator=(const SBStringList &rhs) { - if (this != &rhs) { - if (rhs.IsValid()) - m_opaque_up.reset(new lldb_private::StringList(*rhs)); - else - m_opaque_up.reset(); - } + if (this != &rhs) + m_opaque_up = clone(rhs.m_opaque_up); return *this; } Modified: lldb/trunk/source/API/SBSymbolContext.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBSymbolContext.cpp?rev=355458&r1=355457&r2=355458&view=diff ============================================================================== --- lldb/trunk/source/API/SBSymbolContext.cpp (original) +++ lldb/trunk/source/API/SBSymbolContext.cpp Tue Mar 5 16:05:55 2019 @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "lldb/API/SBSymbolContext.h" +#include "Utils.h" #include "lldb/API/SBStream.h" #include "lldb/Core/Module.h" #include "lldb/Symbol/Function.h" @@ -21,38 +22,26 @@ SBSymbolContext::SBSymbolContext() : m_o SBSymbolContext::SBSymbolContext(const SymbolContext *sc_ptr) : m_opaque_up() { if (sc_ptr) - m_opaque_up.reset(new SymbolContext(*sc_ptr)); + m_opaque_up = llvm::make_unique<SymbolContext>(*sc_ptr); } SBSymbolContext::SBSymbolContext(const SBSymbolContext &rhs) : m_opaque_up() { - if (rhs.IsValid()) { - if (m_opaque_up) - *m_opaque_up = *rhs.m_opaque_up; - else - ref() = *rhs.m_opaque_up; - } + m_opaque_up = clone(rhs.m_opaque_up); } SBSymbolContext::~SBSymbolContext() {} const SBSymbolContext &SBSymbolContext::operator=(const SBSymbolContext &rhs) { - if (this != &rhs) { - if (rhs.IsValid()) - m_opaque_up.reset(new lldb_private::SymbolContext(*rhs.m_opaque_up)); - } + if (this != &rhs) + m_opaque_up = clone(rhs.m_opaque_up); return *this; } void SBSymbolContext::SetSymbolContext(const SymbolContext *sc_ptr) { - if (sc_ptr) { - if (m_opaque_up) - *m_opaque_up = *sc_ptr; - else - m_opaque_up.reset(new SymbolContext(*sc_ptr)); - } else { - if (m_opaque_up) - m_opaque_up->Clear(true); - } + if (sc_ptr) + m_opaque_up = llvm::make_unique<SymbolContext>(*sc_ptr); + else + m_opaque_up->Clear(true); } bool SBSymbolContext::IsValid() const { return m_opaque_up != NULL; } Modified: lldb/trunk/source/API/SBSymbolContextList.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBSymbolContextList.cpp?rev=355458&r1=355457&r2=355458&view=diff ============================================================================== --- lldb/trunk/source/API/SBSymbolContextList.cpp (original) +++ lldb/trunk/source/API/SBSymbolContextList.cpp Tue Mar 5 16:05:55 2019 @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "lldb/API/SBSymbolContextList.h" +#include "Utils.h" #include "lldb/API/SBStream.h" #include "lldb/Symbol/SymbolContext.h" @@ -17,15 +18,17 @@ SBSymbolContextList::SBSymbolContextList : m_opaque_up(new SymbolContextList()) {} SBSymbolContextList::SBSymbolContextList(const SBSymbolContextList &rhs) - : m_opaque_up(new SymbolContextList(*rhs.m_opaque_up)) {} + : m_opaque_up() { + + m_opaque_up = clone(rhs.m_opaque_up); +} SBSymbolContextList::~SBSymbolContextList() {} const SBSymbolContextList &SBSymbolContextList:: operator=(const SBSymbolContextList &rhs) { - if (this != &rhs) { - *m_opaque_up = *rhs.m_opaque_up; - } + if (this != &rhs) + m_opaque_up = clone(rhs.m_opaque_up); return *this; } Modified: lldb/trunk/source/API/SBThread.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBThread.cpp?rev=355458&r1=355457&r2=355458&view=diff ============================================================================== --- lldb/trunk/source/API/SBThread.cpp (original) +++ lldb/trunk/source/API/SBThread.cpp Tue Mar 5 16:05:55 2019 @@ -7,10 +7,18 @@ //===----------------------------------------------------------------------===// #include "lldb/API/SBThread.h" - +#include "Utils.h" +#include "lldb/API/SBAddress.h" +#include "lldb/API/SBDebugger.h" +#include "lldb/API/SBEvent.h" #include "lldb/API/SBFileSpec.h" +#include "lldb/API/SBFrame.h" +#include "lldb/API/SBProcess.h" #include "lldb/API/SBStream.h" #include "lldb/API/SBSymbolContext.h" +#include "lldb/API/SBThreadCollection.h" +#include "lldb/API/SBThreadPlan.h" +#include "lldb/API/SBValue.h" #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Core/Debugger.h" #include "lldb/Core/StreamFile.h" @@ -33,15 +41,6 @@ #include "lldb/Utility/State.h" #include "lldb/Utility/Stream.h" #include "lldb/Utility/StructuredData.h" - -#include "lldb/API/SBAddress.h" -#include "lldb/API/SBDebugger.h" -#include "lldb/API/SBEvent.h" -#include "lldb/API/SBFrame.h" -#include "lldb/API/SBProcess.h" -#include "lldb/API/SBThreadCollection.h" -#include "lldb/API/SBThreadPlan.h" -#include "lldb/API/SBValue.h" #include "lldb/lldb-enumerations.h" #include <memory> @@ -61,8 +60,9 @@ SBThread::SBThread() : m_opaque_sp(new E SBThread::SBThread(const ThreadSP &lldb_object_sp) : m_opaque_sp(new ExecutionContextRef(lldb_object_sp)) {} -SBThread::SBThread(const SBThread &rhs) - : m_opaque_sp(new ExecutionContextRef(*rhs.m_opaque_sp)) {} +SBThread::SBThread(const SBThread &rhs) : m_opaque_sp() { + m_opaque_sp = clone(rhs.m_opaque_sp); +} //---------------------------------------------------------------------- // Assignment operator @@ -70,7 +70,7 @@ SBThread::SBThread(const SBThread &rhs) const lldb::SBThread &SBThread::operator=(const SBThread &rhs) { if (this != &rhs) - *m_opaque_sp = *rhs.m_opaque_sp; + m_opaque_sp = clone(rhs.m_opaque_sp); return *this; } Modified: lldb/trunk/source/API/SBTypeEnumMember.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTypeEnumMember.cpp?rev=355458&r1=355457&r2=355458&view=diff ============================================================================== --- lldb/trunk/source/API/SBTypeEnumMember.cpp (original) +++ lldb/trunk/source/API/SBTypeEnumMember.cpp Tue Mar 5 16:05:55 2019 @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "lldb/API/SBTypeEnumMember.h" +#include "Utils.h" #include "lldb/API/SBDefines.h" #include "lldb/API/SBStream.h" #include "lldb/API/SBType.h" @@ -22,23 +23,19 @@ using namespace lldb_private; SBTypeEnumMember::SBTypeEnumMember() : m_opaque_sp() {} SBTypeEnumMember::~SBTypeEnumMember() {} + SBTypeEnumMember::SBTypeEnumMember( const lldb::TypeEnumMemberImplSP &enum_member_sp) : m_opaque_sp(enum_member_sp) {} SBTypeEnumMember::SBTypeEnumMember(const SBTypeEnumMember &rhs) : m_opaque_sp() { - if (this != &rhs) { - if (rhs.IsValid()) - m_opaque_sp = std::make_shared<TypeEnumMemberImpl>(rhs.ref()); - } + m_opaque_sp = clone(rhs.m_opaque_sp); } SBTypeEnumMember &SBTypeEnumMember::operator=(const SBTypeEnumMember &rhs) { - if (this != &rhs) { - if (rhs.IsValid()) - m_opaque_sp = std::make_shared<TypeEnumMemberImpl>(rhs.ref()); - } + if (this != &rhs) + m_opaque_sp = clone(rhs.m_opaque_sp); return *this; } Modified: lldb/trunk/source/API/SBTypeSummary.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTypeSummary.cpp?rev=355458&r1=355457&r2=355458&view=diff ============================================================================== --- lldb/trunk/source/API/SBTypeSummary.cpp (original) +++ lldb/trunk/source/API/SBTypeSummary.cpp Tue Mar 5 16:05:55 2019 @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "lldb/API/SBTypeSummary.h" +#include "Utils.h" #include "lldb/API/SBStream.h" #include "lldb/API/SBValue.h" #include "lldb/DataFormatters/DataVisualization.h" @@ -17,16 +18,12 @@ using namespace lldb; using namespace lldb_private; -SBTypeSummaryOptions::SBTypeSummaryOptions() { - m_opaque_up.reset(new TypeSummaryOptions()); -} +SBTypeSummaryOptions::SBTypeSummaryOptions() + : m_opaque_up(new TypeSummaryOptions()) {} SBTypeSummaryOptions::SBTypeSummaryOptions( const lldb::SBTypeSummaryOptions &rhs) { - if (rhs.m_opaque_up) - m_opaque_up.reset(new TypeSummaryOptions(*rhs.m_opaque_up)); - else - m_opaque_up.reset(new TypeSummaryOptions()); + m_opaque_up = clone(rhs.m_opaque_up); } SBTypeSummaryOptions::~SBTypeSummaryOptions() {} Added: lldb/trunk/source/API/Utils.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/Utils.h?rev=355458&view=auto ============================================================================== --- lldb/trunk/source/API/Utils.h (added) +++ lldb/trunk/source/API/Utils.h Tue Mar 5 16:05:55 2019 @@ -0,0 +1,30 @@ +//===-- Utils.h -------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLDB_API_UTILS_H +#define LLDB_API_UTILS_H + +#include "llvm/ADT/STLExtras.h" +#include <memory> + +namespace lldb_private { + +template <typename T> std::unique_ptr<T> clone(const std::unique_ptr<T> &src) { + if (src) + return llvm::make_unique<T>(*src); + return nullptr; +} + +template <typename T> std::shared_ptr<T> clone(const std::shared_ptr<T> &src) { + if (src) + return std::make_shared<T>(*src); + return nullptr; +} + +} // namespace lldb_private +#endif _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits