[Lldb-commits] [lldb] 363f05b - [lldb] Delete the SharingPtr class

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Tue Feb 11 04:24:17 PST 2020


Author: Pavel Labath
Date: 2020-02-11T13:23:18+01:00
New Revision: 363f05b83d9cf207e1b024ca105b8d55526178b8

URL: https://github.com/llvm/llvm-project/commit/363f05b83d9cf207e1b024ca105b8d55526178b8
DIFF: https://github.com/llvm/llvm-project/commit/363f05b83d9cf207e1b024ca105b8d55526178b8.diff

LOG: [lldb] Delete the SharingPtr class

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.

Reviewers: teemperor, JDevlieghere, jingham

Subscribers: mgorny, jfb, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D74153

Added: 
    

Modified: 
    lldb/cmake/modules/LLDBFramework.cmake
    lldb/include/lldb/Core/ValueObject.h
    lldb/include/lldb/Core/ValueObjectConstResult.h
    lldb/include/lldb/Core/ValueObjectDynamicValue.h
    lldb/include/lldb/Core/ValueObjectMemory.h
    lldb/include/lldb/Core/ValueObjectRegister.h
    lldb/include/lldb/Core/ValueObjectVariable.h
    lldb/include/lldb/Utility/SharedCluster.h
    lldb/include/lldb/lldb-forward.h
    lldb/source/Core/FormatEntity.cpp
    lldb/source/Core/ValueObject.cpp
    lldb/source/Core/ValueObjectConstResult.cpp
    lldb/source/Core/ValueObjectConstResultImpl.cpp
    lldb/source/Core/ValueObjectList.cpp
    lldb/source/Core/ValueObjectMemory.cpp
    lldb/source/Core/ValueObjectRegister.cpp
    lldb/source/Core/ValueObjectSyntheticFilter.cpp
    lldb/source/Core/ValueObjectVariable.cpp
    lldb/source/Expression/IRInterpreter.cpp
    lldb/source/Utility/CMakeLists.txt
    lldb/unittests/Utility/SharedClusterTest.cpp

Removed: 
    lldb/include/lldb/Utility/SharingPtr.h
    lldb/source/Utility/SharingPtr.cpp


################################################################################
diff  --git a/lldb/cmake/modules/LLDBFramework.cmake b/lldb/cmake/modules/LLDBFramework.cmake
index fd4c2e41d768..c52daaa4fa8b 100644
--- a/lldb/cmake/modules/LLDBFramework.cmake
+++ b/lldb/cmake/modules/LLDBFramework.cmake
@@ -59,8 +59,7 @@ list(REMOVE_ITEM root_public_headers ${root_private_headers})
 set(lldb_header_staging ${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders)
 foreach(header
     ${public_headers}
-    ${root_public_headers}
-    ${LLDB_SOURCE_DIR}/include/lldb/Utility/SharingPtr.h)
+    ${root_public_headers})
 
   get_filename_component(basename ${header} NAME)
   set(staged_header ${lldb_header_staging}/${basename})

