]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/Process/Utility/UnwindLLDB.h
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / Process / Utility / UnwindLLDB.h
1 //===-- UnwindLLDB.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 lldb_UnwindLLDB_h_
11 #define lldb_UnwindLLDB_h_
12
13 // C Includes
14 // C++ Includes
15 #include <vector>
16
17 // Other libraries and framework includes
18 // Project includes
19 #include "lldb/Symbol/FuncUnwinders.h"
20 #include "lldb/Symbol/SymbolContext.h"
21 #include "lldb/Symbol/UnwindPlan.h"
22 #include "lldb/Target/RegisterContext.h"
23 #include "lldb/Target/Unwind.h"
24 #include "lldb/Utility/ConstString.h"
25 #include "lldb/lldb-public.h"
26
27 namespace lldb_private {
28
29 class RegisterContextLLDB;
30
31 class UnwindLLDB : public lldb_private::Unwind {
32 public:
33   UnwindLLDB(lldb_private::Thread &thread);
34
35   ~UnwindLLDB() override = default;
36
37   enum RegisterSearchResult {
38     eRegisterFound = 0,
39     eRegisterNotFound,
40     eRegisterIsVolatile
41   };
42
43 protected:
44   friend class lldb_private::RegisterContextLLDB;
45
46   struct RegisterLocation {
47     enum RegisterLocationTypes {
48       eRegisterNotSaved = 0, // register was not preserved by callee.  If
49                              // volatile reg, is unavailable
50       eRegisterSavedAtMemoryLocation, // register is saved at a specific word of
51                                       // target mem (target_memory_location)
52       eRegisterInRegister, // register is available in a (possible other)
53                            // register (register_number)
54       eRegisterSavedAtHostMemoryLocation, // register is saved at a word in
55                                           // lldb's address space
56       eRegisterValueInferred,        // register val was computed (and is in
57                                      // inferred_value)
58       eRegisterInLiveRegisterContext // register value is in a live (stack frame
59                                      // #0) register
60     };
61     int type;
62     union {
63       lldb::addr_t target_memory_location;
64       uint32_t
65           register_number; // in eRegisterKindLLDB register numbering system
66       void *host_memory_location;
67       uint64_t inferred_value; // eRegisterValueInferred - e.g. stack pointer ==
68                                // cfa + offset
69     } location;
70   };
71
72   void DoClear() override {
73     m_frames.clear();
74     m_candidate_frame.reset();
75     m_unwind_complete = false;
76   }
77
78   uint32_t DoGetFrameCount() override;
79
80   bool DoGetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa,
81                              lldb::addr_t &start_pc) override;
82
83   lldb::RegisterContextSP
84   DoCreateRegisterContextForFrame(lldb_private::StackFrame *frame) override;
85
86   typedef std::shared_ptr<RegisterContextLLDB> RegisterContextLLDBSP;
87
88   // Needed to retrieve the "next" frame (e.g. frame 2 needs to retrieve frame
89   // 1's RegisterContextLLDB)
90   // The RegisterContext for frame_num must already exist or this returns an
91   // empty shared pointer.
92   RegisterContextLLDBSP GetRegisterContextForFrameNum(uint32_t frame_num);
93
94   // Iterate over the RegisterContextLLDB's in our m_frames vector, look for the
95   // first one that
96   // has a saved location for this reg.
97   bool SearchForSavedLocationForRegister(
98       uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation &regloc,
99       uint32_t starting_frame_num, bool pc_register);
100
101   //------------------------------------------------------------------
102   /// Provide the list of user-specified trap handler functions
103   ///
104   /// The Platform is one source of trap handler function names; that
105   /// may be augmented via a setting.  The setting needs to be converted
106   /// into an array of ConstStrings before it can be used - we only want
107   /// to do that once per thread so it's here in the UnwindLLDB object.
108   ///
109   /// @return
110   ///     Vector of ConstStrings of trap handler function names.  May be
111   ///     empty.
112   //------------------------------------------------------------------
113   const std::vector<ConstString> &GetUserSpecifiedTrapHandlerFunctionNames() {
114     return m_user_supplied_trap_handler_functions;
115   }
116
117 private:
118   struct Cursor {
119     lldb::addr_t start_pc; // The start address of the function/symbol for this
120                            // frame - current pc if unknown
121     lldb::addr_t cfa;      // The canonical frame address for this stack frame
122     lldb_private::SymbolContext sctx; // A symbol context we'll contribute to &
123                                       // provide to the StackFrame creation
124     RegisterContextLLDBSP
125         reg_ctx_lldb_sp; // These are all RegisterContextLLDB's
126
127     Cursor()
128         : start_pc(LLDB_INVALID_ADDRESS), cfa(LLDB_INVALID_ADDRESS), sctx(),
129           reg_ctx_lldb_sp() {}
130
131   private:
132     DISALLOW_COPY_AND_ASSIGN(Cursor);
133   };
134
135   typedef std::shared_ptr<Cursor> CursorSP;
136   std::vector<CursorSP> m_frames;
137   CursorSP m_candidate_frame;
138   bool m_unwind_complete; // If this is true, we've enumerated all the frames in
139                           // the stack, and m_frames.size() is the
140   // number of frames, etc.  Otherwise we've only gone as far as directly asked,
141   // and m_frames.size()
142   // is how far we've currently gone.
143
144   std::vector<ConstString> m_user_supplied_trap_handler_functions;
145
146   //-----------------------------------------------------------------
147   // Check if Full UnwindPlan of First frame is valid or not.
148   // If not then try Fallback UnwindPlan of the frame. If Fallback
149   // UnwindPlan succeeds then update the Full UnwindPlan with the
150   // Fallback UnwindPlan.
151   //-----------------------------------------------------------------
152   void UpdateUnwindPlanForFirstFrameIfInvalid(ABI *abi);
153
154   CursorSP GetOneMoreFrame(ABI *abi);
155
156   bool AddOneMoreFrame(ABI *abi);
157
158   bool AddFirstFrame();
159
160   //------------------------------------------------------------------
161   // For UnwindLLDB only
162   //------------------------------------------------------------------
163   DISALLOW_COPY_AND_ASSIGN(UnwindLLDB);
164 };
165
166 } // namespace lldb_private
167
168 #endif // lldb_UnwindLLDB_h_