We were leaking a stack frame in StackFrameList in Thread.cpp which could
cause extra shared pointer references to one or more modules to be leaked.
This would cause many object files to stay around the life of LLDB, so after
a recompile and rexecution, we would keep adding more and more memory. After
fixing the leak, we found many cases where leaked stack frames were still
being used and causing crashes in the test suite. These are now all resolved.



git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@137516 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Symbol/Block.cpp b/source/Symbol/Block.cpp
index 8be43e7..8cca445 100644
--- a/source/Symbol/Block.cpp
+++ b/source/Symbol/Block.cpp
@@ -152,6 +152,36 @@
     sc->block = this;
 }
 
+Module *
+Block::CalculateSymbolContextModule ()
+{
+    if (m_parent_scope)
+        return m_parent_scope->CalculateSymbolContextModule ();
+    return NULL;
+}
+
+CompileUnit *
+Block::CalculateSymbolContextCompileUnit ()
+{
+    if (m_parent_scope)
+        return m_parent_scope->CalculateSymbolContextCompileUnit ();
+    return NULL;
+}
+
+Function *
+Block::CalculateSymbolContextFunction ()
+{
+    if (m_parent_scope)
+        return m_parent_scope->CalculateSymbolContextFunction ();
+    return NULL;
+}
+
+Block *
+Block::CalculateSymbolContextBlock ()
+{
+    return this;
+}
+
 void
 Block::DumpStopContext 
 (
@@ -225,12 +255,11 @@
         }
         else if (child_inline_call_site)
         {
-            SymbolContext sc;
-            CalculateSymbolContext(&sc);
-            if (sc.function)
+            Function *function = CalculateSymbolContextFunction();
+            if (function)
             {
                 s->EOL();
-                s->Indent (sc.function->GetMangled().GetName().AsCString());
+                s->Indent (function->GetMangled().GetName().AsCString());
                 if (child_inline_call_site && child_inline_call_site->IsValid())
                 {
                     s->PutCString(" at ");
@@ -245,10 +274,9 @@
 void
 Block::DumpSymbolContext(Stream *s)
 {
-    SymbolContext sc;
-    CalculateSymbolContext(&sc);
-    if (sc.function)
-        sc.function->DumpSymbolContext(s);
+    Function *function = CalculateSymbolContextFunction();
+    if (function)
+        function->DumpSymbolContext(s);
     s->Printf(", Block{0x%8.8x}", GetID());
 }
 
@@ -297,12 +325,7 @@
 Block::GetParent () const
 {
     if (m_parent_scope)
-    {
-        SymbolContext sc;
-        m_parent_scope->CalculateSymbolContext(&sc);
-        if (sc.block)
-            return sc.block;
-    }
+        return m_parent_scope->CalculateSymbolContextBlock();
     return NULL;
 }
 
@@ -346,11 +369,10 @@
 bool
 Block::GetRangeContainingAddress (const Address& addr, AddressRange &range)
 {
-    SymbolContext sc;
-    CalculateSymbolContext(&sc);
-    if (sc.function)
+    Function *function = CalculateSymbolContextFunction();
+    if (function)
     {
-        const AddressRange &func_range = sc.function->GetAddressRange();
+        const AddressRange &func_range = function->GetAddressRange();
         if (addr.GetSection() == func_range.GetBaseAddress().GetSection())
         {
             const addr_t addr_offset = addr.GetOffset();
@@ -379,11 +401,10 @@
 {
     if (range_idx < m_ranges.size())
     {
-        SymbolContext sc;
-        CalculateSymbolContext(&sc);
-        if (sc.function)
+        Function *function = CalculateSymbolContextFunction();
+        if (function)
         {
-            range.GetBaseAddress() = sc.function->GetAddressRange().GetBaseAddress();
+            range.GetBaseAddress() = function->GetAddressRange().GetBaseAddress();
             range.GetBaseAddress().Slide(m_ranges[range_idx].GetBaseAddress ());
             range.SetByteSize (m_ranges[range_idx].GetByteSize());
             return true;
@@ -398,11 +419,10 @@
     if (m_ranges.empty())
         return false;
 
-    SymbolContext sc;
-    CalculateSymbolContext(&sc);
-    if (sc.function)
+    Function *function = CalculateSymbolContextFunction();
+    if (function)
     {
-        addr = sc.function->GetAddressRange().GetBaseAddress();
+        addr = function->GetAddressRange().GetBaseAddress();
         addr.Slide(m_ranges.front().GetBaseAddress ());
         return true;
     }
diff --git a/source/Symbol/CompileUnit.cpp b/source/Symbol/CompileUnit.cpp
index ea49eb3..8f51210 100644
--- a/source/Symbol/CompileUnit.cpp
+++ b/source/Symbol/CompileUnit.cpp
@@ -57,6 +57,18 @@
     GetModule()->CalculateSymbolContext(sc);
 }
 
+Module *
+CompileUnit::CalculateSymbolContextModule ()
+{
+    return GetModule();
+}
+
+CompileUnit *
+CompileUnit::CalculateSymbolContextCompileUnit ()
+{
+    return this;
+}
+
 void
 CompileUnit::DumpSymbolContext(Stream *s)
 {
diff --git a/source/Symbol/Function.cpp b/source/Symbol/Function.cpp
index 5328159..ca14997 100644
--- a/source/Symbol/Function.cpp
+++ b/source/Symbol/Function.cpp
@@ -386,6 +386,31 @@
     m_comp_unit->CalculateSymbolContext(sc);
 }
 
+Module *
+Function::CalculateSymbolContextModule ()
+{
+    return this->GetCompileUnit()->GetModule();
+}
+
+CompileUnit *
+Function::CalculateSymbolContextCompileUnit ()
+{
+    return this->GetCompileUnit();
+}
+
+Function *
+Function::CalculateSymbolContextFunction ()
+{
+    return this;
+}
+
+//Symbol *
+//Function::CalculateSymbolContextSymbol ()
+//{
+//    return // TODO: find the symbol for the function???
+//}
+
+
 void
 Function::DumpSymbolContext(Stream *s)
 {
diff --git a/source/Symbol/Symbol.cpp b/source/Symbol/Symbol.cpp
index 480405e..7b44d77 100644
--- a/source/Symbol/Symbol.cpp
+++ b/source/Symbol/Symbol.cpp
@@ -366,6 +366,22 @@
     sc->module_sp.reset();
 }
 
+Module *
+Symbol::CalculateSymbolContextModule ()
+{
+    const AddressRange *range = GetAddressRangePtr();
+    if (range)
+        return range->GetBaseAddress().GetModule ();
+    return NULL;
+}
+
+Symbol *
+Symbol::CalculateSymbolContextSymbol ()
+{
+    return this;
+}
+
+
 void
 Symbol::DumpSymbolContext (Stream *s)
 {