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