[Lldb-commits] [lldb] d2700b7 - [lldb/Utility] Add unit tests for RegisterValue::GetScalarValue
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Tue Nov 3 07:12:41 PST 2020
Author: Pavel Labath
Date: 2020-11-03T16:12:32+01:00
New Revision: d2700b7873e305a09a931e98b12ebab7b42deec3
URL: https://github.com/llvm/llvm-project/commit/d2700b7873e305a09a931e98b12ebab7b42deec3
DIFF: https://github.com/llvm/llvm-project/commit/d2700b7873e305a09a931e98b12ebab7b42deec3.diff
LOG: [lldb/Utility] Add unit tests for RegisterValue::GetScalarValue
Buggy cases are commented out.
Also sneak in a modernization of a RegisterValue constructor.
Added:
Modified:
lldb/include/lldb/Utility/RegisterValue.h
lldb/source/Expression/Materializer.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
lldb/unittests/Utility/RegisterValueTest.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Utility/RegisterValue.h b/lldb/include/lldb/Utility/RegisterValue.h
index 4885d5806384..4211b0a59992 100644
--- a/lldb/include/lldb/Utility/RegisterValue.h
+++ b/lldb/include/lldb/Utility/RegisterValue.h
@@ -74,9 +74,9 @@ class RegisterValue {
m_scalar = value;
}
- explicit RegisterValue(uint8_t *bytes, size_t length,
+ explicit RegisterValue(llvm::ArrayRef<uint8_t> bytes,
lldb::ByteOrder byte_order) {
- SetBytes(bytes, length, byte_order);
+ SetBytes(bytes.data(), bytes.size(), byte_order);
}
RegisterValue::Type GetType() const { return m_type; }
diff --git a/lldb/source/Expression/Materializer.cpp b/lldb/source/Expression/Materializer.cpp
index 327e15a26266..a93c127dd0d0 100644
--- a/lldb/source/Expression/Materializer.cpp
+++ b/lldb/source/Expression/Materializer.cpp
@@ -1282,9 +1282,8 @@ class EntityRegister : public Materializer::Entity {
m_register_contents.reset();
- RegisterValue register_value(
- const_cast<uint8_t *>(register_data.GetDataStart()),
- register_data.GetByteSize(), register_data.GetByteOrder());
+ RegisterValue register_value(register_data.GetData(),
+ register_data.GetByteOrder());
if (!reg_context_sp->WriteRegister(&m_register_info, register_value)) {
err.SetErrorStringWithFormat("couldn't write the value of register %s",
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
index 3b6f740a5983..02b6ca40fc9b 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -2091,7 +2091,7 @@ GDBRemoteCommunicationServerLLGS::Handle_P(StringExtractorGDBRemote &packet) {
StreamGDBRemote response;
RegisterValue reg_value(
- reg_bytes, reg_size,
+ makeArrayRef(reg_bytes, reg_size),
m_debugged_process_up->GetArchitecture().GetByteOrder());
Status error = reg_context.WriteRegister(reg_info, reg_value);
if (error.Fail()) {
diff --git a/lldb/unittests/Utility/RegisterValueTest.cpp b/lldb/unittests/Utility/RegisterValueTest.cpp
index 70d79ea0024a..bbefb96519b1 100644
--- a/lldb/unittests/Utility/RegisterValueTest.cpp
+++ b/lldb/unittests/Utility/RegisterValueTest.cpp
@@ -10,6 +10,8 @@
#include "gtest/gtest.h"
using namespace lldb_private;
+using llvm::APInt;
+using llvm::ArrayRef;
TEST(RegisterValueTest, GetSet8) {
RegisterValue R8(uint8_t(47));
@@ -20,3 +22,37 @@ TEST(RegisterValueTest, GetSet8) {
EXPECT_EQ(42u, R8.GetAsUInt32());
EXPECT_EQ(42u, R8.GetAsUInt64());
}
+
+TEST(RegisterValueTest, GetScalarValue) {
+ using RV = RegisterValue;
+ const auto &Get = [](const RV &V) -> llvm::Optional<Scalar> {
+ Scalar S;
+ if (V.GetScalarValue(S))
+ return S;
+ return llvm::None;
+ };
+ EXPECT_EQ(Get(RV(uint8_t(47))), Scalar(47));
+ EXPECT_EQ(Get(RV(uint16_t(4747))), Scalar(4747));
+ EXPECT_EQ(Get(RV(uint32_t(47474242))), Scalar(47474242));
+ EXPECT_EQ(Get(RV(uint64_t(4747424247474242))), Scalar(4747424247474242));
+ EXPECT_EQ(Get(RV(APInt::getMaxValue(128))), Scalar(APInt::getMaxValue(128)));
+ EXPECT_EQ(Get(RV(47.5f)), Scalar(47.5f));
+ EXPECT_EQ(Get(RV(47.5)), Scalar(47.5));
+ EXPECT_EQ(Get(RV(47.5L)), Scalar(47.5L));
+ EXPECT_EQ(Get(RV({0xff, 0xee, 0xdd, 0xcc}, lldb::eByteOrderLittle)),
+ Scalar(0xccddeeff));
+ // EXPECT_EQ(Get(RV({0xff, 0xee, 0xdd, 0xcc}, lldb::eByteOrderBig)),
+ // Scalar(0xffeeddcc));
+ EXPECT_EQ(Get(RV({0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66,
+ 0x55, 0x44, 0x33, 0x22, 0x11, 0x00},
+ lldb::eByteOrderLittle)),
+ Scalar((APInt(128, 0x0011223344556677ull) << 64) |
+ APInt(128, 0x8899aabbccddeeff)));
+#if 0
+ EXPECT_EQ(Get(RV({0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66,
+ 0x55, 0x44, 0x33, 0x22, 0x11, 0x00},
+ lldb::eByteOrderBig)),
+ Scalar((APInt(128, 0xffeeddccbbaa9988ull) << 64) |
+ APInt(128, 0x7766554433221100)));
+#endif
+}
More information about the lldb-commits
mailing list