19#include "llvm/ADT/ArrayRef.h"
20#include "llvm/ADT/StringRef.h"
47 "invalid register value type for register {0}", reg_info.
name);
51 const uint32_t src_len = reg_info.
byte_size;
61 const uint32_t bytes_copied =
67 if (bytes_copied == 0)
69 "failed to copy data for register write of %s", reg_info.
name);
75 const void *src, uint32_t src_len,
94 const uint32_t dst_len = reg_info.
byte_size;
96 if (src_len > dst_len) {
98 "%u bytes is too big to store in register %s (%u bytes)", src_len,
99 reg_info.
name, dst_len);
148 assert(
error.Success() &&
"Expected SetValueFromData to succeed.");
158 bool partial_data_ok) {
173 if (!partial_data_ok && (src_len < reg_info.
byte_size)) {
198 std::vector<uint8_t> native_endian_src(src_len, 0);
200 native_endian_src.data());
201 llvm::APInt uint = llvm::APInt::getZero(src_len * 8);
202 llvm::LoadIntFromMemory(uint, native_endian_src.data(), src_len);
209 else if (reg_info.
byte_size ==
sizeof(
double))
211 else if (reg_info.
byte_size ==
sizeof(
long double))
227 "failed to copy data for register write of %s", reg_info.
name);
235 "invalid register value type for register %s", reg_info.
name);
241 llvm::StringRef vector_str,
242 const uint32_t byte_size,
246 vector_str = vector_str.trim();
247 vector_str.consume_front(
"{");
248 vector_str.consume_back(
"}");
249 vector_str = vector_str.trim();
257 llvm::StringRef cdr = vector_str;
258 std::tie(car, cdr) = vector_str.split(Sep);
259 std::vector<uint8_t> bytes;
265 while (!car.getAsInteger(0,
byte) && bytes.size() < byte_size) {
266 bytes.push_back(
byte);
267 std::tie(car, cdr) = cdr.split(Sep);
271 if (bytes.size() != byte_size)
279 size_t total_byte_size) {
280 if (total_byte_size > 8)
283 if (total_byte_size == 8)
287 (
static_cast<uint64_t
>(1) <<
static_cast<uint64_t
>(total_byte_size * 8)) -
289 return uval64 <= max;
293 size_t total_byte_size) {
294 if (total_byte_size > 8)
297 if (total_byte_size == 8)
300 const int64_t max = (
static_cast<int64_t
>(1)
301 <<
static_cast<uint64_t
>(total_byte_size * 8 - 1)) -
303 const int64_t min = ~(max);
304 return min <= sval64 && sval64 <= max;
308 llvm::StringRef value_str) {
310 if (reg_info ==
nullptr) {
316 if (value_str.empty()) {
320 const uint32_t byte_size = reg_info->
byte_size;
326 long double ldbl_val;
333 if (byte_size >
sizeof(uint64_t)) {
335 "unsupported unsigned integer byte size: %u", byte_size);
338 if (value_str.getAsInteger(0, uval64)) {
340 "'{0}' is not a valid unsigned integer string value", value_str);
347 " is too large to fit in a %u byte unsigned integer value",
354 "unsupported unsigned integer byte size: %u", byte_size);
360 if (byte_size >
sizeof(
long long)) {
362 "unsupported signed integer byte size: %u", byte_size);
366 if (value_str.getAsInteger(0, ival64)) {
368 "'{0}' is not a valid signed integer string value", value_str);
375 " is too large to fit in a %u byte signed integer value",
382 "unsupported signed integer byte size: %u", byte_size);
388 std::string value_string = std::string(value_str);
389 if (byte_size ==
sizeof(
float)) {
390 if (::sscanf(value_string.c_str(),
"%f", &flt_val) != 1) {
392 "'%s' is not a valid float string value", value_string.c_str());
397 }
else if (byte_size ==
sizeof(
double)) {
398 if (::sscanf(value_string.c_str(),
"%lf", &dbl_val) != 1) {
400 "'%s' is not a valid float string value", value_string.c_str());
405 }
else if (byte_size ==
sizeof(
long double)) {
406 if (::sscanf(value_string.c_str(),
"%Lf", &ldbl_val) != 1) {
408 "'%s' is not a valid float string value", value_string.c_str());
415 "unsupported float byte size: %u", byte_size);
440 return m_scalar.SignExtend(sign_bitpos);
477 bool *success_ptr)
const {
488 switch (
buffer.bytes.size()) {
493 return *
reinterpret_cast<const uint16_t *
>(
buffer.bytes.data());
498 *success_ptr =
false;
503 bool *success_ptr)
const {
517 switch (
buffer.bytes.size()) {
523 return *
reinterpret_cast<const uint32_t *
>(
buffer.bytes.data());
528 *success_ptr =
false;
533 bool *success_ptr)
const {
546 return m_scalar.ULongLong(fail_value);
548 switch (
buffer.bytes.size()) {
552 return *(
const uint8_t *)
buffer.bytes.data();
554 return *
reinterpret_cast<const uint16_t *
>(
buffer.bytes.data());
556 return *
reinterpret_cast<const uint32_t *
>(
buffer.bytes.data());
558 return *
reinterpret_cast<const uint64_t *
>(
buffer.bytes.data());
563 *success_ptr =
false;
568 bool *success_ptr)
const {
582 return m_scalar.UInt128(fail_value);
584 switch (
buffer.bytes.size()) {
601 *success_ptr =
false;
620 *success_ptr =
false;
640 *success_ptr =
false;
645 bool *success_ptr)
const {
661 *success_ptr =
false;
678 return buffer.bytes.data();
680 return buffer.bytes.data();
701 return buffer.bytes.size();
707 if (byte_size == 0) {
709 }
else if (byte_size == 1) {
711 }
else if (byte_size <= 2) {
713 }
else if (byte_size <= 4) {
715 }
else if (byte_size <= 8) {
717 }
else if (byte_size <= 16) {
726 if (bytes && length > 0) {
728 buffer.bytes.resize(length);
729 memcpy(
buffer.bytes.data(), bytes, length);
730 buffer.byte_order = byte_order;
759 return !(*
this == rhs);
787 byte_idx =
buffer.bytes.size() - (
bit / 8) - 1;
791 const uint32_t byte_bit =
bit % 8;
792 if (byte_idx <
buffer.bytes.size()) {
793 buffer.bytes[byte_idx] &= ~(1u << byte_bit);
827 byte_idx =
buffer.bytes.size() - (
bit / 8) - 1;
831 const uint32_t byte_bit =
bit % 8;
832 if (byte_idx <
buffer.bytes.size()) {
833 buffer.bytes[byte_idx] |= (1u << byte_bit);
static llvm::raw_ostream & error(Stream &strm)
static bool ParseVectorEncoding(const RegisterInfo *reg_info, llvm::StringRef vector_str, const uint32_t byte_size, RegisterValue *reg_value)
static bool UInt64ValueIsValidForByteSize(uint64_t uval64, size_t total_byte_size)
static bool SInt64ValueIsValidForByteSize(int64_t sval64, size_t total_byte_size)
#define NUM_OF_WORDS_INT128
bool operator==(const RegisterValue &rhs) const
RegisterValue::Type m_type
uint16_t GetAsUInt16(uint16_t fail_value=UINT16_MAX, bool *success_ptr=nullptr) const
bool SignExtend(uint32_t sign_bitpos)
uint32_t SetFromMemoryData(const RegisterInfo ®_info, const void *src, uint32_t src_len, lldb::ByteOrder src_byte_order, Status &error)
long double GetAsLongDouble(long double fail_value=0.0, bool *success_ptr=nullptr) const
bool GetData(DataExtractor &data) const
void SetUInt64(uint64_t uint, Type t=eTypeUInt64)
void SetUInt16(uint16_t uint)
double GetAsDouble(double fail_value=0.0, bool *success_ptr=nullptr) const
void SetUIntN(llvm::APInt uint)
bool ClearBit(uint32_t bit)
bool SetUInt(uint64_t uint, uint32_t byte_size)
Status SetValueFromString(const RegisterInfo *reg_info, llvm::StringRef value_str)
uint32_t GetAsMemoryData(const RegisterInfo ®_info, void *dst, uint32_t dst_len, lldb::ByteOrder dst_byte_order, Status &error) const
uint64_t GetAsUInt64(uint64_t fail_value=UINT64_MAX, bool *success_ptr=nullptr) const
float GetAsFloat(float fail_value=0.0f, bool *success_ptr=nullptr) const
void SetUInt8(uint8_t uint)
llvm::APInt GetAsUInt128(const llvm::APInt &fail_value, bool *success_ptr=nullptr) const
struct lldb_private::RegisterValue::RegisterValueBuffer buffer
void SetBytes(const void *bytes, size_t length, lldb::ByteOrder byte_order)
bool GetScalarValue(Scalar &scalar) const
const void * GetBytes() const
RegisterValue::Type GetType() const
void SetLongDouble(long double f)
bool operator!=(const RegisterValue &rhs) const
Status SetValueFromData(const RegisterInfo ®_info, DataExtractor &data, lldb::offset_t offset, bool partial_data_ok)
void SetType(RegisterValue::Type type)
bool SetBit(uint32_t bit)
uint32_t GetAsUInt32(uint32_t fail_value=UINT32_MAX, bool *success_ptr=nullptr) const
bool CopyValue(const RegisterValue &rhs)
void SetUInt32(uint32_t uint, Type t=eTypeUInt32)
uint32_t GetByteSize() const
lldb::ByteOrder GetByteOrder() const
@ eTypeFloat
< This value is used when the (integer) register is larger than 64-bits.
Status SetValueFromData(const DataExtractor &data, lldb::Encoding encoding, size_t byte_size)
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
static Status FromErrorString(const char *str)
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
bool Success() const
Test for success condition.
#define UNUSED_IF_ASSERT_DISABLED(x)
lldb::ByteOrder InlHostByteOrder()
A class that represents a running process on the host machine.
static uint32_t bit(const uint32_t val, const uint32_t msbit)
@ eEncodingVector
vector registers
@ eEncodingUint
unsigned integer
@ eEncodingSint
signed integer
ByteOrder
Byte ordering definitions.
Every register is described in detail including its name, alternate name (optional),...
lldb::Encoding encoding
Encoding of the register bits.
uint32_t byte_size
Size in bytes of the register.
const char * name
Name of this register, can't be NULL.
lldb::ByteOrder byte_order