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);
202 native_endian_src.data());
203 llvm::APInt uint = llvm::APInt::getZero(src_len * 8);
204 llvm::LoadIntFromMemory(uint, native_endian_src.data(), src_len);
211 else if (reg_info.
byte_size ==
sizeof(
double))
213 else if (reg_info.
byte_size ==
sizeof(
long double))
229 "failed to copy data for register write of %s", reg_info.
name);
237 "invalid register value type for register %s", reg_info.
name);
243 llvm::StringRef vector_str,
244 const uint32_t byte_size,
248 vector_str = vector_str.trim();
249 vector_str.consume_front(
"{");
250 vector_str.consume_back(
"}");
251 vector_str = vector_str.trim();
259 llvm::StringRef cdr = vector_str;
260 std::tie(car, cdr) = vector_str.split(Sep);
261 std::vector<uint8_t> bytes;
267 while (!car.getAsInteger(0,
byte) && bytes.size() < byte_size) {
268 bytes.push_back(
byte);
269 std::tie(car, cdr) = cdr.split(Sep);
273 if (bytes.size() != byte_size)
281 size_t total_byte_size) {
282 if (total_byte_size > 8)
285 if (total_byte_size == 8)
289 (
static_cast<uint64_t
>(1) <<
static_cast<uint64_t
>(total_byte_size * 8)) -
291 return uval64 <= max;
295 size_t total_byte_size) {
296 if (total_byte_size > 8)
299 if (total_byte_size == 8)
302 const int64_t max = (
static_cast<int64_t
>(1)
303 <<
static_cast<uint64_t
>(total_byte_size * 8 - 1)) -
305 const int64_t min = ~(max);
306 return min <= sval64 && sval64 <= max;
310 llvm::StringRef value_str) {
312 if (reg_info ==
nullptr) {
318 if (value_str.empty()) {
322 const uint32_t byte_size = reg_info->
byte_size;
328 long double ldbl_val;
335 if (byte_size >
sizeof(uint64_t)) {
337 "unsupported unsigned integer byte size: %u", byte_size);
340 if (value_str.getAsInteger(0, uval64)) {
342 "'{0}' is not a valid unsigned integer string value", value_str);
349 " is too large to fit in a %u byte unsigned integer value",
356 "unsupported unsigned integer byte size: %u", byte_size);
362 if (byte_size >
sizeof(
long long)) {
364 "unsupported signed integer byte size: %u", byte_size);
368 if (value_str.getAsInteger(0, ival64)) {
370 "'{0}' is not a valid signed integer string value", value_str);
377 " is too large to fit in a %u byte signed integer value",
384 "unsupported signed integer byte size: %u", byte_size);
390 std::string value_string = std::string(value_str);
391 if (byte_size ==
sizeof(
float)) {
392 if (::sscanf(value_string.c_str(),
"%f", &flt_val) != 1) {
394 "'%s' is not a valid float string value", value_string.c_str());
399 }
else if (byte_size ==
sizeof(
double)) {
400 if (::sscanf(value_string.c_str(),
"%lf", &dbl_val) != 1) {
402 "'%s' is not a valid float string value", value_string.c_str());
407 }
else if (byte_size ==
sizeof(
long double)) {
408 if (::sscanf(value_string.c_str(),
"%Lf", &ldbl_val) != 1) {
410 "'%s' is not a valid float string value", value_string.c_str());
417 "unsupported float byte size: %u", byte_size);
442 return m_scalar.SignExtend(sign_bitpos);
479 bool *success_ptr)
const {
490 switch (
buffer.bytes.size()) {
495 return *
reinterpret_cast<const uint16_t *
>(
buffer.bytes.data());
500 *success_ptr =
false;
505 bool *success_ptr)
const {
519 switch (
buffer.bytes.size()) {
525 return *
reinterpret_cast<const uint32_t *
>(
buffer.bytes.data());
530 *success_ptr =
false;
535 bool *success_ptr)
const {
548 return m_scalar.ULongLong(fail_value);
550 switch (
buffer.bytes.size()) {
554 return *(
const uint8_t *)
buffer.bytes.data();
556 return *
reinterpret_cast<const uint16_t *
>(
buffer.bytes.data());
558 return *
reinterpret_cast<const uint32_t *
>(
buffer.bytes.data());
560 return *
reinterpret_cast<const uint64_t *
>(
buffer.bytes.data());
565 *success_ptr =
false;
570 bool *success_ptr)
const {
584 return m_scalar.UInt128(fail_value);
586 switch (
buffer.bytes.size()) {
603 *success_ptr =
false;
622 *success_ptr =
false;
642 *success_ptr =
false;
647 bool *success_ptr)
const {
663 *success_ptr =
false;
680 return buffer.bytes.data();
682 return buffer.bytes.data();
703 return buffer.bytes.size();
709 if (byte_size == 0) {
711 }
else if (byte_size == 1) {
713 }
else if (byte_size <= 2) {
715 }
else if (byte_size <= 4) {
717 }
else if (byte_size <= 8) {
719 }
else if (byte_size <= 16) {
728 if (bytes && length > 0) {
730 buffer.bytes.resize(length);
731 memcpy(
buffer.bytes.data(), bytes, length);
732 buffer.byte_order = byte_order;
761 return !(*
this == rhs);
789 byte_idx =
buffer.bytes.size() - (
bit / 8) - 1;
793 const uint32_t byte_bit =
bit % 8;
794 if (byte_idx <
buffer.bytes.size()) {
795 buffer.bytes[byte_idx] &= ~(1u << byte_bit);
829 byte_idx =
buffer.bytes.size() - (
bit / 8) - 1;
833 const uint32_t byte_bit =
bit % 8;
834 if (byte_idx <
buffer.bytes.size()) {
835 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)
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