<rdar://problem/10103468>

I started work on being able to add symbol files after a debug session
had started with a new "target symfile add" command and quickly ran into
problems with stale Address objects in breakpoint locations that had 
lldb_private::Section pointers into modules that had been removed or 
replaced. This also let to grabbing stale modules from those sections. 
So I needed to thread harded the Address, Section and related objects.

To do this I modified the ModuleChild class to now require a ModuleSP
on initialization so that a weak reference can created. I also changed
all places that were handing out "Section *" to have them hand out SectionSP.
All ObjectFile, SymbolFile and SymbolVendors were inheriting from ModuleChild
so all of the find plug-in, static creation function and constructors now
require ModuleSP references instead of Module *. 

Address objects now have weak references to their sections which can
safely go stale when a module gets destructed. 

This checkin doesn't complete the "target symfile add" command, but it
does get us a lot clioser to being able to do such things without a high
risk of crashing or memory corruption.

llvm-svn: 151336
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 56fc593..2f0d835 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -303,7 +303,11 @@
 SymbolFileDWARF::~SymbolFileDWARF()
 {
     if (m_is_external_ast_source)
-        m_obj_file->GetModule()->GetClangASTContext().RemoveExternalSource ();
+    {
+        ModuleSP module_sp (m_obj_file->GetModule());
+        if (module_sp)
+            module_sp->GetClangASTContext().RemoveExternalSource ();
+    }
 }
 
 static const ConstString &
@@ -346,8 +350,8 @@
 SymbolFileDWARF::InitializeObject()
 {
     // Install our external AST source callbacks so we can complete Clang types.
-    Module *module = m_obj_file->GetModule();
-    if (module)
+    ModuleSP module_sp (m_obj_file->GetModule());
+    if (module_sp)
     {
         const SectionList *section_list = m_obj_file->GetSectionList();
 
@@ -531,17 +535,17 @@
         const SectionList *section_list = m_obj_file->GetSectionList();
         if (section_list)
         {
-            Section *section = section_list->FindSectionByType(sect_type, true).get();
-            if (section)
+            SectionSP section_sp (section_list->FindSectionByType(sect_type, true));
+            if (section_sp)
             {
                 // See if we memory mapped the DWARF segment?
                 if (m_dwarf_data.GetByteSize())
                 {
-                    data.SetData(m_dwarf_data, section->GetOffset (), section->GetByteSize());
+                    data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetByteSize());
                 }
                 else
                 {
-                    if (m_obj_file->ReadSectionData (section, data) == 0)
+                    if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0)
                         data.Clear();
                 }
             }
@@ -2183,7 +2187,7 @@
         
     if (sc.function)
     {        
-        sc.module_sp = sc.function->CalculateSymbolContextModule()->shared_from_this();
+        sc.module_sp = sc.function->CalculateSymbolContextModule();
         return true;
     }
     
@@ -2195,7 +2199,7 @@
 {
     Timer scoped_timer(__PRETTY_FUNCTION__,
                        "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)",
-                       so_addr.GetSection(),
+                       so_addr.GetSection().get(),
                        so_addr.GetOffset(),
                        resolve_scope);
     uint32_t resolved = 0;
@@ -2601,7 +2605,7 @@
     if (num_matches)
     {
         SymbolContext sc;
-        sc.module_sp = m_obj_file->GetModule()->shared_from_this();
+        sc.module_sp = m_obj_file->GetModule();
         assert (sc.module_sp);
         
         DWARFDebugInfo* debug_info = DebugInfo();
@@ -2687,7 +2691,7 @@
     }
 
     SymbolContext sc;
-    sc.module_sp = m_obj_file->GetModule()->shared_from_this();
+    sc.module_sp = m_obj_file->GetModule();
     assert (sc.module_sp);
     
     DWARFCompileUnit* dwarf_cu = NULL;