Index: lldb/trunk/lldb.xcodeproj/project.pbxproj =================================================================== --- lldb/trunk/lldb.xcodeproj/project.pbxproj +++ lldb/trunk/lldb.xcodeproj/project.pbxproj @@ -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 = ""; }; 4C00833F1B9F9BA900D5CF24 /* UtilityFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UtilityFunction.cpp; path = source/Expression/UtilityFunction.cpp; sourceTree = ""; }; 4C00833D1B9F9B8400D5CF24 /* UtilityFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UtilityFunction.h; path = include/lldb/Expression/UtilityFunction.h; sourceTree = ""; }; + DD54302F222F190D00C1F021 /* Utils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Utils.h; path = source/API/Utils.h; sourceTree = ""; }; 2654A6921E552F4600DA1013 /* VASPrintf.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = VASPrintf.h; path = include/lldb/Utility/VASPrintf.h; sourceTree = ""; }; 2654A68F1E552ED500DA1013 /* VASprintf.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = VASprintf.cpp; path = source/Utility/VASprintf.cpp; sourceTree = ""; }; 9A3D43C41F3150D200EB767C /* VASprintfTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = VASprintfTest.cpp; sourceTree = ""; }; @@ -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 */, Index: lldb/trunk/source/API/SBAddress.cpp =================================================================== --- lldb/trunk/source/API/SBAddress.cpp +++ lldb/trunk/source/API/SBAddress.cpp @@ -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(const Address *lldb_object_ptr) : m_opaque_up(new Address()) { if (lldb_object_ptr) - ref() = *lldb_object_ptr; + m_opaque_up = llvm::make_unique
(*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() {} 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; } Index: lldb/trunk/source/API/SBAttachInfo.cpp =================================================================== --- lldb/trunk/source/API/SBAttachInfo.cpp +++ lldb/trunk/source/API/SBAttachInfo.cpp @@ -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 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 @@ 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; } Index: lldb/trunk/source/API/SBCommandReturnObject.cpp =================================================================== --- lldb/trunk/source/API/SBCommandReturnObject.cpp +++ lldb/trunk/source/API/SBCommandReturnObject.cpp @@ -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::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 @@ 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; } Index: lldb/trunk/source/API/SBDeclaration.cpp =================================================================== --- lldb/trunk/source/API/SBDeclaration.cpp +++ lldb/trunk/source/API/SBDeclaration.cpp @@ -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 @@ 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(*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; } Index: lldb/trunk/source/API/SBError.cpp =================================================================== --- lldb/trunk/source/API/SBError.cpp +++ lldb/trunk/source/API/SBError.cpp @@ -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 @@ 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; } Index: lldb/trunk/source/API/SBExpressionOptions.cpp =================================================================== --- lldb/trunk/source/API/SBExpressionOptions.cpp +++ lldb/trunk/source/API/SBExpressionOptions.cpp @@ -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 @@ 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; } Index: lldb/trunk/source/API/SBFileSpec.cpp =================================================================== --- lldb/trunk/source/API/SBFileSpec.cpp +++ lldb/trunk/source/API/SBFileSpec.cpp @@ -9,6 +9,7 @@ #include #include +#include "Utils.h" #include "lldb/API/SBFileSpec.h" #include "lldb/API/SBStream.h" #include "lldb/Host/FileSystem.h" @@ -24,8 +25,9 @@ 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 @@ 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; } Index: lldb/trunk/source/API/SBFileSpecList.cpp =================================================================== --- lldb/trunk/source/API/SBFileSpecList.cpp +++ lldb/trunk/source/API/SBFileSpecList.cpp @@ -8,6 +8,7 @@ #include +#include "Utils.h" #include "lldb/API/SBFileSpec.h" #include "lldb/API/SBFileSpecList.h" #include "lldb/API/SBStream.h" @@ -25,8 +26,7 @@ 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 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; } Index: lldb/trunk/source/API/SBFrame.cpp =================================================================== --- lldb/trunk/source/API/SBFrame.cpp +++ lldb/trunk/source/API/SBFrame.cpp @@ -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 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; } Index: lldb/trunk/source/API/SBLineEntry.cpp =================================================================== --- lldb/trunk/source/API/SBLineEntry.cpp +++ lldb/trunk/source/API/SBLineEntry.cpp @@ -6,43 +6,39 @@ // //===----------------------------------------------------------------------===// -#include - #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 + 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(*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(lldb_object_ref); } SBLineEntry::~SBLineEntry() {} Index: lldb/trunk/source/API/SBMemoryRegionInfo.cpp =================================================================== --- lldb/trunk/source/API/SBMemoryRegionInfo.cpp +++ lldb/trunk/source/API/SBMemoryRegionInfo.cpp @@ -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(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; } Index: lldb/trunk/source/API/SBModuleSpec.cpp =================================================================== --- lldb/trunk/source/API/SBModuleSpec.cpp +++ lldb/trunk/source/API/SBModuleSpec.cpp @@ -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 @@ 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; } Index: lldb/trunk/source/API/SBProcessInfo.cpp =================================================================== --- lldb/trunk/source/API/SBProcessInfo.cpp +++ lldb/trunk/source/API/SBProcessInfo.cpp @@ -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 @@ 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; } Index: lldb/trunk/source/API/SBStringList.cpp =================================================================== --- lldb/trunk/source/API/SBStringList.cpp +++ lldb/trunk/source/API/SBStringList.cpp @@ -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(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(*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; } Index: lldb/trunk/source/API/SBSymbolContext.cpp =================================================================== --- lldb/trunk/source/API/SBSymbolContext.cpp +++ lldb/trunk/source/API/SBSymbolContext.cpp @@ -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(const SymbolContext *sc_ptr) : m_opaque_up() { if (sc_ptr) - m_opaque_up.reset(new SymbolContext(*sc_ptr)); + m_opaque_up = llvm::make_unique(*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(*sc_ptr); + else + m_opaque_up->Clear(true); } bool SBSymbolContext::IsValid() const { return m_opaque_up != NULL; } Index: lldb/trunk/source/API/SBSymbolContextList.cpp =================================================================== --- lldb/trunk/source/API/SBSymbolContextList.cpp +++ lldb/trunk/source/API/SBSymbolContextList.cpp @@ -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 @@ : 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; } Index: lldb/trunk/source/API/SBThread.cpp =================================================================== --- lldb/trunk/source/API/SBThread.cpp +++ lldb/trunk/source/API/SBThread.cpp @@ -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 @@ -61,8 +60,9 @@ 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 @@ 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; } Index: lldb/trunk/source/API/SBTypeEnumMember.cpp =================================================================== --- lldb/trunk/source/API/SBTypeEnumMember.cpp +++ lldb/trunk/source/API/SBTypeEnumMember.cpp @@ -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 @@ 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(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(rhs.ref()); - } + if (this != &rhs) + m_opaque_sp = clone(rhs.m_opaque_sp); return *this; } Index: lldb/trunk/source/API/SBTypeSummary.cpp =================================================================== --- lldb/trunk/source/API/SBTypeSummary.cpp +++ lldb/trunk/source/API/SBTypeSummary.cpp @@ -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() {} Index: lldb/trunk/source/API/Utils.h =================================================================== --- lldb/trunk/source/API/Utils.h +++ lldb/trunk/source/API/Utils.h @@ -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 + +namespace lldb_private { + +template std::unique_ptr clone(const std::unique_ptr &src) { + if (src) + return llvm::make_unique(*src); + return nullptr; +} + +template std::shared_ptr clone(const std::shared_ptr &src) { + if (src) + return std::make_shared(*src); + return nullptr; +} + +} // namespace lldb_private +#endif