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/lldb-public.h"
22 #include "lldb/lldb-private.h"
23 #include "lldb/Host/Endian.h"
24 #include "lldb/Core/Scalar.h"
26 namespace lldb_private {
33 kMaxRegisterByteSize = 32u
51 m_type (eTypeInvalid),
52 m_scalar ((unsigned long)0)
57 RegisterValue (uint8_t inst) :
64 RegisterValue (uint16_t inst) :
71 RegisterValue (uint32_t inst) :
78 RegisterValue (uint64_t inst) :
85 RegisterValue (llvm::APInt inst) :
88 m_scalar = llvm::APInt(inst);
92 RegisterValue (float value) :
99 RegisterValue (double value) :
106 RegisterValue (long double value) :
107 m_type (eTypeLongDouble)
113 RegisterValue (uint8_t *bytes, size_t length, lldb::ByteOrder byte_order)
115 SetBytes (bytes, length, byte_order);
125 CopyValue (const RegisterValue &rhs);
128 SetType (RegisterValue::Type type)
134 SetType (const RegisterInfo *reg_info);
137 GetData (DataExtractor &data) const;
139 // Copy the register value from this object into a buffer in "dst"
140 // and obey the "dst_byte_order" when copying the data. Also watch out
141 // in case "dst_len" is longer or shorter than the register value
142 // described by "reg_info" and only copy the least significant bytes
143 // of the register value, or pad the destination with zeroes if the
144 // register byte size is shorter that "dst_len" (all while correctly
145 // abiding the "dst_byte_order"). Returns the number of bytes copied
148 GetAsMemoryData (const RegisterInfo *reg_info,
151 lldb::ByteOrder dst_byte_order,
155 SetFromMemoryData (const RegisterInfo *reg_info,
158 lldb::ByteOrder src_byte_order,
162 GetScalarValue (Scalar &scalar) const;
165 GetAsUInt8(uint8_t fail_value = UINT8_MAX, bool *success_ptr = nullptr) const
167 if (m_type == eTypeUInt8)
171 return m_scalar.UChar(fail_value);
179 GetAsUInt16(uint16_t fail_value = UINT16_MAX, bool *success_ptr = nullptr) const;
182 GetAsUInt32(uint32_t fail_value = UINT32_MAX, bool *success_ptr = nullptr) const;
185 GetAsUInt64(uint64_t fail_value = UINT64_MAX, bool *success_ptr = nullptr) const;
188 GetAsUInt128(const llvm::APInt& fail_value, bool *success_ptr = nullptr) const;
191 GetAsFloat(float fail_value = 0.0f, bool *success_ptr = nullptr) const;
194 GetAsDouble(double fail_value = 0.0, bool *success_ptr = nullptr) const;
197 GetAsLongDouble(long double fail_value = 0.0, bool *success_ptr = nullptr) const;
202 m_type = eTypeInvalid;
206 ClearBit (uint32_t bit);
209 SetBit (uint32_t bit);
212 operator == (const RegisterValue &rhs) const;
215 operator != (const RegisterValue &rhs) const;
218 operator = (uint8_t uint)
225 operator = (uint16_t uint)
227 m_type = eTypeUInt16;
232 operator = (uint32_t uint)
234 m_type = eTypeUInt32;
239 operator = (uint64_t uint)
241 m_type = eTypeUInt64;
246 operator = (llvm::APInt uint)
248 m_type = eTypeUInt128;
249 m_scalar = llvm::APInt(uint);
260 operator = (double f)
262 m_type = eTypeDouble;
267 operator = (long double f)
269 m_type = eTypeLongDouble;
274 SetUInt8 (uint8_t uint)
281 SetUInt16 (uint16_t uint)
283 m_type = eTypeUInt16;
288 SetUInt32 (uint32_t uint, Type t = eTypeUInt32)
295 SetUInt64 (uint64_t uint, Type t = eTypeUInt64)
302 SetUInt128 (llvm::APInt uint)
304 m_type = eTypeUInt128;
309 SetUInt (uint64_t uint, uint32_t byte_size);
321 m_type = eTypeDouble;
326 SetLongDouble (long double f)
328 m_type = eTypeLongDouble;
333 SetBytes (const void *bytes, size_t length, lldb::ByteOrder byte_order);
336 SignExtend (uint32_t sign_bitpos);
339 SetValueFromCString (const RegisterInfo *reg_info,
340 const char *value_str);
343 SetValueFromData (const RegisterInfo *reg_info,
345 lldb::offset_t offset,
346 bool partial_data_ok);
348 // The default value of 0 for reg_name_right_align_at means no alignment at all.
351 const RegisterInfo *reg_info,
352 bool prefix_with_name,
353 bool prefix_with_alt_name,
355 uint32_t reg_name_right_align_at = 0) const;
361 GetByteOrder () const
363 if (m_type == eTypeBytes)
364 return buffer.byte_order;
365 return endian::InlHostByteOrder();
369 GetByteSize () const;
374 return kMaxRegisterByteSize;
381 RegisterValue::Type m_type;
386 uint8_t bytes[kMaxRegisterByteSize]; // This must be big enough to hold any register for any supported target.
388 lldb::ByteOrder byte_order;
392 } // namespace lldb_private
394 #endif // lldb_RegisterValue_h