Author: Pavel Labath Date: 2020-03-09T14:13:22+01:00 New Revision: c0b1af6878444f075a17d87f523bc6be3343db35
URL: https://github.com/llvm/llvm-project/commit/c0b1af6878444f075a17d87f523bc6be3343db35 DIFF: https://github.com/llvm/llvm-project/commit/c0b1af6878444f075a17d87f523bc6be3343db35.diff LOG: [lldb] Return Unwinder& from Thread::GetUnwinder The function always returns a valid object. Let the return type reflect that, and remove some null checks. Added: Modified: lldb/include/lldb/Target/StackFrameList.h lldb/include/lldb/Target/Thread.h lldb/source/Plugins/Process/Utility/ThreadMemory.cpp lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp lldb/source/Plugins/Process/mach-core/ThreadMachCore.cpp lldb/source/Target/StackFrameList.cpp lldb/source/Target/Thread.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/Target/StackFrameList.h b/lldb/include/lldb/Target/StackFrameList.h index 44b389764bc6..be5e009e8a1e 100644 --- a/lldb/include/lldb/Target/StackFrameList.h +++ b/lldb/include/lldb/Target/StackFrameList.h @@ -94,7 +94,7 @@ class StackFrameList { 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 02e0d3369729..b0bc1b29eb78 100644 --- a/lldb/include/lldb/Target/Thread.h +++ b/lldb/include/lldb/Target/Thread.h @@ -1195,7 +1195,7 @@ class Thread : public std::enable_shared_from_this<Thread>, 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. diff --git a/lldb/source/Plugins/Process/Utility/ThreadMemory.cpp b/lldb/source/Plugins/Process/Utility/ThreadMemory.cpp index 9016e14f93b6..7469e7633e71 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 c3ae95a13b31..714090459cbb 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 7615ae290d0d..6deabf8d5d71 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 4c3d2a5004a5..1950baea4127 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 0047697f7070..e8e72203e204 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<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); + 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); } } } else if (original_idx == 0) { diff --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp index 83dff9603a1f..11c589bb22aa 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<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() { _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits