[Lldb-commits] [lldb] r137294 - in /lldb/trunk: include/lldb/Core/ include/lldb/Target/ source/API/ source/Commands/ source/Core/ source/Plugins/DynamicLoader/MacOSX-DYLD/ source/Plugins/DynamicLoader/MacOSX-Kernel/ source/Plugins/Process/MacOSX-Kernel/ source/Plugins/Process/gdb-remote/ source/Target/

Greg Clayton gclayton at apple.com
Wed Aug 10 19:48:45 PDT 2011


Author: gclayton
Date: Wed Aug 10 21:48:45 2011
New Revision: 137294

URL: http://llvm.org/viewvc/llvm-project?rev=137294&view=rev
Log:
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.


Modified:
    lldb/trunk/include/lldb/Core/ModuleList.h
    lldb/trunk/include/lldb/Target/Target.h
    lldb/trunk/source/API/SBProcess.cpp
    lldb/trunk/source/API/SBTarget.cpp
    lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp
    lldb/trunk/source/Commands/CommandObjectPlatform.cpp
    lldb/trunk/source/Commands/CommandObjectProcess.cpp
    lldb/trunk/source/Commands/CommandObjectTarget.cpp
    lldb/trunk/source/Core/Debugger.cpp
    lldb/trunk/source/Core/ModuleList.cpp
    lldb/trunk/source/Core/ValueObjectRegister.cpp
    lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
    lldb/trunk/source/Plugins/DynamicLoader/MacOSX-Kernel/DynamicLoaderMacOSXKernel.cpp
    lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
    lldb/trunk/source/Target/Process.cpp
    lldb/trunk/source/Target/Target.cpp
    lldb/trunk/source/Target/TargetList.cpp
    lldb/trunk/source/Target/ThreadPlanCallFunction.cpp
    lldb/trunk/source/Target/ThreadPlanTracer.cpp

Modified: lldb/trunk/include/lldb/Core/ModuleList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ModuleList.h?rev=137294&r1=137293&r2=137294&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ModuleList.h (original)
+++ lldb/trunk/include/lldb/Core/ModuleList.h Wed Aug 10 21:48:45 2011
@@ -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.

Modified: lldb/trunk/include/lldb/Target/Target.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=137294&r1=137293&r2=137294&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Target.h (original)
+++ lldb/trunk/include/lldb/Target/Target.h Wed Aug 10 21:48:45 2011
@@ -347,6 +347,9 @@
     lldb::ModuleSP
     GetExecutableModule ();
 
+    Module*
+    GetExecutableModulePointer ();
+
     //------------------------------------------------------------------
     /// Set the main executable module.
     ///

Modified: lldb/trunk/source/API/SBProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBProcess.cpp?rev=137294&r1=137293&r2=137294&view=diff
==============================================================================
--- lldb/trunk/source/API/SBProcess.cpp (original)
+++ lldb/trunk/source/API/SBProcess.cpp Wed Aug 10 21:48:45 2011
@@ -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();

Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=137294&r1=137293&r2=137294&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Wed Aug 10 21:48:45 2011
@@ -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));

Modified: lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp?rev=137294&r1=137293&r2=137294&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp Wed Aug 10 21:48:45 2011
@@ -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;

Modified: lldb/trunk/source/Commands/CommandObjectPlatform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectPlatform.cpp?rev=137294&r1=137293&r2=137294&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectPlatform.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectPlatform.cpp Wed Aug 10 21:48:45 2011
@@ -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();
                 }
             }
 

Modified: lldb/trunk/source/Commands/CommandObjectProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectProcess.cpp?rev=137294&r1=137293&r2=137294&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectProcess.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectProcess.cpp Wed Aug 10 21:48:45 2011
@@ -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);

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=137294&r1=137293&r2=137294&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Wed Aug 10 21:48:45 2011
@@ -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;
 };
 
 

Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=137294&r1=137293&r2=137294&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Wed Aug 10 21:48:45 2011
@@ -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;
                                             }
                                         }

Modified: lldb/trunk/source/Core/ModuleList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ModuleList.cpp?rev=137294&r1=137293&r2=137294&view=diff
==============================================================================
--- lldb/trunk/source/Core/ModuleList.cpp (original)
+++ lldb/trunk/source/Core/ModuleList.cpp Wed Aug 10 21:48:45 2011
@@ -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
 (

Modified: lldb/trunk/source/Core/ValueObjectRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectRegister.cpp?rev=137294&r1=137293&r2=137294&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObjectRegister.cpp (original)
+++ lldb/trunk/source/Core/ValueObjectRegister.cpp Wed Aug 10 21:48:45 2011
@@ -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();
     }

Modified: lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp?rev=137294&r1=137293&r2=137294&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp Wed Aug 10 21:48:45 2011
@@ -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

Modified: lldb/trunk/source/Plugins/DynamicLoader/MacOSX-Kernel/DynamicLoaderMacOSXKernel.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/MacOSX-Kernel/DynamicLoaderMacOSXKernel.cpp?rev=137294&r1=137293&r2=137294&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-Kernel/DynamicLoaderMacOSXKernel.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-Kernel/DynamicLoaderMacOSXKernel.cpp Wed Aug 10 21:48:45 2011
@@ -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();

Modified: lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp?rev=137294&r1=137293&r2=137294&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp (original)
+++ lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp Wed Aug 10 21:48:45 2011
@@ -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;

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=137294&r1=137293&r2=137294&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Wed Aug 10 21:48:45 2011
@@ -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;
 }

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=137294&r1=137293&r2=137294&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Wed Aug 10 21:48:45 2011
@@ -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());

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=137294&r1=137293&r2=137294&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Wed Aug 10 21:48:45 2011
@@ -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());
     }
 }
 

Modified: lldb/trunk/source/Target/TargetList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/TargetList.cpp?rev=137294&r1=137293&r2=137294&view=diff
==============================================================================
--- lldb/trunk/source/Target/TargetList.cpp (original)
+++ lldb/trunk/source/Target/TargetList.cpp Wed Aug 10 21:48:45 2011
@@ -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;

Modified: lldb/trunk/source/Target/ThreadPlanCallFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlanCallFunction.cpp?rev=137294&r1=137293&r2=137294&view=diff
==============================================================================
--- lldb/trunk/source/Target/ThreadPlanCallFunction.cpp (original)
+++ lldb/trunk/source/Target/ThreadPlanCallFunction.cpp Wed Aug 10 21:48:45 2011
@@ -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;
         }
     }

Modified: lldb/trunk/source/Target/ThreadPlanTracer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlanTracer.cpp?rev=137294&r1=137293&r2=137294&view=diff
==============================================================================
--- lldb/trunk/source/Target/ThreadPlanTracer.cpp (original)
+++ lldb/trunk/source/Target/ThreadPlanTracer.cpp Wed Aug 10 21:48:45 2011
@@ -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;





More information about the lldb-commits mailing list