Clarified the intent of the SymbolContextScope class in the header
documentation. Symbol now inherits from the symbol
context scope so that the StackID can use a "SymbolContextScope *"
instead of a blockID (which could have been the same as some other
blockID from another symbol file). 

Modified the stacks that are created on subsequent stops to reuse
the previous stack frame objects which will allow for some internal
optimization using pointer comparisons during stepping. 



git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@112495 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Core/Address.cpp b/source/Core/Address.cpp
index bea7493..070e11d 100644
--- a/source/Core/Address.cpp
+++ b/source/Core/Address.cpp
@@ -241,7 +241,6 @@
 }
 
 Address::Address (addr_t address, const SectionList * sections) :
-    SymbolContextScope(),
     m_section (NULL),
     m_offset (LLDB_INVALID_ADDRESS)
 {
@@ -707,14 +706,6 @@
 }
 
 void
-Address::DumpSymbolContext (Stream *s)
-{
-    SymbolContext sc;
-    CalculateSymbolContext (&sc);
-    sc.Dump (s, NULL);
-}
-
-void
 Address::DumpDebug(Stream *s) const
 {
     *s << (void *)this << ": " << "Address";
diff --git a/source/Plugins/Process/Utility/UnwindLibUnwind.cpp b/source/Plugins/Process/Utility/UnwindLibUnwind.cpp
index e080bc3..bbc58a2 100644
--- a/source/Plugins/Process/Utility/UnwindLibUnwind.cpp
+++ b/source/Plugins/Process/Utility/UnwindLibUnwind.cpp
@@ -65,7 +65,7 @@
 RegisterContext *
 UnwindLibUnwind::CreateRegisterContextForFrame (StackFrame *frame)
 {
-    uint32_t idx = frame->GetConcreteFrameIndex ();
+    uint32_t idx = frame->GetUnwindFrameIndex ();
     const uint32_t frame_count = GetFrameCount();
     if (idx < frame_count)
         return new LibUnwindRegisterContext (m_thread, frame, m_cursors[idx]);
diff --git a/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp b/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp
index 4ef6338..f620b07 100644
--- a/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp
+++ b/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp
@@ -66,7 +66,7 @@
 RegisterContext *
 UnwindMacOSXFrameBackchain::CreateRegisterContextForFrame (StackFrame *frame)
 {
-    uint32_t idx = frame->GetConcreteFrameIndex ();
+    uint32_t idx = frame->GetUnwindFrameIndex ();
     const uint32_t frame_count = GetFrameCount();
     if (idx < frame_count)
         return new RegisterContextMacOSXFrameBackchain (m_thread, frame, m_cursors[idx]);
diff --git a/source/Symbol/Symbol.cpp b/source/Symbol/Symbol.cpp
index 6c91dd4..7ea7193 100644
--- a/source/Symbol/Symbol.cpp
+++ b/source/Symbol/Symbol.cpp
@@ -19,6 +19,7 @@
 
 
 Symbol::Symbol() :
+    SymbolContextScope (),
     UserID (),
     m_mangled (),
     m_type (eSymbolTypeInvalid),
@@ -51,6 +52,7 @@
     uint32_t size,
     uint32_t flags
 ) :
+    SymbolContextScope (),
     UserID (symID),
     m_mangled (name, name_is_mangled),
     m_type (type),
@@ -81,6 +83,7 @@
     const AddressRange &range,
     uint32_t flags
 ) :
+    SymbolContextScope (),
     UserID (symID),
     m_mangled (name, name_is_mangled),
     m_type (type),
@@ -99,6 +102,7 @@
 }
 
 Symbol::Symbol(const Symbol& rhs):
+    SymbolContextScope (rhs),
     UserID (rhs),
     m_mangled (rhs.m_mangled),
     m_type (rhs.m_type),
