]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Target/RegisterContext.h
Merge clang 7.0.1 and several follow-up changes
[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 for expression evaluation, where we need
67   // to push a new state (storing the old one in data_sp) and then restoring
68   // the original state by passing the data_sp we got from ReadAllRegisters to
69   // WriteAllRegisterValues. ReadAllRegisters will do what is necessary to
70   // return a coherent set of register values for this thread, which may mean
71   // e.g. interrupting a thread that is sitting in a kernel trap.  That is a
72   // somewhat disruptive operation, so these API's should only be used when
73   // this behavior is needed.
74
75   virtual bool
76   ReadAllRegisterValues(lldb_private::RegisterCheckpoint &reg_checkpoint);
77
78   virtual bool WriteAllRegisterValues(
79       const lldb_private::RegisterCheckpoint &reg_checkpoint);
80
81   bool CopyFromRegisterContext(lldb::RegisterContextSP context);
82
83   //------------------------------------------------------------------
84   /// Convert from a given register numbering scheme to the lldb register
85   /// numbering scheme
86   ///
87   /// There may be multiple ways to enumerate the registers for a given
88   /// architecture.  ABI references will specify one to be used with
89   /// DWARF, the register numberings from process plugin, there may
90   /// be a variation used for eh_frame unwind instructions (e.g. on Darwin),
91   /// and so on.  Register 5 by itself is meaningless - RegisterKind
92   /// enumeration tells you what context that number should be translated as.
93   ///
94   /// Inside lldb, register numbers are in the eRegisterKindLLDB scheme;
95   /// arguments which take a register number should take one in that
96   /// scheme.
97   ///
98   /// eRegisterKindGeneric is a special numbering scheme which gives us
99   /// constant values for the pc, frame register, stack register, etc., for
100   /// use within lldb.  They may not be defined for all architectures but
101   /// it allows generic code to translate these common registers into the
102   /// lldb numbering scheme.
103   ///
104   /// This method translates a given register kind + register number into
105   /// the eRegisterKindLLDB register numbering.
106   ///
107   /// @param [in] kind
108   ///     The register numbering scheme (RegisterKind) that the following
109   ///     register number is in.
110   ///
111   /// @param [in] num
112   ///     A register number in the 'kind' register numbering scheme.
113   ///
114   /// @return
115   ///     The equivalent register number in the eRegisterKindLLDB
116   ///     numbering scheme, if possible, else LLDB_INVALID_REGNUM.
117   //------------------------------------------------------------------
118   virtual uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind,
119                                                        uint32_t num) = 0;
120
121   //------------------------------------------------------------------
122   // Subclasses can override these functions if desired
123   //------------------------------------------------------------------
124   virtual uint32_t NumSupportedHardwareBreakpoints();
125
126   virtual uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size);
127
128   virtual bool ClearHardwareBreakpoint(uint32_t hw_idx);
129
130   virtual uint32_t NumSupportedHardwareWatchpoints();
131
132   virtual uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
133                                          bool read, bool write);
134
135   virtual bool ClearHardwareWatchpoint(uint32_t hw_index);
136
137   virtual bool HardwareSingleStep(bool enable);
138
139   virtual Status
140   ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info,
141                               lldb::addr_t src_addr, uint32_t src_len,
142                               RegisterValue &reg_value);
143
144   virtual Status
145   WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info,
146                              lldb::addr_t dst_addr, uint32_t dst_len,
147                              const RegisterValue &reg_value);
148
149   //------------------------------------------------------------------
150   // Subclasses should not override these
151   //------------------------------------------------------------------
152   virtual lldb::tid_t GetThreadID() const;
153
154   virtual Thread &GetThread() { return m_thread; }
155
156   const RegisterInfo *GetRegisterInfoByName(llvm::StringRef reg_name,
157                                             uint32_t start_idx = 0);
158
159   const RegisterInfo *GetRegisterInfo(lldb::RegisterKind reg_kind,
160                                       uint32_t reg_num);
161
162   uint64_t GetPC(uint64_t fail_value = LLDB_INVALID_ADDRESS);
163
164   bool SetPC(uint64_t pc);
165
166   bool SetPC(Address addr);
167
168   uint64_t GetSP(uint64_t fail_value = LLDB_INVALID_ADDRESS);
169
170   bool SetSP(uint64_t sp);
171
172   uint64_t GetFP(uint64_t fail_value = LLDB_INVALID_ADDRESS);
173
174   bool SetFP(uint64_t fp);
175
176   const char *GetRegisterName(uint32_t reg);
177
178   uint64_t GetReturnAddress(uint64_t fail_value = LLDB_INVALID_ADDRESS);
179
180   uint64_t GetFlags(uint64_t fail_value = 0);
181
182   uint64_t ReadRegisterAsUnsigned(uint32_t reg, uint64_t fail_value);
183
184   uint64_t ReadRegisterAsUnsigned(const RegisterInfo *reg_info,
185                                   uint64_t fail_value);
186
187   bool WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval);
188
189   bool WriteRegisterFromUnsigned(const RegisterInfo *reg_info, uint64_t uval);
190
191   bool ConvertBetweenRegisterKinds(lldb::RegisterKind source_rk,
192                                    uint32_t source_regnum,
193                                    lldb::RegisterKind target_rk,
194                                    uint32_t &target_regnum);
195
196   //------------------------------------------------------------------
197   // lldb::ExecutionContextScope pure virtual functions
198   //------------------------------------------------------------------
199   lldb::TargetSP CalculateTarget() override;
200
201   lldb::ProcessSP CalculateProcess() override;
202
203   lldb::ThreadSP CalculateThread() override;
204
205   lldb::StackFrameSP CalculateStackFrame() override;
206
207   void CalculateExecutionContext(ExecutionContext &exe_ctx) override;
208
209   uint32_t GetStopID() const { return m_stop_id; }
210
211   void SetStopID(uint32_t stop_id) { m_stop_id = stop_id; }
212
213 protected:
214   //------------------------------------------------------------------
215   // Classes that inherit from RegisterContext can see and modify these
216   //------------------------------------------------------------------
217   Thread &m_thread; // The thread that this register context belongs to.
218   uint32_t m_concrete_frame_idx; // The concrete frame index for this register
219                                  // context
220   uint32_t m_stop_id; // The stop ID that any data in this context is valid for
221 private:
222   //------------------------------------------------------------------
223   // For RegisterContext only
224   //------------------------------------------------------------------
225   DISALLOW_COPY_AND_ASSIGN(RegisterContext);
226 };
227
228 } // namespace lldb_private
229
230 #endif // liblldb_RegisterContext_h_