]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Target/RegisterContext.h
MFV r316933: 5142 libzfs support raidz root pool (loader project)
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Target / RegisterContext.h
1 //===-- RegisterContext.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_RegisterContext_h_
11 #define liblldb_RegisterContext_h_
12
13 // C Includes
14 // C++ Includes
15 // Other libraries and framework includes
16 // Project includes
17 #include "lldb/Target/ExecutionContextScope.h"
18 #include "lldb/lldb-private.h"
19
20 namespace lldb_private {
21
22 class RegisterContext : public std::enable_shared_from_this<RegisterContext>,
23                         public ExecutionContextScope {
24 public:
25   //------------------------------------------------------------------
26   // Constructors and Destructors
27   //------------------------------------------------------------------
28   RegisterContext(Thread &thread, uint32_t concrete_frame_idx);
29
30   ~RegisterContext() override;
31
32   void InvalidateIfNeeded(bool force);
33
34   //------------------------------------------------------------------
35   // Subclasses must override these functions
36   //------------------------------------------------------------------
37   virtual void InvalidateAllRegisters() = 0;
38
39   virtual size_t GetRegisterCount() = 0;
40
41   virtual const RegisterInfo *GetRegisterInfoAtIndex(size_t reg) = 0;
42
43   // Detect the register size dynamically.
44   uint32_t UpdateDynamicRegisterSize(const lldb_private::ArchSpec &arch,
45                                      RegisterInfo *reg_info);
46
47   virtual size_t GetRegisterSetCount() = 0;
48
49   virtual const RegisterSet *GetRegisterSet(size_t reg_set) = 0;
50
51   virtual bool ReadRegister(const RegisterInfo *reg_info,
52                             RegisterValue &reg_value) = 0;
53
54   virtual bool WriteRegister(const RegisterInfo *reg_info,
55                              const RegisterValue &reg_value) = 0;
56
57   virtual bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) {
58     return false;
59   }
60
61   virtual bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) {
62     return false;
63   }
64
65   // These two functions are used to implement "push" and "pop" of register
66   // states.  They are used primarily
67   // for expression evaluation, where we need to push a new state (storing the
68   // old one in data_sp) and then
69   // restoring the original state by passing the data_sp we got from
70   // ReadAllRegisters to WriteAllRegisterValues.
71   // ReadAllRegisters will do what is necessary to return a coherent set of
72   // register values for this thread, which
73   // may mean e.g. interrupting a thread that is sitting in a kernel trap.  That
74   // is a somewhat disruptive operation,
75   // so these API's should only be used when this behavior is needed.
76
77   virtual bool
78   ReadAllRegisterValues(lldb_private::RegisterCheckpoint &reg_checkpoint);
79
80   virtual bool WriteAllRegisterValues(
81       const lldb_private::RegisterCheckpoint &reg_checkpoint);
82
83   bool CopyFromRegisterContext(lldb::RegisterContextSP context);
84
85   //------------------------------------------------------------------
86   /// Convert from a given register numbering scheme to the lldb register
87   /// numbering scheme
88   ///
89   /// There may be multiple ways to enumerate the registers for a given
90   /// architecture.  ABI references will specify one to be used with
91   /// DWARF, the register numberings from process plugin, there may
92   /// be a variation used for eh_frame unwind instructions (e.g. on Darwin),
93   /// and so on.  Register 5 by itself is meaningless - RegisterKind
94   /// enumeration tells you what context that number should be translated as.
95   ///
96   /// Inside lldb, register numbers are in the eRegisterKindLLDB scheme;
97   /// arguments which take a register number should take one in that
98   /// scheme.
99   ///
100   /// eRegisterKindGeneric is a special numbering scheme which gives us
101   /// constant values for the pc, frame register, stack register, etc., for
102   /// use within lldb.  They may not be defined for all architectures but
103   /// it allows generic code to translate these common registers into the
104   /// lldb numbering scheme.
105   ///
106   /// This method translates a given register kind + register number into
107   /// the eRegisterKindLLDB register numbering.
108   ///
109   /// @param [in] kind
110   ///     The register numbering scheme (RegisterKind) that the following
111   ///     register number is in.
112   ///
113   /// @param [in] num
114   ///     A register number in the 'kind' register numbering scheme.
115   ///
116   /// @return
117   ///     The equivalent register number in the eRegisterKindLLDB
118   ///     numbering scheme, if possible, else LLDB_INVALID_REGNUM.
119   //------------------------------------------------------------------
120   virtual uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind,
121                                                        uint32_t num) = 0;
122
123   //------------------------------------------------------------------
124   // Subclasses can override these functions if desired
125   //------------------------------------------------------------------
126   virtual uint32_t NumSupportedHardwareBreakpoints();
127
128   virtual uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size);
129
130   virtual bool ClearHardwareBreakpoint(uint32_t hw_idx);
131
132   virtual uint32_t NumSupportedHardwareWatchpoints();
133
134   virtual uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
135                                          bool read, bool write);
136
137   virtual bool ClearHardwareWatchpoint(uint32_t hw_index);
138
139   virtual bool HardwareSingleStep(bool enable);
140
141   virtual Status
142   ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info,
143                               lldb::addr_t src_addr, uint32_t src_len,
144                               RegisterValue &reg_value);
145
146   virtual Status
147   WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info,
148                              lldb::addr_t dst_addr, uint32_t dst_len,
149                              const RegisterValue &reg_value);
150
151   //------------------------------------------------------------------
152   // Subclasses should not override these
153   //------------------------------------------------------------------
154   virtual lldb::tid_t GetThreadID() const;
155
156   virtual Thread &GetThread() { return m_thread; }
157
158   const RegisterInfo *GetRegisterInfoByName(llvm::StringRef reg_name,
159                                             uint32_t start_idx = 0);
160
161   const RegisterInfo *GetRegisterInfo(lldb::RegisterKind reg_kind,
162                                       uint32_t reg_num);
163
164   uint64_t GetPC(uint64_t fail_value = LLDB_INVALID_ADDRESS);
165
166   bool SetPC(uint64_t pc);
167
168   bool SetPC(Address addr);
169
170   uint64_t GetSP(uint64_t fail_value = LLDB_INVALID_ADDRESS);
171
172   bool SetSP(uint64_t sp);
173
174   uint64_t GetFP(uint64_t fail_value = LLDB_INVALID_ADDRESS);
175
176   bool SetFP(uint64_t fp);
177
178   const char *GetRegisterName(uint32_t reg);
179
180   uint64_t GetReturnAddress(uint64_t fail_value = LLDB_INVALID_ADDRESS);
181
182   uint64_t GetFlags(uint64_t fail_value = 0);
183
184   uint64_t ReadRegisterAsUnsigned(uint32_t reg, uint64_t fail_value);
185
186   uint64_t ReadRegisterAsUnsigned(const RegisterInfo *reg_info,
187                                   uint64_t fail_value);
188
189   bool WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval);
190
191   bool WriteRegisterFromUnsigned(const RegisterInfo *reg_info, uint64_t uval);
192
193   bool ConvertBetweenRegisterKinds(lldb::RegisterKind source_rk,
194                                    uint32_t source_regnum,
195                                    lldb::RegisterKind target_rk,
196                                    uint32_t &target_regnum);
197
198   //------------------------------------------------------------------
199   // lldb::ExecutionContextScope pure virtual functions
200   //------------------------------------------------------------------
201   lldb::TargetSP CalculateTarget() override;
202
203   lldb::ProcessSP CalculateProcess() override;
204
205   lldb::ThreadSP CalculateThread() override;
206
207   lldb::StackFrameSP CalculateStackFrame() override;
208
209   void CalculateExecutionContext(ExecutionContext &exe_ctx) override;
210
211   uint32_t GetStopID() const { return m_stop_id; }
212
213   void SetStopID(uint32_t stop_id) { m_stop_id = stop_id; }
214
215 protected:
216   //------------------------------------------------------------------
217   // Classes that inherit from RegisterContext can see and modify these
218   //------------------------------------------------------------------
219   Thread &m_thread; // The thread that this register context belongs to.
220   uint32_t m_concrete_frame_idx; // The concrete frame index for this register
221                                  // context
222   uint32_t m_stop_id; // The stop ID that any data in this context is valid for
223 private:
224   //------------------------------------------------------------------
225   // For RegisterContext only
226   //------------------------------------------------------------------
227   DISALLOW_COPY_AND_ASSIGN(RegisterContext);
228 };
229
230 } // namespace lldb_private
231
232 #endif // liblldb_RegisterContext_h_