LLDB  mainline
Unwind.h
Go to the documentation of this file.
1 //===-- Unwind.h ------------------------------------------------*- C++ -*-===//
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 #ifndef LLDB_TARGET_UNWIND_H
10 #define LLDB_TARGET_UNWIND_H
11 
12 #include <mutex>
13 
14 #include "lldb/lldb-private.h"
15 
16 namespace lldb_private {
17 
18 class Unwind {
19 protected:
20  // Classes that inherit from Unwind can see and modify these
21  Unwind(Thread &thread) : m_thread(thread), m_unwind_mutex() {}
22 
23 public:
24  virtual ~Unwind() = default;
25 
26  void Clear() {
27  std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);
28  DoClear();
29  }
30 
32  std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);
33  return DoGetFrameCount();
34  }
35 
37  lldb::addr_t cfa;
39  uint32_t idx;
40  bool behaves_like_zeroth_frame = (end_idx == 0);
41 
42  for (idx = 0; idx < end_idx; idx++) {
43  if (!DoGetFrameInfoAtIndex(idx, cfa, pc, behaves_like_zeroth_frame)) {
44  break;
45  }
46  }
47  return idx;
48  }
49 
51  lldb::addr_t &pc, bool &behaves_like_zeroth_frame) {
52  std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);
53  return DoGetFrameInfoAtIndex(frame_idx, cfa, pc, behaves_like_zeroth_frame);
54  }
55 
56  lldb::RegisterContextSP CreateRegisterContextForFrame(StackFrame *frame) {
57  std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);
58  return DoCreateRegisterContextForFrame(frame);
59  }
60 
61  Thread &GetThread() { return m_thread; }
62 
63 protected:
64  // Classes that inherit from Unwind can see and modify these
65  virtual void DoClear() = 0;
66 
67  virtual uint32_t DoGetFrameCount() = 0;
68 
69  virtual bool DoGetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa,
71  bool &behaves_like_zeroth_frame) = 0;
72 
73  virtual lldb::RegisterContextSP
75 
77  std::recursive_mutex m_unwind_mutex;
78 
79 private:
80  Unwind(const Unwind &) = delete;
81  const Unwind &operator=(const Unwind &) = delete;
82 };
83 
84 } // namespace lldb_private
85 
86 #endif // LLDB_TARGET_UNWIND_H
lldb_private::Unwind::GetFrameInfoAtIndex
bool GetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa, lldb::addr_t &pc, bool &behaves_like_zeroth_frame)
Definition: Unwind.h:50
lldb_private::Unwind::m_unwind_mutex
std::recursive_mutex m_unwind_mutex
Definition: Unwind.h:77
lldb_private::Unwind::~Unwind
virtual ~Unwind()=default
lldb_private::Unwind::GetFramesUpTo
uint32_t GetFramesUpTo(uint32_t end_idx)
Definition: Unwind.h:36
lldb_private::Unwind::m_thread
Thread & m_thread
Definition: Unwind.h:76
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
pc
@ pc
Definition: CompactUnwindInfo.cpp:1250
lldb_private::Unwind::DoClear
virtual void DoClear()=0
lldb_private::Thread
Definition: Thread.h:60
lldb_private::Unwind::operator=
const Unwind & operator=(const Unwind &)=delete
lldb_private::Unwind::GetThread
Thread & GetThread()
Definition: Unwind.h:61
lldb-private.h
lldb_private::Unwind::CreateRegisterContextForFrame
lldb::RegisterContextSP CreateRegisterContextForFrame(StackFrame *frame)
Definition: Unwind.h:56
lldb_private::Unwind::DoCreateRegisterContextForFrame
virtual lldb::RegisterContextSP DoCreateRegisterContextForFrame(StackFrame *frame)=0
uint32_t
lldb_private::Unwind::Clear
void Clear()
Definition: Unwind.h:26
lldb_private::Unwind::DoGetFrameCount
virtual uint32_t DoGetFrameCount()=0
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::Unwind::DoGetFrameInfoAtIndex
virtual bool DoGetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa, lldb::addr_t &pc, bool &behaves_like_zeroth_frame)=0
lldb_private::Unwind::Unwind
Unwind(Thread &thread)
Definition: Unwind.h:21
lldb_private::Unwind::GetFrameCount
uint32_t GetFrameCount()
Definition: Unwind.h:31
lldb_private::StackFrame
Definition: StackFrame.h:40
lldb_private::Unwind
Definition: Unwind.h:18