@@ -121,6 +125,7 @@
 {
     if (this != &rhs)
     {
+        SymbolContextScope::operator= (rhs);
         UserID::operator= (rhs);
         m_mangled = rhs.m_mangled;
         m_type = rhs.m_type;
@@ -335,3 +340,43 @@
     return "<unknown SymbolType>";
 }
 
+
+void
+Symbol::CalculateSymbolContext (SymbolContext *sc)
+{
+    // Symbols can reconstruct the symbol and the module in the symbol context
+    sc->symbol = this;
+    const AddressRange *range = GetAddressRangePtr();
+    if (range)
+    {   
+        Module *module = range->GetBaseAddress().GetModule ();
+        if (module)
+        {
+            sc->module_sp = module->GetSP();
+            return;
+        }
+    }
+    sc->module_sp.reset();
+}
+
+void
+Symbol::DumpSymbolContext (Stream *s)
+{
+    bool dumped_module = false;
+    const AddressRange *range = GetAddressRangePtr();
+    if (range)
+    {   
+        Module *module = range->GetBaseAddress().GetModule ();
+        if (module)
+        {
+            dumped_module = true;
+            module->DumpSymbolContext(s);
+        }
+    }
+    if (dumped_module)
+        s->PutCString(", ");
+    
+    s->Printf("Symbol{0x%8.8x}", GetID());
+}
+
+
diff --git a/source/Symbol/Variable.cpp b/source/Symbol/Variable.cpp
index cb3d1c6..a5c74e6 100644
--- a/source/Symbol/Variable.cpp
+++ b/source/Symbol/Variable.cpp
@@ -37,7 +37,7 @@
     m_name(name),
     m_type(type),
     m_scope(scope),
-    m_context(context),
+    m_owner_scope(context),
     m_declaration(decl_ptr),
     m_location(location),
     m_external(external),
@@ -82,10 +82,10 @@
         }
     }
 
-    if (show_context && m_context != NULL)
+    if (show_context && m_owner_scope != NULL)
     {
         s->PutCString(", context = ( ");
-        m_context->DumpSymbolContext(s);
+        m_owner_scope->DumpSymbolContext(s);
         s->PutCString(" )");
     }
 
@@ -117,8 +117,8 @@
 void
 Variable::CalculateSymbolContext (SymbolContext *sc)
 {
-    if (m_context)
-        m_context->CalculateSymbolContext(sc);
+    if (m_owner_scope)
+        m_owner_scope->CalculateSymbolContext(sc);
     else
         sc->Clear();
 }
diff --git a/source/Target/StackFrame.cpp b/source/Target/StackFrame.cpp
index 967df88..4aef251 100644
--- a/source/Target/StackFrame.cpp
+++ b/source/Target/StackFrame.cpp
@@ -29,26 +29,26 @@
 // The first bits in the flags are reserved for the SymbolContext::Scope bits
 // so we know if we have tried to look up information in our internal symbol
 // context (m_sc) already.
-#define RESOLVED_FRAME_ADDR (uint32_t(eSymbolContextEverything + 1))
-#define RESOLVED_FRAME_ID   (RESOLVED_FRAME_ADDR << 1)
-#define GOT_FRAME_BASE      (RESOLVED_FRAME_ID << 1)
-#define FRAME_IS_OBSOLETE   (GOT_FRAME_BASE << 1)
-#define RESOLVED_VARIABLES  (FRAME_IS_OBSOLETE << 1)
+#define RESOLVED_FRAME_CODE_ADDR        (uint32_t(eSymbolContextEverything + 1))
+#define RESOLVED_FRAME_ID_START_ADDR    (RESOLVED_FRAME_CODE_ADDR << 1)
+#define RESOLVED_FRAME_ID_SYMBOL_SCOPE  (RESOLVED_FRAME_ID_START_ADDR << 1)
+#define GOT_FRAME_BASE                  (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1)
+#define RESOLVED_VARIABLES              (GOT_FRAME_BASE << 1)
 
 StackFrame::StackFrame 
 (
     lldb::user_id_t frame_idx, 
-    lldb::user_id_t concrete_frame_index, 
+    lldb::user_id_t unwind_frame_index, 
     Thread &thread, 
     lldb::addr_t cfa, 
     lldb::addr_t pc, 
     const SymbolContext *sc_ptr
 ) :
     m_frame_index (frame_idx),
-    m_concrete_frame_index (concrete_frame_index),    
+    m_unwind_frame_index (unwind_frame_index),    
     m_thread (thread),
     m_reg_context_sp (),
-    m_id (LLDB_INVALID_UID, cfa, LLDB_INVALID_UID),
+    m_id (LLDB_INVALID_ADDRESS, cfa, NULL),
     m_frame_code_addr (NULL, pc),
     m_sc (),
     m_flags (),
@@ -67,7 +67,7 @@
 StackFrame::StackFrame 
 (
     lldb::user_id_t frame_idx, 
-    lldb::user_id_t concrete_frame_index, 
+    lldb::user_id_t unwind_frame_index, 
     Thread &thread, 
     const RegisterContextSP &reg_context_sp, 
     lldb::addr_t cfa, 
@@ -75,10 +75,10 @@
     const SymbolContext *sc_ptr
 ) :
     m_frame_index (frame_idx),
-    m_concrete_frame_index (concrete_frame_index),    
+    m_unwind_frame_index (unwind_frame_index),    
     m_thread (thread),
     m_reg_context_sp (reg_context_sp),
-    m_id (LLDB_INVALID_UID, cfa, LLDB_INVALID_UID),
+    m_id (LLDB_INVALID_ADDRESS, cfa, NULL),
     m_frame_code_addr (NULL, pc),
     m_sc (),
     m_flags (),
@@ -103,7 +103,7 @@
 StackFrame::StackFrame 
 (
     lldb::user_id_t frame_idx, 
-    lldb::user_id_t concrete_frame_index, 
+    lldb::user_id_t unwind_frame_index, 
     Thread &thread, 
     const RegisterContextSP &reg_context_sp, 
     lldb::addr_t cfa, 
@@ -111,10 +111,10 @@
     const SymbolContext *sc_ptr
 ) :
     m_frame_index (frame_idx),
-    m_concrete_frame_index (concrete_frame_index),    
+    m_unwind_frame_index (unwind_frame_index),    
     m_thread (thread),
     m_reg_context_sp (reg_context_sp),
-    m_id (LLDB_INVALID_UID, cfa, LLDB_INVALID_UID),
+    m_id (LLDB_INVALID_ADDRESS, cfa, NULL),
     m_frame_code_addr (pc_addr),
     m_sc (),
     m_flags (),
@@ -160,41 +160,92 @@
     // Make sure we have resolved our stack ID's start PC before we give
     // it out to any external clients. This allows us to not have to lookup
     // this information if it is never asked for.
-    if (m_flags.IsClear(RESOLVED_FRAME_ID) && m_id.GetStartAddress() == LLDB_INVALID_ADDRESS)
+    if (m_flags.IsClear(RESOLVED_FRAME_ID_START_ADDR))
     {
-        m_flags.Set (RESOLVED_FRAME_ID);
+        m_flags.Set (RESOLVED_FRAME_ID_START_ADDR);
 
-        // Resolve our PC to section offset if we haven't alreday done so
-        // and if we don't have a module. The resolved address section will
-        // contain the module to which it belongs.
-        if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_ADDR))
-            GetFrameCodeAddress();
-
-        if (GetSymbolContext (eSymbolContextFunction).function)
-        {
-            m_id.SetStartAddress (m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (&m_thread.GetProcess()));
-        }
-        else if (GetSymbolContext (eSymbolContextSymbol).symbol)
-        {
-            AddressRange *symbol_range_ptr = m_sc.symbol->GetAddressRangePtr();
-            if (symbol_range_ptr)
-                m_id.SetStartAddress(symbol_range_ptr->GetBaseAddress().GetLoadAddress (&m_thread.GetProcess()));
-        }
-        
-        // We didn't find a function or symbol, just use the frame code address
-        // which will be the same as the PC in the frame.
         if (m_id.GetStartAddress() == LLDB_INVALID_ADDRESS)
