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_
13 #include "lldb/Target/ExecutionContextScope.h"
14 #include "lldb/lldb-private.h"
16 namespace lldb_private {
18 class RegisterContext : public std::enable_shared_from_this<RegisterContext>,
19 public ExecutionContextScope {
21 //------------------------------------------------------------------
22 // Constructors and Destructors
23 //------------------------------------------------------------------
24 RegisterContext(Thread &thread, uint32_t concrete_frame_idx);
26 ~RegisterContext() override;
28 void InvalidateIfNeeded(bool force);
30 //------------------------------------------------------------------
31 // Subclasses must override these functions
32 //------------------------------------------------------------------
33 virtual void InvalidateAllRegisters() = 0;
35 virtual size_t GetRegisterCount() = 0;
37 virtual const RegisterInfo *GetRegisterInfoAtIndex(size_t reg) = 0;
39 // Detect the register size dynamically.
40 uint32_t UpdateDynamicRegisterSize(const lldb_private::ArchSpec &arch,
41 RegisterInfo *reg_info);
43 virtual size_t GetRegisterSetCount() = 0;
45 virtual const RegisterSet *GetRegisterSet(size_t reg_set) = 0;
47 virtual bool ReadRegister(const RegisterInfo *reg_info,
48 RegisterValue ®_value) = 0;
50 virtual bool WriteRegister(const RegisterInfo *reg_info,
51 const RegisterValue ®_value) = 0;
53 virtual bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) {
57 virtual bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) {
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.
72 ReadAllRegisterValues(lldb_private::RegisterCheckpoint ®_checkpoint);
74 virtual bool WriteAllRegisterValues(
75 const lldb_private::RegisterCheckpoint ®_checkpoint);
77 bool CopyFromRegisterContext(lldb::RegisterContextSP context);
79 //------------------------------------------------------------------
80 /// Convert from a given register numbering scheme to the lldb register
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.
90 /// Inside lldb, register numbers are in the eRegisterKindLLDB scheme;
91 /// arguments which take a register number should take one in that
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.
100 /// This method translates a given register kind + register number into
101 /// the eRegisterKindLLDB register numbering.
104 /// The register numbering scheme (RegisterKind) that the following
105 /// register number is in.
108 /// A register number in the 'kind' register numbering scheme.
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,
117 //------------------------------------------------------------------
118 // Subclasses can override these functions if desired
119 //------------------------------------------------------------------
120 virtual uint32_t NumSupportedHardwareBreakpoints();
122 virtual uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size);
124 virtual bool ClearHardwareBreakpoint(uint32_t hw_idx);
126 virtual uint32_t NumSupportedHardwareWatchpoints();
128 virtual uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
129 bool read, bool write);
131 virtual bool ClearHardwareWatchpoint(uint32_t hw_index);
133 virtual bool HardwareSingleStep(bool enable);
136 ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info,
137 lldb::addr_t src_addr, uint32_t src_len,
138 RegisterValue ®_value);
141 WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info,
142 lldb::addr_t dst_addr, uint32_t dst_len,
143 const RegisterValue ®_value);
145 //------------------------------------------------------------------
146 // Subclasses should not override these
147 //------------------------------------------------------------------
148 virtual lldb::tid_t GetThreadID() const;
150 virtual Thread &GetThread() { return m_thread; }
152 const RegisterInfo *GetRegisterInfoByName(llvm::StringRef reg_name,
153 uint32_t start_idx = 0);
155 const RegisterInfo *GetRegisterInfo(lldb::RegisterKind reg_kind,
158 uint64_t GetPC(uint64_t fail_value = LLDB_INVALID_ADDRESS);
160 bool SetPC(uint64_t pc);
162 bool SetPC(Address addr);
164 uint64_t GetSP(uint64_t fail_value = LLDB_INVALID_ADDRESS);
166 bool SetSP(uint64_t sp);
168 uint64_t GetFP(uint64_t fail_value = LLDB_INVALID_ADDRESS);
170 bool SetFP(uint64_t fp);
172 const char *GetRegisterName(uint32_t reg);
174 uint64_t GetReturnAddress(uint64_t fail_value = LLDB_INVALID_ADDRESS);
176 uint64_t GetFlags(uint64_t fail_value = 0);
178 uint64_t ReadRegisterAsUnsigned(uint32_t reg, uint64_t fail_value);
180 uint64_t ReadRegisterAsUnsigned(const RegisterInfo *reg_info,
181 uint64_t fail_value);
183 bool WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval);
185 bool WriteRegisterFromUnsigned(const RegisterInfo *reg_info, uint64_t uval);
187 bool ConvertBetweenRegisterKinds(lldb::RegisterKind source_rk,
188 uint32_t source_regnum,
189 lldb::RegisterKind target_rk,
190 uint32_t &target_regnum);
192 //------------------------------------------------------------------
193 // lldb::ExecutionContextScope pure virtual functions
194 //------------------------------------------------------------------
195 lldb::TargetSP CalculateTarget() override;
197 lldb::ProcessSP CalculateProcess() override;
199 lldb::ThreadSP CalculateThread() override;
201 lldb::StackFrameSP CalculateStackFrame() override;
203 void CalculateExecutionContext(ExecutionContext &exe_ctx) override;
205 uint32_t GetStopID() const { return m_stop_id; }
207 void SetStopID(uint32_t stop_id) { m_stop_id = stop_id; }
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
216 uint32_t m_stop_id; // The stop ID that any data in this context is valid for
218 //------------------------------------------------------------------
219 // For RegisterContext only
220 //------------------------------------------------------------------
221 DISALLOW_COPY_AND_ASSIGN(RegisterContext);
224 } // namespace lldb_private
226 #endif // liblldb_RegisterContext_h_