[lldb] Return Unwinder& from Thread::GetUnwinder

The function always returns a valid object. Let the return type reflect
that, and remove some null checks.
This commit is contained in:
Pavel Labath 2020-03-09 14:10:41 +01:00
parent 6ba0a4ec3b
commit c0b1af6878
8 changed files with 38 additions and 60 deletions

View File

@ -94,7 +94,7 @@ protected:
void GetFramesUpTo(uint32_t end_idx);
void GetOnlyConcreteFramesUpTo(uint32_t end_idx, Unwind *unwinder);
void GetOnlyConcreteFramesUpTo(uint32_t end_idx, Unwind &unwinder);
void SynthesizeTailCallFrames(StackFrame &next_frame);

View File

@ -1195,7 +1195,7 @@ protected:
typedef std::vector<lldb::ThreadPlanSP> plan_stack;
virtual lldb_private::Unwind *GetUnwinder();
virtual Unwind &GetUnwinder();
// Check to see whether the thread is still at the last breakpoint hit that
// stopped it.

View File

@ -54,20 +54,14 @@ RegisterContextSP ThreadMemory::GetRegisterContext() {
RegisterContextSP
ThreadMemory::CreateRegisterContextForFrame(StackFrame *frame) {
RegisterContextSP reg_ctx_sp;
uint32_t concrete_frame_idx = 0;
if (frame)
concrete_frame_idx = frame->GetConcreteFrameIndex();
if (concrete_frame_idx == 0) {
reg_ctx_sp = GetRegisterContext();
} else {
Unwind *unwinder = GetUnwinder();
if (unwinder != nullptr)
reg_ctx_sp = unwinder->CreateRegisterContextForFrame(frame);
}
return reg_ctx_sp;
if (concrete_frame_idx == 0)
return GetRegisterContext();
return GetUnwinder().CreateRegisterContextForFrame(frame);
}
bool ThreadMemory::CalculateStopInfo() {

View File

@ -229,9 +229,7 @@ ThreadElfCore::CreateRegisterContextForFrame(StackFrame *frame) {
reg_ctx_sp = m_thread_reg_ctx_sp;
} else {
Unwind *unwinder = GetUnwinder();
if (unwinder != nullptr)
reg_ctx_sp = unwinder->CreateRegisterContextForFrame(frame);
reg_ctx_sp = GetUnwinder().CreateRegisterContextForFrame(frame);
}
return reg_ctx_sp;
}

View File

@ -311,9 +311,7 @@ ThreadGDBRemote::CreateRegisterContextForFrame(StackFrame *frame) {
read_all_registers_at_once, write_all_registers_at_once);
}
} else {
Unwind *unwinder = GetUnwinder();
if (unwinder != nullptr)
reg_ctx_sp = unwinder->CreateRegisterContextForFrame(frame);
reg_ctx_sp = GetUnwinder().CreateRegisterContextForFrame(frame);
}
return reg_ctx_sp;
}

View File

@ -83,9 +83,7 @@ ThreadMachCore::CreateRegisterContextForFrame(StackFrame *frame) {
}
reg_ctx_sp = m_thread_reg_ctx_sp;
} else {
Unwind *unwinder = GetUnwinder();
if (unwinder != nullptr)
reg_ctx_sp = unwinder->CreateRegisterContextForFrame(frame);
reg_ctx_sp = GetUnwinder().CreateRegisterContextForFrame(frame);
}
return reg_ctx_sp;
}

View File

