1 //===-- HistoryUnwind.cpp ---------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "lldb/lldb-private.h"
11 #include "Plugins/Process/Utility/HistoryUnwind.h"
12 #include "Plugins/Process/Utility/RegisterContextHistory.h"
14 #include "lldb/Target/Process.h"
15 #include "lldb/Target/StackFrame.h"
16 #include "lldb/Target/Target.h"
17 #include "lldb/Target/Thread.h"
22 using namespace lldb_private;
26 HistoryUnwind::HistoryUnwind(Thread &thread, std::vector<lldb::addr_t> pcs)
27 : Unwind(thread), m_pcs(pcs) {}
31 HistoryUnwind::~HistoryUnwind() {}
33 void HistoryUnwind::DoClear() {
34 std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);
38 lldb::RegisterContextSP
39 HistoryUnwind::DoCreateRegisterContextForFrame(StackFrame *frame) {
40 RegisterContextSP rctx;
42 addr_t pc = frame->GetFrameCodeAddress().GetLoadAddress(
43 &frame->GetThread()->GetProcess()->GetTarget());
44 if (pc != LLDB_INVALID_ADDRESS) {
45 rctx = std::make_shared<RegisterContextHistory>(
46 *frame->GetThread().get(), frame->GetConcreteFrameIndex(),
47 frame->GetThread()->GetProcess()->GetAddressByteSize(), pc);
53 bool HistoryUnwind::DoGetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa,
55 // FIXME do not throw away the lock after we acquire it..
56 std::unique_lock<std::recursive_mutex> guard(m_unwind_mutex);
58 if (frame_idx < m_pcs.size()) {
60 pc = m_pcs[frame_idx];
66 uint32_t HistoryUnwind::DoGetFrameCount() { return m_pcs.size(); }