diff  --git a/lldb/include/lldb/Core/ValueObject.h b/lldb/include/lldb/Core/ValueObject.h
index 4a410e9e19df..4f8ea9d23d78 100644
--- a/lldb/include/lldb/Core/ValueObject.h
+++ b/lldb/include/lldb/Core/ValueObject.h
@@ -902,7 +902,7 @@ class ValueObject : public UserID {
   // Use this constructor to create a "root variable object".  The ValueObject
   // will be locked to this context through-out its lifespan.
 
-  ValueObject(ExecutionContextScope *exe_scope,
+  ValueObject(ExecutionContextScope *exe_scope, ValueObjectManager &manager,
               AddressType child_ptr_or_ref_addr_type = eAddressTypeLoad);
 
   // Use this constructor to create a ValueObject owned by another ValueObject.

diff  --git a/lldb/include/lldb/Core/ValueObjectConstResult.h b/lldb/include/lldb/Core/ValueObjectConstResult.h
index 3bc957ef2b84..57d6b530df7b 100644
--- a/lldb/include/lldb/Core/ValueObjectConstResult.h
+++ b/lldb/include/lldb/Core/ValueObjectConstResult.h
@@ -121,30 +121,34 @@ class ValueObjectConstResult : public ValueObject {
   friend class ValueObjectConstResultImpl;
 
   ValueObjectConstResult(ExecutionContextScope *exe_scope,
+                         ValueObjectManager &manager,
                          lldb::ByteOrder byte_order, uint32_t addr_byte_size,
                          lldb::addr_t address);
 
   ValueObjectConstResult(ExecutionContextScope *exe_scope,
-                         const CompilerType &compiler_type,
-                         ConstString name, const DataExtractor &data,
-                         lldb::addr_t address);
+                         ValueObjectManager &manager,
+                         const CompilerType &compiler_type, ConstString name,
+                         const DataExtractor &data, lldb::addr_t address);
 
   ValueObjectConstResult(ExecutionContextScope *exe_scope,
-                         const CompilerType &compiler_type,
-                         ConstString name,
+                         ValueObjectManager &manager,
+                         const CompilerType &compiler_type, ConstString name,
                          const lldb::DataBufferSP &result_data_sp,
                          lldb::ByteOrder byte_order, uint32_t addr_size,
                          lldb::addr_t address);
 
   ValueObjectConstResult(ExecutionContextScope *exe_scope,
-                         const CompilerType &compiler_type,
-                         ConstString name, lldb::addr_t address,
-                         AddressType address_type, uint32_t addr_byte_size);
+                         ValueObjectManager &manager,
+                         const CompilerType &compiler_type, ConstString name,
+                         lldb::addr_t address, AddressType address_type,
+                         uint32_t addr_byte_size);
 
-  ValueObjectConstResult(ExecutionContextScope *exe_scope, const Value &value,
+  ValueObjectConstResult(ExecutionContextScope *exe_scope,
+                         ValueObjectManager &manager, const Value &value,
                          ConstString name, Module *module = nullptr);
 
-  ValueObjectConstResult(ExecutionContextScope *exe_scope, const Status &error);
+  ValueObjectConstResult(ExecutionContextScope *exe_scope,
+                         ValueObjectManager &manager, const Status &error);
 
   DISALLOW_COPY_AND_ASSIGN(ValueObjectConstResult);
 };

diff  --git a/lldb/include/lldb/Core/ValueObjectDynamicValue.h b/lldb/include/lldb/Core/ValueObjectDynamicValue.h
index f656d42e9a97..6b6e71d7c41a 100644
--- a/lldb/include/lldb/Core/ValueObjectDynamicValue.h
+++ b/lldb/include/lldb/Core/ValueObjectDynamicValue.h
@@ -14,7 +14,6 @@
 #include "lldb/Symbol/CompilerType.h"
 #include "lldb/Symbol/Type.h"
 #include "lldb/Utility/ConstString.h"
-#include "lldb/Utility/SharingPtr.h"
 #include "lldb/lldb-defines.h"
 #include "lldb/lldb-enumerations.h"
 #include "lldb/lldb-forward.h"

diff  --git a/lldb/include/lldb/Core/ValueObjectMemory.h b/lldb/include/lldb/Core/ValueObjectMemory.h
index df3557f14989..a50f66bf02ee 100644
--- a/lldb/include/lldb/Core/ValueObjectMemory.h
+++ b/lldb/include/lldb/Core/ValueObjectMemory.h
@@ -64,10 +64,12 @@ class ValueObjectMemory : public ValueObject {
   CompilerType m_compiler_type;
 
 private:
-  ValueObjectMemory(ExecutionContextScope *exe_scope, llvm::StringRef name,
+  ValueObjectMemory(ExecutionContextScope *exe_scope,
+                    ValueObjectManager &manager, llvm::StringRef name,
                     const Address &address, lldb::TypeSP &type_sp);
 
-  ValueObjectMemory(ExecutionContextScope *exe_scope, llvm::StringRef name,
+  ValueObjectMemory(ExecutionContextScope *exe_scope,
+                    ValueObjectManager &manager, llvm::StringRef name,
                     const Address &address, const CompilerType &ast_type);
   // For ValueObject only
   DISALLOW_COPY_AND_ASSIGN(ValueObjectMemory);

diff  --git a/lldb/include/lldb/Core/ValueObjectRegister.h b/lldb/include/lldb/Core/ValueObjectRegister.h
index 28dad993d05a..59c982d489f0 100644
--- a/lldb/include/lldb/Core/ValueObjectRegister.h
+++ b/lldb/include/lldb/Core/ValueObjectRegister.h
@@ -69,6 +69,7 @@ class ValueObjectRegisterSet : public ValueObject {
   friend class ValueObjectRegisterContext;
 
   ValueObjectRegisterSet(ExecutionContextScope *exe_scope,
+                         ValueObjectManager &manager,
                          lldb::RegisterContextSP &reg_ctx_sp, uint32_t set_idx);
 
   // For ValueObject only
@@ -123,6 +124,7 @@ class ValueObjectRegister : public ValueObject {
   ValueObjectRegister(ValueObject &parent, lldb::RegisterContextSP &reg_ctx_sp,
                       uint32_t reg_num);
   ValueObjectRegister(ExecutionContextScope *exe_scope,
+                      ValueObjectManager &manager,
                       lldb::RegisterContextSP &reg_ctx_sp, uint32_t reg_num);
 
   // For ValueObject only

diff  --git a/lldb/include/lldb/Core/ValueObjectVariable.h b/lldb/include/lldb/Core/ValueObjectVariable.h
index 86bb8ef90070..9b795cc4ec66 100644
--- a/lldb/include/lldb/Core/ValueObjectVariable.h
+++ b/lldb/include/lldb/Core/ValueObjectVariable.h
@@ -77,6 +77,7 @@ class ValueObjectVariable : public ValueObject {
 
 private:
   ValueObjectVariable(ExecutionContextScope *exe_scope,
+                      ValueObjectManager &manager,
                       const lldb::VariableSP &var_sp);
   // For ValueObject only
   DISALLOW_COPY_AND_ASSIGN(ValueObjectVariable);

diff  --git a/lldb/include/lldb/Utility/SharedCluster.h b/lldb/include/lldb/Utility/SharedCluster.h
index 38b2d19c7093..a8ee67c069f4 100644
--- a/lldb/include/lldb/Utility/SharedCluster.h
+++ b/lldb/include/lldb/Utility/SharedCluster.h
@@ -10,46 +10,24 @@
 #define utility_SharedCluster_h_
 
 #include "lldb/Utility/LLDBAssert.h"
-#include "lldb/Utility/SharingPtr.h"
-
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 
+#include <memory>
 #include <mutex>
 
 namespace lldb_private {
 
-namespace imp {
-template <typename T>
-class shared_ptr_refcount : public lldb_private::imp::shared_count {
+template <class T>
+class ClusterManager : public std::enable_shared_from_this<ClusterManager<T>> {
 public:
-  template <class Y>
-  shared_ptr_refcount(Y *in) : shared_count(0), manager(in) {}
-
-  shared_ptr_refcount() : shared_count(0) {}
-
-  ~shared_ptr_refcount() override {}
-
-  void on_zero_shared() override { manager->DecrementRefCount(); }
-
-private:
-  T *manager;
-};
-
-} // namespace imp
-
-template <class T> class ClusterManager {
-public:
-  ClusterManager() : m_objects(), m_external_ref(0), m_mutex() {}
+  static std::shared_ptr<ClusterManager> Create() {
+    return std::shared_ptr<ClusterManager>(new ClusterManager());
+  }
 
   ~ClusterManager() {
     for (T *obj : m_objects)
       delete obj;
-
-    // Decrement refcount should have been called on this ClusterManager, and
-    // it should have locked the mutex, now we will unlock it before we destroy
-    // it...
-    m_mutex.unlock();
   }
 
   void ManageObject(T *new_object) {
@@ -59,33 +37,20 @@ template <class T> class ClusterManager {
     m_objects.push_back(new_object);
   }
 
-  typename lldb_private::SharingPtr<T> GetSharedPointer(T *desired_object) {
-    {
-      std::lock_guard<std::mutex> guard(m_mutex);
-      m_external_ref++;
-      if (!llvm::is_contained(m_objects, desired_object)) {
-        lldbassert(false && "object not found in shared cluster when expected");
-        desired_object = nullptr;
-      }
+  std::shared_ptr<T> GetSharedPointer(T *desired_object) {
+    std::lock_guard<std::mutex> guard(m_mutex);
+    auto this_sp = this->shared_from_this();
+    if (!llvm::is_contained(m_objects, desired_object)) {
+      lldbassert(false && "object not found in shared cluster when expected");
+      desired_object = nullptr;
     }
-    return typename lldb_private::SharingPtr<T>(
-        desired_object, new imp::shared_ptr_refcount<ClusterManager>(this));
+    return {std::move(this_sp), desired_object};
   }
 
 private:
-  void DecrementRefCount() {
-    m_mutex.lock();
-    m_external_ref--;
-    if (m_external_ref == 0)
-      delete this;
-    else
-      m_mutex.unlock();
-  }
-
-  friend class imp::shared_ptr_refcount<ClusterManager>;
+  ClusterManager() : m_objects(), m_mutex() {}
 
   llvm::SmallVector<T *, 16> m_objects;
-  int m_external_ref;
   std::mutex m_mutex;
 };
 

diff  --git a/lldb/include/lldb/Utility/SharingPtr.h b/lldb/include/lldb/Utility/SharingPtr.h
deleted file mode 100644
index 76e340a3ae66..000000000000
--- a/lldb/include/lldb/Utility/SharingPtr.h
+++ /dev/null
@@ -1,359 +0,0 @@
-//===---------------------SharingPtr.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 utility_SharingPtr_h_
-#define utility_SharingPtr_h_
-
-#include <memory>
-
-// Microsoft Visual C++ currently does not enable std::atomic to work in CLR
-// mode - as such we need to "hack around it" for MSVC++ builds only using
-// Windows specific intrinsics instead of the C++11 atomic support
-#ifdef _MSC_VER
-#include <intrin.h>
-#else
-#include <atomic>
-#endif
-
-#include <stddef.h>
-
-
-//#define ENABLE_SP_LOGGING 1 // DON'T CHECK THIS LINE IN UNLESS COMMENTED OUT
-#if defined(ENABLE_SP_LOGGING)
-
-extern "C" void track_sp(void *sp_this, void *ptr, long count);
-
-#endif
-
-namespace lldb_private {
-
-namespace imp {
-
-class shared_count {
-  shared_count(const shared_count &) = delete;
-  shared_count &operator=(const shared_count &) = delete;
-
-public:
-  explicit shared_count(long refs = 0) : shared_owners_(refs) {}
-
-  void add_shared();
-  void release_shared();
-  long use_count() const { return shared_owners_ + 1; }
-
-protected:
-#ifdef _MSC_VER
-  long shared_owners_;
-#else
-  std::atomic<long> shared_owners_;
-#endif
-  virtual ~shared_count();
-
-private:
-  virtual void on_zero_shared() = 0;
-};
-
-template <class T> class shared_ptr_pointer : public shared_count {
-  T data_;
-
-public:
-  shared_ptr_pointer(T p) : data_(p) {}
-
-private:
-  void on_zero_shared() override;
-
-  shared_ptr_pointer(const shared_ptr_pointer &) = delete;
-  shared_ptr_pointer &operator=(const shared_ptr_pointer &) = delete;
-};
-
-template <class T> void shared_ptr_pointer<T>::on_zero_shared() {
-  delete data_;
-}
-
-template <class T> class shared_ptr_emplace : public shared_count {
-  T data_;
-
-public:
-  shared_ptr_emplace() : data_() {}
-
-  template <class A0> shared_ptr_emplace(A0 &a0) : data_(a0) {}
-
-  template <class A0, class A1>
-  shared_ptr_emplace(A0 &a0, A1 &a1) : data_(a0, a1) {}
-
-  template <class A0, class A1, class A2>
-  shared_ptr_emplace(A0 &a0, A1 &a1, A2 &a2) : data_(a0, a1, a2) {}
-
-  template <class A0, class A1, class A2, class A3>
-  shared_ptr_emplace(A0 &a0, A1 &a1, A2 &a2, A3 &a3) : data_(a0, a1, a2, a3) {}
-
-  template <class A0, class A1, class A2, class A3, class A4>
-  shared_ptr_emplace(A0 &a0, A1 &a1, A2 &a2, A3 &a3, A4 &a4)
-      : data_(a0, a1, a2, a3, a4) {}
-
-private:
-  void on_zero_shared() override;
-
-public:
-  T *get() { return &data_; }
-};
-
-template <class T> void shared_ptr_emplace<T>::on_zero_shared() {}
-
-} // namespace imp
-
-template <class T> class SharingPtr {
-public:
-  typedef T element_type;
-
-private:
-  element_type *ptr_;
-  imp::shared_count *cntrl_;
-
-  struct nat {
-    int for_bool_;
-  };
-
-public:
-  SharingPtr();
-  SharingPtr(std::nullptr_t);
-  template <class Y> explicit SharingPtr(Y *p);
-  template <class Y> explicit SharingPtr(Y *p, imp::shared_count *ctrl_block);
-  template <class Y> SharingPtr(const SharingPtr<Y> &r, element_type *p);
-  SharingPtr(const SharingPtr &r);
-  template <class Y> SharingPtr(const SharingPtr<Y> &r);
-
-  ~SharingPtr();
-
-  SharingPtr &operator=(const SharingPtr &r);
-  template <class Y> SharingPtr &operator=(const SharingPtr<Y> &r);
-
-  void swap(SharingPtr &r);
-  void reset();
-  template <class Y> void reset(Y *p);
-
-  element_type *get() const { return ptr_; }
-  element_type &operator*() const { return *ptr_; }
-  element_type *operator->() const { return ptr_; }
-  long use_count() const { return cntrl_ ? cntrl_->use_count() : 0; }
-  bool unique() const { return use_count() == 1; }
-  bool empty() const { return cntrl_ == nullptr; }
-  operator nat *() const { return (nat *)get(); }
-
-  static SharingPtr<T> make_shared();
-
-  template <class A0> static SharingPtr<T> make_shared(A0 &);
-
-  template <class A0, class A1> static SharingPtr<T> make_shared(A0 &, A1 &);
-
-  template <class A0, class A1, class A2>
-  static SharingPtr<T> make_shared(A0 &, A1 &, A2 &);
-
-  template <class A0, class A1, class A2, class A3>
-  static SharingPtr<T> make_shared(A0 &, A1 &, A2 &, A3 &);
-
-  template <class A0, class A1, class A2, class A3, class A4>
-  static SharingPtr<T> make_shared(A0 &, A1 &, A2 &, A3 &, A4 &);
-
-private:
-  template <class U> friend class SharingPtr;
-};
-
-template <class T>
-inline SharingPtr<T>::SharingPtr() : ptr_(nullptr), cntrl_(nullptr) {}
-
-template <class T>
-inline SharingPtr<T>::SharingPtr(std::nullptr_t)
-    : ptr_(nullptr), cntrl_(nullptr) {}
-
-template <class T>
-template <class Y>
-SharingPtr<T>::SharingPtr(Y *p) : ptr_(p), cntrl_(nullptr) {
-  std::unique_ptr<Y> hold(p);
-  typedef imp::shared_ptr_pointer<Y *> _CntrlBlk;
-  cntrl_ = new _CntrlBlk(p);
-  hold.release();
-}
-
-template <class T>
-template <class Y>
-SharingPtr<T>::SharingPtr(Y *p, imp::shared_count *cntrl_block)
-    : ptr_(p), cntrl_(cntrl_block) {}
-
-template <class T>
-template <class Y>
-inline SharingPtr<T>::SharingPtr(const SharingPtr<Y> &r, element_type *p)
-    : ptr_(p), cntrl_(r.cntrl_) {
-  if (cntrl_)
-    cntrl_->add_shared();
-}
-
-template <class T>
-inline SharingPtr<T>::SharingPtr(const SharingPtr &r)
-    : ptr_(r.ptr_), cntrl_(r.cntrl_) {
-  if (cntrl_)
-    cntrl_->add_shared();
-}
-
-template <class T>
-template <class Y>
-inline SharingPtr<T>::SharingPtr(const SharingPtr<Y> &r)
-    : ptr_(r.ptr_), cntrl_(r.cntrl_) {
-  if (cntrl_)
-    cntrl_->add_shared();
-}
-
-template <class T> SharingPtr<T>::~SharingPtr() {
-  if (cntrl_)
-    cntrl_->release_shared();
-}
-
-template <class T>
-inline SharingPtr<T> &SharingPtr<T>::operator=(const SharingPtr &r) {
-  SharingPtr(r).swap(*this);
-  return *this;
-}
-
-template <class T>
-template <class Y>
-inline SharingPtr<T> &SharingPtr<T>::operator=(const SharingPtr<Y> &r) {
-  SharingPtr(r).swap(*this);
-  return *this;
-}
-
-template <class T> inline void SharingPtr<T>::swap(SharingPtr &r) {
-  std::swap(ptr_, r.ptr_);
-  std::swap(cntrl_, r.cntrl_);
-}
-
-template <class T> inline void SharingPtr<T>::reset() {
-  SharingPtr().swap(*this);
-}
-
-template <class T> template <class Y> inline void SharingPtr<T>::reset(Y *p) {
-  SharingPtr(p).swap(*this);
-}
-
-template <class T> SharingPtr<T> SharingPtr<T>::make_shared() {
-  typedef imp::shared_ptr_emplace<T> CntrlBlk;
-  SharingPtr<T> r;
-  r.cntrl_ = new CntrlBlk();
-  r.ptr_ = static_cast<CntrlBlk *>(r.cntrl_)->get();
-  return r;
-}
-
-template <class T>
-template <class A0>
-SharingPtr<T> SharingPtr<T>::make_shared(A0 &a0) {
-  typedef imp::shared_ptr_emplace<T> CntrlBlk;
-  SharingPtr<T> r;
-  r.cntrl_ = new CntrlBlk(a0);
-  r.ptr_ = static_cast<CntrlBlk *>(r.cntrl_)->get();
-  return r;
-}
-
-template <class T>
-template <class A0, class A1>
-SharingPtr<T> SharingPtr<T>::make_shared(A0 &a0, A1 &a1) {
-  typedef imp::shared_ptr_emplace<T> CntrlBlk;
-  SharingPtr<T> r;
-  r.cntrl_ = new CntrlBlk(a0, a1);
-  r.ptr_ = static_cast<CntrlBlk *>(r.cntrl_)->get();
-  return r;
-}
-
-template <class T>
-template <class A0, class A1, class A2>
-SharingPtr<T> SharingPtr<T>::make_shared(A0 &a0, A1 &a1, A2 &a2) {
-  typedef imp::shared_ptr_emplace<T> CntrlBlk;
-  SharingPtr<T> r;
-  r.cntrl_ = new CntrlBlk(a0, a1, a2);
-  r.ptr_ = static_cast<CntrlBlk *>(r.cntrl_)->get();
-  return r;
-}
-
-template <class T>
-template <class A0, class A1, class A2, class A3>
-SharingPtr<T> SharingPtr<T>::make_shared(A0 &a0, A1 &a1, A2 &a2, A3 &a3) {
-  typedef imp::shared_ptr_emplace<T> CntrlBlk;
-  SharingPtr<T> r;
-  r.cntrl_ = new CntrlBlk(a0, a1, a2, a3);
-  r.ptr_ = static_cast<CntrlBlk *>(r.cntrl_)->get();
-  return r;
-}
-
-template <class T>
-template <class A0, class A1, class A2, class A3, class A4>
-SharingPtr<T> SharingPtr<T>::make_shared(A0 &a0, A1 &a1, A2 &a2, A3 &a3,
-                                         A4 &a4) {
-  typedef imp::shared_ptr_emplace<T> CntrlBlk;
-  SharingPtr<T> r;
-  r.cntrl_ = new CntrlBlk(a0, a1, a2, a3, a4);
-  r.ptr_ = static_cast<CntrlBlk *>(r.cntrl_)->get();
-  return r;
-}
-
-template <class T> inline SharingPtr<T> make_shared() {
-  return SharingPtr<T>::make_shared();
-}
-
-template <class T, class A0> inline SharingPtr<T> make_shared(A0 &a0) {
-  return SharingPtr<T>::make_shared(a0);
-}
-
-template <class T, class A0, class A1>
-inline SharingPtr<T> make_shared(A0 &a0, A1 &a1) {
-  return SharingPtr<T>::make_shared(a0, a1);
-}
-
-template <class T, class A0, class A1, class A2>
-inline SharingPtr<T> make_shared(A0 &a0, A1 &a1, A2 &a2) {
-  return SharingPtr<T>::make_shared(a0, a1, a2);
-}
-
-template <class T, class A0, class A1, class A2, class A3>
-inline SharingPtr<T> make_shared(A0 &a0, A1 &a1, A2 &a2, A3 &a3) {
-  return SharingPtr<T>::make_shared(a0, a1, a2, a3);
-}
-
-template <class T, class A0, class A1, class A2, class A3, class A4>
-inline SharingPtr<T> make_shared(A0 &a0, A1 &a1, A2 &a2, A3 &a3, A4 &a4) {
-  return SharingPtr<T>::make_shared(a0, a1, a2, a3, a4);
-}
-
-template <class T, class U>
-inline bool operator==(const SharingPtr<T> &__x, const SharingPtr<U> &__y) {
-  return __x.get() == __y.get();
-}
-
-template <class T, class U>
-inline bool operator!=(const SharingPtr<T> &__x, const SharingPtr<U> &__y) {
-  return !(__x == __y);
-}
-
-template <class T, class U>
-inline bool operator<(const SharingPtr<T> &__x, const SharingPtr<U> &__y) {
-  return __x.get() < __y.get();
-}
-
-template <class T> inline void swap(SharingPtr<T> &__x, SharingPtr<T> &__y) {
-  __x.swap(__y);
-}
-
-template <class T, class U>
-inline SharingPtr<T> static_pointer_cast(const SharingPtr<U> &r) {
-  return SharingPtr<T>(r, static_cast<T *>(r.get()));
-}
-
-template <class T, class U>
-SharingPtr<T> const_pointer_cast(const SharingPtr<U> &r) {
-  return SharingPtr<T>(r, const_cast<T *>(r.get()));
-}
-
-} // namespace lldb_private
-
-#endif // utility_SharingPtr_h_

diff  --git a/lldb/include/lldb/lldb-forward.h b/lldb/include/lldb/lldb-forward.h
index 0ca5d031b3e5..0b3de880ee31 100644
--- a/lldb/include/lldb/lldb-forward.h
+++ b/lldb/include/lldb/lldb-forward.h
@@ -11,7 +11,7 @@
 
 #if defined(__cplusplus)
 
-#include "lldb/Utility/SharingPtr.h"
+#include <memory>
 
 // lldb forward declarations
 namespace lldb_private {
@@ -452,7 +452,7 @@ typedef std::weak_ptr<lldb_private::UnixSignals> UnixSignalsWP;
 typedef std::shared_ptr<lldb_private::UnwindAssembly> UnwindAssemblySP;
 typedef std::shared_ptr<lldb_private::UnwindPlan> UnwindPlanSP;
 typedef std::shared_ptr<lldb_private::UtilityFunction> UtilityFunctionSP;
-typedef lldb_private::SharingPtr<lldb_private::ValueObject> ValueObjectSP;
+typedef std::shared_ptr<lldb_private::ValueObject> ValueObjectSP;
 typedef std::shared_ptr<lldb_private::Value> ValueSP;
 typedef std::shared_ptr<lldb_private::ValueList> ValueListSP;
 typedef std::shared_ptr<lldb_private::Variable> VariableSP;

diff  --git a/lldb/source/Core/FormatEntity.cpp b/lldb/source/Core/FormatEntity.cpp
index aaec84758ac6..b258b6f5413b 100644
--- a/lldb/source/Core/FormatEntity.cpp
+++ b/lldb/source/Core/FormatEntity.cpp
@@ -46,7 +46,6 @@
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/Logging.h"
 #include "lldb/Utility/RegisterValue.h"
-#include "lldb/Utility/SharingPtr.h"
 #include "lldb/Utility/Stream.h"
 #include "lldb/Utility/StreamString.h"
 #include "lldb/Utility/StringList.h"

diff  --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp
index 9dfa909e4686..80e41c91e68b 100644
--- a/lldb/source/Core/ValueObject.cpp
+++ b/lldb/source/Core/ValueObject.cpp
@@ -45,7 +45,6 @@
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/Logging.h"
 #include "lldb/Utility/Scalar.h"
-#include "lldb/Utility/SharingPtr.h"
 #include "lldb/Utility/Stream.h"
 #include "lldb/Utility/StreamString.h"
 #include "lldb/lldb-private-types.h"
@@ -105,12 +104,13 @@ ValueObject::ValueObject(ValueObject &parent)
 
 // ValueObject constructor
 ValueObject::ValueObject(ExecutionContextScope *exe_scope,
+                         ValueObjectManager &manager,
                          AddressType child_ptr_or_ref_addr_type)
     : UserID(++g_value_obj_uid), // Unique identifier for every value object
       m_parent(nullptr), m_root(nullptr), m_update_point(exe_scope), m_name(),
       m_data(), m_value(), m_error(), m_value_str(), m_old_value_str(),
       m_location_str(), m_summary_str(), m_object_desc_str(),
-      m_manager(), m_children(), m_synthetic_children(),
+      m_manager(&manager), m_children(), m_synthetic_children(),
       m_dynamic_value(nullptr), m_synthetic_value(nullptr),
       m_deref_valobj(nullptr), m_format(eFormatDefault),
       m_last_format(eFormatDefault), m_last_format_mgr_revision(0),
@@ -134,7 +134,6 @@ ValueObject::ValueObject(ExecutionContextScope *exe_scope,
       m_data.SetAddressByteSize(arch.GetAddressByteSize());
     }
   }
-  m_manager = new ValueObjectManager();
   m_manager->ManageObject(this);
 }
 

diff  --git a/lldb/source/Core/ValueObjectConstResult.cpp b/lldb/source/Core/ValueObjectConstResult.cpp
index 4fe05e0b3333..80d7783ea267 100644
--- a/lldb/source/Core/ValueObjectConstResult.cpp
+++ b/lldb/source/Core/ValueObjectConstResult.cpp
@@ -29,16 +29,18 @@ ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
                                              ByteOrder byte_order,
                                              uint32_t addr_byte_size,
                                              lldb::addr_t address) {
-  return (new ValueObjectConstResult(exe_scope, byte_order, addr_byte_size,
-                                     address))
+  auto manager_sp = ValueObjectManager::Create();
+  return (new ValueObjectConstResult(exe_scope, *manager_sp, byte_order,
+                                     addr_byte_size, address))
       ->GetSP();
 }
 
 ValueObjectConstResult::ValueObjectConstResult(ExecutionContextScope *exe_scope,
+                                               ValueObjectManager &manager,
                                                ByteOrder byte_order,
                                                uint32_t addr_byte_size,
                                                lldb::addr_t address)
-    : ValueObject(exe_scope), m_type_name(), m_byte_size(0),
+    : ValueObject(exe_scope, manager), m_type_name(), m_byte_size(0),
       m_impl(this, address) {
   SetIsConstant();
   SetValueIsValid(true);
@@ -52,15 +54,17 @@ ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
                                              ConstString name,
                                              const DataExtractor &data,
                                              lldb::addr_t address) {
-  return (new ValueObjectConstResult(exe_scope, compiler_type, name, data,
-                                     address))
+  auto manager_sp = ValueObjectManager::Create();
+  return (new ValueObjectConstResult(exe_scope, *manager_sp, compiler_type,
+                                     name, data, address))
       ->GetSP();
 }
 
 ValueObjectConstResult::ValueObjectConstResult(
-    ExecutionContextScope *exe_scope, const CompilerType &compiler_type,
-    ConstString name, const DataExtractor &data, lldb::addr_t address)
-    : ValueObject(exe_scope), m_type_name(), m_byte_size(0),
+    ExecutionContextScope *exe_scope, ValueObjectManager &manager,
+    const CompilerType &compiler_type, ConstString name,
+    const DataExtractor &data, lldb::addr_t address)
+    : ValueObject(exe_scope, manager), m_type_name(), m_byte_size(0),
       m_impl(this, address) {
   m_data = data;
 
@@ -86,8 +90,10 @@ ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
                                              lldb::ByteOrder data_byte_order,
                                              uint32_t data_addr_size,
                                              lldb::addr_t address) {
-  return (new ValueObjectConstResult(exe_scope, compiler_type, name, data_sp,
-                                     data_byte_order, data_addr_size, address))
+  auto manager_sp = ValueObjectManager::Create();
+  return (new ValueObjectConstResult(exe_scope, *manager_sp, compiler_type,
+                                     name, data_sp, data_byte_order,
+                                     data_addr_size, address))
       ->GetSP();
 }
 
@@ -95,15 +101,18 @@ ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
                                              Value &value,
                                              ConstString name,
                                              Module *module) {
-  return (new ValueObjectConstResult(exe_scope, value, name, module))->GetSP();
+  auto manager_sp = ValueObjectManager::Create();
+  return (new ValueObjectConstResult(exe_scope, *manager_sp, value, name,
+                                     module))
+      ->GetSP();
 }
 
 ValueObjectConstResult::ValueObjectConstResult(
-    ExecutionContextScope *exe_scope, const CompilerType &compiler_type,
-    ConstString name, const lldb::DataBufferSP &data_sp,
-    lldb::ByteOrder data_byte_order, uint32_t data_addr_size,
-    lldb::addr_t address)
-    : ValueObject(exe_scope), m_type_name(), m_byte_size(0),
+    ExecutionContextScope *exe_scope, ValueObjectManager &manager,
+    const CompilerType &compiler_type, ConstString name,
+    const lldb::DataBufferSP &data_sp, lldb::ByteOrder data_byte_order,
+    uint32_t data_addr_size, lldb::addr_t address)
+    : ValueObject(exe_scope, manager), m_type_name(), m_byte_size(0),
       m_impl(this, address) {
   m_data.SetByteOrder(data_byte_order);
   m_data.SetAddressByteSize(data_addr_size);
@@ -123,16 +132,18 @@ ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
                                              lldb::addr_t address,
                                              AddressType address_type,
                                              uint32_t addr_byte_size) {
-  return (new ValueObjectConstResult(exe_scope, compiler_type, name, address,
-                                     address_type, addr_byte_size))
+  auto manager_sp = ValueObjectManager::Create();
+  return (new ValueObjectConstResult(exe_scope, *manager_sp, compiler_type,
+                                     name, address, address_type,
+                                     addr_byte_size))
       ->GetSP();
 }
 
 ValueObjectConstResult::ValueObjectConstResult(
-    ExecutionContextScope *exe_scope, const CompilerType &compiler_type,
-    ConstString name, lldb::addr_t address, AddressType address_type,
-    uint32_t addr_byte_size)
-    : ValueObject(exe_scope), m_type_name(), m_byte_size(0),
+    ExecutionContextScope *exe_scope, ValueObjectManager &manager,
+    const CompilerType &compiler_type, ConstString name, lldb::addr_t address,
+    AddressType address_type, uint32_t addr_byte_size)
+    : ValueObject(exe_scope, manager), m_type_name(), m_byte_size(0),
       m_impl(this, address) {
   m_value.GetScalar() = address;
   m_data.SetAddressByteSize(addr_byte_size);
@@ -161,21 +172,25 @@ ValueObjectConstResult::ValueObjectConstResult(
 
 ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
                                              const Status &error) {
-  return (new ValueObjectConstResult(exe_scope, error))->GetSP();
+  auto manager_sp = ValueObjectManager::Create();
+  return (new ValueObjectConstResult(exe_scope, *manager_sp, error))->GetSP();
 }
 
 ValueObjectConstResult::ValueObjectConstResult(ExecutionContextScope *exe_scope,
+                                               ValueObjectManager &manager,
                                                const Status &error)
-    : ValueObject(exe_scope), m_type_name(), m_byte_size(0), m_impl(this) {
+    : ValueObject(exe_scope, manager), m_type_name(), m_byte_size(0),
+      m_impl(this) {
   m_error = error;
   SetIsConstant();
 }
 
 ValueObjectConstResult::ValueObjectConstResult(ExecutionContextScope *exe_scope,
+                                               ValueObjectManager &manager,
                                                const Value &value,
-                                               ConstString name,
-                                               Module *module)
-    : ValueObject(exe_scope), m_type_name(), m_byte_size(0), m_impl(this) {
+                                               ConstString name, Module *module)
+    : ValueObject(exe_scope, manager), m_type_name(), m_byte_size(0),
+      m_impl(this) {
   m_value = value;
   m_name = name;
   ExecutionContext exe_ctx;

diff  --git a/lldb/source/Core/ValueObjectConstResultImpl.cpp b/lldb/source/Core/ValueObjectConstResultImpl.cpp
index d39f3bbe60f2..e4cbbec849ec 100644
--- a/lldb/source/Core/ValueObjectConstResultImpl.cpp
+++ b/lldb/source/Core/ValueObjectConstResultImpl.cpp
@@ -18,7 +18,6 @@
 #include "lldb/Utility/DataBufferHeap.h"
 #include "lldb/Utility/Endian.h"
 #include "lldb/Utility/Scalar.h"
-#include "lldb/Utility/SharingPtr.h"
 
 #include <string>
 

diff  --git a/lldb/source/Core/ValueObjectList.cpp b/lldb/source/Core/ValueObjectList.cpp
index 798596b1360d..28907261f0a6 100644
--- a/lldb/source/Core/ValueObjectList.cpp
+++ b/lldb/source/Core/ValueObjectList.cpp
@@ -10,7 +10,6 @@
 
 #include "lldb/Core/ValueObject.h"
 #include "lldb/Utility/ConstString.h"
-#include "lldb/Utility/SharingPtr.h"
 
 #include <utility>
 

diff  --git a/lldb/source/Core/ValueObjectMemory.cpp b/lldb/source/Core/ValueObjectMemory.cpp
index b7559bfe5fd2..b1fd51386682 100644
--- a/lldb/source/Core/ValueObjectMemory.cpp
+++ b/lldb/source/Core/ValueObjectMemory.cpp
@@ -32,21 +32,27 @@ ValueObjectSP ValueObjectMemory::Create(ExecutionContextScope *exe_scope,
                                         llvm::StringRef name,
                                         const Address &address,
                                         lldb::TypeSP &type_sp) {
-  return (new ValueObjectMemory(exe_scope, name, address, type_sp))->GetSP();
+  auto manager_sp = ValueObjectManager::Create();
+  return (new ValueObjectMemory(exe_scope, *manager_sp, name, address, type_sp))
+      ->GetSP();
 }
 
 ValueObjectSP ValueObjectMemory::Create(ExecutionContextScope *exe_scope,
                                         llvm::StringRef name,
                                         const Address &address,
                                         const CompilerType &ast_type) {
-  return (new ValueObjectMemory(exe_scope, name, address, ast_type))->GetSP();
+  auto manager_sp = ValueObjectManager::Create();
+  return (new ValueObjectMemory(exe_scope, *manager_sp, name, address,
+                                ast_type))
+      ->GetSP();
 }
 
 ValueObjectMemory::ValueObjectMemory(ExecutionContextScope *exe_scope,
+                                     ValueObjectManager &manager,
                                      llvm::StringRef name,
                                      const Address &address,
                                      lldb::TypeSP &type_sp)
-    : ValueObject(exe_scope), m_address(address), m_type_sp(type_sp),
+    : ValueObject(exe_scope, manager), m_address(address), m_type_sp(type_sp),
       m_compiler_type() {
   // Do not attempt to construct one of these objects with no variable!
   assert(m_type_sp.get() != nullptr);
@@ -70,10 +76,11 @@ ValueObjectMemory::ValueObjectMemory(ExecutionContextScope *exe_scope,
 }
 
 ValueObjectMemory::ValueObjectMemory(ExecutionContextScope *exe_scope,
+                                     ValueObjectManager &manager,
                                      llvm::StringRef name,
                                      const Address &address,
                                      const CompilerType &ast_type)
-    : ValueObject(exe_scope), m_address(address), m_type_sp(),
+    : ValueObject(exe_scope, manager), m_address(address), m_type_sp(),
       m_compiler_type(ast_type) {
   // Do not attempt to construct one of these objects with no variable!
   assert(m_compiler_type.GetTypeSystem());

diff  --git a/lldb/source/Core/ValueObjectRegister.cpp b/lldb/source/Core/ValueObjectRegister.cpp
index 2523417f073f..bd1e2359afae 100644
--- a/lldb/source/Core/ValueObjectRegister.cpp
+++ b/lldb/source/Core/ValueObjectRegister.cpp
@@ -41,14 +41,18 @@ ValueObjectSP
 ValueObjectRegisterSet::Create(ExecutionContextScope *exe_scope,
                                lldb::RegisterContextSP &reg_ctx_sp,
                                uint32_t set_idx) {
-  return (new ValueObjectRegisterSet(exe_scope, reg_ctx_sp, set_idx))->GetSP();
+  auto manager_sp = ValueObjectManager::Create();
+  return (new ValueObjectRegisterSet(exe_scope, *manager_sp, reg_ctx_sp,
+                                     set_idx))
+      ->GetSP();
 }
 
 ValueObjectRegisterSet::ValueObjectRegisterSet(ExecutionContextScope *exe_scope,
+                                               ValueObjectManager &manager,
                                                lldb::RegisterContextSP &reg_ctx,
                                                uint32_t reg_set_idx)
-    : ValueObject(exe_scope), m_reg_ctx_sp(reg_ctx), m_reg_set(nullptr),
-      m_reg_set_idx(reg_set_idx) {
+    : ValueObject(exe_scope, manager), m_reg_ctx_sp(reg_ctx),
+      m_reg_set(nullptr), m_reg_set_idx(reg_set_idx) {
   assert(reg_ctx);
   m_reg_set = reg_ctx->GetRegisterSet(m_reg_set_idx);
   if (m_reg_set) {
@@ -174,13 +178,16 @@ ValueObjectRegister::ValueObjectRegister(ValueObject &parent,
 ValueObjectSP ValueObjectRegister::Create(ExecutionContextScope *exe_scope,
                                           lldb::RegisterContextSP &reg_ctx_sp,
                                           uint32_t reg_num) {
-  return (new ValueObjectRegister(exe_scope, reg_ctx_sp, reg_num))->GetSP();
+  auto manager_sp = ValueObjectManager::Create();
+  return (new ValueObjectRegister(exe_scope, *manager_sp, reg_ctx_sp, reg_num))
+      ->GetSP();
 }
 
 ValueObjectRegister::ValueObjectRegister(ExecutionContextScope *exe_scope,
+                                         ValueObjectManager &manager,
                                          lldb::RegisterContextSP &reg_ctx,
                                          uint32_t reg_num)
-    : ValueObject(exe_scope), m_reg_ctx_sp(reg_ctx), m_reg_info(),
+    : ValueObject(exe_scope, manager), m_reg_ctx_sp(reg_ctx), m_reg_info(),
       m_reg_value(), m_type_name(), m_compiler_type() {
   assert(reg_ctx);
   ConstructObject(reg_num);

diff  --git a/lldb/source/Core/ValueObjectSyntheticFilter.cpp b/lldb/source/Core/ValueObjectSyntheticFilter.cpp
index db7a695448d0..9ca9513aa583 100644
--- a/lldb/source/Core/ValueObjectSyntheticFilter.cpp
+++ b/lldb/source/Core/ValueObjectSyntheticFilter.cpp
@@ -14,7 +14,6 @@
 #include "lldb/Target/ExecutionContext.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/Logging.h"
-#include "lldb/Utility/SharingPtr.h"
 #include "lldb/Utility/Status.h"
 
 #include "llvm/ADT/STLExtras.h"

diff  --git a/lldb/source/Core/ValueObjectVariable.cpp b/lldb/source/Core/ValueObjectVariable.cpp
index d0664276dc17..8199c6101395 100644
--- a/lldb/source/Core/ValueObjectVariable.cpp
+++ b/lldb/source/Core/ValueObjectVariable.cpp
@@ -50,12 +50,14 @@ using namespace lldb_private;
 lldb::ValueObjectSP
 ValueObjectVariable::Create(ExecutionContextScope *exe_scope,
                             const lldb::VariableSP &var_sp) {
-  return (new ValueObjectVariable(exe_scope, var_sp))->GetSP();
+  auto manager_sp = ValueObjectManager::Create();
+  return (new ValueObjectVariable(exe_scope, *manager_sp, var_sp))->GetSP();
 }
 
 ValueObjectVariable::ValueObjectVariable(ExecutionContextScope *exe_scope,
+                                         ValueObjectManager &manager,
                                          const lldb::VariableSP &var_sp)
-    : ValueObject(exe_scope), m_variable_sp(var_sp) {
+    : ValueObject(exe_scope, manager), m_variable_sp(var_sp) {
   // Do not attempt to construct one of these objects with no variable!
   assert(m_variable_sp.get() != nullptr);
   m_name = var_sp->GetName();

diff  --git a/lldb/source/Expression/IRInterpreter.cpp b/lldb/source/Expression/IRInterpreter.cpp
index d734ce1655b0..3ae843f69d70 100644
--- a/lldb/source/Expression/IRInterpreter.cpp
+++ b/lldb/source/Expression/IRInterpreter.cpp
@@ -1510,7 +1510,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
         lldb_private::ValueObject *vobj = retVal.get();
 
         // Check if the return value is valid
-        if (vobj == nullptr || retVal.empty()) {
+        if (vobj == nullptr || !retVal) {
           error.SetErrorToGenericError();
           error.SetErrorStringWithFormat("unable to get the return value");
           return false;

diff  --git a/lldb/source/Utility/CMakeLists.txt b/lldb/source/Utility/CMakeLists.txt
index df486e2c0a4c..1bbacc384475 100644
--- a/lldb/source/Utility/CMakeLists.txt
+++ b/lldb/source/Utility/CMakeLists.txt
@@ -39,7 +39,6 @@ add_lldb_library(lldbUtility
   ReproducerInstrumentation.cpp
   Scalar.cpp
   SelectHelper.cpp
-  SharingPtr.cpp
   State.cpp
   Status.cpp
   Stream.cpp

diff  --git a/lldb/source/Utility/SharingPtr.cpp b/lldb/source/Utility/SharingPtr.cpp
deleted file mode 100644
index 22f3d40a6d56..000000000000
--- a/lldb/source/Utility/SharingPtr.cpp
+++ /dev/null
@@ -1,134 +0,0 @@
-//===-- SharingPtr.cpp ----------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "lldb/Utility/SharingPtr.h"
-
-#if defined(ENABLE_SP_LOGGING)
-
-// If ENABLE_SP_LOGGING is defined, then log all shared pointer assignments and
-// allow them to be queried using a pointer by a call to:
-#include <assert.h>
-#include <execinfo.h>
-
-#include "llvm/ADT/STLExtras.h"
-
-#include <map>
-#include <mutex>
-#include <vector>
-
-class Backtrace {
-public:
-  Backtrace();
-
-  ~Backtrace();
-
-  void GetFrames();
-
-  void Dump() const;
-
-private:
-  void *m_sp_this;
-  std::vector<void *> m_frames;
-};
-
-Backtrace::Backtrace() : m_frames() {}
-
-Backtrace::~Backtrace() {}
-
-void Backtrace::GetFrames() {
-  void *frames[1024];
-  const int count = ::backtrace(frames, llvm::array_lengthof(frames));
-  if (count > 2)
-    m_frames.assign(frames + 2, frames + (count - 2));
-}
-
-void Backtrace::Dump() const {
-  if (!m_frames.empty())
-    ::backtrace_symbols_fd(m_frames.data(), m_frames.size(), STDOUT_FILENO);
-  write(STDOUT_FILENO, "\n\n", 2);
-}
-
-extern "C" void track_sp(void *sp_this, void *ptr, long use_count) {
-  typedef std::pair<void *, Backtrace> PtrBacktracePair;
-  typedef std::map<void *, PtrBacktracePair> PtrToBacktraceMap;
-  static std::mutex g_mutex;
-  std::lock_guard<std::mutex> guard(g_mutex);
-  static PtrToBacktraceMap g_map;
-
-  if (sp_this) {
-    printf("sp(%p) -> %p %lu\n", sp_this, ptr, use_count);
-
-    if (ptr) {
-      Backtrace bt;
-      bt.GetFrames();
-      g_map[sp_this] = std::make_pair(ptr, bt);
-    } else {
-      g_map.erase(sp_this);
-    }
-  } else {
-    if (ptr)
-      printf("Searching for shared pointers that are tracking %p: ", ptr);
-    else
-      printf("Dump all live shared pointres: ");
-
-    uint32_t matches = 0;
-    PtrToBacktraceMap::iterator pos, end = g_map.end();
-    for (pos = g_map.begin(); pos != end; ++pos) {
-      if (ptr == NULL || pos->second.first == ptr) {
-        ++matches;
-        printf("\nsp(%p): %p\n", pos->first, pos->second.first);
-        pos->second.second.Dump();
-      }
-    }
-    if (matches == 0) {
-      printf("none.\n");
-    }
-  }
-}
-// Put dump_sp_refs in the lldb namespace to it gets through our exports lists
-// filter in the LLDB.framework or lldb.so
-namespace lldb {
-
-void dump_sp_refs(void *ptr) {
-  // Use a specially crafted call to "track_sp" which will dump info on all
-  // live shared pointers that reference "ptr"
-  track_sp(NULL, ptr, 0);
-}
-}
-
-#endif
-
-namespace lldb_private {
-
-namespace imp {
-
-shared_count::~shared_count() {}
-
-void shared_count::add_shared() {
-#ifdef _MSC_VER
-  _InterlockedIncrement(&shared_owners_);
-#else
-  ++shared_owners_;
-#endif
-}
-
-void shared_count::release_shared() {
-#ifdef _MSC_VER
-  if (_InterlockedDecrement(&shared_owners_) == -1)
-#else
-  if (--shared_owners_ == -1)
-#endif
-  {
-    on_zero_shared();
-    delete this;
-  }
-}
-
-} // imp
-
-} // namespace lldb

diff  --git a/lldb/unittests/Utility/SharedClusterTest.cpp b/lldb/unittests/Utility/SharedClusterTest.cpp
index a41b12aa18d8..56dd4da2ed91 100644
--- a/lldb/unittests/Utility/SharedClusterTest.cpp
+++ b/lldb/unittests/Utility/SharedClusterTest.cpp
@@ -25,30 +25,33 @@ class DestructNotifier {
 
 TEST(SharedCluster, ClusterManager) {
   std::vector<int> Queue;
-  auto *CM = new ClusterManager<DestructNotifier>();
-  auto *One = new DestructNotifier(Queue, 1);
-  auto *Two = new DestructNotifier(Queue, 2);
-  CM->ManageObject(One);
-  CM->ManageObject(Two);
-
-  ASSERT_THAT(Queue, testing::IsEmpty());
   {
-    SharingPtr<DestructNotifier> OnePtr = CM->GetSharedPointer(One);
-    ASSERT_EQ(OnePtr->Key, 1);
-    ASSERT_THAT(Queue, testing::IsEmpty());
+    auto CM = ClusterManager<DestructNotifier>::Create();
+    auto *One = new DestructNotifier(Queue, 1);
+    auto *Two = new DestructNotifier(Queue, 2);
+    CM->ManageObject(One);
+    CM->ManageObject(Two);
 
+    ASSERT_THAT(Queue, testing::IsEmpty());
     {
-      SharingPtr<DestructNotifier> OnePtrCopy = OnePtr;
-      ASSERT_EQ(OnePtrCopy->Key, 1);
+      std::shared_ptr<DestructNotifier> OnePtr = CM->GetSharedPointer(One);
+      ASSERT_EQ(OnePtr->Key, 1);
       ASSERT_THAT(Queue, testing::IsEmpty());
-    }
 
-    {
-      SharingPtr<DestructNotifier> TwoPtr = CM->GetSharedPointer(Two);
-      ASSERT_EQ(TwoPtr->Key, 2);
+      {
+        std::shared_ptr<DestructNotifier> OnePtrCopy = OnePtr;
+        ASSERT_EQ(OnePtrCopy->Key, 1);
+        ASSERT_THAT(Queue, testing::IsEmpty());
+      }
+
+      {
+        std::shared_ptr<DestructNotifier> TwoPtr = CM->GetSharedPointer(Two);
+        ASSERT_EQ(TwoPtr->Key, 2);
+        ASSERT_THAT(Queue, testing::IsEmpty());
+      }
+
       ASSERT_THAT(Queue, testing::IsEmpty());
     }
-
     ASSERT_THAT(Queue, testing::IsEmpty());
   }
   ASSERT_THAT(Queue, testing::ElementsAre(1, 2));


        


More information about the lldb-commits mailing list