diff --git a/lldb/source/Utility/RegisterValue.cpp b/lldb/source/Utility/RegisterValue.cpp index 0e99451c3b700..12c349a143c0f 100644 --- a/lldb/source/Utility/RegisterValue.cpp +++ b/lldb/source/Utility/RegisterValue.cpp @@ -199,7 +199,7 @@ Status RegisterValue::SetValueFromData(const RegisterInfo ®_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 { diff --git a/lldb/unittests/Utility/RegisterValueTest.cpp b/lldb/unittests/Utility/RegisterValueTest.cpp index e0863a41605e6..6239dbe21634a 100644 --- a/lldb/unittests/Utility/RegisterValueTest.cpp +++ b/lldb/unittests/Utility/RegisterValueTest.cpp @@ -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 @@ -54,3 +56,41 @@ TEST(RegisterValueTest, GetScalarValue) { Scalar((APInt(128, 0xffeeddccbbaa9988ull) << 64) | APInt(128, 0x7766554433221100))); } + +static const Scalar etalon128(APInt(128, 0xffeeddccbbaa9988ull) << 64 | + APInt(128, 0x7766554433221100ull)); + +void TestSetValueFromData128(void *src, const lldb::ByteOrder endianness) { + RegisterInfo ri{"uint128_register", + nullptr, + 16, + 0, + lldb::Encoding::eEncodingUint, + lldb::Format::eFormatDefault, + {0, 0, 0, LLDB_INVALID_REGNUM, 0}, + nullptr, + nullptr, + nullptr}; + 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) { + uint8_t src[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, + 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; + TestSetValueFromData128(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) { + uint8_t src[] = {0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, + 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00}; + TestSetValueFromData128(src, lldb::ByteOrder::eByteOrderBig); +}