Added the ability to remove orphaned module shared pointers from a ModuleList.
This is helping us track down some extra references to ModuleSP objects that
are causing things to get kept around for too long. 

Added a module pointer accessor to target and change a lot of code to use 
it where it would be more efficient.

"taret delete" can now specify "--clean=1" which will cleanup the global module
list for any orphaned module in the shared module cache which can save memory
and also help track down module reference leaks like we have now.



git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@137294 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/lldb/Core/ModuleList.h b/include/lldb/Core/ModuleList.h
index 6573252..020d13f 100644
--- a/include/lldb/Core/ModuleList.h
+++ b/include/lldb/Core/ModuleList.h
@@ -363,6 +363,9 @@
     size_t
     Remove (ModuleList &module_list);
     
+    size_t
+    RemoveOrphans ();
+
     bool
     ResolveFileAddress (lldb::addr_t vm_addr,
                         Address& so_addr);
@@ -428,6 +431,9 @@
                        const ConstString *object_name_ptr,
                        ModuleList &matching_module_list);
 
+    static uint32_t
+    RemoveOrphanSharedModules ();
+
 protected:
     //------------------------------------------------------------------
     // Class typedefs.
diff --git a/include/lldb/Target/Target.h b/include/lldb/Target/Target.h
index 82355d7..a5abf53 100644
--- a/include/lldb/Target/Target.h
+++ b/include/lldb/Target/Target.h
@@ -347,6 +347,9 @@
     lldb::ModuleSP
     GetExecutableModule ();
 
+    Module*
+    GetExecutableModulePointer ();
+
     //------------------------------------------------------------------
     /// Set the main executable module.
     ///
