[Lldb-commits] [lldb] 2025 11 01 fix register value set value from data method (PR #166363)
Matej Košík via lldb-commits
lldb-commits at lists.llvm.org
Tue Nov 4 04:17:02 PST 2025
https://github.com/sedymrak created https://github.com/llvm/llvm-project/pull/166363
These changes generalize LLDB codebase so that it is able to print integer registers that do not have the conventional size (neither 8-bits, nor 16-bits nor 32-bits nor 64-bits).
>From de6f9a818d4210bc4838e6cebc3645167d660ca5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matej=20Ko=C5=A1=C3=ADk?= <matej.kosik at codasip.com>
Date: Fri, 31 Oct 2025 18:12:18 +0100
Subject: [PATCH 1/6] [lldb] reorganize existing tests (in order to facility
sucessive additions)
---
lldb/unittests/Utility/RegisterValueTest.cpp | 27 ++++++++++----------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/lldb/unittests/Utility/RegisterValueTest.cpp b/lldb/unittests/Utility/RegisterValueTest.cpp
index 6239dbe21634a..92c0172e0c909 100644
--- a/lldb/unittests/Utility/RegisterValueTest.cpp
+++ b/lldb/unittests/Utility/RegisterValueTest.cpp
@@ -57,13 +57,11 @@ TEST(RegisterValueTest, GetScalarValue) {
APInt(128, 0x7766554433221100)));
}
-static const Scalar etalon128(APInt(128, 0xffeeddccbbaa9988ull) << 64 |
- APInt(128, 0x7766554433221100ull));
-
-void TestSetValueFromData128(void *src, const lldb::ByteOrder endianness) {
+void TestSetValueFromData(const Scalar &etalon, void *src, size_t src_byte_size,
+ const lldb::ByteOrder endianness) {
RegisterInfo ri{"uint128_register",
nullptr,
- 16,
+ static_cast<uint32_t>(src_byte_size),
0,
lldb::Encoding::eEncodingUint,
lldb::Format::eFormatDefault,
@@ -71,26 +69,29 @@ void TestSetValueFromData128(void *src, const lldb::ByteOrder endianness) {
nullptr,
nullptr,
nullptr};
- DataExtractor src_extractor(src, 16, endianness, 8);
+ DataExtractor src_extractor(src, src_byte_size, 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);
+ EXPECT_EQ(s, etalon);
}
+static const Scalar etalon128(APInt(128, 0x0f0e0d0c0b0a0908ull) << 1 * 64 |
+ APInt(128, 0x0706050403020100ull) << 0 * 64);
+
// 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);
+ uint8_t src[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
+ TestSetValueFromData(etalon128, src, 16, 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);
+ uint8_t src[] = {0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
+ 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00};
+ TestSetValueFromData(etalon128, src, 16, lldb::ByteOrder::eByteOrderBig);
}
>From 97d473096c4421530e1639c281c0400c75fddbcc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matej=20Ko=C5=A1=C3=ADk?= <matej.kosik at codasip.com>
Date: Fri, 31 Oct 2025 19:04:26 +0100
Subject: [PATCH 2/6] [lldb] add new tests that demonstrate the problem
---
lldb/unittests/Utility/RegisterValueTest.cpp | 25 ++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/lldb/unittests/Utility/RegisterValueTest.cpp b/lldb/unittests/Utility/RegisterValueTest.cpp
index 92c0172e0c909..d6b7b2e448d8b 100644
--- a/lldb/unittests/Utility/RegisterValueTest.cpp
+++ b/lldb/unittests/Utility/RegisterValueTest.cpp
@@ -95,3 +95,28 @@ TEST(RegisterValueTest, SetValueFromData_128_be) {
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00};
TestSetValueFromData(etalon128, src, 16, lldb::ByteOrder::eByteOrderBig);
}
+
+static const Scalar etalon256(APInt(256, 0x1f1e1d1c1b1a1918ull) << 3 * 64 |
+ APInt(256, 0x1716151413121110ull) << 2 * 64 |
+ APInt(256, 0x0f0e0d0c0b0a0908ull) << 1 * 64 |
+ APInt(256, 0x0706050403020100ull) << 0 * 64);
+
+// Test that the "RegisterValue::SetValueFromData" method works correctly
+// with 256-bit little-endian data that represents an integer.
+TEST(RegisterValueTest, SetValueFromData_256_le) {
+ uint8_t src[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f};
+ TestSetValueFromData(etalon256, src, 32, lldb::ByteOrder::eByteOrderLittle);
+}
+
+// Test that the "RegisterValue::SetValueFromData" method works correctly
+// with 256-bit big-endian data that represents an integer.
+TEST(RegisterValueTest, SetValueFromData_256_be) {
+ uint8_t src[] = {0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18,
+ 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10,
+ 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
+ 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00};
+ TestSetValueFromData(etalon256, src, 32, lldb::ByteOrder::eByteOrderBig);
+}
>From 268b9e26c63aed6a1be76ad8dea45c98cab366cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matej=20Ko=C5=A1=C3=ADk?= <matej.kosik at codasip.com>
Date: Fri, 31 Oct 2025 21:33:35 +0100
Subject: [PATCH 3/6] [lldb] fix the "RegisterValue::SetValueFromData" method
---
lldb/source/Utility/RegisterValue.cpp | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/lldb/source/Utility/RegisterValue.cpp b/lldb/source/Utility/RegisterValue.cpp
index 12c349a143c0f..f49671456116b 100644
--- a/lldb/source/Utility/RegisterValue.cpp
+++ b/lldb/source/Utility/RegisterValue.cpp
@@ -207,6 +207,18 @@ Status RegisterValue::SetValueFromData(const RegisterInfo ®_info,
int128.x[1] = data1;
}
SetUInt128(llvm::APInt(128, 2, int128.x));
+ } else {
+ std::vector<uint8_t> bytes(src_len, 0);
+ for (size_t i = 0; i < src_len; i++)
+ bytes[i] = src.GetU8(&src_offset);
+ if (src.GetByteOrder() == eByteOrderBig)
+ std::reverse(bytes.begin(), bytes.end());
+ // The number of 64-bit wide words that are stored in "src".
+ size_t size64 = (reg_info.byte_size - 1) / 8 + 1;
+ bytes.resize(size64 * sizeof(uint64_t), 0);
+ llvm::APInt uint = llvm::APInt::getZero(src_len * 8);
+ llvm::LoadIntFromMemory(uint, bytes.data(), src_len);
+ SetUInt128(uint);
}
break;
case eEncodingIEEE754:
>From 82d98f928cf6213f80dc0493368bcfb008a270f3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matej=20Ko=C5=A1=C3=ADk?= <matej.kosik at codasip.com>
Date: Fri, 31 Oct 2025 22:04:03 +0100
Subject: [PATCH 4/6] [lldb] add new tests that demonstrate the problem
---
lldb/unittests/Utility/RegisterValueTest.cpp | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/lldb/unittests/Utility/RegisterValueTest.cpp b/lldb/unittests/Utility/RegisterValueTest.cpp
index d6b7b2e448d8b..48a920b11e4e0 100644
--- a/lldb/unittests/Utility/RegisterValueTest.cpp
+++ b/lldb/unittests/Utility/RegisterValueTest.cpp
@@ -77,6 +77,23 @@ void TestSetValueFromData(const Scalar &etalon, void *src, size_t src_byte_size,
EXPECT_EQ(s, etalon);
}
+static const Scalar etalon72(APInt(72, 0x0000000000000008ull) << 1 * 64 |
+ APInt(72, 0x0706050403020100ull) << 0 * 64);
+
+// Test that the "RegisterValue::SetValueFromData" method works correctly
+// with 72-bit little-endian data that represents an integer.
+TEST(RegisterValueTest, SetValueFromData_72_le) {
+ uint8_t src[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
+ TestSetValueFromData(etalon72, src, 9, lldb::ByteOrder::eByteOrderLittle);
+}
+
+// Test that the "RegisterValue::SetValueFromData" method works correctly
+// with 72-bit big-endian data that represents an integer.
+TEST(RegisterValueTest, SetValueFromData_72_be) {
+ uint8_t src[] = {0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00};
+ TestSetValueFromData(etalon72, src, 9, lldb::ByteOrder::eByteOrderBig);
+}
+
static const Scalar etalon128(APInt(128, 0x0f0e0d0c0b0a0908ull) << 1 * 64 |
APInt(128, 0x0706050403020100ull) << 0 * 64);
>From c7fd216e8529fa29d750a3fb4a17612fc476b0d3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matej=20Ko=C5=A1=C3=ADk?= <matej.kosik at codasip.com>
Date: Fri, 31 Oct 2025 23:38:39 +0100
Subject: [PATCH 5/6] [lldb] fix the "RegisterValue::SetValueFromData" method
---
lldb/source/Utility/RegisterValue.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lldb/source/Utility/RegisterValue.cpp b/lldb/source/Utility/RegisterValue.cpp
index f49671456116b..9021eed0bcf6e 100644
--- a/lldb/source/Utility/RegisterValue.cpp
+++ b/lldb/source/Utility/RegisterValue.cpp
@@ -196,7 +196,7 @@ Status RegisterValue::SetValueFromData(const RegisterInfo ®_info,
SetUInt32(src.GetMaxU32(&src_offset, src_len));
else if (reg_info.byte_size <= 8)
SetUInt64(src.GetMaxU64(&src_offset, src_len));
- else if (reg_info.byte_size <= 16) {
+ else if (reg_info.byte_size == 16) {
uint64_t data1 = src.GetU64(&src_offset);
uint64_t data2 = src.GetU64(&src_offset);
if (src.GetByteOrder() == eByteOrderLittle) {
>From ba5be9656e6dc0018993388315e15aadb2260463 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matej=20Ko=C5=A1=C3=ADk?= <matej.kosik at codasip.com>
Date: Mon, 3 Nov 2025 11:51:14 +0100
Subject: [PATCH 6/6] [lldb] rename an existing enum value so that it better
expresses its meaning
---
lldb/include/lldb/Utility/RegisterValue.h | 8 ++++----
lldb/source/Utility/RegisterValue.cpp | 24 +++++++++++------------
2 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/lldb/include/lldb/Utility/RegisterValue.h b/lldb/include/lldb/Utility/RegisterValue.h
index 49aaf68be17fc..0226fe36a7990 100644
--- a/lldb/include/lldb/Utility/RegisterValue.h
+++ b/lldb/include/lldb/Utility/RegisterValue.h
@@ -46,7 +46,7 @@ class RegisterValue {
eTypeUInt16,
eTypeUInt32,
eTypeUInt64,
- eTypeUInt128,
+ eTypeUIntBig, // an integer that has more than 64 bits
eTypeFloat,
eTypeDouble,
eTypeLongDouble,
@@ -69,7 +69,7 @@ class RegisterValue {
m_scalar = inst;
}
- explicit RegisterValue(llvm::APInt inst) : m_type(eTypeUInt128) {
+ explicit RegisterValue(llvm::APInt inst) : m_type(eTypeUIntBig) {
m_scalar = llvm::APInt(std::move(inst));
}
@@ -178,7 +178,7 @@ class RegisterValue {
}
void operator=(llvm::APInt uint) {
- m_type = eTypeUInt128;
+ m_type = eTypeUIntBig;
m_scalar = llvm::APInt(std::move(uint));
}
@@ -218,7 +218,7 @@ class RegisterValue {
}
void SetUInt128(llvm::APInt uint) {
- m_type = eTypeUInt128;
+ m_type = eTypeUIntBig;
m_scalar = std::move(uint);
}
diff --git a/lldb/source/Utility/RegisterValue.cpp b/lldb/source/Utility/RegisterValue.cpp
index 9021eed0bcf6e..9501951c094e6 100644
--- a/lldb/source/Utility/RegisterValue.cpp
+++ b/lldb/source/Utility/RegisterValue.cpp
@@ -127,7 +127,7 @@ bool RegisterValue::GetScalarValue(Scalar &scalar) const {
case eTypeUInt16:
case eTypeUInt32:
case eTypeUInt64:
- case eTypeUInt128:
+ case eTypeUIntBig:
case eTypeFloat:
case eTypeDouble:
case eTypeLongDouble:
@@ -454,7 +454,7 @@ bool RegisterValue::SignExtend(uint32_t sign_bitpos) {
case eTypeUInt16:
case eTypeUInt32:
case eTypeUInt64:
- case eTypeUInt128:
+ case eTypeUIntBig:
return m_scalar.SignExtend(sign_bitpos);
case eTypeFloat:
case eTypeDouble:
@@ -477,7 +477,7 @@ bool RegisterValue::CopyValue(const RegisterValue &rhs) {
case eTypeUInt16:
case eTypeUInt32:
case eTypeUInt64:
- case eTypeUInt128:
+ case eTypeUIntBig:
case eTypeFloat:
case eTypeDouble:
case eTypeLongDouble:
@@ -593,7 +593,7 @@ llvm::APInt RegisterValue::GetAsUInt128(const llvm::APInt &fail_value,
case eTypeUInt16:
case eTypeUInt32:
case eTypeUInt64:
- case eTypeUInt128:
+ case eTypeUIntBig:
case eTypeFloat:
case eTypeDouble:
case eTypeLongDouble:
@@ -626,7 +626,7 @@ float RegisterValue::GetAsFloat(float fail_value, bool *success_ptr) const {
break;
case eTypeUInt32:
case eTypeUInt64:
- case eTypeUInt128:
+ case eTypeUIntBig:
case eTypeFloat:
case eTypeDouble:
case eTypeLongDouble:
@@ -646,7 +646,7 @@ double RegisterValue::GetAsDouble(double fail_value, bool *success_ptr) const {
case eTypeUInt32:
case eTypeUInt64:
- case eTypeUInt128:
+ case eTypeUIntBig:
case eTypeFloat:
case eTypeDouble:
case eTypeLongDouble:
@@ -667,7 +667,7 @@ long double RegisterValue::GetAsLongDouble(long double fail_value,
case eTypeUInt32:
case eTypeUInt64:
- case eTypeUInt128:
+ case eTypeUIntBig:
case eTypeFloat:
case eTypeDouble:
case eTypeLongDouble:
@@ -686,7 +686,7 @@ const void *RegisterValue::GetBytes() const {
case eTypeUInt16:
case eTypeUInt32:
case eTypeUInt64:
- case eTypeUInt128:
+ case eTypeUIntBig:
case eTypeFloat:
case eTypeDouble:
case eTypeLongDouble:
@@ -708,7 +708,7 @@ uint32_t RegisterValue::GetByteSize() const {
return 2;
case eTypeUInt32:
case eTypeUInt64:
- case eTypeUInt128:
+ case eTypeUIntBig:
case eTypeFloat:
case eTypeDouble:
case eTypeLongDouble:
@@ -759,7 +759,7 @@ bool RegisterValue::operator==(const RegisterValue &rhs) const {
case eTypeUInt16:
case eTypeUInt32:
case eTypeUInt64:
- case eTypeUInt128:
+ case eTypeUIntBig:
case eTypeFloat:
case eTypeDouble:
case eTypeLongDouble:
@@ -784,7 +784,7 @@ bool RegisterValue::ClearBit(uint32_t bit) {
case eTypeUInt16:
case eTypeUInt32:
case eTypeUInt64:
- case eTypeUInt128:
+ case eTypeUIntBig:
if (bit < (GetByteSize() * 8)) {
return m_scalar.ClearBit(bit);
}
@@ -824,7 +824,7 @@ bool RegisterValue::SetBit(uint32_t bit) {
case eTypeUInt16:
case eTypeUInt32:
case eTypeUInt64:
- case eTypeUInt128:
+ case eTypeUIntBig:
if (bit < (GetByteSize() * 8)) {
return m_scalar.SetBit(bit);
}
More information about the lldb-commits
mailing list