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"
15 #include "lldb/Target/StackFrame.h"
16 #include "lldb/Target/Target.h"
17 #include "lldb/Target/Thread.h"
18 
19 #include <memory>
20 
21 using namespace lldb;
22 using namespace lldb_private;
23 
24 // Constructor
25 
26 HistoryUnwind::HistoryUnwind(Thread &thread, std::vector<lldb::addr_t> pcs,
27  bool pcs_are_call_addresses)
28  : Unwind(thread), m_pcs(pcs),
29  m_pcs_are_call_addresses(pcs_are_call_addresses) {}
30 
31 // Destructor
32 
34 
36  std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);
37  m_pcs.clear();
38 }
39 
40 lldb::RegisterContextSP
42  RegisterContextSP rctx;
43  if (frame) {
45  &frame->GetThread()->GetProcess()->GetTarget());
46  if (pc != LLDB_INVALID_ADDRESS) {
47  rctx = std::make_shared<RegisterContextHistory>(
48  *frame->GetThread().get(), frame->GetConcreteFrameIndex(),
49  frame->GetThread()->GetProcess()->GetAddressByteSize(), pc);
50  }
51  }
52  return rctx;
53 }
54 
57  bool &behaves_like_zeroth_frame) {
58  // FIXME do not throw away the lock after we acquire it..
59  std::unique_lock<std::recursive_mutex> guard(m_unwind_mutex);
60  guard.unlock();
61  if (frame_idx < m_pcs.size()) {
62  cfa = frame_idx;
63  pc = m_pcs[frame_idx];
65  behaves_like_zeroth_frame = true;
66  else
67  behaves_like_zeroth_frame = (frame_idx == 0);
68  return true;
69  }
70  return false;
71 }
72 
lldb_private::Unwind::m_unwind_mutex
std::recursive_mutex m_unwind_mutex
Definition: Unwind.h:77
lldb_private::StackFrame::GetFrameCodeAddress
const Address & GetFrameCodeAddress()
Get an Address for the current pc value in this StackFrame.
Definition: StackFrame.cpp:188
lldb_private::HistoryUnwind::~HistoryUnwind
~HistoryUnwind() override
StackFrame.h
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
pc
@ pc
Definition: CompactUnwindInfo.cpp:1250
Process.h
Target.h
lldb_private::StackFrame::GetConcreteFrameIndex
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:407
lldb_private::Thread
Definition: Thread.h:60
lldb_private::HistoryUnwind::DoGetFrameCount
uint32_t DoGetFrameCount() override
Definition: HistoryUnwind.cpp:73
lldb_private::HistoryUnwind::DoCreateRegisterContextForFrame
lldb::RegisterContextSP DoCreateRegisterContextForFrame(StackFrame *frame) override
Definition: HistoryUnwind.cpp:41
Thread.h
lldb_private::HistoryUnwind::DoGetFrameInfoAtIndex
bool DoGetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa, lldb::addr_t &pc, bool &behaves_like_zeroth_frame) override
Definition: HistoryUnwind.cpp:55
lldb-private.h
lldb_private::StackFrame::GetThread
lldb::ThreadSP GetThread() const
Definition: StackFrame.h:125
uint32_t
lldb_private::Address::GetLoadAddress
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition: Address.cpp:310
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:86
lldb_private::HistoryUnwind::m_pcs
std::vector< lldb::addr_t > m_pcs
Definition: HistoryUnwind.h:38
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::HistoryUnwind::DoClear
void DoClear() override
Definition: HistoryUnwind.cpp:35
HistoryUnwind.h
lldb_private::StackFrame
Definition: StackFrame.h:40
lldb_private::Unwind
Definition: Unwind.h:18
lldb
Definition: SBAddress.h:15
RegisterContextHistory.h
lldb_private::HistoryUnwind::m_pcs_are_call_addresses
bool m_pcs_are_call_addresses
This boolean indicates that the PCs in the non-0 frames are call addresses and not return addresses.
Definition: HistoryUnwind.h:41