diff options
| -rw-r--r-- | lldb/include/lldb/Target/Thread.h | 4 | ||||
| -rw-r--r-- | lldb/source/Target/ExecutionContext.cpp | 9 | ||||
| -rw-r--r-- | lldb/source/Target/StackFrameList.cpp | 37 |
3 files changed, 39 insertions, 11 deletions
diff --git a/lldb/include/lldb/Target/Thread.h b/lldb/include/lldb/Target/Thread.h index d0984c6d45a..cc47dc708dd 100644 --- a/lldb/include/lldb/Target/Thread.h +++ b/lldb/include/lldb/Target/Thread.h @@ -381,7 +381,9 @@ public: virtual lldb::StackFrameSP GetFrameWithStackID (const StackID &stack_id) { - return GetStackFrameList()->GetFrameWithStackID (stack_id); + if (stack_id.IsValid()) + return GetStackFrameList()->GetFrameWithStackID (stack_id); + return lldb::StackFrameSP(); } uint32_t diff --git a/lldb/source/Target/ExecutionContext.cpp b/lldb/source/Target/ExecutionContext.cpp index 6ab03553cbc..8b5731e8028 100644 --- a/lldb/source/Target/ExecutionContext.cpp +++ b/lldb/source/Target/ExecutionContext.cpp @@ -806,9 +806,12 @@ ExecutionContextRef::GetThreadSP () const lldb::StackFrameSP ExecutionContextRef::GetFrameSP () const { - lldb::ThreadSP thread_sp (GetThreadSP()); - if (thread_sp) - return thread_sp->GetFrameWithStackID (m_stack_id); + if (m_stack_id.IsValid()) + { + lldb::ThreadSP thread_sp (GetThreadSP()); + if (thread_sp) + return thread_sp->GetFrameWithStackID (m_stack_id); + } return lldb::StackFrameSP(); } diff --git a/lldb/source/Target/StackFrameList.cpp b/lldb/source/Target/StackFrameList.cpp index ef798cbb13a..69309dfae7b 100644 --- a/lldb/source/Target/StackFrameList.cpp +++ b/lldb/source/Target/StackFrameList.cpp @@ -595,19 +595,42 @@ StackFrameList::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx) return frame_sp; } +static bool +CompareStackID (const StackFrameSP &stack_sp, const StackID &stack_id) +{ + return stack_sp->GetStackID() < stack_id; +} + StackFrameSP StackFrameList::GetFrameWithStackID (const StackID &stack_id) { - uint32_t frame_idx = 0; StackFrameSP frame_sp; - do + + if (stack_id.IsValid()) { - frame_sp = GetFrameAtIndex (frame_idx); - if (frame_sp && frame_sp->GetStackID() == stack_id) - break; - frame_idx++; + Mutex::Locker locker (m_mutex); + uint32_t frame_idx = 0; + // Do a binary search in case the stack frame is already in our cache + collection::const_iterator begin = m_frames.begin(); + collection::const_iterator end = m_frames.end(); + if (begin != end) + { + collection::const_iterator pos = std::lower_bound (begin, end, stack_id, CompareStackID); + if (pos != end && (*pos)->GetStackID() == stack_id) + return *pos; + + if (m_frames.back()->GetStackID() < stack_id) + frame_idx = m_frames.size(); + } + do + { + frame_sp = GetFrameAtIndex (frame_idx); + if (frame_sp && frame_sp->GetStackID() == stack_id) + break; + frame_idx++; + } + while (frame_sp); } - while (frame_sp); return frame_sp; } |

