JDevlieghere updated this revision to Diff 189377.
JDevlieghere added a comment.

- Add clone utility.
- Updated other SB classes to make use of the clone function as well.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58946/new/

https://reviews.llvm.org/D58946

Files:
  lldb/source/API/SBAddress.cpp
  lldb/source/API/SBAttachInfo.cpp
  lldb/source/API/SBCommandReturnObject.cpp
  lldb/source/API/SBDeclaration.cpp
  lldb/source/API/SBError.cpp
  lldb/source/API/SBExpressionOptions.cpp
  lldb/source/API/SBFileSpec.cpp
  lldb/source/API/SBFileSpecList.cpp
  lldb/source/API/SBFrame.cpp
  lldb/source/API/SBLineEntry.cpp
  lldb/source/API/SBMemoryRegionInfo.cpp
  lldb/source/API/SBModuleSpec.cpp
  lldb/source/API/SBProcessInfo.cpp
  lldb/source/API/SBStringList.cpp
  lldb/source/API/SBSymbolContext.cpp
  lldb/source/API/SBSymbolContextList.cpp
  lldb/source/API/SBThread.cpp
  lldb/source/API/SBTypeEnumMember.cpp
  lldb/source/API/SBTypeSummary.cpp
  lldb/source/API/Utils.h

Index: lldb/source/API/Utils.h
===================================================================
--- /dev/null
+++ lldb/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 <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
Index: lldb/source/API/SBTypeSummary.cpp
===================================================================
--- lldb/source/API/SBTypeSummary.cpp
+++ lldb/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/source/API/SBTypeEnumMember.cpp
===================================================================
--- lldb/source/API/SBTypeEnumMember.cpp
+++ lldb/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<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;
 }
 
Index: lldb/source/API/SBThread.cpp
===================================================================
--- lldb/source/API/SBThread.cpp
+++ lldb/source/API/SBThread.cpp
@@ -8,6 +8,7 @@
 
 #include "lldb/API/SBThread.h"
 
+#include "Utils.h"
 #include "lldb/API/SBFileSpec.h"
 #include "lldb/API/SBStream.h"
 #include "lldb/API/SBSymbolContext.h"
@@ -61,8 +62,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 +72,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/source/API/SBSymbolContextList.cpp
===================================================================
--- lldb/source/API/SBSymbolContextList.cpp
+++ lldb/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/source/API/SBSymbolContext.cpp
===================================================================
--- lldb/source/API/SBSymbolContext.cpp
+++ lldb/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<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; }
Index: lldb/source/API/SBStringList.cpp
===================================================================
--- lldb/source/API/SBStringList.cpp
+++ lldb/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<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;
 }
 
Index: lldb/source/API/SBProcessInfo.cpp
===================================================================
--- lldb/source/API/SBProcessInfo.cpp
+++ lldb/source/API/SBProcessInfo.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "lldb/API/SBProcessInfo.h"
-
+#include "Utils.h"
 #include "lldb/API/SBFileSpec.h"
 #include "lldb/Target/Process.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/source/API/SBModuleSpec.cpp
===================================================================
--- lldb/source/API/SBModuleSpec.cpp
+++ lldb/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/source/API/SBMemoryRegionInfo.cpp
===================================================================
--- lldb/source/API/SBMemoryRegionInfo.cpp
+++ lldb/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/source/API/SBLineEntry.cpp
===================================================================
--- lldb/source/API/SBLineEntry.cpp
+++ lldb/source/API/SBLineEntry.cpp
@@ -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() {}
Index: lldb/source/API/SBFrame.cpp
===================================================================
--- lldb/source/API/SBFrame.cpp
+++ lldb/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/source/API/SBFileSpecList.cpp
===================================================================
--- lldb/source/API/SBFileSpecList.cpp
+++ lldb/source/API/SBFileSpecList.cpp
@@ -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(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/source/API/SBFileSpec.cpp
===================================================================
--- lldb/source/API/SBFileSpec.cpp
+++ lldb/source/API/SBFileSpec.cpp
@@ -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 @@
 
 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/source/API/SBExpressionOptions.cpp
===================================================================
--- lldb/source/API/SBExpressionOptions.cpp
+++ lldb/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/source/API/SBError.cpp
===================================================================
--- lldb/source/API/SBError.cpp
+++ lldb/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/source/API/SBDeclaration.cpp
===================================================================
--- lldb/source/API/SBDeclaration.cpp
+++ lldb/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<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;
 }
 
Index: lldb/source/API/SBCommandReturnObject.cpp
===================================================================
--- lldb/source/API/SBCommandReturnObject.cpp
+++ lldb/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/source/API/SBAttachInfo.cpp
===================================================================
--- lldb/source/API/SBAttachInfo.cpp
+++ lldb/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/source/API/SBAddress.cpp
===================================================================
--- lldb/source/API/SBAddress.cpp
+++ lldb/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<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() {}
 
 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;
 }
 
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to