From: Pavel Labath Date: Mon, 9 Mar 2020 13:10:41 +0000 (+0100) Subject: [lldb] Return Unwinder& from Thread::GetUnwinder X-Git-Tag: llvmorg-12-init~12632 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c0b1af6878444f075a17d87f523bc6be3343db35;p=platform%2Fupstream%2Fllvm.git [lldb] Return Unwinder& from Thread::GetUnwinder The function always returns a valid object. Let the return type reflect that, and remove some null checks. --- diff --git a/lldb/include/lldb/Target/StackFrameList.h b/lldb/include/lldb/Target/StackFrameList.h index 44b3897..be5e009 100644 --- a/lldb/include/lldb/Target/StackFrameList.h +++ b/lldb/include/lldb/Target/StackFrameList.h @@ -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); diff --git a/lldb/include/lldb/Target/Thread.h b/lldb/include/lldb/Target/Thread.h index 02e0d33..b0bc1b2 100644 --- a/lldb/include/lldb/Target/Thread.h +++ b/lldb/include/lldb/Target/Thread.h @@ -1195,7 +1195,7 @@ protected: typedef std::vector 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. diff --git a/lldb/source/Plugins/Process/Utility/ThreadMemory.cpp b/lldb/source/Plugins/Process/Utility/ThreadMemory.cpp index 9016e14..7469e76 100644 --- a/lldb/source/Plugins/Process/Utility/ThreadMemory.cpp +++ b/lldb/source/Plugins/Process/Utility/ThreadMemory.cpp @@ -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() { diff --git a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp index c3ae95a..7140904 100644 --- a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp +++ b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp @@ -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; } diff --git a/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp index 7615ae2..6deabf8 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp @@ -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; } diff --git a/lldb/source/Plugins/Process/mach-core/ThreadMachCore.cpp b/lldb/source/Plugins/Process/mach-core/ThreadMachCore.cpp index 4c3d2a5..1950bae 100644 --- a/lldb/source/Plugins/Process/mach-core/ThreadMachCore.cpp +++ b/lldb/source/Plugins/Process/mach-core/ThreadMachCore.cpp @@ -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; } diff --git a/lldb/source/Target/StackFrameList.cpp b/lldb/source/Target/StackFrameList.cpp index 0047697..e8e7220 100644 --- a/lldb/source/Target/StackFrameList.cpp +++ b/lldb/source/Target/StackFrameList.cpp @@ -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( - 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); + 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( + 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); } } } else if (original_idx == 0) { diff --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp index 83dff96..11c589b 100644 --- a/lldb/source/Target/Thread.cpp +++ b/lldb/source/Target/Thread.cpp @@ -1658,9 +1658,7 @@ StackFrameListSP Thread::GetStackFrameList() { void Thread::ClearStackFrames() { std::lock_guard 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() {