19#include "llvm/ADT/ArrayRef.h"
20#include "llvm/ADT/StringRef.h"
46 error.SetErrorStringWithFormat(
47 "invalid register value type for register %s", reg_info.
name);
51 const uint32_t src_len = reg_info.
byte_size;
56 error.SetErrorString(
"invalid register value to copy into");
61 const uint32_t bytes_copied =
67 if (bytes_copied == 0)
68 error.SetErrorStringWithFormat(
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) {
97 error.SetErrorStringWithFormat(
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) {
162 error.SetErrorString(
"empty data.");
167 error.SetErrorString(
"invalid register info.");
173 if (!partial_data_ok && (src_len < reg_info.
byte_size)) {
174 error.SetErrorString(
"not enough data.");
200 uint64_t data1 = src.
GetU64(&src_offset);
201 uint64_t data2 = src.
GetU64(&src_offset);
215 else if (reg_info.
byte_size ==
sizeof(
double))
217 else if (reg_info.
byte_size ==
sizeof(
long double))
232 error.SetErrorStringWithFormat(
233 "failed to copy data for register write of %s", reg_info.
name);
240 error.SetErrorStringWithFormat(
241 "invalid register value type for register %s", reg_info.
name);
247 llvm::StringRef vector_str,
248 const uint32_t byte_size,
252 vector_str = vector_str.trim();
253 vector_str.consume_front(
"{");
254 vector_str.consume_back(
"}");
255 vector_str = vector_str.trim();
263 llvm::StringRef cdr = vector_str;
264 std::tie(car, cdr) = vector_str.split(Sep);
265 std::vector<uint8_t> bytes;
271 while (!car.getAsInteger(0,
byte) && bytes.size() < byte_size) {
272 bytes.push_back(
byte);
273 std::tie(car, cdr) = cdr.split(Sep);
277 if (bytes.size() != byte_size)
285 size_t total_byte_size) {
286 if (total_byte_size > 8)
289 if (total_byte_size == 8)
293 (
static_cast<uint64_t
>(1) <<
static_cast<uint64_t
>(total_byte_size * 8)) -
295 return uval64 <= max;
299 size_t total_byte_size) {
300 if (total_byte_size > 8)
303 if (total_byte_size == 8)
306 const int64_t max = (
static_cast<int64_t
>(1)
307 <<
static_cast<uint64_t
>(total_byte_size * 8 - 1)) -
309 const int64_t min = ~(max);
310 return min <= sval64 && sval64 <= max;
314 llvm::StringRef value_str) {
316 if (reg_info ==
nullptr) {
317 error.SetErrorString(
"Invalid register info argument.");
322 if (value_str.empty()) {
323 error.SetErrorString(
"Invalid c-string value string.");
326 const uint32_t byte_size = reg_info->
byte_size;
332 long double ldbl_val;
335 error.SetErrorString(
"Invalid encoding.");
339 if (byte_size >
sizeof(uint64_t)) {
340 error.SetErrorStringWithFormat(
341 "unsupported unsigned integer byte size: %u", byte_size);
344 if (value_str.getAsInteger(0, uval64)) {
345 error.SetErrorStringWithFormatv(
346 "'{0}' is not a valid unsigned integer string value", value_str);
351 error.SetErrorStringWithFormat(
353 " is too large to fit in a %u byte unsigned integer value",
359 error.SetErrorStringWithFormat(
360 "unsupported unsigned integer byte size: %u", byte_size);
366 if (byte_size >
sizeof(
long long)) {
367 error.SetErrorStringWithFormat(
"unsupported signed integer byte size: %u",
372 if (value_str.getAsInteger(0, ival64)) {
373 error.SetErrorStringWithFormatv(
374 "'{0}' is not a valid signed integer string value", value_str);
379 error.SetErrorStringWithFormat(
381 " is too large to fit in a %u byte signed integer value",
387 error.SetErrorStringWithFormat(
"unsupported signed integer byte size: %u",
394 std::string value_string = std::string(value_str);
395 if (byte_size ==
sizeof(
float)) {
396 if (::sscanf(value_string.c_str(),
"%f", &flt_val) != 1) {
397 error.SetErrorStringWithFormat(
"'%s' is not a valid float string value",
398 value_string.c_str());
403 }
else if (byte_size ==
sizeof(
double)) {
404 if (::sscanf(value_string.c_str(),
"%lf", &dbl_val) != 1) {
405 error.SetErrorStringWithFormat(
"'%s' is not a valid float string value",
406 value_string.c_str());
411 }
else if (byte_size ==
sizeof(
long double)) {
412 if (::sscanf(value_string.c_str(),
"%Lf", &ldbl_val) != 1) {
413 error.SetErrorStringWithFormat(
"'%s' is not a valid float string value",
414 value_string.c_str());
420 error.SetErrorStringWithFormat(
"unsupported float byte size: %u",
428 error.SetErrorString(
"unrecognized vector encoding string value.");
482 bool *success_ptr)
const {
498 return *
reinterpret_cast<const uint16_t *
>(
buffer.
bytes.data());
503 *success_ptr =
false;
508 bool *success_ptr)
const {
528 return *
reinterpret_cast<const uint32_t *
>(
buffer.
bytes.data());
533 *success_ptr =
false;
538 bool *success_ptr)
const {
559 return *
reinterpret_cast<const uint16_t *
>(
buffer.
bytes.data());
561 return *
reinterpret_cast<const uint32_t *
>(
buffer.
bytes.data());
563 return *
reinterpret_cast<const uint64_t *
>(
buffer.
bytes.data());
568 *success_ptr =
false;
573 bool *success_ptr)
const {
604 *success_ptr =
false;
623 *success_ptr =
false;
643 *success_ptr =
false;
648 bool *success_ptr)
const {
664 *success_ptr =
false;
710 if (byte_size == 0) {
712 }
else if (byte_size == 1) {
714 }
else if (byte_size <= 2) {
716 }
else if (byte_size <= 4) {
718 }
else if (byte_size <= 8) {
720 }
else if (byte_size <= 16) {
729 if (bytes && length > 0) {
762 return !(*
this == rhs);
794 const uint32_t byte_bit =
bit % 8;
834 const uint32_t byte_bit =
bit % 8;
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
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)
void SetUInt128(llvm::APInt uint)
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
unsigned int UInt(unsigned int fail_value=0) const
bool SetBit(uint32_t bit)
size_t GetByteSize() const
Status SetValueFromData(const DataExtractor &data, lldb::Encoding encoding, size_t byte_size)
bool SignExtend(uint32_t bit_pos)
unsigned long long ULongLong(unsigned long long fail_value=0) const
void GetBytes(llvm::MutableArrayRef< uint8_t > storage) const
Store the binary representation of this value into the given storage.
bool ClearBit(uint32_t bit)
float Float(float fail_value=0.0f) const
double Double(double fail_value=0.0) const
unsigned short UShort(unsigned short fail_value=0) const
long double LongDouble(long double fail_value=0.0) const
llvm::APInt UInt128(const llvm::APInt &fail_value) const
bool Success() const
Test for success condition.
#define UNUSED_IF_ASSERT_DISABLED(x)
A class that represents a running process on the host machine.
@ 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