diff --git a/source/API/SBProcess.cpp b/source/API/SBProcess.cpp
index 521c1a6..180a5af 100644
--- a/source/API/SBProcess.cpp
+++ b/source/API/SBProcess.cpp
@@ -804,7 +804,7 @@
     {
         char path[PATH_MAX];
         GetTarget().GetExecutable().GetPath (path, sizeof(path));
-        Module *exe_module = m_opaque_sp->GetTarget().GetExecutableModule ().get();
+        Module *exe_module = m_opaque_sp->GetTarget().GetExecutableModulePointer();
         const char *exe_name = NULL;
         if (exe_module)
             exe_name = exe_module->GetFileSpec().GetFilename().AsCString();
diff --git a/source/API/SBTarget.cpp b/source/API/SBTarget.cpp
index 0367d65..93d3cf1 100644
--- a/source/API/SBTarget.cpp
+++ b/source/API/SBTarget.cpp
@@ -459,9 +459,9 @@
     SBFileSpec exe_file_spec;
     if (m_opaque_sp)
     {
-        ModuleSP exe_module_sp (m_opaque_sp->GetExecutableModule ());
-        if (exe_module_sp)
-            exe_file_spec.SetFileSpec (exe_module_sp->GetFileSpec());
+        Module *exe_module = m_opaque_sp->GetExecutableModulePointer();
+        if (exe_module)
+            exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
     }
 
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
diff --git a/source/Commands/CommandObjectBreakpoint.cpp b/source/Commands/CommandObjectBreakpoint.cpp
index de83d9f..2e894ed 100644
--- a/source/Commands/CommandObjectBreakpoint.cpp
+++ b/source/Commands/CommandObjectBreakpoint.cpp
@@ -306,7 +306,6 @@
     else if  (!m_options.m_func_regexp.empty())
         break_type = eSetTypeFunctionRegexp;
 
-    ModuleSP module_sp = target->GetExecutableModule();
     Breakpoint *bp = NULL;
     FileSpec module_spec;
     bool use_module = false;
diff --git a/source/Commands/CommandObjectPlatform.cpp b/source/Commands/CommandObjectPlatform.cpp
index ecc24a6..ed6c7f9 100644
--- a/source/Commands/CommandObjectPlatform.cpp
+++ b/source/Commands/CommandObjectPlatform.cpp
@@ -374,17 +374,16 @@
             Error error;
             const uint32_t argc = args.GetArgumentCount();
             Target *target = m_interpreter.GetExecutionContext().target;
-            ModuleSP exe_module_sp;
             if (target)
             {
-                exe_module_sp = target->GetExecutableModule();
-                if (exe_module_sp)
+                Module *exe_module = target->GetExecutableModulePointer();
+                if (exe_module)
                 {
-                    m_options.launch_info.GetExecutableFile () = exe_module_sp->GetFileSpec();
+                    m_options.launch_info.GetExecutableFile () = exe_module->GetFileSpec();
                     char exe_path[PATH_MAX];
                     if (m_options.launch_info.GetExecutableFile ().GetPath (exe_path, sizeof(exe_path)))
                         m_options.launch_info.GetArguments().AppendArgument (exe_path);
-                    m_options.launch_info.GetArchitecture() = exe_module_sp->GetArchitecture();
+                    m_options.launch_info.GetArchitecture() = exe_module->GetArchitecture();
                 }
             }
 
diff --git a/source/Commands/CommandObjectProcess.cpp b/source/Commands/CommandObjectProcess.cpp
index 8ccdebb..2c22880 100644
--- a/source/Commands/CommandObjectProcess.cpp
+++ b/source/Commands/CommandObjectProcess.cpp
@@ -162,7 +162,7 @@
 
         // If our listener is NULL, users aren't allows to launch
         char filename[PATH_MAX];
-        const Module *exe_module = target->GetExecutableModule().get();
+        const Module *exe_module = target->GetExecutableModulePointer();
 
         if (exe_module == NULL)
         {
@@ -762,22 +762,22 @@
         {
             // Okay, we're done.  Last step is to warn if the executable module has changed:
             char new_path[PATH_MAX];
+            ModuleSP new_exec_module_sp (target->GetExecutableModule());
             if (!old_exec_module_sp)
             {
                 // We might not have a module if we attached to a raw pid...
-                ModuleSP new_module_sp (target->GetExecutableModule());
-                if (new_module_sp)
+                if (new_exec_module_sp)
                 {
-                    new_module_sp->GetFileSpec().GetPath(new_path, PATH_MAX);
+                    new_exec_module_sp->GetFileSpec().GetPath(new_path, PATH_MAX);
                     result.AppendMessageWithFormat("Executable module set to \"%s\".\n", new_path);
                 }
             }
-            else if (old_exec_module_sp->GetFileSpec() != target->GetExecutableModule()->GetFileSpec())
+            else if (old_exec_module_sp->GetFileSpec() != new_exec_module_sp->GetFileSpec())
             {
                 char old_path[PATH_MAX];
                 
-                old_exec_module_sp->GetFileSpec().GetPath(old_path, PATH_MAX);
-                target->GetExecutableModule()->GetFileSpec().GetPath (new_path, PATH_MAX);
+                old_exec_module_sp->GetFileSpec().GetPath (old_path, PATH_MAX);
+                new_exec_module_sp->GetFileSpec().GetPath (new_path, PATH_MAX);
                 
                 result.AppendWarningWithFormat("Executable module changed from \"%s\" to \"%s\".\n",
                                                     old_path, new_path);
diff --git a/source/Commands/CommandObjectTarget.cpp b/source/Commands/CommandObjectTarget.cpp
index e0b9169..a17cfc8 100644
--- a/source/Commands/CommandObjectTarget.cpp
+++ b/source/Commands/CommandObjectTarget.cpp
@@ -26,6 +26,7 @@
 #include "lldb/Interpreter/CommandReturnObject.h"
 #include "lldb/Interpreter/Options.h"
 #include "lldb/Interpreter/OptionGroupArchitecture.h"
+#include "lldb/Interpreter/OptionGroupBoolean.h"
 #include "lldb/Interpreter/OptionGroupFile.h"
 #include "lldb/Interpreter/OptionGroupVariable.h"
 #include "lldb/Interpreter/OptionGroupPlatform.h"
@@ -52,11 +53,11 @@
 {
     const ArchSpec &target_arch = target->GetArchitecture();
     
-    ModuleSP exe_module_sp (target->GetExecutableModule ());
+    Module *exe_module = target->GetExecutableModulePointer();
     char exe_path[PATH_MAX];
     bool exe_valid = false;
-    if (exe_module_sp)
-        exe_valid = exe_module_sp->GetFileSpec().GetPath (exe_path, sizeof(exe_path));
+    if (exe_module)
+        exe_valid = exe_module->GetFileSpec().GetPath (exe_path, sizeof(exe_path));
     
     if (!exe_valid)
         ::strcpy (exe_path, "<none>");
@@ -410,12 +411,16 @@
 {
 public:
     CommandObjectTargetDelete (CommandInterpreter &interpreter) :
-    CommandObject (interpreter,
-                   "target delete",
-                   "Delete one or more targets by target index.",
-                   NULL,
-                   0)
+        CommandObject (interpreter,
+                       "target delete",
+                       "Delete one or more targets by target index.",
+                       NULL,
+                       0),
+        m_option_group (interpreter),
+        m_cleanup_option (LLDB_OPT_SET_1, false, "clean", 'c', 0, eArgTypeNone, "Perform extra cleanup to minimize memory consumption after deleting the target.", false)
     {
+        m_option_group.Append (&m_cleanup_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+        m_option_group.Finalize();
     }
     
     virtual
@@ -487,12 +492,28 @@
                 target_list.DeleteTarget(target_sp);
                 target_sp->Destroy();
             }
+            // If "--clean" was specified, prune any orphaned shared modules from
+            // the global shared module list
+            if (m_cleanup_option.GetOptionValue ())
+            {
+                ModuleList::RemoveOrphanSharedModules();
+            }
             result.GetOutputStream().Printf("%u targets deleted.\n", (uint32_t)num_targets_to_delete);
             result.SetStatus(eReturnStatusSuccessFinishResult);
         }
         
         return result.Succeeded();
     }
+    
+    Options *
+    GetOptions ()
+    {
+        return &m_option_group;
+    }
+
+protected:
+    OptionGroupOptions m_option_group;
+    OptionGroupBoolean m_cleanup_option;
 };
 
 
diff --git a/source/Core/Debugger.cpp b/source/Core/Debugger.cpp
index 309afd4..8d13293 100644
--- a/source/Core/Debugger.cpp
+++ b/source/Core/Debugger.cpp
@@ -1256,17 +1256,17 @@
                                              (::strncmp (var_name_begin, "file.basename}", strlen("file.basename}")) == 0) ||
                                              (::strncmp (var_name_begin, "file.fullpath}", strlen("file.fullpath}")) == 0))
                                     {
-                                        ModuleSP exe_module_sp (exe_ctx->process->GetTarget().GetExecutableModule());
-                                        if (exe_module_sp)
+                                        Module *exe_module = exe_ctx->process->GetTarget().GetExecutableModulePointer();
+                                        if (exe_module)
                                         {
                                             if (var_name_begin[0] == 'n' || var_name_begin[5] == 'f')
                                             {
-                                                format_file_spec.GetFilename() = exe_module_sp->GetFileSpec().GetFilename();
+                                                format_file_spec.GetFilename() = exe_module->GetFileSpec().GetFilename();
                                                 var_success = format_file_spec;
                                             }
                                             else
                                             {
-                                                format_file_spec = exe_module_sp->GetFileSpec();
+                                                format_file_spec = exe_module->GetFileSpec();
                                                 var_success = format_file_spec;
                                             }
                                         }
diff --git a/source/Core/ModuleList.cpp b/source/Core/ModuleList.cpp
index 7a47483..cf83d4b 100644
--- a/source/Core/ModuleList.cpp
+++ b/source/Core/ModuleList.cpp
@@ -108,6 +108,28 @@
     return false;
 }
 
+
+size_t
+ModuleList::RemoveOrphans ()
+{
+    Mutex::Locker locker(m_modules_mutex);
+    collection::reverse_iterator pos = m_modules.rbegin();
+    size_t remove_count = 0;
+    while (pos != m_modules.rend())
+    {
+        if (pos->unique())
+        {
+            pos = m_modules.erase (pos);
+            ++remove_count;
+        }
+        else
+        {
+            ++pos;
+        }
+    }
+    return remove_count;
+}
+
 size_t
 ModuleList::Remove (ModuleList &module_list)
 {
@@ -680,6 +702,12 @@
     return shared_module_list.FindModules (&in_file_spec, &arch, uuid_ptr, object_name_ptr, matching_module_list);
 }
 
+uint32_t
+ModuleList::RemoveOrphanSharedModules ()
+{
+    return GetSharedModuleList ().RemoveOrphans();    
+}
+
 Error
 ModuleList::GetSharedModule
 (
diff --git a/source/Core/ValueObjectRegister.cpp b/source/Core/ValueObjectRegister.cpp
index db3d559..beada80 100644
--- a/source/Core/ValueObjectRegister.cpp
+++ b/source/Core/ValueObjectRegister.cpp
@@ -307,7 +307,7 @@
         Process *process = m_reg_ctx_sp->CalculateProcess ();
         if (process)
         {
-            Module *exe_module = process->GetTarget().GetExecutableModule ().get();
+            Module *exe_module = process->GetTarget().GetExecutableModulePointer();
             if (exe_module)
             {
                 m_clang_type = exe_module->GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize (m_reg_info.encoding, 
@@ -338,7 +338,7 @@
     Process *process = m_reg_ctx_sp->CalculateProcess ();
     if (process)
     {
-        Module *exe_module = process->GetTarget().GetExecutableModule ().get();
+        Module *exe_module = process->GetTarget().GetExecutableModulePointer();
         if (exe_module)
             return exe_module->GetClangASTContext().getASTContext();
     }
diff --git a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
index 92f359b..b051cb0 100644
--- a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
+++ b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
@@ -89,7 +89,7 @@
     if (!create)
     {
         create = true;
-        Module* exe_module = process->GetTarget().GetExecutableModule().get();
+        Module* exe_module = process->GetTarget().GetExecutableModulePointer();
         if (exe_module)
         {
             ObjectFile *object_file = exe_module->GetObjectFile();
@@ -225,7 +225,7 @@
     }
 
     // Check some default values
-    Module *executable = m_process->GetTarget().GetExecutableModule().get();
+    Module *executable = m_process->GetTarget().GetExecutableModulePointer();
 
     if (executable)
     {
@@ -267,7 +267,7 @@
         {
             if (module_sp)
             {
-                if (image_info.UUIDValid())
+                if (image_info_uuid_is_valid)
                 {
                     if (module_sp->GetUUID() != image_info.uuid)
                         module_sp.reset();
@@ -1217,7 +1217,7 @@
         
         if (exe_module_sp)
         {
-            if (exe_module_sp.get() != m_process->GetTarget().GetExecutableModule().get())
+            if (exe_module_sp.get() != m_process->GetTarget().GetExecutableModulePointer())
             {
                 // Don't load dependent images since we are in dyld where we will know
                 // and find out about all images that are loaded
diff --git a/source/Plugins/DynamicLoader/MacOSX-Kernel/DynamicLoaderMacOSXKernel.cpp b/source/Plugins/DynamicLoader/MacOSX-Kernel/DynamicLoaderMacOSXKernel.cpp
index 847d18e..142a6f1 100644
--- a/source/Plugins/DynamicLoader/MacOSX-Kernel/DynamicLoaderMacOSXKernel.cpp
+++ b/source/Plugins/DynamicLoader/MacOSX-Kernel/DynamicLoaderMacOSXKernel.cpp
@@ -52,7 +52,7 @@
     bool create = force;
     if (!create)
     {
-        Module* exe_module = process->GetTarget().GetExecutableModule().get();
+        Module* exe_module = process->GetTarget().GetExecutableModulePointer();
         if (exe_module)
         {
             ObjectFile *object_file = exe_module->GetObjectFile();
diff --git a/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp b/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
index 5d4f465..401fd9a 100644
--- a/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
+++ b/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
@@ -59,14 +59,14 @@
 ProcessKDP::CanDebug(Target &target, bool plugin_specified_by_name)
 {
     // For now we are just making sure the file exists for a given module
-    ModuleSP exe_module_sp(target.GetExecutableModule());
-    if (exe_module_sp.get())
+    Module *exe_module = target.GetExecutableModulePointer();
+    if (exe_module)
     {
         const llvm::Triple &triple_ref = target.GetArchitecture().GetTriple();
         if (triple_ref.getOS() == llvm::Triple::Darwin && 
             triple_ref.getVendor() == llvm::Triple::Apple)
         {
-            ObjectFile *exe_objfile = exe_module_sp->GetObjectFile();
+            ObjectFile *exe_objfile = exe_module->GetObjectFile();
             if (exe_objfile->GetType() == ObjectFile::eTypeExecutable && 
                 exe_objfile->GetStrata() == ObjectFile::eStrataKernel)
                 return true;
diff --git a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 6396714..558a02a 100644
--- a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -104,9 +104,9 @@
 ProcessGDBRemote::CanDebug (Target &target, bool plugin_specified_by_name)
 {
     // For now we are just making sure the file exists for a given module
-    ModuleSP exe_module_sp(target.GetExecutableModule());
-    if (exe_module_sp.get())
-        return exe_module_sp->GetFileSpec().Exists();
+    Module *exe_module = target.GetExecutableModulePointer();
+    if (exe_module)
+        return exe_module->GetFileSpec().Exists();
     // However, if there is no executable module, we return true since we might be preparing to attach.
     return true;
 }
diff --git a/source/Target/Process.cpp b/source/Target/Process.cpp
index a81b68b..9876d72 100644
--- a/source/Target/Process.cpp
+++ b/source/Target/Process.cpp
@@ -2019,7 +2019,7 @@
     m_dyld_ap.reset();
     m_process_input_reader.reset();
 
-    Module *exe_module = m_target.GetExecutableModule().get();
+    Module *exe_module = m_target.GetExecutableModulePointer();
     if (exe_module)
     {
         char local_exec_file_path[PATH_MAX];
@@ -2327,8 +2327,7 @@
         ModuleSP module_sp (modules.GetModuleAtIndex(i));
         if (module_sp && module_sp->IsExecutable())
         {
-            ModuleSP target_exe_module_sp (m_target.GetExecutableModule());
-            if (target_exe_module_sp != module_sp)
+            if (m_target.GetExecutableModulePointer() != module_sp.get())
                 m_target.SetExecutableModule (module_sp, false);
             break;
         }
@@ -3319,11 +3318,11 @@
 void
 Process::UpdateInstanceName ()
 {
-    ModuleSP module_sp = GetTarget().GetExecutableModule();
-    if (module_sp)
+    Module *module = GetTarget().GetExecutableModulePointer();
+    if (module)
     {
         StreamString sstr;
-        sstr.Printf ("%s", module_sp->GetFileSpec().GetFilename().AsCString());
+        sstr.Printf ("%s", module->GetFileSpec().GetFilename().AsCString());
                     
         GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(),
                                                          sstr.GetData());
diff --git a/source/Target/Target.cpp b/source/Target/Target.cpp
index e65f2d1..600a06b 100644
--- a/source/Target/Target.cpp
+++ b/source/Target/Target.cpp
@@ -98,8 +98,9 @@
     }
     else
     {
-        if (GetExecutableModule())
-            s->PutCString (GetExecutableModule()->GetFileSpec().GetFilename().GetCString());
+        Module *exe_module = GetExecutableModulePointer();
+        if (exe_module)
+            s->PutCString (exe_module->GetFileSpec().GetFilename().GetCString());
         else
             s->PutCString ("No executable module.");
     }
@@ -437,10 +438,13 @@
 ModuleSP
 Target::GetExecutableModule ()
 {
-    ModuleSP executable_sp;
-    if (m_images.GetSize() > 0)
-        executable_sp = m_images.GetModuleAtIndex(0);
-    return executable_sp;
+    return m_images.GetModuleAtIndex(0);
+}
+
+Module*
+Target::GetExecutableModulePointer ()
+{
+    return m_images.GetModulePointerAtIndex(0);
 }
 
 void
@@ -915,14 +919,11 @@
 )
 {
     Target *target = (Target *)baton;
-    if (target->m_images.GetSize() > 1)
+    ModuleSP exe_module_sp (target->GetExecutableModule());
+    if (exe_module_sp)
     {
-        ModuleSP exe_module_sp (target->GetExecutableModule());
-        if (exe_module_sp)
-        {
-            target->m_images.Clear();
-            target->SetExecutableModule (exe_module_sp, true);
-        }
+        target->m_images.Clear();
+        target->SetExecutableModule (exe_module_sp, true);
     }
 }
 
@@ -1013,14 +1014,13 @@
 {
     StreamString sstr;
     
-    ModuleSP module_sp = GetExecutableModule();
-    if (module_sp)
+    Module *exe_module = GetExecutableModulePointer();
+    if (exe_module)
     {
         sstr.Printf ("%s_%s", 
-                     module_sp->GetFileSpec().GetFilename().AsCString(), 
-                     module_sp->GetArchitecture().GetArchitectureName());
-        GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(),
-                                                         sstr.GetData());
+                     exe_module->GetFileSpec().GetFilename().AsCString(), 
+                     exe_module->GetArchitecture().GetArchitectureName());
+        GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData());
     }
 }
 
diff --git a/source/Target/TargetList.cpp b/source/Target/TargetList.cpp
index 18b05e6..e8a8ba9 100644
--- a/source/Target/TargetList.cpp
+++ b/source/Target/TargetList.cpp
@@ -148,15 +148,15 @@
     collection::const_iterator pos, end = m_target_list.end();
     for (pos = m_target_list.begin(); pos != end; ++pos)
     {
-        ModuleSP module_sp ((*pos)->GetExecutableModule());
+        Module *exe_module = (*pos)->GetExecutableModulePointer();
 
-        if (module_sp)
+        if (exe_module)
         {
-            if (FileSpec::Equal (exe_file_spec, module_sp->GetFileSpec(), full_match))
+            if (FileSpec::Equal (exe_file_spec, exe_module->GetFileSpec(), full_match))
             {
                 if (exe_arch_ptr)
                 {
-                    if (*exe_arch_ptr != module_sp->GetArchitecture())
+                    if (*exe_arch_ptr != exe_module->GetArchitecture())
                         continue;
                 }
                 target_sp = *pos;
diff --git a/source/Target/ThreadPlanCallFunction.cpp b/source/Target/ThreadPlanCallFunction.cpp
index 8ec93b9..d2bd858 100644
--- a/source/Target/ThreadPlanCallFunction.cpp
+++ b/source/Target/ThreadPlanCallFunction.cpp
@@ -65,9 +65,9 @@
     
     m_function_sp = thread.GetRegisterContext()->GetSP() - abi->GetRedZoneSize();
     
-    ModuleSP executableModuleSP (target.GetExecutableModule());
+    Module *exe_module = target.GetExecutableModulePointer();
 
-    if (!executableModuleSP)
+    if (exe_module == NULL)
     {
         if (log)
             log->Printf ("Can't execute code without an executable module.");
@@ -75,7 +75,7 @@
     }
     else
     {
-        ObjectFile *objectFile = executableModuleSP->GetObjectFile();
+        ObjectFile *objectFile = exe_module->GetObjectFile();
         if (!objectFile)
         {
             if (log)
@@ -181,9 +181,9 @@
     
     m_function_sp = thread.GetRegisterContext()->GetSP() - abi->GetRedZoneSize();
     
-    ModuleSP executableModuleSP (target.GetExecutableModule());
+    Module *exe_module = target.GetExecutableModulePointer();
     
-    if (!executableModuleSP)
+    if (exe_module == NULL)
     {
         if (log)
             log->Printf ("Can't execute code without an executable module.");
@@ -191,7 +191,7 @@
     }
     else
     {
-        ObjectFile *objectFile = executableModuleSP->GetObjectFile();
+        ObjectFile *objectFile = exe_module->GetObjectFile();
         if (!objectFile)
         {
             if (log)
@@ -204,7 +204,7 @@
         {
             if (log)
                 log->Printf ("Could not find entry point address for executable module \"%s\".", 
-                             executableModuleSP->GetFileSpec().GetFilename().AsCString());
+                             exe_module->GetFileSpec().GetFilename().AsCString());
             return;
         }
     }
diff --git a/source/Target/ThreadPlanTracer.cpp b/source/Target/ThreadPlanTracer.cpp
index 8856427..177fdab 100644
--- a/source/Target/ThreadPlanTracer.cpp
+++ b/source/Target/ThreadPlanTracer.cpp
@@ -117,12 +117,12 @@
     
     m_abi = process.GetABI().get();
     
-    ModuleSP exe_module_sp (target.GetExecutableModule());
+    Module *exe_module = target.GetExecutableModulePointer();
     
-    if (exe_module_sp)
+    if (exe_module)
     {
-        m_intptr_type = TypeFromUser(exe_module_sp->GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, arch.GetAddressByteSize() * 8),
-                                     exe_module_sp->GetClangASTContext().getASTContext());
+        m_intptr_type = TypeFromUser(exe_module->GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, arch.GetAddressByteSize() * 8),
+                                     exe_module->GetClangASTContext().getASTContext());
     }
     
     const unsigned int buf_size = 32;