-            m_id.SetStartAddress (m_frame_code_addr.GetLoadAddress (&m_thread.GetProcess()));
+        {
+            // Resolve our PC to section offset if we haven't alreday done so
+            // and if we don't have a module. The resolved address section will
+            // contain the module to which it belongs.
+            if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR))
+                GetFrameCodeAddress();
+
+            if (GetSymbolContext (eSymbolContextFunction).function)
+            {
+                m_id.SetStartAddress (m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (&m_thread.GetProcess()));
+            }
+            else if (GetSymbolContext (eSymbolContextSymbol).symbol)
+            {
+                AddressRange *symbol_range_ptr = m_sc.symbol->GetAddressRangePtr();
+                if (symbol_range_ptr)
+                    m_id.SetStartAddress(symbol_range_ptr->GetBaseAddress().GetLoadAddress (&m_thread.GetProcess()));
+            }
+            
+            // We didn't find a function or symbol, just use the frame code address
+            // which will be the same as the PC in the frame.
+            if (m_id.GetStartAddress() == LLDB_INVALID_ADDRESS)
+                m_id.SetStartAddress (m_frame_code_addr.GetLoadAddress (&m_thread.GetProcess()));
+        }
+    }
+    
+    if (m_flags.IsClear (RESOLVED_FRAME_ID_SYMBOL_SCOPE))
+    {
+        if (m_id.GetSymbolContextScope ())
+        {
+            m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
+        }
+        else
+        {
+            GetSymbolContext (eSymbolContextFunction | eSymbolContextBlock);
+            
+            if (m_sc.block)
+            {
+                Block *inline_block = m_sc.block->GetContainingInlinedBlock();
+                if (inline_block)
+                {
+                    // Use the block with the inlined function info
+                    // as the symbol context since we want this frame
+                    // to have only the variables for the inlined function
+                    SetSymbolContextScope (inline_block);
+                }
+                else
+                {
+                    // This block is not inlined with means it has no
+                    // inlined parents either, so we want to use the top
+                    // most function block.
+                    SetSymbolContextScope (&m_sc.function->GetBlock(false));
+                }
+            }
+            else
+            {
+                // The current stack frame doesn't have a block. Check to see
+                // if it has a symbol. If it does we will use this as the 
+                // symbol scope. It is ok if "m_sc.symbol" is NULL below as
+                // it will set the symbol context to NULL and set the
+                // RESOLVED_FRAME_ID_SYMBOL_SCOPE flag bit.
+                GetSymbolContext (eSymbolContextSymbol);
+                SetSymbolContextScope (m_sc.symbol);
+            }
+        }
     }
     return m_id;
 }
 
+void
+StackFrame::SetSymbolContextScope (SymbolContextScope *symbol_scope)
+{
+    m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
+    m_id.SetSymbolContextScope (symbol_scope);
+}
+
 Address&
 StackFrame::GetFrameCodeAddress()
 {
-    if (m_flags.IsClear(RESOLVED_FRAME_ADDR) && !m_frame_code_addr.IsSectionOffset())
+    if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) && !m_frame_code_addr.IsSectionOffset())
     {
-        m_flags.Set (RESOLVED_FRAME_ADDR);
+        m_flags.Set (RESOLVED_FRAME_CODE_ADDR);
 
         // Resolve the PC into a temporary address because if ResolveLoadAddress
         // fails to resolve the address, it will clear the address object...
@@ -263,7 +314,7 @@
         // Resolve our PC to section offset if we haven't alreday done so
         // and if we don't have a module. The resolved address section will
         // contain the module to which it belongs
-        if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_ADDR))
+        if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR))
             GetFrameCodeAddress();
 
         // If this is not frame zero, then we need to subtract 1 from the PC
