Convert lldb::ModuleSP to use an instrusive ref counted pointer.
We had some cases where getting the shared pointer for a module from
the global module list was causing a performance issue when debugging
with DWARF in .o files. Now that the module uses intrusive ref counts,
we can easily convert any pointer to a shared pointer.



git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@139983 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Commands/CommandCompletions.cpp b/source/Commands/CommandCompletions.cpp
index ff3c0c4..3ea62aa 100644
--- a/source/Commands/CommandCompletions.cpp
+++ b/source/Commands/CommandCompletions.cpp
@@ -684,7 +684,7 @@
     bool complete
 )
 {
-    if (context.module_sp != NULL)
+    if (context.module_sp)
     {
         const char *cur_file_name = context.module_sp->GetFileSpec().GetFilename().GetCString();
         const char *cur_dir_name = context.module_sp->GetFileSpec().GetDirectory().GetCString();
diff --git a/source/Core/Module.cpp b/source/Core/Module.cpp
index 4c99796..2786600 100644
--- a/source/Core/Module.cpp
+++ b/source/Core/Module.cpp
@@ -131,7 +131,8 @@
 ModuleSP
 Module::GetSP () const
 {
-    return ModuleList::GetModuleSP (this);
+    ModuleSP module_sp(const_cast<Module*>(this));
+    return module_sp;
 }
 
 const lldb_private::UUID&
diff --git a/source/Expression/ClangASTSource.cpp b/source/Expression/ClangASTSource.cpp
index a5ac2c3..26bf0b9 100644
--- a/source/Expression/ClangASTSource.cpp
+++ b/source/Expression/ClangASTSource.cpp
@@ -10,6 +10,7 @@
 
 #include "clang/AST/ASTContext.h"
 #include "lldb/Core/Log.h"
+#include "lldb/Core/Module.h"
 #include "lldb/Expression/ClangASTSource.h"
 #include "lldb/Expression/ClangExpression.h"
 #include "lldb/Expression/ClangExpressionDeclMap.h"
diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h
index 4317877..4f2b70e 100644
--- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h
+++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h
@@ -98,7 +98,7 @@
     AppleIsModuleObjCLibrary (const lldb::ModuleSP &module_sp);
 
     static enum ObjCRuntimeVersions
-    GetObjCVersion (Process *process, ModuleSP &objc_module_sp);
+    GetObjCVersion (Process *process, lldb::ModuleSP &objc_module_sp);
 
     //------------------------------------------------------------------
     // PluginInterface protocol
diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h
index 0e7d87c..1f2ace4 100644
--- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h
+++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h
@@ -15,12 +15,8 @@
 // Other libraries and framework includes
 // Project includes
 #include "lldb/lldb-private.h"
-#include "lldb/Target/LanguageRuntime.h"
 #include "lldb/Target/ObjCLanguageRuntime.h"
-#include "lldb/Core/ValueObject.h"
 #include "AppleObjCRuntime.h"
-#include "AppleObjCTrampolineHandler.h"
-#include "AppleThreadPlanStepThroughObjCTrampoline.h"
 
 namespace lldb_private {
     
diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
index 4d4d4fb..ef62462 100644
--- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -91,8 +91,9 @@
 const char *AppleObjCRuntimeV2::g_objc_class_symbol_prefix = "OBJC_CLASS_$_";
 const char *AppleObjCRuntimeV2::g_objc_class_data_section_name = "__objc_data";
 
-AppleObjCRuntimeV2::AppleObjCRuntimeV2 (Process *process, ModuleSP &objc_module_sp) : 
-    lldb_private::AppleObjCRuntime (process),
+AppleObjCRuntimeV2::AppleObjCRuntimeV2 (Process *process, 
+                                        const ModuleSP &objc_module_sp) : 
+    AppleObjCRuntime (process),
     m_get_class_name_args(LLDB_INVALID_ADDRESS),
     m_get_class_name_args_mutex(Mutex::eMutexTypeNormal),
     m_isa_to_name_cache(),
@@ -109,7 +110,7 @@
     
     StreamString errors;
     
-    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));  // FIXME - a more appropriate log channel?
+    LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));  // FIXME - a more appropriate log channel?
     
     int32_t debug;
     if (log)
@@ -417,7 +418,7 @@
 //------------------------------------------------------------------
 // Static Functions
 //------------------------------------------------------------------