@ -218,17 +218,14 @@ void StackFrameList::SetCurrentInlinedDepth(uint32_t new_depth) {
}
void StackFrameList::GetOnlyConcreteFramesUpTo(uint32_t end_idx,
Unwind *unwinder) {
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);
uint32_t num_frames = unwinder.GetFramesUpTo(end_idx);
if (num_frames <= end_idx + 1) {
// Done unwinding.
m_concrete_frames_fetched = UINT32_MAX;
@ -425,7 +422,7 @@ void StackFrameList::GetFramesUpTo(uint32_t end_idx) {
if (m_frames.size() > end_idx || GetAllFramesFetched())
return;
Unwind *unwinder = m_thread.GetUnwinder();
Unwind &unwinder = m_thread.GetUnwinder();
if (!m_show_inlined_frames) {
GetOnlyConcreteFramesUpTo(end_idx, unwinder);
@ -463,9 +460,8 @@ void StackFrameList::GetFramesUpTo(uint32_t end_idx) {
RegisterContextSP reg_ctx_sp(m_thread.GetRegisterContext());
if (reg_ctx_sp) {
const bool success = unwinder &&
unwinder->GetFrameInfoAtIndex(
idx, cfa, pc, behaves_like_zeroth_frame);
const bool success = unwinder.GetFrameInfoAtIndex(
idx, cfa, pc, behaves_like_zeroth_frame);
// 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.
@ -484,9 +480,8 @@ void StackFrameList::GetFramesUpTo(uint32_t end_idx) {
cfa = unwind_frame_sp->m_id.GetCallFrameAddress();
}
} else {
const bool success = unwinder &&
unwinder->GetFrameInfoAtIndex(
idx, cfa, pc, behaves_like_zeroth_frame);
const bool success =
unwinder.GetFrameInfoAtIndex(idx, cfa, pc, behaves_like_zeroth_frame);
if (!success) {
// We've gotten to the end of the stack.
SetAllFramesFetched();
@ -669,31 +664,28 @@ StackFrameSP StackFrameList::GetFrameAtIndex(uint32_t idx) {
// GetFramesUpTo.
frame_sp = m_frames[idx];
} else {
Unwind *unwinder = m_thread.GetUnwinder();
if (unwinder) {
addr_t pc, cfa;
bool behaves_like_zeroth_frame = (idx == 0);
if (unwinder->GetFrameInfoAtIndex(idx, cfa, pc,
behaves_like_zeroth_frame)) {
const bool cfa_is_valid = true;
frame_sp = std::make_shared<StackFrame>(
m_thread.shared_from_this(), idx, idx, cfa, cfa_is_valid, pc,
StackFrame::Kind::Regular, behaves_like_zeroth_frame, nullptr);
addr_t pc, cfa;
bool behaves_like_zeroth_frame = (idx == 0);
if (m_thread.GetUnwinder().GetFrameInfoAtIndex(
idx, cfa, pc, behaves_like_zeroth_frame)) {
const bool cfa_is_valid = true;
frame_sp = std::make_shared<StackFrame>(
m_thread.shared_from_this(), idx, idx, cfa, cfa_is_valid, pc,
StackFrame::Kind::Regular, behaves_like_zeroth_frame, nullptr);
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 nullptr
// or valid.
frame_sp->SetSymbolContextScope(
frame_sp->GetSymbolContext(eSymbolContextSymbol).symbol);
}
SetFrameAtIndex(idx, frame_sp);
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 nullptr
// or valid.
frame_sp->SetSymbolContextScope(
frame_sp->GetSymbolContext(eSymbolContextSymbol).symbol);
}
SetFrameAtIndex(idx, frame_sp);
}
}
} else if (original_idx == 0) {

View File

@ -1658,9 +1658,7 @@ StackFrameListSP Thread::GetStackFrameList() {
void Thread::ClearStackFrames() {
std::lock_guard<std::recursive_mutex> guard(m_frame_mutex);
Unwind *unwinder = GetUnwinder();
if (unwinder)
unwinder->Clear();
GetUnwinder().Clear();
// Only store away the old "reference" StackFrameList if we got all its
// frames:
@ -2099,10 +2097,10 @@ size_t Thread::GetStackFrameStatus(Stream &strm, uint32_t first_frame,
strm, first_frame, num_frames, show_frame_info, num_frames_with_source);
}
Unwind *Thread::GetUnwinder() {
Unwind &Thread::GetUnwinder() {
if (!m_unwinder_up)
m_unwinder_up.reset(new UnwindLLDB(*this));
return m_unwinder_up.get();
return *m_unwinder_up;
}
void Thread::Flush() {