@@ -479,7 +530,11 @@
 bool
 StackFrame::IsInlined ()
 {
-    return m_id.GetInlineBlockID() != LLDB_INVALID_UID;
+    if (m_sc.block == NULL)
+        GetSymbolContext (eSymbolContextBlock);
+    if (m_sc.block)
+        return m_sc.block->GetContainingInlinedBlock() != NULL;
+    return false;
 }
 
 Target *
@@ -532,13 +587,35 @@
 }
 
 void
-StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &frame)
+StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame)
 {
-    assert (GetStackID() == frame.GetStackID());    // TODO: remove this after some testing
-    m_variable_list_sp = frame.m_variable_list_sp;
-    m_value_object_list.Swap (frame.m_value_object_list);
+    assert (GetStackID() == prev_frame.GetStackID());    // TODO: remove this after some testing
+    m_variable_list_sp = prev_frame.m_variable_list_sp;
+    m_value_object_list.Swap (prev_frame.m_value_object_list);
     if (!m_disassembly.GetString().empty())
         m_disassembly.GetString().swap (m_disassembly.GetString());
 }
     
 
+void
+StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame)
+{
+    assert (GetStackID() == curr_frame.GetStackID());    // TODO: remove this after some testing
+    assert (&m_thread == &curr_frame.m_thread);
+    m_frame_index = curr_frame.m_frame_index;
+    m_unwind_frame_index = curr_frame.m_unwind_frame_index;
+    m_reg_context_sp = curr_frame.m_reg_context_sp;
+    m_frame_code_addr = curr_frame.m_frame_code_addr;
+    assert (m_sc.target_sp.get() == NULL || curr_frame.m_sc.target_sp.get() == NULL || m_sc.target_sp.get() == curr_frame.m_sc.target_sp.get());
+    assert (m_sc.module_sp.get() == NULL || curr_frame.m_sc.module_sp.get() == NULL || m_sc.module_sp.get() == curr_frame.m_sc.module_sp.get());
+    assert (m_sc.comp_unit == NULL || curr_frame.m_sc.comp_unit == NULL || m_sc.comp_unit == curr_frame.m_sc.comp_unit);
+    assert (m_sc.function == NULL || curr_frame.m_sc.function == NULL || m_sc.function == curr_frame.m_sc.function);
+    assert (m_sc.symbol == NULL || curr_frame.m_sc.symbol == NULL || m_sc.symbol == curr_frame.m_sc.symbol);
+    m_sc = curr_frame.m_sc;
+    m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything);
+    m_flags.Set (m_sc.GetResolvedMask());
+    m_frame_base.Clear();
+    m_frame_base_error.Clear();
+}
+    
+
diff --git a/source/Target/StackFrameList.cpp b/source/Target/StackFrameList.cpp
index be4e6e4..75351ff 100644
--- a/source/Target/StackFrameList.cpp
+++ b/source/Target/StackFrameList.cpp
@@ -16,6 +16,7 @@
 #include "lldb/Core/StreamFile.h"
 #include "lldb/Symbol/Block.h"
 #include "lldb/Symbol/Function.h"
+#include "lldb/Symbol/Symbol.h"
 #include "lldb/Target/RegisterContext.h"
 #include "lldb/Target/StackFrame.h"
 #include "lldb/Target/Thread.h"
@@ -60,7 +61,8 @@
             StreamFile s(stdout);
 #endif
             Unwind *unwinder = m_thread.GetUnwinder ();
-            addr_t pc, cfa;
+            addr_t pc = LLDB_INVALID_ADDRESS;
+            addr_t cfa = LLDB_INVALID_ADDRESS;
 
             // If we are going to show inlined stack frames as actual frames,
             // we need to calculate all concrete frames first, then iterate