-lldb_private::LanguageRuntime *
+LanguageRuntime *
 AppleObjCRuntimeV2::CreateInstance (Process *process, lldb::LanguageType language)
 {
     // FIXME: This should be a MacOS or iOS process, and we need to look for the OBJC section to make
@@ -581,7 +582,7 @@
 // this code relies on the assumption that an Objective-C object always starts
 // with an ISA at offset 0. an ISA is effectively a pointer to an instance of
 // struct class_t in the ObjCv2 runtime
-lldb_private::ObjCLanguageRuntime::ObjCISA
+ObjCLanguageRuntime::ObjCISA
 AppleObjCRuntimeV2::GetISA(ValueObject& valobj)
 {
     if (ClangASTType::GetMinimumLanguage(valobj.GetClangAST(),valobj.GetClangType()) != lldb::eLanguageTypeObjC)
@@ -602,7 +603,7 @@
     uint8_t pointer_size = valobj.GetUpdatePoint().GetProcessSP()->GetAddressByteSize();
     
     Error error;
-    lldb_private::ObjCLanguageRuntime::ObjCISA isa = 
+    ObjCLanguageRuntime::ObjCISA isa = 
     valobj.GetUpdatePoint().GetProcessSP()->ReadUnsignedIntegerFromMemory(isa_pointer,
                                                                           pointer_size,
                                                                           0,
@@ -613,7 +614,7 @@
 // TODO: should we have a transparent_kvo parameter here to say if we 
 // want to replace the KVO swizzled class with the actual user-level type?
 ConstString
-AppleObjCRuntimeV2::GetActualTypeName(lldb_private::ObjCLanguageRuntime::ObjCISA isa)
+AppleObjCRuntimeV2::GetActualTypeName(ObjCLanguageRuntime::ObjCISA isa)
 {
     if (!IsValidISA(isa))
         return ConstString(NULL);
@@ -713,8 +714,8 @@
         return ConstString("unknown");
 }
 
-lldb_private::ObjCLanguageRuntime::ObjCISA
-AppleObjCRuntimeV2::GetParentClass(lldb_private::ObjCLanguageRuntime::ObjCISA isa)
+ObjCLanguageRuntime::ObjCISA
+AppleObjCRuntimeV2::GetParentClass(ObjCLanguageRuntime::ObjCISA isa)
 {
     if (!IsValidISA(isa))
         return 0;
diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
index 229a1b3..64ef444 100644
--- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
+++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
@@ -18,12 +18,8 @@
 // Other libraries and framework includes
 // Project includes
 #include "lldb/lldb-private.h"
-#include "lldb/Target/LanguageRuntime.h"
 #include "lldb/Target/ObjCLanguageRuntime.h"
-#include "lldb/Core/ValueObject.h"
 #include "AppleObjCRuntime.h"
-#include "AppleObjCTrampolineHandler.h"
-#include "AppleThreadPlanStepThroughObjCTrampoline.h"
 
 namespace lldb_private {
 
@@ -81,7 +77,7 @@
     GetByteOffsetForIvar (ClangASTType &parent_qual_type, const char *ivar_name);
     
     virtual bool
-    IsValidISA(ObjCISA isa)
+    IsValidISA (ObjCLanguageRuntime::ObjCISA isa)
     {
         return (isa != 0);
     }
@@ -89,28 +85,29 @@
     // this is not a valid ISA in the sense that no valid
     // class pointer can live at address 1. we use it to refer to
     // tagged types, where the ISA must be dynamically determined
-    static const ObjCISA g_objc_Tagged_ISA = 1;
+    static const ObjCLanguageRuntime::ObjCISA g_objc_Tagged_ISA = 1;
     
-    virtual ObjCISA
+    virtual ObjCLanguageRuntime::ObjCISA
     GetISA(ValueObject& valobj);   
     
     virtual ConstString
-    GetActualTypeName(ObjCISA isa);
+    GetActualTypeName(ObjCLanguageRuntime::ObjCISA isa);
     
-    virtual ObjCISA
-    GetParentClass(ObjCISA isa);
+    virtual ObjCLanguageRuntime::ObjCISA
+    GetParentClass(ObjCLanguageRuntime::ObjCISA isa);
     
 protected:
     
 private:
     
-    typedef std::map<ObjCISA,ConstString> ISAToNameCache;
-    typedef std::map<ObjCISA,ObjCISA> ISAToParentCache;
+    typedef std::map<ObjCLanguageRuntime::ObjCISA, ConstString> ISAToNameCache;
+    typedef std::map<ObjCLanguageRuntime::ObjCISA, ObjCLanguageRuntime::ObjCISA> ISAToParentCache;
     
     typedef ISAToNameCache::iterator ISAToNameIterator;
     typedef ISAToParentCache::iterator ISAToParentIterator;
     
-    AppleObjCRuntimeV2(Process *process, ModuleSP &objc_module_sp);
+    AppleObjCRuntimeV2 (Process *process, 
+                        const lldb::ModuleSP &objc_module_sp);
     
     bool
     IsTaggedPointer(lldb::addr_t ptr);
diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
index 8bee154..9a5dbc2 100644
--- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
+++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
@@ -22,6 +22,10 @@
 #include "lldb/Core/Log.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/Value.h"
+#include "lldb/Expression/ClangExpression.h"
+#include "lldb/Expression/ClangFunction.h"
+#include "lldb/Expression/ClangUtilityFunction.h"
+
 #include "lldb/Symbol/ClangASTContext.h"
 #include "lldb/Target/ObjCLanguageRuntime.h"
 #include "lldb/Target/Process.h"
@@ -156,6 +160,10 @@
     SetUpRegion ();
 }
 
+AppleObjCTrampolineHandler::~AppleObjCTrampolineHandler()
+{
+}
+
 void
 AppleObjCTrampolineHandler::AppleObjCVTables::VTableRegion::SetUpRegion()
 {
@@ -301,11 +309,12 @@
     }
 }
         
-AppleObjCTrampolineHandler::AppleObjCVTables::AppleObjCVTables (ProcessSP &process_sp, ModuleSP &objc_module_sp) :
-        m_process_sp(process_sp),
-        m_trampoline_header(LLDB_INVALID_ADDRESS),
-        m_trampolines_changed_bp_id(LLDB_INVALID_BREAK_ID),
-        m_objc_module_sp(objc_module_sp)
+AppleObjCTrampolineHandler::AppleObjCVTables::AppleObjCVTables (const ProcessSP &process_sp, 
+                                                                const ModuleSP &objc_module_sp) :
+    m_process_sp (process_sp),
+    m_trampoline_header (LLDB_INVALID_ADDRESS),
+    m_trampolines_changed_bp_id (LLDB_INVALID_BREAK_ID),
+    m_objc_module_sp (objc_module_sp)
 {
     
 }
@@ -510,7 +519,8 @@
     {NULL}
 };
 
-AppleObjCTrampolineHandler::AppleObjCTrampolineHandler (ProcessSP process_sp, ModuleSP objc_module_sp) :
+AppleObjCTrampolineHandler::AppleObjCTrampolineHandler (const ProcessSP &process_sp, 
+                                                        const ModuleSP &objc_module_sp) :
     m_process_sp (process_sp),
     m_objc_module_sp (objc_module_sp),
     m_impl_fn_addr (LLDB_INVALID_ADDRESS),
diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.h b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.h
index 742685f..96094c1 100644
--- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.h
+++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.h
@@ -13,28 +13,27 @@
 // C Includes
 // C++ Includes
 #include <map>
-#include <string>
+#include <vector>
 // Other libraries and framework includes
 // Project includes
-#include "lldb/Expression/ClangExpression.h"
-#include "lldb/Expression/ClangFunction.h"
-#include "lldb/Expression/ClangUtilityFunction.h"
+#include "lldb/lldb-public.h"
 #include "lldb/Host/Mutex.h"
 
 
 namespace lldb_private
 {
-using namespace lldb;
   
 class AppleObjCTrampolineHandler {
 public:
     
-    AppleObjCTrampolineHandler (ProcessSP process_sp, ModuleSP objc_module_sp);
+    AppleObjCTrampolineHandler (const lldb::ProcessSP &process_sp, 
+                                const lldb::ModuleSP &objc_module_sp);
     
-    ~AppleObjCTrampolineHandler() {}
+    ~AppleObjCTrampolineHandler();
             
-    ThreadPlanSP
-    GetStepThroughDispatchPlan (Thread &thread, bool stop_others);
+    lldb::ThreadPlanSP
+    GetStepThroughDispatchPlan (Thread &thread, 
+                                bool stop_others);
     
     ClangFunction *
     GetLookupImplementationWrapperFunction ();
@@ -80,7 +79,7 @@
     private:
         struct VTableDescriptor 
         {
-            VTableDescriptor(uint32_t in_flags, addr_t in_code_start) :
+            VTableDescriptor(uint32_t in_flags, lldb::addr_t in_code_start) :
                 flags(in_flags),
                 code_start(in_code_start) {}
             
@@ -151,7 +150,8 @@
         };
         
     public:
-        AppleObjCVTables(ProcessSP &process_sp, ModuleSP &objc_module_sp);
+        AppleObjCVTables(const lldb::ProcessSP &process_sp, 
+                         const lldb::ModuleSP &objc_module_sp);
         
         ~AppleObjCVTables();
                 
@@ -177,7 +177,7 @@
         }
         
     private:
-        ProcessSP m_process_sp;
+        lldb::ProcessSP m_process_sp;
         typedef std::vector<VTableRegion> region_collection;
         lldb::addr_t m_trampoline_header;
         lldb::break_id_t m_trampolines_changed_bp_id;
@@ -190,8 +190,8 @@
     
     typedef std::map<lldb::addr_t, int> MsgsendMap; // This table maps an dispatch fn address to the index in g_dispatch_functions
     MsgsendMap m_msgSend_map;
-    ProcessSP m_process_sp;
-    ModuleSP m_objc_module_sp;
+    lldb::ProcessSP m_process_sp;
+    lldb::ModuleSP m_objc_module_sp;
     std::auto_ptr<ClangFunction> m_impl_function;
     std::auto_ptr<ClangUtilityFunction> m_impl_code;
     Mutex m_impl_function_mutex;
diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp
index f235fd5..62941bf 100644
--- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp
+++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp
@@ -23,6 +23,8 @@
 #include "lldb/Target/ThreadPlanStepOut.h"
 #include "lldb/Core/Log.h"
 
+
+using namespace lldb;
 using namespace lldb_private;
 
 //----------------------------------------------------------------------
diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h
index e2d2ebc..e66ffad 100644
--- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h
+++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h
@@ -82,9 +82,9 @@
     lldb::addr_t m_object_addr;  // This is only for Description.
     lldb::addr_t m_isa_addr;     // isa_addr and sel_addr are the keys we will use to cache the implementation.
     lldb::addr_t m_sel_addr;
-    ThreadPlanSP m_func_sp;       // This is the function call plan.  We fill it at start, then set it
-                                  // to NULL when this plan is done.  That way we know to go to:
-    ThreadPlanSP m_run_to_sp;     // The plan that runs to the target.
+    lldb::ThreadPlanSP m_func_sp;       // This is the function call plan.  We fill it at start, then set it
+                                        // to NULL when this plan is done.  That way we know to go to:
+    lldb::ThreadPlanSP m_run_to_sp;     // The plan that runs to the target.
     ClangFunction *m_impl_function;  // This is a pointer to a impl function that 
                                      // is owned by the client that pushes this plan.
     bool m_stop_others;
diff --git a/source/Symbol/SymbolContext.cpp b/source/Symbol/SymbolContext.cpp
index 6d570d7..23722f6 100644
--- a/source/Symbol/SymbolContext.cpp
+++ b/source/Symbol/SymbolContext.cpp
@@ -82,6 +82,10 @@
     sc_scope->CalculateSymbolContext (this);
 }
 
+SymbolContext::~SymbolContext ()
+{
+}
+
 const SymbolContext&
 SymbolContext::operator= (const SymbolContext& rhs)
 {
@@ -447,7 +451,7 @@
         // for methods matching name.
     }
 
-    if (module_sp != NULL)
+    if (module_sp)
         module_sp->FindFunctions (name, eFunctionNameTypeBase | eFunctionNameTypeFull, include_symbols, true, sc_list);
 
     if (target_sp)
@@ -489,6 +493,24 @@
 //
 //----------------------------------------------------------------------
 
+SymbolContextSpecifier::SymbolContextSpecifier (const TargetSP &target_sp) :
+    m_target_sp (target_sp),
+    m_module_spec (),
+    m_module_sp (),
+    m_file_spec_ap (),
+    m_start_line (0),
+    m_end_line (0),
+    m_function_spec (),
+    m_class_name (),
+    m_address_range_ap (),
+    m_type (eNothingSpecified)
+{
+}   
+
+SymbolContextSpecifier::~SymbolContextSpecifier()
+{
+}
+
 bool
 SymbolContextSpecifier::AddLineSpecification (uint32_t line_no, SpecificationType type)
 {
diff --git a/source/Utility/SharingPtr.cpp b/source/Utility/SharingPtr.cpp
index 88c103a..3ee0128 100644
--- a/source/Utility/SharingPtr.cpp
+++ b/source/Utility/SharingPtr.cpp
@@ -14,40 +14,42 @@
 namespace imp
 {
 
-template <class T>
-inline T
-increment(T& t)
-{
-    return __sync_add_and_fetch(&t, 1);
-}
-
-template <class T>
-inline T
-decrement(T& t)
-{
-    return __sync_add_and_fetch(&t, -1);
-}
-
-shared_count::~shared_count()
-{
-}
-
-void
-shared_count::add_shared()
-{
-    increment(shared_owners_);
-}
-
-void
-shared_count::release_shared()
-{
-    if (decrement(shared_owners_) == -1)
+    template <class T>
+    inline T
+    increment(T& t)
     {
-        on_zero_shared();
-        delete this;
+        return __sync_add_and_fetch(&t, 1);
     }
-}
+
+    template <class T>
+    inline T
+    decrement(T& t)
+    {
+        return __sync_add_and_fetch(&t, -1);
+    }
+
+    shared_count::~shared_count()
+    {
+    }
+
+    void
+    shared_count::add_shared()
+    {
+        increment(shared_owners_);
+    }
+
+    void
+    shared_count::release_shared()
+    {
+        if (decrement(shared_owners_) == -1)
+        {
+            on_zero_shared();
+            delete this;
+        }
+    }
 
 } // imp
 
+
 } // namespace lldb
+