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 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.
76 ReadAllRegisterValues(lldb_private::RegisterCheckpoint ®_checkpoint);
78 virtual bool WriteAllRegisterValues(
79 const lldb_private::RegisterCheckpoint ®_checkpoint);
81 bool CopyFromRegisterContext(lldb::RegisterContextSP context);
83 //------------------------------------------------------------------
84 /// Convert from a given register numbering scheme to the lldb register
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.
94 /// Inside lldb, register numbers are in the eRegisterKindLLDB scheme;
95 /// arguments which take a register number should take one in that
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.
104 /// This method translates a given register kind + register number into
105 /// the eRegisterKindLLDB register numbering.
108 /// The register numbering scheme (RegisterKind) that the following
109 /// register number is in.
112 /// A register number in the 'kind' register numbering scheme.
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,
121 //------------------------------------------------------------------
122 // Subclasses can override these functions if desired
123 //------------------------------------------------------------------
124 virtual uint32_t NumSupportedHardwareBreakpoints();
126 virtual uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size);
128 virtual bool ClearHardwareBreakpoint(uint32_t hw_idx);
130 virtual uint32_t NumSupportedHardwareWatchpoints();
132 virtual uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
133 bool read, bool write);
135 virtual bool ClearHardwareWatchpoint(uint32_t hw_index);
137 virtual bool HardwareSingleStep(bool enable);
140 ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info,
141 lldb::addr_t src_addr, uint32_t src_len,
142 RegisterValue ®_value);
145 WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info,
146 lldb::addr_t dst_addr, uint32_t dst_len,
147 const RegisterValue ®_value);
149 //------------------------------------------------------------------
150 // Subclasses should not override these
151 //------------------------------------------------------------------
152 virtual lldb::tid_t GetThreadID() const;
154 virtual Thread &GetThread() { return m_thread; }
156 const RegisterInfo *GetRegisterInfoByName(llvm::StringRef reg_name,
157 uint32_t start_idx = 0);
159 const RegisterInfo *GetRegisterInfo(lldb::RegisterKind reg_kind,
162 uint64_t GetPC(uint64_t fail_value = LLDB_INVALID_ADDRESS);
164 bool SetPC(uint64_t pc);
166 bool SetPC(Address addr);
168 uint64_t GetSP(uint64_t fail_value = LLDB_INVALID_ADDRESS);
170 bool SetSP(uint64_t sp);
172 uint64_t GetFP(uint64_t fail_value = LLDB_INVALID_ADDRESS);
174 bool SetFP(uint64_t fp);
176 const char *GetRegisterName(uint32_t reg);
178 uint64_t GetReturnAddress(uint64_t fail_value = LLDB_INVALID_ADDRESS);
180 uint64_t GetFlags(uint64_t fail_value = 0);
182 uint64_t ReadRegisterAsUnsigned(uint32_t reg, uint64_t fail_value);
184 uint64_t ReadRegisterAsUnsigned(const RegisterInfo *reg_info,
185 uint64_t fail_value);
187 bool WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval);
189 bool WriteRegisterFromUnsigned(const RegisterInfo *reg_info, uint64_t uval);
191 bool ConvertBetweenRegisterKinds(lldb::RegisterKind source_rk,
192 uint32_t source_regnum,
193 lldb::RegisterKind target_rk,
194 uint32_t &target_regnum);
196 //------------------------------------------------------------------
197 // lldb::ExecutionContextScope pure virtual functions
198 //------------------------------------------------------------------
199 lldb::TargetSP CalculateTarget() override;
201 lldb::ProcessSP CalculateProcess() override;
203 lldb::ThreadSP CalculateThread() override;
205 lldb::StackFrameSP CalculateStackFrame() override;
207 void CalculateExecutionContext(ExecutionContext &exe_ctx) override;
209 uint32_t GetStopID() const { return m_stop_id; }
211 void SetStopID(uint32_t stop_id) { m_stop_id = stop_id; }
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
220 uint32_t m_stop_id; // The stop ID that any data in this context is valid for
222 //------------------------------------------------------------------
223 // For RegisterContext only
224 //------------------------------------------------------------------
225 DISALLOW_COPY_AND_ASSIGN(RegisterContext);
228 } // namespace lldb_private
230 #endif // liblldb_RegisterContext_h_