@@ -77,12 +79,13 @@
                     // if we need to
                     if (m_frames.empty())
                     {
+                        cfa = m_thread.m_reg_context_sp->GetSP();
                         m_thread.GetRegisterContext();
                         unwind_frame_sp.reset (new StackFrame (m_frames.size(), 
                                                                idx, 
                                                                m_thread, 
                                                                m_thread.m_reg_context_sp, 
-                                                               m_thread.m_reg_context_sp->GetSP(), 
+                                                               cfa, 
                                                                m_thread.m_reg_context_sp->GetPC(), 
                                                                NULL));
                         m_frames.push_back (unwind_frame_sp);
@@ -90,6 +93,7 @@
                     else
                     {
                         unwind_frame_sp = m_frames.front();
+                        cfa = unwind_frame_sp->m_id.GetCallFrameAddress();
                     }
                 }
                 else
@@ -100,48 +104,64 @@
                     m_frames.push_back (unwind_frame_sp);
                 }
 
-                Block *block = unwind_frame_sp->GetSymbolContext (eSymbolContextBlock).block;
+                Block *unwind_block = unwind_frame_sp->GetSymbolContext (eSymbolContextBlock).block;
                 
-                if (block)
+                if (unwind_block)
                 {
-                    for (block = block->GetContainingInlinedBlock(); block != NULL; block = block->GetInlinedParent ())
+                    Block *inlined_block = unwind_block->GetContainingInlinedBlock();
+                    if (inlined_block)
                     {
-                        SymbolContext inline_sc;
-                        Block *parent_block = block->GetInlinedParent();
+                        for (; inlined_block != NULL; inlined_block = inlined_block->GetInlinedParent ())
+                        {
+                            SymbolContext inline_sc;
+                            Block *parent_block = inlined_block->GetInlinedParent();
 
-                        const bool is_inlined_frame = parent_block != NULL;
-                    
-                        if (parent_block == NULL)
-                            parent_block = block->GetParent();
+                            const bool is_inlined_frame = parent_block != NULL;
                         
-                        parent_block->CalculateSymbolContext (&inline_sc);
-                    
-                        Address previous_frame_lookup_addr (m_frames.back()->GetFrameCodeAddress());
-                        if (unwind_frame_sp->GetFrameIndex() > 0 && m_frames.back().get() == unwind_frame_sp.get())
-                            previous_frame_lookup_addr.Slide (-1);
-                    
-                        AddressRange range;
-                        block->GetRangeContainingAddress (previous_frame_lookup_addr, range);
-                    
-                        const InlineFunctionInfo* inline_info = block->InlinedFunctionInfo();
-                        assert (inline_info);
-                        inline_sc.line_entry.range.GetBaseAddress() = m_frames.back()->GetFrameCodeAddress();
-                        inline_sc.line_entry.file = inline_info->GetCallSite().GetFile();
-                        inline_sc.line_entry.line = inline_info->GetCallSite().GetLine();
-                        inline_sc.line_entry.column = inline_info->GetCallSite().GetColumn();
-                                        
-                        StackFrameSP frame_sp(new StackFrame (m_frames.size(),
-                                                              idx,
-                                                              m_thread,
-                                                              unwind_frame_sp->GetRegisterContextSP (),
-                                                              unwind_frame_sp->GetStackID().GetCallFrameAddress(),  // CFA
-                                                              range.GetBaseAddress(),
-                                                              &inline_sc));                                           // The symbol context for this inline frame
+                            if (parent_block == NULL)
+                                parent_block = inlined_block->GetParent();
+                            
+                            parent_block->CalculateSymbolContext (&inline_sc);
                         
-                        if (is_inlined_frame)
-                            frame_sp->SetInlineBlockID (block->GetID());
+                            Address previous_frame_lookup_addr (m_frames.back()->GetFrameCodeAddress());
+                            if (unwind_frame_sp->GetFrameIndex() > 0 && m_frames.back().get() == unwind_frame_sp.get())
+                                previous_frame_lookup_addr.Slide (-1);
                         
-                        m_frames.push_back (frame_sp);
+                            AddressRange range;
+                            inlined_block->GetRangeContainingAddress (previous_frame_lookup_addr, range);
+                        
+                            const InlineFunctionInfo* inline_info = inlined_block->InlinedFunctionInfo();
+                            assert (inline_info);
+                            inline_sc.line_entry.range.GetBaseAddress() = m_frames.back()->GetFrameCodeAddress();
+                            inline_sc.line_entry.file = inline_info->GetCallSite().GetFile();
+                            inline_sc.line_entry.line = inline_info->GetCallSite().GetLine();
+                            inline_sc.line_entry.column = inline_info->GetCallSite().GetColumn();
+                                            
+                            StackFrameSP frame_sp(new StackFrame (m_frames.size(),
+                                                                  idx,
+                                                                  m_thread,
+                                                                  unwind_frame_sp->GetRegisterContextSP (),
+                                                                  cfa,
+                                                                  range.GetBaseAddress(),
+                                                                  &inline_sc));                                           // The symbol context for this inline frame
+                            
+                            if (is_inlined_frame)
+                            {
+                                // Use the block with the inlined function info
+                                // as the symbol context since we want this frame
+                                // to have only the variables for the inlined function
+                                frame_sp->SetSymbolContextScope (parent_block);
+                            }
+                            else
+                            {
+                                // This block is not inlined with means it has no
+                                // inlined parents either, so we want to use the top
+                                // most function block.
+                                frame_sp->SetSymbolContextScope (&unwind_frame_sp->GetSymbolContext (eSymbolContextFunction).function->GetBlock(false));
+                            }
+                            
+                            m_frames.push_back (frame_sp);
+                        }
                     }
                 }
             }
