<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.




git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@151336 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Target/StackFrame.cpp b/source/Target/StackFrame.cpp
index 5324a69..1d6cb93 100644
--- a/source/Target/StackFrame.cpp
+++ b/source/Target/StackFrame.cpp
@@ -50,7 +50,7 @@
     m_concrete_frame_index (unwind_frame_index),    
     m_reg_context_sp (),
     m_id (pc, cfa, NULL),
-    m_frame_code_addr (NULL, pc),
+    m_frame_code_addr (pc),
     m_sc (),
     m_flags (),
     m_frame_base (),
@@ -78,7 +78,7 @@
     m_concrete_frame_index (unwind_frame_index),    
     m_reg_context_sp (reg_context_sp),
     m_id (pc, cfa, NULL),
-    m_frame_code_addr (NULL, pc),
+    m_frame_code_addr (pc),
     m_sc (),
     m_flags (),
     m_frame_base (),
@@ -135,19 +135,18 @@
             m_flags.Set (eSymbolContextTarget);
     }
     
-    Module *pc_module = pc_addr.GetModulePtr();
-    if (m_sc.module_sp.get() == NULL || m_sc.module_sp.get() != pc_module)
+    ModuleSP pc_module_sp (pc_addr.GetModule());
+    if (!m_sc.module_sp || m_sc.module_sp != pc_module_sp)
     {
-        if (pc_module)
+        if (pc_module_sp)
         {
-            m_sc.module_sp = pc_module->shared_from_this();
+            m_sc.module_sp = pc_module_sp;
             m_flags.Set (eSymbolContextModule);
         }
         else
         {
             m_sc.module_sp.reset();
         }
-
     }
 }
 
@@ -219,16 +218,11 @@
             {
                 if (m_frame_code_addr.SetOpcodeLoadAddress (m_frame_code_addr.GetOffset(), target_sp.get()))
                 {
-                    const Section *section = m_frame_code_addr.GetSection();
-                    if (section)
+                    ModuleSP module_sp (m_frame_code_addr.GetModule());
+                    if (module_sp)
                     {
-                        Module *module = section->GetModule();
-                        if (module)
-                        {
-                            m_sc.module_sp = module->shared_from_this();
-                            if (m_sc.module_sp)
-                                m_flags.Set(eSymbolContextModule);
-                        }
+                        m_sc.module_sp = module_sp;
+                        m_flags.Set(eSymbolContextModule);
                     }
                 }
             }
@@ -240,8 +234,7 @@
 void
 StackFrame::ChangePC (addr_t pc)
 {
-    m_frame_code_addr.SetOffset(pc);
-    m_frame_code_addr.SetSection(NULL);
+    m_frame_code_addr.SetRawAddress(pc);
     m_sc.Clear();
     m_flags.Reset(0);
     ThreadSP thread_sp (GetThread());