1 //===-- RegisterValue.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 lldb_RegisterValue_h
11 #define lldb_RegisterValue_h
17 // Other libraries and framework includes
18 #include "llvm/ADT/APInt.h"
21 #include "lldb/Core/Scalar.h"
22 #include "lldb/Host/Endian.h"
23 #include "lldb/lldb-private.h"
24 #include "lldb/lldb-public.h"
26 namespace lldb_private {
30 enum { kMaxRegisterByteSize = 32u };
45 RegisterValue() : m_type(eTypeInvalid), m_scalar((unsigned long)0) {}
47 explicit RegisterValue(uint8_t inst) : m_type(eTypeUInt8) { m_scalar = inst; }
49 explicit RegisterValue(uint16_t inst) : m_type(eTypeUInt16) {
53 explicit RegisterValue(uint32_t inst) : m_type(eTypeUInt32) {
57 explicit RegisterValue(uint64_t inst) : m_type(eTypeUInt64) {
61 explicit RegisterValue(llvm::APInt inst) : m_type(eTypeUInt128) {
62 m_scalar = llvm::APInt(inst);
65 explicit RegisterValue(float value) : m_type(eTypeFloat) { m_scalar = value; }
67 explicit RegisterValue(double value) : m_type(eTypeDouble) {
71 explicit RegisterValue(long double value) : m_type(eTypeLongDouble) {
75 explicit RegisterValue(uint8_t *bytes, size_t length,
76 lldb::ByteOrder byte_order) {
77 SetBytes(bytes, length, byte_order);
80 RegisterValue::Type GetType() const { return m_type; }
82 bool CopyValue(const RegisterValue &rhs);
84 void SetType(RegisterValue::Type type) { m_type = type; }
86 RegisterValue::Type SetType(const RegisterInfo *reg_info);
88 bool GetData(DataExtractor &data) const;
90 // Copy the register value from this object into a buffer in "dst"
91 // and obey the "dst_byte_order" when copying the data. Also watch out
92 // in case "dst_len" is longer or shorter than the register value
93 // described by "reg_info" and only copy the least significant bytes
94 // of the register value, or pad the destination with zeroes if the
95 // register byte size is shorter that "dst_len" (all while correctly
96 // abiding the "dst_byte_order"). Returns the number of bytes copied
98 uint32_t GetAsMemoryData(const RegisterInfo *reg_info, void *dst,
99 uint32_t dst_len, lldb::ByteOrder dst_byte_order,
102 uint32_t SetFromMemoryData(const RegisterInfo *reg_info, const void *src,
103 uint32_t src_len, lldb::ByteOrder src_byte_order,
106 bool GetScalarValue(Scalar &scalar) const;
108 uint8_t GetAsUInt8(uint8_t fail_value = UINT8_MAX,
109 bool *success_ptr = nullptr) const {
110 if (m_type == eTypeUInt8) {
113 return m_scalar.UChar(fail_value);
120 uint16_t GetAsUInt16(uint16_t fail_value = UINT16_MAX,
121 bool *success_ptr = nullptr) const;
123 uint32_t GetAsUInt32(uint32_t fail_value = UINT32_MAX,
124 bool *success_ptr = nullptr) const;
126 uint64_t GetAsUInt64(uint64_t fail_value = UINT64_MAX,
127 bool *success_ptr = nullptr) const;
129 llvm::APInt GetAsUInt128(const llvm::APInt &fail_value,
130 bool *success_ptr = nullptr) const;
132 float GetAsFloat(float fail_value = 0.0f, bool *success_ptr = nullptr) const;
134 double GetAsDouble(double fail_value = 0.0,
135 bool *success_ptr = nullptr) const;
137 long double GetAsLongDouble(long double fail_value = 0.0,
138 bool *success_ptr = nullptr) const;
140 void SetValueToInvalid() { m_type = eTypeInvalid; }
142 bool ClearBit(uint32_t bit);
144 bool SetBit(uint32_t bit);
146 bool operator==(const RegisterValue &rhs) const;
148 bool operator!=(const RegisterValue &rhs) const;
150 void operator=(uint8_t uint) {
155 void operator=(uint16_t uint) {
156 m_type = eTypeUInt16;
160 void operator=(uint32_t uint) {
161 m_type = eTypeUInt32;
165 void operator=(uint64_t uint) {
166 m_type = eTypeUInt64;
170 void operator=(llvm::APInt uint) {
171 m_type = eTypeUInt128;
172 m_scalar = llvm::APInt(uint);
175 void operator=(float f) {
180 void operator=(double f) {
181 m_type = eTypeDouble;
185 void operator=(long double f) {
186 m_type = eTypeLongDouble;
190 void SetUInt8(uint8_t uint) {
195 void SetUInt16(uint16_t uint) {
196 m_type = eTypeUInt16;
200 void SetUInt32(uint32_t uint, Type t = eTypeUInt32) {
205 void SetUInt64(uint64_t uint, Type t = eTypeUInt64) {
210 void SetUInt128(llvm::APInt uint) {
211 m_type = eTypeUInt128;
215 bool SetUInt(uint64_t uint, uint32_t byte_size);
217 void SetFloat(float f) {
222 void SetDouble(double f) {
223 m_type = eTypeDouble;
227 void SetLongDouble(long double f) {
228 m_type = eTypeLongDouble;
232 void SetBytes(const void *bytes, size_t length, lldb::ByteOrder byte_order);
234 bool SignExtend(uint32_t sign_bitpos);
236 Error SetValueFromString(const RegisterInfo *reg_info,
237 llvm::StringRef value_str);
238 Error SetValueFromString(const RegisterInfo *reg_info,
239 const char *value_str) = delete;
241 Error SetValueFromData(const RegisterInfo *reg_info, DataExtractor &data,
242 lldb::offset_t offset, bool partial_data_ok);
244 // The default value of 0 for reg_name_right_align_at means no alignment at
246 bool Dump(Stream *s, const RegisterInfo *reg_info, bool prefix_with_name,
247 bool prefix_with_alt_name, lldb::Format format,
248 uint32_t reg_name_right_align_at = 0) const;
250 const void *GetBytes() const;
252 lldb::ByteOrder GetByteOrder() const {
253 if (m_type == eTypeBytes)
254 return buffer.byte_order;
255 return endian::InlHostByteOrder();
258 uint32_t GetByteSize() const;
260 static uint32_t GetMaxByteSize() { return kMaxRegisterByteSize; }
265 RegisterValue::Type m_type;
269 uint8_t bytes[kMaxRegisterByteSize]; // This must be big enough to hold any
270 // register for any supported target.
272 lldb::ByteOrder byte_order;
276 } // namespace lldb_private
278 #endif // lldb_RegisterValue_h