2010-06-09 00:52:24 +08:00
|
|
|
//===-- StackFrameList.cpp --------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-08-25 08:35:26 +08:00
|
|
|
#include "lldb/Target/StackFrameList.h"
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
2010-08-28 02:24:16 +08:00
|
|
|
#include "lldb/Core/StreamFile.h"
|
2010-08-25 08:35:26 +08:00
|
|
|
#include "lldb/Symbol/Block.h"
|
|
|
|
#include "lldb/Symbol/Function.h"
|
2010-08-31 02:11:35 +08:00
|
|
|
#include "lldb/Symbol/Symbol.h"
|
2010-08-25 08:35:26 +08:00
|
|
|
#include "lldb/Target/RegisterContext.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/StackFrame.h"
|
2010-08-25 08:35:26 +08:00
|
|
|
#include "lldb/Target/Thread.h"
|
|
|
|
#include "lldb/Target/Unwind.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-08-28 02:24:16 +08:00
|
|
|
//#define DEBUG_STACK_FRAMES 1
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// StackFrameList constructor
|
|
|
|
//----------------------------------------------------------------------
|
2010-09-04 01:10:42 +08:00
|
|
|
StackFrameList::StackFrameList
|
|
|
|
(
|
|
|
|
Thread &thread,
|
|
|
|
const lldb::StackFrameListSP &prev_frames_sp,
|
|
|
|
bool show_inline_frames
|
|
|
|
) :
|
2010-08-25 08:35:26 +08:00
|
|
|
m_thread (thread),
|
2010-09-04 01:10:42 +08:00
|
|
|
m_prev_frames_sp (prev_frames_sp),
|
2010-08-25 08:35:26 +08:00
|
|
|
m_show_inlined_frames (show_inline_frames),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_mutex (Mutex::eMutexTypeRecursive),
|
2010-08-28 02:24:16 +08:00
|
|
|
m_frames (),
|
2010-08-27 05:32:51 +08:00
|
|
|
m_selected_frame_idx (0)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Destructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
StackFrameList::~StackFrameList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t
|
2010-09-04 01:10:42 +08:00
|
|
|
StackFrameList::GetNumFrames (bool can_create)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_mutex);
|
2010-08-25 08:35:26 +08:00
|
|
|
|
2010-09-04 01:10:42 +08:00
|
|
|
if (can_create && m_frames.size() <= 1)
|
2010-08-25 08:35:26 +08:00
|
|
|
{
|
2010-08-28 02:24:16 +08:00
|
|
|
if (m_show_inlined_frames)
|
2010-08-25 08:35:26 +08:00
|
|
|
{
|
2010-08-28 02:24:16 +08:00
|
|
|
#if defined (DEBUG_STACK_FRAMES)
|
|
|
|
StreamFile s(stdout);
|
|
|
|
#endif
|
2010-08-25 08:35:26 +08:00
|
|
|
Unwind *unwinder = m_thread.GetUnwinder ();
|
2010-08-31 02:11:35 +08:00
|
|
|
addr_t pc = LLDB_INVALID_ADDRESS;
|
|
|
|
addr_t cfa = LLDB_INVALID_ADDRESS;
|
2010-08-28 02:24:16 +08:00
|
|
|
|
2010-08-25 08:35:26 +08:00
|
|
|
// If we are going to show inlined stack frames as actual frames,
|
|
|
|
// we need to calculate all concrete frames first, then iterate
|
|
|
|
// through all of them and count up how many inlined functions are
|
2010-08-28 02:24:16 +08:00
|
|
|
// in each frame.
|
|
|
|
const uint32_t unwind_frame_count = unwinder->GetFrameCount();
|
2010-08-25 08:35:26 +08:00
|
|
|
|
2010-08-28 02:24:16 +08:00
|
|
|
StackFrameSP unwind_frame_sp;
|
|
|
|
for (uint32_t idx=0; idx<unwind_frame_count; ++idx)
|
2010-08-25 08:35:26 +08:00
|
|
|
{
|
|
|
|
if (idx == 0)
|
|
|
|
{
|
2010-08-28 02:24:16 +08:00
|
|
|
// We might have already created frame zero, only create it
|
|
|
|
// if we need to
|
|
|
|
if (m_frames.empty())
|
|
|
|
{
|
2010-08-31 02:11:35 +08:00
|
|
|
cfa = m_thread.m_reg_context_sp->GetSP();
|
2010-08-28 02:24:16 +08:00
|
|
|
m_thread.GetRegisterContext();
|
|
|
|
unwind_frame_sp.reset (new StackFrame (m_frames.size(),
|
|
|
|
idx,
|
|
|
|
m_thread,
|
|
|
|
m_thread.m_reg_context_sp,
|
2010-08-31 02:11:35 +08:00
|
|
|
cfa,
|
2010-08-28 02:24:16 +08:00
|
|
|
m_thread.m_reg_context_sp->GetPC(),
|
|
|
|
NULL));
|
|
|
|
m_frames.push_back (unwind_frame_sp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unwind_frame_sp = m_frames.front();
|
2010-08-31 02:11:35 +08:00
|
|
|
cfa = unwind_frame_sp->m_id.GetCallFrameAddress();
|
2010-08-28 02:24:16 +08:00
|
|
|
}
|
2010-08-25 08:35:26 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const bool success = unwinder->GetFrameInfoAtIndex(idx, cfa, pc);
|
|
|
|
assert (success);
|
2010-08-28 02:24:16 +08:00
|
|
|
unwind_frame_sp.reset (new StackFrame (m_frames.size(), idx, m_thread, cfa, pc, NULL));
|
|
|
|
m_frames.push_back (unwind_frame_sp);
|
2010-08-25 08:35:26 +08:00
|
|
|
}
|
|
|
|
|
2010-08-31 02:11:35 +08:00
|
|
|
Block *unwind_block = unwind_frame_sp->GetSymbolContext (eSymbolContextBlock).block;
|
2010-08-28 02:24:16 +08:00
|
|
|
|
2010-08-31 02:11:35 +08:00
|
|
|
if (unwind_block)
|
2010-08-25 08:35:26 +08:00
|
|
|
{
|
2010-08-31 02:11:35 +08:00
|
|
|
Block *inlined_block = unwind_block->GetContainingInlinedBlock();
|
|
|
|
if (inlined_block)
|
2010-08-25 08:35:26 +08:00
|
|
|
{
|
2010-08-31 02:11:35 +08:00
|
|
|
for (; inlined_block != NULL; inlined_block = inlined_block->GetInlinedParent ())
|
|
|
|
{
|
|
|
|
SymbolContext inline_sc;
|
|
|
|
Block *parent_block = inlined_block->GetInlinedParent();
|
2010-08-28 02:24:16 +08:00
|
|
|
|
2010-08-31 02:11:35 +08:00
|
|
|
const bool is_inlined_frame = parent_block != NULL;
|
2010-08-28 02:24:16 +08:00
|
|
|
|
2010-08-31 02:11:35 +08:00
|
|
|
if (parent_block == NULL)
|
|
|
|
parent_block = inlined_block->GetParent();
|
|
|
|
|
|
|
|
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);
|
2010-08-28 02:24:16 +08:00
|
|
|
|
2010-08-31 02:11:35 +08:00
|
|
|
AddressRange range;
|
|
|
|
inlined_block->GetRangeContainingAddress (previous_frame_lookup_addr, range);
|
2010-08-28 02:24:16 +08:00
|
|
|
|
2010-09-07 12:20:48 +08:00
|
|
|
const InlineFunctionInfo* inline_info = inlined_block->GetInlinedFunctionInfo();
|
2010-08-31 02:11:35 +08:00
|
|
|
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);
|
|
|
|
}
|
2010-08-28 02:24:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-09-04 01:10:42 +08:00
|
|
|
|
|
|
|
if (m_prev_frames_sp)
|
2010-08-28 02:24:16 +08:00
|
|
|
{
|
2010-09-04 01:10:42 +08:00
|
|
|
StackFrameList *prev_frames = m_prev_frames_sp.get();
|
2010-08-28 02:24:16 +08:00
|
|
|
StackFrameList *curr_frames = this;
|
|
|
|
|
|
|
|
#if defined (DEBUG_STACK_FRAMES)
|
2010-08-28 05:47:54 +08:00
|
|
|
s.PutCString("\nprev_frames:\n");
|
2010-08-28 02:24:16 +08:00
|
|
|
prev_frames->Dump (&s);
|
2010-08-28 05:47:54 +08:00
|
|
|
s.PutCString("\ncurr_frames:\n");
|
2010-08-28 02:24:16 +08:00
|
|
|
curr_frames->Dump (&s);
|
|
|
|
s.EOL();
|
|
|
|
#endif
|
|
|
|
size_t curr_frame_num, prev_frame_num;
|
|
|
|
|
|
|
|
for (curr_frame_num = curr_frames->m_frames.size(), prev_frame_num = prev_frames->m_frames.size();
|
|
|
|
curr_frame_num > 0 && prev_frame_num > 0;
|
|
|
|
--curr_frame_num, --prev_frame_num)
|
|
|
|
{
|
|
|
|
const size_t curr_frame_idx = curr_frame_num-1;
|
|
|
|
const size_t prev_frame_idx = prev_frame_num-1;
|
|
|
|
StackFrameSP curr_frame_sp (curr_frames->m_frames[curr_frame_idx]);
|
|
|
|
StackFrameSP prev_frame_sp (prev_frames->m_frames[prev_frame_idx]);
|
|
|
|
|
|
|
|
#if defined (DEBUG_STACK_FRAMES)
|
2010-09-04 01:10:42 +08:00
|
|
|
s.Printf("\n\nCurr frame #%u ", curr_frame_idx);
|
2010-08-28 02:24:16 +08:00
|
|
|
if (curr_frame_sp)
|
2010-09-04 01:10:42 +08:00
|
|
|
curr_frame_sp->Dump (&s, true, false);
|
2010-08-28 02:24:16 +08:00
|
|
|
else
|
|
|
|
s.PutCString("NULL");
|
2010-09-04 01:10:42 +08:00
|
|
|
s.Printf("\nPrev frame #%u ", prev_frame_idx);
|
2010-08-28 02:24:16 +08:00
|
|
|
if (prev_frame_sp)
|
2010-09-04 01:10:42 +08:00
|
|
|
prev_frame_sp->Dump (&s, true, false);
|
2010-08-28 02:24:16 +08:00
|
|
|
else
|
|
|
|
s.PutCString("NULL");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
StackFrame *curr_frame = curr_frame_sp.get();
|
|
|
|
StackFrame *prev_frame = prev_frame_sp.get();
|
|
|
|
|
|
|
|
if (curr_frame == NULL || prev_frame == NULL)
|
|
|
|
break;
|
2010-08-26 10:28:22 +08:00
|
|
|
|
2010-08-31 02:11:35 +08:00
|
|
|
// Check the stack ID to make sure they are equal
|
|
|
|
if (curr_frame->GetStackID() != prev_frame->GetStackID())
|
2010-08-28 02:24:16 +08:00
|
|
|
break;
|
|
|
|
|
2010-08-31 02:11:35 +08:00
|
|
|
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);
|
2010-08-28 02:24:16 +08:00
|
|
|
|
|
|
|
#if defined (DEBUG_STACK_FRAMES)
|
2010-08-28 05:47:54 +08:00
|
|
|
s.Printf("\n Copying previous frame to current frame");
|
2010-08-28 02:24:16 +08:00
|
|
|
#endif
|
2010-08-25 08:35:26 +08:00
|
|
|
}
|
2010-08-28 02:24:16 +08:00
|
|
|
// We are done with the old stack frame list, we can release it now
|
2010-09-04 01:10:42 +08:00
|
|
|
m_prev_frames_sp.reset();
|
2010-08-25 08:35:26 +08:00
|
|
|
}
|
2010-08-28 05:47:54 +08:00
|
|
|
|
|
|
|
#if defined (DEBUG_STACK_FRAMES)
|
|
|
|
s.PutCString("\n\nNew frames:\n");
|
|
|
|
Dump (&s);
|
|
|
|
s.EOL();
|
|
|
|
#endif
|
2010-08-25 08:35:26 +08:00
|
|
|
}
|
2010-08-28 02:24:16 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_frames.resize(m_thread.GetUnwinder()->GetFrameCount());
|
|
|
|
}
|
2010-08-25 08:35:26 +08:00
|
|
|
}
|
2010-08-28 02:24:16 +08:00
|
|
|
return m_frames.size();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-08-28 02:24:16 +08:00
|
|
|
void
|
|
|
|
StackFrameList::Dump (Stream *s)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-08-28 02:24:16 +08:00
|
|
|
if (s == NULL)
|
|
|
|
return;
|
|
|
|
Mutex::Locker locker (m_mutex);
|
2010-08-25 08:35:26 +08:00
|
|
|
|
2010-08-28 02:24:16 +08:00
|
|
|
const_iterator pos, begin = m_frames.begin(), end = m_frames.end();
|
|
|
|
for (pos = begin; pos != end; ++pos)
|
|
|
|
{
|
|
|
|
StackFrame *frame = (*pos).get();
|
|
|
|
s->Printf("%p: ", frame);
|
|
|
|
if (frame)
|
2010-08-31 02:11:35 +08:00
|
|
|
{
|
|
|
|
frame->GetStackID().Dump (s);
|
2010-10-04 09:05:56 +08:00
|
|
|
frame->DumpUsingSettingsFormat (s);
|
2010-08-31 02:11:35 +08:00
|
|
|
}
|
2010-08-28 02:24:16 +08:00
|
|
|
else
|
|
|
|
s->Printf("frame #%u", std::distance (begin, pos));
|
|
|
|
s->EOL();
|
|
|
|
}
|
|
|
|
s->EOL();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
StackFrameSP
|
2010-08-25 08:35:26 +08:00
|
|
|
StackFrameList::GetFrameAtIndex (uint32_t idx)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
StackFrameSP frame_sp;
|
2010-08-28 02:24:16 +08:00
|
|
|
Mutex::Locker locker (m_mutex);
|
|
|
|
if (idx < m_frames.size())
|
|
|
|
frame_sp = m_frames[idx];
|
2010-08-25 08:35:26 +08:00
|
|
|
|
2010-08-28 02:24:16 +08:00
|
|
|
if (frame_sp)
|
|
|
|
return frame_sp;
|
2010-08-25 08:35:26 +08:00
|
|
|
|
2010-08-28 02:24:16 +08:00
|
|
|
// Special case the first frame (idx == 0) so that we don't need to
|
|
|
|
// know how many stack frames there are to get it. If we need any other
|
|
|
|
// frames, then we do need to know if "idx" is a valid index.
|
|
|
|
if (idx == 0)
|
|
|
|
{
|
|
|
|
// If this is the first frame, we want to share the thread register
|
|
|
|
// context with the stack frame at index zero.
|
|
|
|
m_thread.GetRegisterContext();
|
|
|
|
assert (m_thread.m_reg_context_sp.get());
|
|
|
|
frame_sp.reset (new StackFrame (0,
|
|
|
|
0,
|
|
|
|
m_thread,
|
|
|
|
m_thread.m_reg_context_sp,
|
|
|
|
m_thread.m_reg_context_sp->GetSP(),
|
|
|
|
m_thread.m_reg_context_sp->GetPC(),
|
|
|
|
NULL));
|
|
|
|
|
|
|
|
SetFrameAtIndex(idx, frame_sp);
|
|
|
|
}
|
|
|
|
else if (idx < GetNumFrames())
|
|
|
|
{
|
2010-08-26 10:28:22 +08:00
|
|
|
if (m_show_inlined_frames)
|
|
|
|
{
|
2010-08-28 02:24:16 +08:00
|
|
|
// When inline frames are enabled we cache up all frames in GetNumFrames()
|
|
|
|
frame_sp = m_frames[idx];
|
2010-08-26 10:28:22 +08:00
|
|
|
}
|
2010-08-25 08:35:26 +08:00
|
|
|
else
|
|
|
|
{
|
2010-08-28 02:24:16 +08:00
|
|
|
Unwind *unwinder = m_thread.GetUnwinder ();
|
|
|
|
if (unwinder)
|
|
|
|
{
|
|
|
|
addr_t pc, cfa;
|
|
|
|
if (unwinder->GetFrameInfoAtIndex(idx, cfa, pc))
|
|
|
|
{
|
|
|
|
frame_sp.reset (new StackFrame (idx, idx, m_thread, cfa, pc, NULL));
|
2010-08-31 02:11:35 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2010-08-28 02:24:16 +08:00
|
|
|
SetFrameAtIndex(idx, frame_sp);
|
|
|
|
}
|
|
|
|
}
|
2010-08-25 08:35:26 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return frame_sp;
|
|
|
|
}
|
|
|
|
|
2011-01-07 06:15:06 +08:00
|
|
|
StackFrameSP
|
|
|
|
StackFrameList::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx)
|
|
|
|
{
|
|
|
|
// First try assuming the unwind index is the same as the frame index. The
|
|
|
|
// unwind index is always greater than or equal to the frame index, so it
|
|
|
|
// is a good place to start. If we have inlined frames we might have 5
|
|
|
|
// concrete frames (frame unwind indexes go from 0-4), but we might have 15
|
|
|
|
// frames after we make all the inlined frames. Most of the time the unwind
|
|
|
|
// frame index (or the concrete frame index) is the same as the frame index.
|
|
|
|
uint32_t frame_idx = unwind_idx;
|
|
|
|
StackFrameSP frame_sp (GetFrameAtIndex (frame_idx));
|
|
|
|
while (frame_sp)
|
|
|
|
{
|
|
|
|
if (frame_sp->GetFrameIndex() == unwind_idx)
|
|
|
|
break;
|
|
|
|
frame_sp = GetFrameAtIndex (++frame_idx);
|
|
|
|
}
|
|
|
|
return frame_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 08:35:26 +08:00
|
|
|
bool
|
2010-08-28 02:24:16 +08:00
|
|
|
StackFrameList::SetFrameAtIndex (uint32_t idx, StackFrameSP &frame_sp)
|
2010-08-25 08:35:26 +08:00
|
|
|
{
|
2010-08-28 02:24:16 +08:00
|
|
|
if (idx >= m_frames.size())
|
|
|
|
m_frames.resize(idx + 1);
|
2010-08-25 08:35:26 +08:00
|
|
|
// Make sure allocation succeeded by checking bounds again
|
2010-08-28 02:24:16 +08:00
|
|
|
if (idx < m_frames.size())
|
2010-08-25 08:35:26 +08:00
|
|
|
{
|
2010-08-28 02:24:16 +08:00
|
|
|
m_frames[idx] = frame_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false; // resize failed, out of memory?
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2010-08-27 05:32:51 +08:00
|
|
|
StackFrameList::GetSelectedFrameIndex () const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_mutex);
|
2010-08-27 05:32:51 +08:00
|
|
|
return m_selected_frame_idx;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t
|
2010-08-27 05:32:51 +08:00
|
|
|
StackFrameList::SetSelectedFrame (lldb_private::StackFrame *frame)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_mutex);
|
2010-08-25 08:35:26 +08:00
|
|
|
const_iterator pos;
|
2010-08-28 02:24:16 +08:00
|
|
|
const_iterator begin = m_frames.begin();
|
|
|
|
const_iterator end = m_frames.end();
|
2010-06-09 00:52:24 +08:00
|
|
|
for (pos = begin; pos != end; ++pos)
|
|
|
|
{
|
|
|
|
if (pos->get() == frame)
|
|
|
|
{
|
2010-08-27 05:32:51 +08:00
|
|
|
m_selected_frame_idx = std::distance (begin, pos);
|
|
|
|
return m_selected_frame_idx;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
2010-08-27 05:32:51 +08:00
|
|
|
m_selected_frame_idx = 0;
|
|
|
|
return m_selected_frame_idx;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mark a stack frame as the current frame using the frame index
|
|
|
|
void
|
2010-08-27 05:32:51 +08:00
|
|
|
StackFrameList::SetSelectedFrameByIndex (uint32_t idx)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_mutex);
|
2010-08-27 05:32:51 +08:00
|
|
|
m_selected_frame_idx = idx;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// The thread has been run, reset the number stack frames to zero so we can
|
|
|
|
// determine how many frames we have lazily.
|
|
|
|
void
|
|
|
|
StackFrameList::Clear ()
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_mutex);
|
2010-08-28 02:24:16 +08:00
|
|
|
m_frames.clear();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StackFrameList::InvalidateFrames (uint32_t start_idx)
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_mutex);
|
2010-08-25 08:35:26 +08:00
|
|
|
if (m_show_inlined_frames)
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
else
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-08-28 02:24:16 +08:00
|
|
|
const size_t num_frames = m_frames.size();
|
2010-08-25 08:35:26 +08:00
|
|
|
while (start_idx < num_frames)
|
|
|
|
{
|
2010-08-28 02:24:16 +08:00
|
|
|
m_frames[start_idx].reset();
|
2010-08-25 08:35:26 +08:00
|
|
|
++start_idx;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
2010-09-04 01:10:42 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
StackFrameList::Merge (std::auto_ptr<StackFrameList>& curr_ap, lldb::StackFrameListSP& prev_sp)
|
|
|
|
{
|
|
|
|
Mutex::Locker curr_locker (curr_ap.get() ? curr_ap->m_mutex.GetMutex() : NULL);
|
|
|
|
Mutex::Locker prev_locker (prev_sp.get() ? prev_sp->m_mutex.GetMutex() : NULL);
|
|
|
|
|
|
|
|
#if defined (DEBUG_STACK_FRAMES)
|
|
|
|
StreamFile s(stdout);
|
|
|
|
s.PutCString("\n\nStackFrameList::Merge():\nPrev:\n");
|
|
|
|
if (prev_sp.get())
|
|
|
|
prev_sp->Dump (&s);
|
|
|
|
else
|
|
|
|
s.PutCString ("NULL");
|
|
|
|
s.PutCString("\nCurr:\n");
|
|
|
|
if (curr_ap.get())
|
|
|
|
curr_ap->Dump (&s);
|
|
|
|
else
|
|
|
|
s.PutCString ("NULL");
|
|
|
|
s.EOL();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (curr_ap.get() == NULL || curr_ap->GetNumFrames (false) == 0)
|
|
|
|
{
|
|
|
|
#if defined (DEBUG_STACK_FRAMES)
|
|
|
|
s.PutCString("No current frames, leave previous frames alone...\n");
|
|
|
|
#endif
|
|
|
|
curr_ap.release();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prev_sp.get() == NULL || prev_sp->GetNumFrames (false) == 0)
|
|
|
|
{
|
|
|
|
#if defined (DEBUG_STACK_FRAMES)
|
|
|
|
s.PutCString("No previous frames, so use current frames...\n");
|
|
|
|
#endif
|
|
|
|
// We either don't have any previous frames, or since we have more than
|
|
|
|
// one current frames it means we have all the frames and can safely
|
|
|
|
// replace our previous frames.
|
|
|
|
prev_sp.reset (curr_ap.release());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint32_t num_curr_frames = curr_ap->GetNumFrames (false);
|
|
|
|
|
|
|
|
if (num_curr_frames > 1)
|
|
|
|
{
|
|
|
|
#if defined (DEBUG_STACK_FRAMES)
|
|
|
|
s.PutCString("We have more than one current frame, so use current frames...\n");
|
|
|
|
#endif
|
|
|
|
// We have more than one current frames it means we have all the frames
|
|
|
|
// and can safely replace our previous frames.
|
|
|
|
prev_sp.reset (curr_ap.release());
|
|
|
|
|
|
|
|
#if defined (DEBUG_STACK_FRAMES)
|
|
|
|
s.PutCString("\nMerged:\n");
|
|
|
|
prev_sp->Dump (&s);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
StackFrameSP prev_frame_zero_sp(prev_sp->GetFrameAtIndex (0));
|
|
|
|
StackFrameSP curr_frame_zero_sp(curr_ap->GetFrameAtIndex (0));
|
|
|
|
StackID curr_stack_id (curr_frame_zero_sp->GetStackID());
|
|
|
|
StackID prev_stack_id (prev_frame_zero_sp->GetStackID());
|
|
|
|
|
|
|
|
//const uint32_t num_prev_frames = prev_sp->GetNumFrames (false);
|
|
|
|
|
|
|
|
#if defined (DEBUG_STACK_FRAMES)
|
|
|
|
s.Printf("\n%u previous frames with one current frame\n", num_prev_frames);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// We have only a single current frame
|
|
|
|
// Our previous stack frames only had a single frame as well...
|
|
|
|
if (curr_stack_id == prev_stack_id)
|
|
|
|
{
|
|
|
|
#if defined (DEBUG_STACK_FRAMES)
|
|
|
|
s.Printf("\nPrevious frame #0 is same as current frame #0, merge the cached data\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
curr_frame_zero_sp->UpdateCurrentFrameFromPreviousFrame (*prev_frame_zero_sp);
|
|
|
|
// prev_frame_zero_sp->UpdatePreviousFrameFromCurrentFrame (*curr_frame_zero_sp);
|
|
|
|
// prev_sp->SetFrameAtIndex (0, prev_frame_zero_sp);
|
|
|
|
}
|
|
|
|
else if (curr_stack_id < prev_stack_id)
|
|
|
|
{
|
|
|
|
#if defined (DEBUG_STACK_FRAMES)
|
|
|
|
s.Printf("\nCurrent frame #0 has a stack ID that is less than the previous frame #0, insert current frame zero in front of previous\n");
|
|
|
|
#endif
|
|
|
|
prev_sp->m_frames.insert (prev_sp->m_frames.begin(), curr_frame_zero_sp);
|
|
|
|
}
|
|
|
|
|
|
|
|
curr_ap.release();
|
|
|
|
|
|
|
|
#if defined (DEBUG_STACK_FRAMES)
|
|
|
|
s.PutCString("\nMerged:\n");
|
|
|
|
prev_sp->Dump (&s);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2010-09-24 01:40:12 +08:00
|
|
|
|
|
|
|
lldb::StackFrameSP
|
|
|
|
StackFrameList::GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr)
|
|
|
|
{
|
|
|
|
const_iterator pos;
|
|
|
|
const_iterator begin = m_frames.begin();
|
|
|
|
const_iterator end = m_frames.end();
|
|
|
|
lldb::StackFrameSP ret_sp;
|
|
|
|
|
|
|
|
for (pos = begin; pos != end; ++pos)
|
|
|
|
{
|
|
|
|
if (pos->get() == stack_frame_ptr)
|
|
|
|
{
|
|
|
|
ret_sp = (*pos);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret_sp;
|
|
|
|
}
|
|
|
|
|