LLDB mainline
HistoryUnwind.cpp
Go to the documentation of this file.
1//===-- HistoryUnwind.cpp -------------------------------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#include "lldb/lldb-private.h"
10
13
14#include "lldb/Target/Process.h"
16#include "lldb/Target/Target.h"
17#include "lldb/Target/Thread.h"
18
19#include <memory>
20
21using namespace lldb;
22using namespace lldb_private;
23
24// Constructor
25
26HistoryUnwind::HistoryUnwind(Thread &thread, std::vector<lldb::addr_t> pcs,
27 HistoryPCType pc_type)
28 : Unwind(thread), m_pcs(pcs), m_pc_type(pc_type) {}
29
30// Destructor
31
33
35 std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);
36 m_pcs.clear();
37}
38
42 if (frame) {
44 &frame->GetThread()->GetProcess()->GetTarget());
45 if (pc != LLDB_INVALID_ADDRESS) {
46 rctx = std::make_shared<RegisterContextHistory>(
47 *frame->GetThread().get(), frame->GetConcreteFrameIndex(),
48 frame->GetThread()->GetProcess()->GetAddressByteSize(), pc);
49 }
50 }
51 return rctx;
52}
53
54static bool BehavesLikeZerothFrame(HistoryPCType pc_type, uint32_t frame_idx) {
55 switch (pc_type) {
57 return (frame_idx == 0);
59 return false;
61 return true;
62 }
63 llvm_unreachable("Fully covered switch above");
64}
65
68 bool &behaves_like_zeroth_frame) {
69 // FIXME do not throw away the lock after we acquire it..
70 std::unique_lock<std::recursive_mutex> guard(m_unwind_mutex);
71 guard.unlock();
72 if (frame_idx < m_pcs.size()) {
73 cfa = frame_idx;
74 pc = m_pcs[frame_idx];
75 behaves_like_zeroth_frame = BehavesLikeZerothFrame(m_pc_type, frame_idx);
76 return true;
77 }
78 return false;
79}
80
81uint32_t HistoryUnwind::DoGetFrameCount() { return m_pcs.size(); }
static bool BehavesLikeZerothFrame(HistoryPCType pc_type, uint32_t frame_idx)
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition Address.cpp:301
lldb::RegisterContextSP DoCreateRegisterContextForFrame(StackFrame *frame) override
std::vector< lldb::addr_t > m_pcs
uint32_t DoGetFrameCount() override
HistoryUnwind(Thread &thread, std::vector< lldb::addr_t > pcs, HistoryPCType pc_type=HistoryPCType::Returns)
bool DoGetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa, lldb::addr_t &pc, bool &behaves_like_zeroth_frame) override
This base class provides an interface to stack frames.
Definition StackFrame.h:44
lldb::ThreadSP GetThread() const
Definition StackFrame.h:128
uint32_t GetConcreteFrameIndex() const
Query this frame to find what frame it is in this Thread's StackFrameList, not counting inlined frame...
Definition StackFrame.h:455
const Address & GetFrameCodeAddress()
Get an Address for the current pc value in this StackFrame.
std::recursive_mutex m_unwind_mutex
Definition Unwind.h:77
Unwind(Thread &thread)
Definition Unwind.h:21
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
HistoryPCType
Specifies the type of PCs when creating a HistoryThread.
@ Returns
PCs are return addresses, except for topmost frame.
@ ReturnsNoZerothFrame
All PCs are return addresses.
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP