]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Target/Unwind.h
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r304659, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Target / Unwind.h
1 //===-- Unwind.h ------------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_Unwind_h_
11 #define liblldb_Unwind_h_
12
13 // C Includes
14 // C++ Includes
15 #include <mutex>
16
17 // Other libraries and framework includes
18 // Project includes
19 #include "lldb/lldb-private.h"
20
21 namespace lldb_private {
22
23 class Unwind {
24 protected:
25   //------------------------------------------------------------------
26   // Classes that inherit from Unwind can see and modify these
27   //------------------------------------------------------------------
28   Unwind(Thread &thread) : m_thread(thread), m_unwind_mutex() {}
29
30 public:
31   virtual ~Unwind() {}
32
33   void Clear() {
34     std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);
35     DoClear();
36   }
37
38   uint32_t GetFrameCount() {
39     std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);
40     return DoGetFrameCount();
41   }
42
43   uint32_t GetFramesUpTo(uint32_t end_idx) {
44     lldb::addr_t cfa;
45     lldb::addr_t pc;
46     uint32_t idx;
47
48     for (idx = 0; idx < end_idx; idx++) {
49       if (!DoGetFrameInfoAtIndex(idx, cfa, pc)) {
50         break;
51       }
52     }
53     return idx;
54   }
55
56   bool GetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa,
57                            lldb::addr_t &pc) {
58     std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);
59     return DoGetFrameInfoAtIndex(frame_idx, cfa, pc);
60   }
61
62   lldb::RegisterContextSP CreateRegisterContextForFrame(StackFrame *frame) {
63     std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);
64     return DoCreateRegisterContextForFrame(frame);
65   }
66
67   Thread &GetThread() { return m_thread; }
68
69 protected:
70   //------------------------------------------------------------------
71   // Classes that inherit from Unwind can see and modify these
72   //------------------------------------------------------------------
73   virtual void DoClear() = 0;
74
75   virtual uint32_t DoGetFrameCount() = 0;
76
77   virtual bool DoGetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa,
78                                      lldb::addr_t &pc) = 0;
79
80   virtual lldb::RegisterContextSP
81   DoCreateRegisterContextForFrame(StackFrame *frame) = 0;
82
83   Thread &m_thread;
84   std::recursive_mutex m_unwind_mutex;
85
86 private:
87   DISALLOW_COPY_AND_ASSIGN(Unwind);
88 };
89
90 } // namespace lldb_private
91
92 #endif // liblldb_Unwind_h_