1 //===-- RegisterContext.h ---------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_RegisterContext_h_
11 #define liblldb_RegisterContext_h_
15 // Other libraries and framework includes
17 #include "lldb/Target/ExecutionContextScope.h"
18 #include "lldb/lldb-private.h"
20 namespace lldb_private {
22 class RegisterContext : public std::enable_shared_from_this<RegisterContext>,
23 public ExecutionContextScope {
25 //------------------------------------------------------------------
26 // Constructors and Destructors
27 //------------------------------------------------------------------
28 RegisterContext(Thread &thread, uint32_t concrete_frame_idx);
30 ~RegisterContext() override;
32 void InvalidateIfNeeded(bool force);
34 //------------------------------------------------------------------
35 // Subclasses must override these functions
36 //------------------------------------------------------------------
37 virtual void InvalidateAllRegisters() = 0;
39 virtual size_t GetRegisterCount() = 0;
41 virtual const RegisterInfo *GetRegisterInfoAtIndex(size_t reg) = 0;
43 // Detect the register size dynamically.
44 uint32_t UpdateDynamicRegisterSize(const lldb_private::ArchSpec &arch,
45 RegisterInfo *reg_info);
47 virtual size_t GetRegisterSetCount() = 0;
49 virtual const RegisterSet *GetRegisterSet(size_t reg_set) = 0;
51 virtual bool ReadRegister(const RegisterInfo *reg_info,
52 RegisterValue ®_value) = 0;
54 virtual bool WriteRegister(const RegisterInfo *reg_info,
55 const RegisterValue ®_value) = 0;
57 virtual bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) {
61 virtual bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) {
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.
78 ReadAllRegisterValues(lldb_private::RegisterCheckpoint ®_checkpoint);
80 virtual bool WriteAllRegisterValues(
81 const lldb_private::RegisterCheckpoint ®_checkpoint);
83 bool CopyFromRegisterContext(lldb::RegisterContextSP context);
85 //------------------------------------------------------------------
86 /// Convert from a given register numbering scheme to the lldb register
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.
96 /// Inside lldb, register numbers are in the eRegisterKindLLDB scheme;
97 /// arguments which take a register number should take one in that
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.
106 /// This method translates a given register kind + register number into
107 /// the eRegisterKindLLDB register numbering.
110 /// The register numbering scheme (RegisterKind) that the following
111 /// register number is in.
114 /// A register number in the 'kind' register numbering scheme.
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,
123 //------------------------------------------------------------------
124 // Subclasses can override these functions if desired
125 //------------------------------------------------------------------
126 virtual uint32_t NumSupportedHardwareBreakpoints();
128 virtual uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size);
130 virtual bool ClearHardwareBreakpoint(uint32_t hw_idx);
132 virtual uint32_t NumSupportedHardwareWatchpoints();
134 virtual uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
135 bool read, bool write);
137 virtual bool ClearHardwareWatchpoint(uint32_t hw_index);
139 virtual bool HardwareSingleStep(bool enable);
142 ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info,
143 lldb::addr_t src_addr, uint32_t src_len,
144 RegisterValue ®_value);
147 WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info,
148 lldb::addr_t dst_addr, uint32_t dst_len,
149 const RegisterValue ®_value);
151 //------------------------------------------------------------------
152 // Subclasses should not override these
153 //------------------------------------------------------------------
154 virtual lldb::tid_t GetThreadID() const;
156 virtual Thread &GetThread() { return m_thread; }
158 const RegisterInfo *GetRegisterInfoByName(llvm::StringRef reg_name,
159 uint32_t start_idx = 0);
161 const RegisterInfo *GetRegisterInfo(lldb::RegisterKind reg_kind,
164 uint64_t GetPC(uint64_t fail_value = LLDB_INVALID_ADDRESS);
166 bool SetPC(uint64_t pc);
168 bool SetPC(Address addr);
170 uint64_t GetSP(uint64_t fail_value = LLDB_INVALID_ADDRESS);
172 bool SetSP(uint64_t sp);
174 uint64_t GetFP(uint64_t fail_value = LLDB_INVALID_ADDRESS);
176 bool SetFP(uint64_t fp);
178 const char *GetRegisterName(uint32_t reg);
180 uint64_t GetReturnAddress(uint64_t fail_value = LLDB_INVALID_ADDRESS);
182 uint64_t GetFlags(uint64_t fail_value = 0);
184 uint64_t ReadRegisterAsUnsigned(uint32_t reg, uint64_t fail_value);
186 uint64_t ReadRegisterAsUnsigned(const RegisterInfo *reg_info,
187 uint64_t fail_value);
189 bool WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval);
191 bool WriteRegisterFromUnsigned(const RegisterInfo *reg_info, uint64_t uval);
193 bool ConvertBetweenRegisterKinds(lldb::RegisterKind source_rk,
194 uint32_t source_regnum,
195 lldb::RegisterKind target_rk,
196 uint32_t &target_regnum);
198 //------------------------------------------------------------------
199 // lldb::ExecutionContextScope pure virtual functions
200 //------------------------------------------------------------------
201 lldb::TargetSP CalculateTarget() override;
203 lldb::ProcessSP CalculateProcess() override;
205 lldb::ThreadSP CalculateThread() override;
207 lldb::StackFrameSP CalculateStackFrame() override;
209 void CalculateExecutionContext(ExecutionContext &exe_ctx) override;
211 uint32_t GetStopID() const { return m_stop_id; }
213 void SetStopID(uint32_t stop_id) { m_stop_id = stop_id; }
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
222 uint32_t m_stop_id; // The stop ID that any data in this context is valid for
224 //------------------------------------------------------------------
225 // For RegisterContext only
226 //------------------------------------------------------------------
227 DISALLOW_COPY_AND_ASSIGN(RegisterContext);
230 } // namespace lldb_private
232 #endif // liblldb_RegisterContext_h_