]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.h
Update LLDB snapshot to upstream r225923 (git 2b588ecd)
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / Process / Utility / RegisterContextLLDB.h
1 //===-- RegisterContextLLDB.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_RegisterContextLLDB_h_
11 #define lldb_RegisterContextLLDB_h_
12
13 #include <vector>
14
15 #include "lldb/lldb-private.h"
16 #include "lldb/Target/RegisterContext.h"
17 #include "lldb/Symbol/UnwindPlan.h"
18 #include "lldb/Symbol/SymbolContext.h"
19 #include "lldb/Utility/RegisterNumber.h"
20 #include "UnwindLLDB.h"
21
22 namespace lldb_private {
23
24 class UnwindLLDB;
25
26 class RegisterContextLLDB : public lldb_private::RegisterContext
27 {
28 public:
29     typedef std::shared_ptr<RegisterContextLLDB> SharedPtr;
30
31     RegisterContextLLDB (lldb_private::Thread &thread,
32                          const SharedPtr& next_frame,
33                          lldb_private::SymbolContext& sym_ctx,
34                          uint32_t frame_number, lldb_private::UnwindLLDB& unwind_lldb);
35
36     ///
37     // pure virtual functions from the base class that we must implement
38     ///
39
40     virtual
41     ~RegisterContextLLDB () { }
42
43     virtual void
44     InvalidateAllRegisters ();
45
46     virtual size_t
47     GetRegisterCount ();
48
49     virtual const lldb_private::RegisterInfo *
50     GetRegisterInfoAtIndex (size_t reg);
51
52     virtual size_t
53     GetRegisterSetCount ();
54
55     virtual const lldb_private::RegisterSet *
56     GetRegisterSet (size_t reg_set);
57
58     virtual bool
59     ReadRegister (const lldb_private::RegisterInfo *reg_info, lldb_private::RegisterValue &value);
60
61     virtual bool
62     WriteRegister (const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value);
63
64     virtual bool
65     ReadAllRegisterValues (lldb::DataBufferSP &data_sp);
66
67     virtual bool
68     WriteAllRegisterValues (const lldb::DataBufferSP &data_sp);
69
70     virtual uint32_t
71     ConvertRegisterKindToRegisterNumber (lldb::RegisterKind kind, uint32_t num);
72
73     bool
74     IsValid () const;
75
76     bool
77     IsTrapHandlerFrame () const;
78
79     bool
80     GetCFA (lldb::addr_t& cfa);
81
82     bool
83     GetStartPC (lldb::addr_t& start_pc);
84
85     bool
86     ReadPC (lldb::addr_t& start_pc);
87
88 private:
89
90     enum FrameType
91     {
92         eNormalFrame,
93         eTrapHandlerFrame,
94         eDebuggerFrame,  // a debugger inferior function call frame; we get caller's registers from debugger
95         eSkipFrame,      // The unwind resulted in a bogus frame but may get back on track so we don't want to give up yet
96         eNotAValidFrame  // this frame is invalid for some reason - most likely it is past the top (end) of the stack
97     };
98
99     // UnwindLLDB needs to pass around references to RegisterLocations
100     friend class UnwindLLDB;
101
102
103     // Returns true if we have an unwind loop -- the same stack frame unwinding 
104     // multiple times.
105     bool
106     CheckIfLoopingStack ();
107
108     // Indicates whether this frame is frame zero -- the currently
109     // executing frame -- or not.
110     bool
111     IsFrameZero () const;
112
113     void
114     InitializeZerothFrame ();
115
116     void
117     InitializeNonZerothFrame();
118
119     SharedPtr
120     GetNextFrame () const;
121
122     SharedPtr
123     GetPrevFrame () const;
124
125     // A SkipFrame occurs when the unwind out of frame 0 didn't go right -- we've got one bogus frame at frame #1.
126     // There is a good chance we'll get back on track if we follow the frame pointer chain (or whatever is appropriate
127     // on this ABI) so we allow one invalid frame to be in the stack.  Ideally we'll mark this frame specially at some
128     // point and indicate to the user that the unwinder had a hiccup.  Often when this happens we will miss a frame of
129     // the program's actual stack in the unwind and we want to flag that for the user somehow.
130     bool
131     IsSkipFrame () const;
132
133
134     //------------------------------------------------------------------
135     /// Determines if a SymbolContext is a trap handler or not
136     ///
137     /// Given a SymbolContext, determines if this is a trap handler function
138     /// aka asynchronous signal handler.
139     ///
140     /// @return
141     ///     Returns true if the SymbolContext is a trap handler.
142     //------------------------------------------------------------------
143     bool
144     IsTrapHandlerSymbol (lldb_private::Process *process, const lldb_private::SymbolContext &m_sym_ctx) const;
145
146     // Provide a location for where THIS function saved the CALLER's register value
147     // Or a frame "below" this one saved it, i.e. a function called by this one, preserved a register that this
148     // function didn't modify/use.
149     //
150     // The RegisterLocation type may be set to eRegisterNotAvailable -- this will happen for a volatile register
151     // being queried mid-stack.  Instead of floating frame 0's contents of that register up the stack (which may
152     // or may not be the value of that reg when the function was executing), we won't return any value.
153     //
154     // If a non-volatile register (a "preserved" register) is requested mid-stack and no frames "below" the requested
155     // stack have saved the register anywhere, it is safe to assume that frame 0's register values are still the same
156     // as the requesting frame's.
157     lldb_private::UnwindLLDB::RegisterSearchResult
158     SavedLocationForRegister (uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation &regloc);
159
160     bool
161     ReadRegisterValueFromRegisterLocation (lldb_private::UnwindLLDB::RegisterLocation regloc,
162                                            const lldb_private::RegisterInfo *reg_info,
163                                            lldb_private::RegisterValue &value);
164
165     bool
166     WriteRegisterValueToRegisterLocation (lldb_private::UnwindLLDB::RegisterLocation regloc,
167                                           const lldb_private::RegisterInfo *reg_info,
168                                           const lldb_private::RegisterValue &value);
169
170     //------------------------------------------------------------------
171     /// If the unwind has to the caller frame has failed, try something else
172     ///
173     /// If lldb is using an assembly language based UnwindPlan for a frame and
174     /// the unwind to the caller frame fails, try falling back to a generic
175     /// UnwindPlan (architecture default unwindplan) to see if that might work
176     /// better.  This is mostly helping to work around problems where the 
177     /// assembly language inspection fails on hand-written assembly code.
178     ///
179     /// @return
180     ///     Returns true if a fallback unwindplan was found & was installed.
181     //------------------------------------------------------------------
182     bool
183     TryFallbackUnwindPlan ();
184
185     //------------------------------------------------------------------
186     /// Switch to the fallback unwind plan unconditionally without any safety
187     /// checks that it is providing better results than the normal unwind plan.
188     ///
189     /// The only time it is valid to call this method is if the full unwindplan is
190     /// found to be fundamentally incorrect/impossible.
191     ///
192     /// Returns true if it was able to install the fallback unwind plan.
193     //------------------------------------------------------------------
194     bool
195     ForceSwitchToFallbackUnwindPlan ();
196
197     // Get the contents of a general purpose (address-size) register for this frame
198     // (usually retrieved from the next frame)
199     bool
200     ReadGPRValue (lldb::RegisterKind register_kind, uint32_t regnum, lldb::addr_t &value);
201
202     bool
203     ReadGPRValue (const RegisterNumber &reg_num, lldb::addr_t &value);
204
205     // Get the CFA register for a given frame.
206     bool
207     ReadCFAValueForRow (lldb::RegisterKind register_kind, const UnwindPlan::RowSP &row, lldb::addr_t &value);
208
209     lldb::UnwindPlanSP
210     GetFastUnwindPlanForFrame ();
211
212     lldb::UnwindPlanSP
213     GetFullUnwindPlanForFrame ();
214
215     void
216     UnwindLogMsg (const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
217
218     void
219     UnwindLogMsgVerbose (const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
220
221     bool
222     IsUnwindPlanValidForCurrentPC(lldb::UnwindPlanSP unwind_plan_sp, int &valid_pc_offset);
223
224
225     lldb_private::Thread& m_thread;
226
227     ///
228     // The following tell us how to retrieve the CALLER's register values (ie the "previous" frame, aka the frame above)
229     // i.e. where THIS frame saved them
230     ///
231
232     lldb::UnwindPlanSP m_fast_unwind_plan_sp;     // may be NULL
233     lldb::UnwindPlanSP m_full_unwind_plan_sp;
234     lldb::UnwindPlanSP m_fallback_unwind_plan_sp; // may be NULL
235
236     bool m_all_registers_available;               // Can we retrieve all regs or just nonvolatile regs?
237     int m_frame_type;                             // enum FrameType
238
239     lldb::addr_t m_cfa;
240     lldb_private::Address m_start_pc;
241     lldb_private::Address m_current_pc;
242
243     int m_current_offset;                         // how far into the function we've executed; -1 if unknown
244                                                   // 0 if no instructions have been executed yet.
245
246     int m_current_offset_backed_up_one;           // how far into the function we've executed; -1 if unknown
247                                                   // 0 if no instructions have been executed yet.
248                                                   // On architectures where the return address on the stack points
249                                                   // to the instruction after the CALL, this value will have 1
250                                                   // subtracted from it.  Else a function that ends in a CALL will
251                                                   // have an offset pointing into the next function's address range.
252                                                   // m_current_pc has the actual address of the "current" pc.
253
254     lldb_private::SymbolContext& m_sym_ctx;
255     bool m_sym_ctx_valid;                         // if ResolveSymbolContextForAddress fails, don't try to use m_sym_ctx
256
257     uint32_t m_frame_number;                      // What stack frame this RegisterContext is
258
259     std::map<uint32_t, lldb_private::UnwindLLDB::RegisterLocation> m_registers; // where to find reg values for this frame
260
261     lldb_private::UnwindLLDB& m_parent_unwind;    // The UnwindLLDB that is creating this RegisterContextLLDB
262
263     //------------------------------------------------------------------
264     // For RegisterContextLLDB only
265     //------------------------------------------------------------------
266
267     DISALLOW_COPY_AND_ASSIGN (RegisterContextLLDB);
268 };
269
270 } // namespace lldb_private
271
272 #endif  // lldb_RegisterContextLLDB_h_