[StackFrame] Factor GetOnlyConcreteFramesUpTo out of GetFramesUpTo (NFC)

Splitting GetOnlyConcreteFramesUpTo will make it easier to implement
support for synthetic tail call frames in backtraces. This is just a
prep change, no functionality is affected.

llvm-svn: 338588
This commit is contained in:
Vedant Kumar 2018-08-01 17:07:40 +00:00
parent 6d302c93cc
commit eb8fa58e97
2 changed files with 195 additions and 190 deletions

View File

@ -83,6 +83,8 @@ protected:
void GetFramesUpTo(uint32_t end_idx);
void GetOnlyConcreteFramesUpTo(uint32_t end_idx, Unwind *unwinder);
bool GetAllFramesFetched() { return m_concrete_frames_fetched == UINT32_MAX; }
void SetAllFramesFetched() { m_concrete_frames_fetched = UINT32_MAX; }

View File

@ -226,8 +226,27 @@ void StackFrameList::SetCurrentInlinedDepth(uint32_t new_depth) {
m_current_inlined_pc = m_thread.GetRegisterContext()->GetPC();
}
void StackFrameList::GetOnlyConcreteFramesUpTo(uint32_t end_idx,
Unwind *unwinder) {
assert(m_thread.IsValid() && "Expected valid thread");
assert(m_frames.size() <= end_idx && "Expected there to be frames to fill");
if (end_idx < m_concrete_frames_fetched)
return;
if (!unwinder)
return;
uint32_t num_frames = unwinder->GetFramesUpTo(end_idx);
if (num_frames <= end_idx + 1) {
// Done unwinding.
m_concrete_frames_fetched = UINT32_MAX;
}
m_frames.resize(num_frames);
}
void StackFrameList::GetFramesUpTo(uint32_t end_idx) {
// this makes sure we do not fetch frames for an invalid thread
// Do not fetch frames for an invalid thread.
if (!m_thread.IsValid())
return;
@ -238,7 +257,11 @@ void StackFrameList::GetFramesUpTo(uint32_t end_idx) {
Unwind *unwinder = m_thread.GetUnwinder();
if (m_show_inlined_frames) {
if (!m_show_inlined_frames) {
GetOnlyConcreteFramesUpTo(end_idx, unwinder);
return;
}
#if defined(DEBUG_STACK_FRAMES)
StreamFile s(stdout, false);
#endif
@ -264,7 +287,7 @@ void StackFrameList::GetFramesUpTo(uint32_t end_idx) {
lldb::addr_t cfa = LLDB_INVALID_ADDRESS;
if (idx == 0) {
// We might have already created frame zero, only create it if we need
// to
// to.
if (m_frames.empty()) {
RegisterContextSP reg_ctx_sp(m_thread.GetRegisterContext());
@ -273,16 +296,15 @@ void StackFrameList::GetFramesUpTo(uint32_t end_idx) {
unwinder && unwinder->GetFrameInfoAtIndex(idx, cfa, pc);
// There shouldn't be any way not to get the frame info for frame
// 0. But if the unwinder can't make one, lets make one by hand
// with the
// SP as the CFA and see if that gets any further.
// with the SP as the CFA and see if that gets any further.
if (!success) {
cfa = reg_ctx_sp->GetSP();
pc = reg_ctx_sp->GetPC();
}
unwind_frame_sp.reset(new StackFrame(m_thread.shared_from_this(),
m_frames.size(), idx,
reg_ctx_sp, cfa, pc, nullptr));
m_frames.size(), idx, reg_ctx_sp,
cfa, pc, nullptr));
m_frames.push_back(unwind_frame_sp);
}
} else {
@ -301,8 +323,8 @@ void StackFrameList::GetFramesUpTo(uint32_t end_idx) {
const bool stop_id_is_valid = false;
const bool is_history_frame = false;
unwind_frame_sp.reset(new StackFrame(
m_thread.shared_from_this(), m_frames.size(), idx, cfa,
cfa_is_valid, pc, 0, stop_id_is_valid, is_history_frame, nullptr));
m_thread.shared_from_this(), m_frames.size(), idx, cfa, cfa_is_valid,
pc, 0, stop_id_is_valid, is_history_frame, nullptr));
m_frames.push_back(unwind_frame_sp);
}
@ -355,11 +377,6 @@ void StackFrameList::GetFramesUpTo(uint32_t end_idx) {
StackFrameList *prev_frames = m_prev_frames_sp.get();
StackFrameList *curr_frames = this;
// curr_frames->m_current_inlined_depth = prev_frames->m_current_inlined_depth;
// curr_frames->m_current_inlined_pc = prev_frames->m_current_inlined_pc;
// printf ("GetFramesUpTo: Copying current inlined depth: %d 0x%" PRIx64 ".\n",
// curr_frames->m_current_inlined_depth, curr_frames->m_current_inlined_pc);
#if defined(DEBUG_STACK_FRAMES)
s.PutCString("\nprev_frames:\n");
prev_frames->Dump(&s);
@ -397,21 +414,20 @@ void StackFrameList::GetFramesUpTo(uint32_t end_idx) {
if (curr_frame == nullptr || prev_frame == nullptr)
break;
// Check the stack ID to make sure they are equal
// Check the stack ID to make sure they are equal.
if (curr_frame->GetStackID() != prev_frame->GetStackID())
break;
prev_frame->UpdatePreviousFrameFromCurrentFrame(*curr_frame);
// Now copy the fixed up previous frame into the current frames so the
// pointer doesn't change
// 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");
#endif
}
// We are done with the old stack frame list, we can release it now
// We are done with the old stack frame list, we can release it now.
m_prev_frames_sp.reset();
}
@ -420,19 +436,6 @@ void StackFrameList::GetFramesUpTo(uint32_t end_idx) {
Dump(&s);
s.EOL();
#endif
} else {
if (end_idx < m_concrete_frames_fetched)
return;
if (unwinder) {
uint32_t num_frames = unwinder->GetFramesUpTo(end_idx);
if (num_frames <= end_idx + 1) {
// Done unwinding.
m_concrete_frames_fetched = UINT32_MAX;
}
m_frames.resize(num_frames);
}
}
}
uint32_t StackFrameList::GetNumFrames(bool can_create) {