Path: blob/main/contrib/llvm-project/lldb/source/Plugins/Process/Utility/HistoryUnwind.cpp
39644 views
//===-- HistoryUnwind.cpp -------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/lldb-private.h"910#include "Plugins/Process/Utility/HistoryUnwind.h"11#include "Plugins/Process/Utility/RegisterContextHistory.h"1213#include "lldb/Target/Process.h"14#include "lldb/Target/StackFrame.h"15#include "lldb/Target/Target.h"16#include "lldb/Target/Thread.h"1718#include <memory>1920using namespace lldb;21using namespace lldb_private;2223// Constructor2425HistoryUnwind::HistoryUnwind(Thread &thread, std::vector<lldb::addr_t> pcs,26bool pcs_are_call_addresses)27: Unwind(thread), m_pcs(pcs),28m_pcs_are_call_addresses(pcs_are_call_addresses) {}2930// Destructor3132HistoryUnwind::~HistoryUnwind() = default;3334void HistoryUnwind::DoClear() {35std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);36m_pcs.clear();37}3839lldb::RegisterContextSP40HistoryUnwind::DoCreateRegisterContextForFrame(StackFrame *frame) {41RegisterContextSP rctx;42if (frame) {43addr_t pc = frame->GetFrameCodeAddress().GetLoadAddress(44&frame->GetThread()->GetProcess()->GetTarget());45if (pc != LLDB_INVALID_ADDRESS) {46rctx = std::make_shared<RegisterContextHistory>(47*frame->GetThread().get(), frame->GetConcreteFrameIndex(),48frame->GetThread()->GetProcess()->GetAddressByteSize(), pc);49}50}51return rctx;52}5354bool HistoryUnwind::DoGetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa,55lldb::addr_t &pc,56bool &behaves_like_zeroth_frame) {57// FIXME do not throw away the lock after we acquire it..58std::unique_lock<std::recursive_mutex> guard(m_unwind_mutex);59guard.unlock();60if (frame_idx < m_pcs.size()) {61cfa = frame_idx;62pc = m_pcs[frame_idx];63if (m_pcs_are_call_addresses)64behaves_like_zeroth_frame = true;65else66behaves_like_zeroth_frame = (frame_idx == 0);67return true;68}69return false;70}7172uint32_t HistoryUnwind::DoGetFrameCount() { return m_pcs.size(); }737475