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);
52 error.SetErrorString(
"destination is too big");
56 const uint32_t src_len = reg_info.byte_size;
61 error.SetErrorString(
"invalid register value to copy into");
72 if (bytes_copied == 0)
73 error.SetErrorStringWithFormat(
74 "failed to copy data for register write of %s", reg_info.name);
100 error.SetErrorStringWithFormat(
101 "register buffer is too small to receive %u bytes of data.", src_len);
105 const uint32_t dst_len = reg_info.byte_size;
107 if (src_len > dst_len) {
108 error.SetErrorStringWithFormat(
109 "%u bytes is too big to store in register %s (%u bytes)", src_len,
110 reg_info.name, dst_len);
158 assert(
error.Success() &&
"Expected SetValueFromData to succeed.");
168 bool partial_data_ok) {
172 error.SetErrorString(
"empty data.");
176 if (reg_info.byte_size == 0) {
177 error.SetErrorString(
"invalid register info.");
183 if (!partial_data_ok && (src_len < reg_info.byte_size)) {
184 error.SetErrorString(
"not enough data.");
190 if (src_len > reg_info.byte_size)
191 src_len = reg_info.byte_size;
199 switch (reg_info.encoding) {
204 if (reg_info.byte_size == 1)
206 else if (reg_info.byte_size <= 2)
208 else if (reg_info.byte_size <= 4)
210 else if (reg_info.byte_size <= 8)
212 else if (reg_info.byte_size <= 16) {
213 uint64_t data1 = src.
GetU64(&src_offset);
214 uint64_t data2 = src.
GetU64(&src_offset);
226 if (reg_info.byte_size ==
sizeof(
float))
228 else if (reg_info.byte_size ==
sizeof(
double))
230 else if (reg_info.byte_size ==
sizeof(
long double))
235 buffer.length = reg_info.byte_size;
247 error.SetErrorStringWithFormat(
248 "failed to copy data for register write of %s", reg_info.name);
255 error.SetErrorStringWithFormat(
256 "invalid register value type for register %s", reg_info.name);
262 llvm::StringRef vector_str,
267 vector_str = vector_str.trim();
268 vector_str.consume_front(
"{");
269 vector_str.consume_back(
"}");
270 vector_str = vector_str.trim();
278 llvm::StringRef cdr = vector_str;
279 std::tie(car, cdr) = vector_str.split(Sep);
280 std::vector<uint8_t> bytes;
286 while (!car.getAsInteger(0,
byte) && bytes.size() < byte_size) {
287 bytes.push_back(
byte);
288 std::tie(car, cdr) = cdr.split(Sep);
292 if (bytes.size() != byte_size)
300 size_t total_byte_size) {
301 if (total_byte_size > 8)
304 if (total_byte_size == 8)
308 (
static_cast<uint64_t
>(1) <<
static_cast<uint64_t
>(total_byte_size * 8)) -
310 return uval64 <= max;
314 size_t total_byte_size) {
315 if (total_byte_size > 8)
318 if (total_byte_size == 8)
321 const int64_t max = (
static_cast<int64_t
>(1)
322 <<
static_cast<uint64_t
>(total_byte_size * 8 - 1)) -
324 const int64_t min = ~(max);
325 return min <= sval64 && sval64 <= max;
329 llvm::StringRef value_str) {
331 if (reg_info ==
nullptr) {
332 error.SetErrorString(
"Invalid register info argument.");
337 if (value_str.empty()) {
338 error.SetErrorString(
"Invalid c-string value string.");
341 const uint32_t byte_size = reg_info->byte_size;
347 long double ldbl_val;
348 switch (reg_info->encoding) {
350 error.SetErrorString(
"Invalid encoding.");
354 if (byte_size >
sizeof(uint64_t)) {
355 error.SetErrorStringWithFormat(
356 "unsupported unsigned integer byte size: %u", byte_size);
359 if (value_str.getAsInteger(0, uval64)) {
360 error.SetErrorStringWithFormat(
361 "'%s' is not a valid unsigned integer string value",
362 value_str.str().c_str());
367 error.SetErrorStringWithFormat(
369 " is too large to fit in a %u byte unsigned integer value",
374 if (!
SetUInt(uval64, reg_info->byte_size)) {
375 error.SetErrorStringWithFormat(
376 "unsupported unsigned integer byte size: %u", byte_size);
382 if (byte_size >
sizeof(
long long)) {
383 error.SetErrorStringWithFormat(
"unsupported signed integer byte size: %u",
388 if (value_str.getAsInteger(0, ival64)) {
389 error.SetErrorStringWithFormat(
390 "'%s' is not a valid signed integer string value",
391 value_str.str().c_str());
396 error.SetErrorStringWithFormat(
398 " is too large to fit in a %u byte signed integer value",
403 if (!
SetUInt(ival64, reg_info->byte_size)) {
404 error.SetErrorStringWithFormat(
"unsupported signed integer byte size: %u",
411 std::string value_string = std::string(value_str);
412 if (byte_size ==
sizeof(
float)) {
413 if (::sscanf(value_string.c_str(),
"%f", &flt_val) != 1) {
414 error.SetErrorStringWithFormat(
"'%s' is not a valid float string value",
415 value_string.c_str());
420 }
else if (byte_size ==
sizeof(
double)) {
421 if (::sscanf(value_string.c_str(),
"%lf", &dbl_val) != 1) {
422 error.SetErrorStringWithFormat(
"'%s' is not a valid float string value",
423 value_string.c_str());
428 }
else if (byte_size ==
sizeof(
long double)) {
429 if (::sscanf(value_string.c_str(),
"%Lf", &ldbl_val) != 1) {
430 error.SetErrorStringWithFormat(
"'%s' is not a valid float string value",
431 value_string.c_str());
437 error.SetErrorStringWithFormat(
"unsupported float byte size: %u",
445 error.SetErrorString(
"unrecognized vector encoding string value.");
501 bool *success_ptr)
const {
522 *success_ptr =
false;
527 bool *success_ptr)
const {
552 *success_ptr =
false;
557 bool *success_ptr)
const {
576 return *(
const uint8_t *)
buffer.bytes;
582 return *
reinterpret_cast<const uint64_t *
>(
buffer.bytes);
587 *success_ptr =
false;
592 bool *success_ptr)
const {
617 (
reinterpret_cast<const type128 *
>(
buffer.bytes))->x);
622 *success_ptr =
false;
641 *success_ptr =
false;
661 *success_ptr =
false;
666 bool *success_ptr)
const {
682 *success_ptr =
false;
728 if (byte_size == 0) {
730 }
else if (byte_size == 1) {
732 }
else if (byte_size <= 2) {
734 }
else if (byte_size <= 4) {
736 }
else if (byte_size <= 8) {
738 }
else if (byte_size <= 16) {
752 "Storing too many bytes in a RegisterValue.");
793 return !(*
this == rhs);
821 byte_idx =
buffer.length - (
bit / 8) - 1;
826 if (byte_idx <
buffer.length) {
827 buffer.bytes[byte_idx] &= ~(1u << byte_bit);
861 byte_idx =
buffer.length - (
bit / 8) - 1;
866 if (byte_idx <
buffer.length) {
867 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
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
void SetBytes(const void *bytes, size_t length, lldb::ByteOrder byte_order)
bool GetScalarValue(Scalar &scalar) const
const void * GetBytes() const
uint8_t bytes[kMaxRegisterByteSize]
RegisterValue::Type GetType() const
void SetLongDouble(long double f)
struct lldb_private::RegisterValue::@40 buffer
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
lldb::ByteOrder byte_order
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.