20#include "llvm/ADT/ArrayRef.h"
21#include "llvm/ADT/StringRef.h"
54 auto buffer_sp = std::make_shared<DataBufferHeap>(byte_size, 0);
58 const uint8_t *source_bytes = source.
GetDataStart() + source_offset;
59 uint8_t *destination_bytes = buffer_sp->GetBytes();
60 if (source_byte_order == byte_order)
61 std::copy_n(source_bytes, byte_size, destination_bytes);
63 std::reverse_copy(source_bytes, source_bytes + byte_size,
68 return data.
SetData(buffer_sp) == byte_size;
80 "invalid register value type for register {0}", reg_info.
name);
84 const uint32_t src_len = reg_info.
byte_size;
94 const uint32_t bytes_copied =
100 if (bytes_copied == 0)
102 "failed to copy data for register write of %s", reg_info.
name);
108 const void *src, uint32_t src_len,
127 const uint32_t dst_len = reg_info.
byte_size;
129 if (src_len > dst_len) {
131 "%u bytes is too big to store in register %s (%u bytes)", src_len,
132 reg_info.
name, dst_len);
181 assert(
error.Success() &&
"Expected SetValueFromData to succeed.");
191 bool partial_data_ok) {
206 if (!partial_data_ok && (src_len < reg_info.
byte_size)) {
231 std::vector<uint8_t> native_endian_src(src_len, 0);
233 native_endian_src.data());
234 llvm::APInt uint = llvm::APInt::getZero(src_len * 8);
235 llvm::LoadIntFromMemory(uint, native_endian_src.data(), src_len);
242 else if (reg_info.
byte_size ==
sizeof(
double))
244 else if (reg_info.
byte_size ==
sizeof(
long double))
260 "failed to copy data for register write of %s", reg_info.
name);
268 "invalid register value type for register %s", reg_info.
name);
274 llvm::StringRef vector_str,
275 const uint32_t byte_size,
279 vector_str = vector_str.trim();
280 vector_str.consume_front(
"{");
281 vector_str.consume_back(
"}");
282 vector_str = vector_str.trim();
290 llvm::StringRef cdr = vector_str;
291 std::tie(car, cdr) = vector_str.split(Sep);
292 std::vector<uint8_t> bytes;
298 while (!car.getAsInteger(0,
byte) && bytes.size() < byte_size) {
299 bytes.push_back(
byte);
300 std::tie(car, cdr) = cdr.split(Sep);
304 if (bytes.size() != byte_size)
312 size_t total_byte_size) {
313 if (total_byte_size > 8)
316 if (total_byte_size == 8)
320 (
static_cast<uint64_t
>(1) <<
static_cast<uint64_t
>(total_byte_size * 8)) -
322 return uval64 <= max;
326 size_t total_byte_size) {
327 if (total_byte_size > 8)
330 if (total_byte_size == 8)
333 const int64_t max = (
static_cast<int64_t
>(1)
334 <<
static_cast<uint64_t
>(total_byte_size * 8 - 1)) -
336 const int64_t min = ~(max);
337 return min <= sval64 && sval64 <= max;
341 llvm::StringRef value_str) {
343 if (reg_info ==
nullptr) {
349 if (value_str.empty()) {
353 const uint32_t byte_size = reg_info->
byte_size;
359 long double ldbl_val;
366 if (byte_size >
sizeof(uint64_t)) {
368 "unsupported unsigned integer byte size: %u", byte_size);
371 if (value_str.getAsInteger(0, uval64)) {
373 "'{0}' is not a valid unsigned integer string value", value_str);
380 " is too large to fit in a %u byte unsigned integer value",
387 "unsupported unsigned integer byte size: %u", byte_size);
393 if (byte_size >
sizeof(
long long)) {
395 "unsupported signed integer byte size: %u", byte_size);
399 if (value_str.getAsInteger(0, ival64)) {
401 "'{0}' is not a valid signed integer string value", value_str);
408 " is too large to fit in a %u byte signed integer value",
415 "unsupported signed integer byte size: %u", byte_size);
421 std::string value_string = std::string(value_str);
422 if (byte_size ==
sizeof(
float)) {
423 if (::sscanf(value_string.c_str(),
"%f", &flt_val) != 1) {
425 "'%s' is not a valid float string value", value_string.c_str());
430 }
else if (byte_size ==
sizeof(
double)) {
431 if (::sscanf(value_string.c_str(),
"%lf", &dbl_val) != 1) {
433 "'%s' is not a valid float string value", value_string.c_str());
438 }
else if (byte_size ==
sizeof(
long double)) {
439 if (::sscanf(value_string.c_str(),
"%Lf", &ldbl_val) != 1) {
441 "'%s' is not a valid float string value", value_string.c_str());
448 "unsupported float byte size: %u", byte_size);
473 return m_scalar.SignExtend(sign_bitpos);
510 bool *success_ptr)
const {
521 switch (
buffer.bytes.size()) {
526 return *
reinterpret_cast<const uint16_t *
>(
buffer.bytes.data());
531 *success_ptr =
false;
536 bool *success_ptr)
const {
550 switch (
buffer.bytes.size()) {
556 return *
reinterpret_cast<const uint32_t *
>(
buffer.bytes.data());
561 *success_ptr =
false;
566 bool *success_ptr)
const {
579 return m_scalar.ULongLong(fail_value);
581 switch (
buffer.bytes.size()) {
585 return *(
const uint8_t *)
buffer.bytes.data();
587 return *
reinterpret_cast<const uint16_t *
>(
buffer.bytes.data());
589 return *
reinterpret_cast<const uint32_t *
>(
buffer.bytes.data());
591 return *
reinterpret_cast<const uint64_t *
>(
buffer.bytes.data());
596 *success_ptr =
false;
601 bool *success_ptr)
const {
615 return m_scalar.UInt128(fail_value);
617 switch (
buffer.bytes.size()) {
634 *success_ptr =
false;
653 *success_ptr =
false;
673 *success_ptr =
false;
678 bool *success_ptr)
const {
694 *success_ptr =
false;
711 return buffer.bytes.data();
713 return buffer.bytes.data();
734 return buffer.bytes.size();
740 if (byte_size == 0) {
742 }
else if (byte_size == 1) {
744 }
else if (byte_size <= 2) {
746 }
else if (byte_size <= 4) {
748 }
else if (byte_size <= 8) {
750 }
else if (byte_size <= 16) {
759 if (bytes && length > 0) {
761 buffer.bytes.resize(length);
762 memcpy(
buffer.bytes.data(), bytes, length);
763 buffer.byte_order = byte_order;
792 return !(*
this == rhs);
820 byte_idx =
buffer.bytes.size() - (
bit / 8) - 1;
824 const uint32_t byte_bit =
bit % 8;
825 if (byte_idx <
buffer.bytes.size()) {
826 buffer.bytes[byte_idx] &= ~(1u << byte_bit);
860 byte_idx =
buffer.bytes.size() - (
bit / 8) - 1;
864 const uint32_t byte_bit =
bit % 8;
865 if (byte_idx <
buffer.bytes.size()) {
866 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