]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/include/lldb/Target/Unwind.h
MFC r355940:
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / include / lldb / Target / Unwind.h
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 liblldb_Unwind_h_
10 #define liblldb_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() {}
25
26   void Clear() {
27     std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);
28     DoClear();
29   }
30
31   uint32_t GetFrameCount() {
32     std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);
33     return DoGetFrameCount();
34   }
35
36   uint32_t GetFramesUpTo(uint32_t end_idx) {
37     lldb::addr_t cfa;
38     lldb::addr_t pc;
39     uint32_t idx;
40
41     for (idx = 0; idx < end_idx; idx++) {
42       if (!DoGetFrameInfoAtIndex(idx, cfa, pc)) {
43         break;
44       }
45     }
46     return idx;
47   }
48
49   bool GetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa,
50                            lldb::addr_t &pc) {
51     std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);
52     return DoGetFrameInfoAtIndex(frame_idx, cfa, pc);
53   }
54
55   lldb::RegisterContextSP CreateRegisterContextForFrame(StackFrame *frame) {
56     std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);
57     return DoCreateRegisterContextForFrame(frame);
58   }
59
60   Thread &GetThread() { return m_thread; }
61
62 protected:
63   // Classes that inherit from Unwind can see and modify these
64   virtual void DoClear() = 0;
65
66   virtual uint32_t DoGetFrameCount() = 0;
67
68   virtual bool DoGetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa,
69                                      lldb::addr_t &pc) = 0;
70
71   virtual lldb::RegisterContextSP
72   DoCreateRegisterContextForFrame(StackFrame *frame) = 0;
73
74   Thread &m_thread;
75   std::recursive_mutex m_unwind_mutex;
76
77 private:
78   DISALLOW_COPY_AND_ASSIGN(Unwind);
79 };
80
81 } // namespace lldb_private
82
83 #endif // liblldb_Unwind_h_