LLDB mainline
RegisterContext.h
Go to the documentation of this file.
1//===-- RegisterContext.h ---------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_TARGET_REGISTERCONTEXT_H
10#define LLDB_TARGET_REGISTERCONTEXT_H
11
14#include "lldb/lldb-private.h"
15
16namespace lldb_private {
17
18class RegisterContext : public std::enable_shared_from_this<RegisterContext>,
20public:
21 // Constructors and Destructors
22 RegisterContext(Thread &thread, uint32_t concrete_frame_idx);
23
24 ~RegisterContext() override;
25
26 void InvalidateIfNeeded(bool force);
27
28 // Subclasses must override these functions
29 virtual void InvalidateAllRegisters() = 0;
30
31 virtual size_t GetRegisterCount() = 0;
32
33 virtual const RegisterInfo *GetRegisterInfoAtIndex(size_t reg) = 0;
34
35 virtual size_t GetRegisterSetCount() = 0;
36
37 virtual const RegisterSet *GetRegisterSet(size_t reg_set) = 0;
38
40
41 virtual bool ReadRegister(const RegisterInfo *reg_info,
42 RegisterValue &reg_value) = 0;
43
44 virtual bool WriteRegister(const RegisterInfo *reg_info,
45 const RegisterValue &reg_value) = 0;
46
48 return false;
49 }
50
51 virtual bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) {
52 return false;
53 }
54
55 virtual bool RegisterWriteCausesReconfigure(const llvm::StringRef name) {
56 return false;
57 }
58
59 virtual bool ReconfigureRegisterInfo() { return false; }
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
73
74 virtual bool WriteAllRegisterValues(
75 const lldb_private::RegisterCheckpoint &reg_checkpoint);
76
78
79 /// Convert from a given register numbering scheme to the lldb register
80 /// numbering scheme
81 ///
82 /// There may be multiple ways to enumerate the registers for a given
83 /// architecture. ABI references will specify one to be used with
84 /// DWARF, the register numberings from process plugin, there may
85 /// be a variation used for eh_frame unwind instructions (e.g. on Darwin),
86 /// and so on. Register 5 by itself is meaningless - RegisterKind
87 /// enumeration tells you what context that number should be translated as.
88 ///
89 /// Inside lldb, register numbers are in the eRegisterKindLLDB scheme;
90 /// arguments which take a register number should take one in that
91 /// scheme.
92 ///
93 /// eRegisterKindGeneric is a special numbering scheme which gives us
94 /// constant values for the pc, frame register, stack register, etc., for
95 /// use within lldb. They may not be defined for all architectures but
96 /// it allows generic code to translate these common registers into the
97 /// lldb numbering scheme.
98 ///
99 /// This method translates a given register kind + register number into
100 /// the eRegisterKindLLDB register numbering.
101 ///
102 /// \param [in] kind
103 /// The register numbering scheme (RegisterKind) that the following
104 /// register number is in.
105 ///
106 /// \param [in] num
107 /// A register number in the 'kind' register numbering scheme.
108 ///
109 /// \return
110 /// The equivalent register number in the eRegisterKindLLDB
111 /// numbering scheme, if possible, else LLDB_INVALID_REGNUM.
113 uint32_t num);
114
115 // Subclasses can override these functions if desired
116 virtual uint32_t NumSupportedHardwareBreakpoints();
117
118 virtual uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size);
119
120 virtual bool ClearHardwareBreakpoint(uint32_t hw_idx);
121
122 virtual uint32_t NumSupportedHardwareWatchpoints();
123
124 virtual uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
125 bool read, bool write);
126
127 virtual bool ClearHardwareWatchpoint(uint32_t hw_index);
128
129 virtual bool HardwareSingleStep(bool enable);
130
131 virtual Status
133 lldb::addr_t src_addr, uint32_t src_len,
134 RegisterValue &reg_value);
135
136 virtual Status
138 lldb::addr_t dst_addr, uint32_t dst_len,
139 const RegisterValue &reg_value);
140
141 // Subclasses should not override these
142 virtual lldb::tid_t GetThreadID() const;
143
144 virtual Thread &GetThread() { return m_thread; }
145
146 const RegisterInfo *GetRegisterInfoByName(llvm::StringRef reg_name,
147 uint32_t start_idx = 0);
148
150 uint32_t reg_num);
151
152 uint64_t GetPC(uint64_t fail_value = LLDB_INVALID_ADDRESS);
153
154 // Returns the register value containing thread specific data, like TLS data
155 // and other thread specific stuff.
156 uint64_t GetThreadPointer(uint64_t fail_value = LLDB_INVALID_ADDRESS);
157
158 /// Get an address suitable for symbolication.
159 /// When symbolicating -- computing line, block, function --
160 /// for a function in the middle of the stack, using the return
161 /// address can lead to unexpected results for the user.
162 /// A function that ends in a tail-call may have another function
163 /// as the "return" address, but it will never actually return.
164 /// Or a noreturn call in the middle of a function is the end of
165 /// a block of instructions, and a DWARF location list entry for
166 /// the return address may be a very different code path with
167 /// incorrect results when printing variables for this frame.
168 ///
169 /// At a source line view, the user expects the current-line indictation
170 /// to point to the function call they're under, not the next source line.
171 ///
172 /// The return address (GetPC()) should always be shown to the user,
173 /// but when computing context, keeping within the bounds of the
174 /// call instruction is what the user expects to see.
175 ///
176 /// \param [out] address
177 /// An Address object that will be filled in, if a PC can be retrieved.
178 ///
179 /// \return
180 /// Returns true if the Address param was filled in.
181 bool GetPCForSymbolication(Address &address);
182
183 bool SetPC(uint64_t pc);
184
185 bool SetPC(Address addr);
186
187 uint64_t GetSP(uint64_t fail_value = LLDB_INVALID_ADDRESS);
188
189 bool SetSP(uint64_t sp);
190
191 uint64_t GetFP(uint64_t fail_value = LLDB_INVALID_ADDRESS);
192
193 bool SetFP(uint64_t fp);
194
195 const char *GetRegisterName(uint32_t reg);
196
197 uint64_t GetReturnAddress(uint64_t fail_value = LLDB_INVALID_ADDRESS);
198
199 uint64_t GetFlags(uint64_t fail_value = 0);
200
201 uint64_t ReadRegisterAsUnsigned(uint32_t reg, uint64_t fail_value);
202
203 uint64_t ReadRegisterAsUnsigned(const RegisterInfo *reg_info,
204 uint64_t fail_value);
205
206 bool WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval);
207
208 bool WriteRegisterFromUnsigned(const RegisterInfo *reg_info, uint64_t uval);
209
211 uint32_t source_regnum,
212 lldb::RegisterKind target_rk,
213 uint32_t &target_regnum);
214
215 // lldb::ExecutionContextScope pure virtual functions
217
219
221
223
224 void CalculateExecutionContext(ExecutionContext &exe_ctx) override;
225
226 uint32_t GetStopID() const { return m_stop_id; }
227
228 void SetStopID(uint32_t stop_id) { m_stop_id = stop_id; }
229
230protected:
231 /// Indicates that this frame is currently executing code,
232 /// that the PC value is not a return-pc but an actual executing
233 /// instruction. Some places in lldb will treat a return-pc
234 /// value differently than the currently-executing-pc value,
235 /// and this method can indicate if that should be done.
236 /// The base class implementation only uses the frame index,
237 /// but subclasses may have additional information that they
238 /// can use to detect frames in this state, for instance a
239 /// frame above a trap handler (sigtramp etc)..
240 virtual bool BehavesLikeZerothFrame() const {
241 return m_concrete_frame_idx == 0;
242 }
243
244 // Classes that inherit from RegisterContext can see and modify these
245 Thread &m_thread; // The thread that this register context belongs to.
246 uint32_t m_concrete_frame_idx; // The concrete frame index for this register
247 // context
248 uint32_t m_stop_id; // The stop ID that any data in this context is valid for
249private:
250 // For RegisterContext only
252 const RegisterContext &operator=(const RegisterContext &) = delete;
253};
254
255} // namespace lldb_private
256
257#endif // LLDB_TARGET_REGISTERCONTEXT_H
A section + offset based address class.
Definition Address.h:62
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
virtual uint32_t NumSupportedHardwareBreakpoints()
bool ConvertBetweenRegisterKinds(lldb::RegisterKind source_rk, uint32_t source_regnum, lldb::RegisterKind target_rk, uint32_t &target_regnum)
virtual void InvalidateAllRegisters()=0
virtual bool HardwareSingleStep(bool enable)
virtual bool RegisterWriteCausesReconfigure(const llvm::StringRef name)
virtual bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp)
virtual uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size)
virtual const RegisterSet * GetRegisterSet(size_t reg_set)=0
virtual bool ClearHardwareBreakpoint(uint32_t hw_idx)
void CalculateExecutionContext(ExecutionContext &exe_ctx) override
Reconstruct the object's execution context into sc.
virtual uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size, bool read, bool write)
virtual bool ClearHardwareWatchpoint(uint32_t hw_index)
bool CopyFromRegisterContext(lldb::RegisterContextSP context)
virtual lldb::tid_t GetThreadID() const
virtual bool BehavesLikeZerothFrame() const
Indicates that this frame is currently executing code, that the PC value is not a return-pc but an ac...
virtual Status ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info, lldb::addr_t src_addr, uint32_t src_len, RegisterValue &reg_value)
virtual uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind, uint32_t num)
Convert from a given register numbering scheme to the lldb register numbering scheme.
bool GetPCForSymbolication(Address &address)
Get an address suitable for symbolication.
lldb::StackFrameSP CalculateStackFrame() override
uint64_t GetPC(uint64_t fail_value=LLDB_INVALID_ADDRESS)
uint64_t GetThreadPointer(uint64_t fail_value=LLDB_INVALID_ADDRESS)
uint64_t GetReturnAddress(uint64_t fail_value=LLDB_INVALID_ADDRESS)
uint64_t ReadRegisterAsUnsigned(uint32_t reg, uint64_t fail_value)
virtual const RegisterInfo * GetRegisterInfoAtIndex(size_t reg)=0
uint64_t GetSP(uint64_t fail_value=LLDB_INVALID_ADDRESS)
const char * GetRegisterName(uint32_t reg)
virtual bool WriteRegister(const RegisterInfo *reg_info, const RegisterValue &reg_value)=0
uint64_t GetFlags(uint64_t fail_value=0)
RegisterContext(Thread &thread, uint32_t concrete_frame_idx)
void SetStopID(uint32_t stop_id)
lldb::TargetSP CalculateTarget() override
const RegisterInfo * GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num)
RegisterContext(const RegisterContext &)=delete
virtual size_t GetRegisterCount()=0
const RegisterContext & operator=(const RegisterContext &)=delete
lldb::ProcessSP CalculateProcess() override
virtual uint32_t NumSupportedHardwareWatchpoints()
virtual size_t GetRegisterSetCount()=0
virtual Status WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info, lldb::addr_t dst_addr, uint32_t dst_len, const RegisterValue &reg_value)
virtual bool ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp)
bool WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval)
lldb::ThreadSP CalculateThread() override
uint64_t GetFP(uint64_t fail_value=LLDB_INVALID_ADDRESS)
const RegisterInfo * GetRegisterInfoByName(llvm::StringRef reg_name, uint32_t start_idx=0)
virtual lldb::ByteOrder GetByteOrder()
virtual bool ReadRegister(const RegisterInfo *reg_info, RegisterValue &reg_value)=0
An error handling class.
Definition Status.h:118
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::Process > ProcessSP
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
uint64_t tid_t
Definition lldb-types.h:84
RegisterKind
Register numbering types.
Every register is described in detail including its name, alternate name (optional),...
Registers are grouped into register sets.