@@ -188,34 +208,15 @@
                     if (curr_frame == NULL || prev_frame == NULL)
                         break;
 
-                    // Do a quick sanity check to see if the CFA values are the same.
-                    if (curr_frame->m_id.GetCallFrameAddress() != prev_frame->m_id.GetCallFrameAddress())
+                    // Check the stack ID to make sure they are equal
+                    if (curr_frame->GetStackID() != prev_frame->GetStackID())
                         break;
 
-                    // Now check our function or symbol
-                    SymbolContext curr_sc (curr_frame->GetSymbolContext (eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
-                    SymbolContext prev_sc (prev_frame->GetSymbolContext (eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
-                    if (curr_sc.function && curr_sc.function == prev_sc.function)
-                    {
-                        // Same function
-                        if (curr_sc.block != prev_sc.block)
-                        {
-                            // Same function different block
-                            if (m_show_inlined_frames)
-                                break;
-                        }
-                    }
-                    else if (curr_sc.symbol && curr_sc.symbol == prev_sc.symbol)
-                    {
-                        // Same symbol
-                    }
-                    else if (curr_frame->GetFrameCodeAddress() != prev_frame->GetFrameCodeAddress())
-                    {
-                        // No symbols for this frame and the PC was different
-                        break;
-                    }
-
-                    curr_frame->UpdateCurrentFrameFromPreviousFrame (*prev_frame);
+                    prev_frame->UpdatePreviousFrameFromCurrentFrame (*curr_frame);
+                    // Now copy the fixed up previous frame into the current frames
+                    // so the pointer doesn't change
+                    m_frames[curr_frame_idx] = prev_frame_sp;
+                    //curr_frame->UpdateCurrentFrameFromPreviousFrame (*prev_frame);
                     
 #if defined (DEBUG_STACK_FRAMES)
                     s.Printf("\n    Copying previous frame to current frame");
@@ -253,7 +254,10 @@
         StackFrame *frame = (*pos).get();
         s->Printf("%p: ", frame);
         if (frame)
+        {
+            frame->GetStackID().Dump (s);
             frame->Dump(s, true);
+        }
         else
             s->Printf("frame #%u", std::distance (begin, pos));
         s->EOL();
@@ -289,17 +293,6 @@
                                         m_thread.m_reg_context_sp->GetPC(), 
                                         NULL));
         
-        if (m_show_inlined_frames)
-        {
-            Block *block = frame_sp->GetSymbolContext (eSymbolContextBlock).block;
-            
-            if (block)
-            {
-                Block *inline_block = block->GetContainingInlinedBlock();
-                if (inline_block)
-                    frame_sp->SetInlineBlockID (inline_block->GetID());
-            }
-        }
         SetFrameAtIndex(idx, frame_sp);
     }
     else if (idx < GetNumFrames())
@@ -318,11 +311,23 @@
                 if (unwinder->GetFrameInfoAtIndex(idx, cfa, pc))
                 {
                     frame_sp.reset (new StackFrame (idx, idx, m_thread, cfa, pc, NULL));
+                    
+                    Function *function = frame_sp->GetSymbolContext (eSymbolContextFunction).function;
+                    if (function)
+                    {
+                        // When we aren't showing inline functions we always use
+                        // the top most function block as the scope.
+                        frame_sp->SetSymbolContextScope (&function->GetBlock(false));
+                    }
+                    else 
+                    {
+                        // Set the symbol scope from the symbol regardless if it is NULL or valid.
+                        frame_sp->SetSymbolContextScope (frame_sp->GetSymbolContext (eSymbolContextSymbol).symbol);
+                    }
                     SetFrameAtIndex(idx, frame_sp);
                 }
             }
         }
