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