Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lldb/source/Utility/RegisterValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ Status RegisterValue::SetValueFromData(const RegisterInfo &reg_info,
else if (reg_info.byte_size <= 16) {
uint64_t data1 = src.GetU64(&src_offset);
uint64_t data2 = src.GetU64(&src_offset);
if (src.GetByteOrder() == eByteOrderBig) {
if (src.GetByteOrder() == eByteOrderLittle) {
int128.x[0] = data1;
int128.x[1] = data2;
} else {
Expand Down
55 changes: 55 additions & 0 deletions lldb/unittests/Utility/RegisterValueTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//

#include "lldb/Utility/RegisterValue.h"
#include "lldb/Utility/DataExtractor.h"
#include "lldb/lldb-private-types.h"
#include "gtest/gtest.h"
#include <optional>

Expand Down Expand Up @@ -54,3 +56,56 @@ TEST(RegisterValueTest, GetScalarValue) {
Scalar((APInt(128, 0xffeeddccbbaa9988ull) << 64) |
APInt(128, 0x7766554433221100)));
}

static const Scalar etalon128(APInt(128, 0xffeeddccbbaa9988ull) << 64 |
APInt(128, 0x7766554433221100ull));

void TestSetValueFromData128(const RegisterInfo &ri, void *src,
const lldb::ByteOrder endianness) {
DataExtractor src_extractor(src, 16, endianness, 8);
RegisterValue rv;
EXPECT_TRUE(rv.SetValueFromData(ri, src_extractor, 0, false).Success());
Scalar s;
EXPECT_TRUE(rv.GetScalarValue(s));
EXPECT_EQ(s, etalon128);
}

// Test that the "RegisterValue::SetValueFromData" method works correctly
// with 128-bit little-endian data that represents an integer.
TEST(RegisterValueTest, SetValueFromData_128_le) {
RegisterValue rv;
RegisterInfo ri{"uint128_register",
nullptr,
16,
0,
lldb::Encoding::eEncodingUint,
lldb::Format::eFormatDefault,
{0, 0, 0, LLDB_INVALID_REGNUM, 0},
nullptr,
nullptr,
nullptr};

uint8_t src[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
TestSetValueFromData128(ri, src, lldb::ByteOrder::eByteOrderLittle);
}

// Test that the "RegisterValue::SetValueFromData" method works correctly
// with 128-bit big-endian data that represents an integer.
TEST(RegisterValueTest, SetValueFromData_128_be) {
RegisterValue rv;
RegisterInfo ri{"uint128_register",
nullptr,
16,
0,
lldb::Encoding::eEncodingUint,
lldb::Format::eFormatDefault,
{0, 0, 0, LLDB_INVALID_REGNUM, 0},
nullptr,
nullptr,
nullptr};

uint8_t src[] = {0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88,
0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00};
TestSetValueFromData128(ri, src, lldb::ByteOrder::eByteOrderBig);
}
Loading