-        
     }
     return frame_sp;
 }
diff --git a/source/Target/StackID.cpp b/source/Target/StackID.cpp
index 6d34d3b..215e85e 100644
--- a/source/Target/StackID.cpp
+++ b/source/Target/StackID.cpp
@@ -13,15 +13,36 @@
 // C++ Includes
 // Other libraries and framework includes
 // Project includes
+#include "lldb/Core/Stream.h"
+#include "lldb/Symbol/Block.h"
+#include "lldb/Symbol/Symbol.h"
+#include "lldb/Symbol/SymbolContext.h"
 
 using namespace lldb_private;
 
 
+void
+StackID::Dump (Stream *s)
+{
+    s->Printf("StackID (start_pc = 0x%16.16llx, cfa = 0x%16.16llx, symbol_scope = %p", (uint64_t)m_start_pc, (uint64_t)m_cfa, m_symbol_scope);
+    if (m_symbol_scope)
+    {
+        SymbolContext sc;
+    
+        m_symbol_scope->CalculateSymbolContext (&sc);
+        if (sc.block)
+            s->Printf(" (Block {0x%8.8x})", sc.block->GetID());
+        else if (sc.symbol)
+            s->Printf(" (Symbol{0x%8.8x})", sc.symbol->GetID());
+    }
+    s->PutCString(") ");
+}
+
 bool
 lldb_private::operator== (const StackID& lhs, const StackID& rhs)
 {
     return lhs.GetCallFrameAddress()    == rhs.GetCallFrameAddress()    && 
-           lhs.GetInlineBlockID()       == rhs.GetInlineBlockID()       &&
+           lhs.GetSymbolContextScope()  == rhs.GetSymbolContextScope()  &&
            lhs.GetStartAddress()        == rhs.GetStartAddress();
 }
 
@@ -29,14 +50,12 @@
 lldb_private::operator!= (const StackID& lhs, const StackID& rhs)
 {
     return lhs.GetCallFrameAddress()    != rhs.GetCallFrameAddress()    || 
-           lhs.GetInlineBlockID()       != rhs.GetInlineBlockID()       || 
+           lhs.GetSymbolContextScope()  != rhs.GetSymbolContextScope()  || 
            lhs.GetStartAddress()        != rhs.GetStartAddress();
 }
 
 bool
 lldb_private::operator< (const StackID& lhs, const StackID& rhs)
 {
-    if (lhs.GetCallFrameAddress() < rhs.GetCallFrameAddress())
-        return true;
-    return lhs.GetInlineBlockID() < rhs.GetInlineBlockID();
+    return lhs.GetCallFrameAddress()    < rhs.GetCallFrameAddress();
 }