[Lldb-commits] [PATCH] D109879: [lldb] [DynamicRegisterInfo] Update RegisterInfo with copy of value_regs/invalidate_regs
Michał Górny via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Thu Sep 16 06:43:33 PDT 2021
mgorny updated this revision to Diff 372919.
mgorny added a comment.
Now with a trivial unit test.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D109879/new/
https://reviews.llvm.org/D109879
Files:
lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
lldb/unittests/Process/Utility/CMakeLists.txt
lldb/unittests/Process/Utility/DynamicRegisterInfoTest.cpp
Index: lldb/unittests/Process/Utility/DynamicRegisterInfoTest.cpp
===================================================================
--- /dev/null
+++ lldb/unittests/Process/Utility/DynamicRegisterInfoTest.cpp
@@ -0,0 +1,44 @@
+//===-- DynamicRegisterInfoTest.cpp ---------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+#include "Plugins/Process/Utility/DynamicRegisterInfo.h"
+
+using namespace lldb_private;
+
+TEST(DynamicRegisterInfoTest, regs_copy) {
+ DynamicRegisterInfo info;
+
+ uint32_t value_regs[] = {1, LLDB_INVALID_REGNUM};
+ uint32_t invalidate_regs[] = {2, 3, LLDB_INVALID_REGNUM};
+
+ struct RegisterInfo new_reg {
+ "foo", nullptr, 8, 0, lldb::eEncodingUint, lldb::eFormatUnsigned,
+ {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, 0, 0},
+ value_regs, invalidate_regs, nullptr, 0
+ };
+
+ ConstString group{"group"};
+ info.AddRegister(new_reg, group);
+
+ // AddRegister() should have created a copy of these two arrays,
+ // so local changes should not affect returned RegisterInfo.
+ value_regs[0] = 4;
+ invalidate_regs[0] = 5;
+ invalidate_regs[1] = 6;
+
+ const RegisterInfo *added_reg = info.GetRegisterInfoAtIndex(0);
+ ASSERT_NE(added_reg, nullptr);
+ ASSERT_EQ(added_reg->value_regs[0], 1U);
+ ASSERT_EQ(added_reg->value_regs[1], LLDB_INVALID_REGNUM);
+ ASSERT_EQ(added_reg->invalidate_regs[0], 2U);
+ ASSERT_EQ(added_reg->invalidate_regs[1], 3U);
+ ASSERT_EQ(added_reg->invalidate_regs[2], LLDB_INVALID_REGNUM);
+}
Index: lldb/unittests/Process/Utility/CMakeLists.txt
===================================================================
--- lldb/unittests/Process/Utility/CMakeLists.txt
+++ lldb/unittests/Process/Utility/CMakeLists.txt
@@ -15,9 +15,10 @@
${NETBSD_SOURCES})
add_lldb_unittest(ProcessUtilityTests
- RegisterContextTest.cpp
+ DynamicRegisterInfoTest.cpp
LinuxProcMapsTest.cpp
MemoryTagManagerAArch64MTETest.cpp
+ RegisterContextTest.cpp
${PLATFORM_SOURCES}
LINK_LIBS
Index: lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
===================================================================
--- lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
+++ lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
@@ -402,12 +402,22 @@
assert(reg_info.name);
uint32_t i;
if (reg_info.value_regs) {
- for (i = 0; reg_info.value_regs[i] != LLDB_INVALID_REGNUM; ++i)
- m_value_regs_map[reg_num].push_back(reg_info.value_regs[i]);
+ reg_num_collection ®s = m_value_regs_map[reg_num];
+ for (i = 0;; ++i) {
+ regs.push_back(reg_info.value_regs[i]);
+ if (reg_info.value_regs[i] == LLDB_INVALID_REGNUM)
+ break;
+ }
+ reg_info.value_regs = regs.data();
}
if (reg_info.invalidate_regs) {
- for (i = 0; reg_info.invalidate_regs[i] != LLDB_INVALID_REGNUM; ++i)
- m_invalidate_regs_map[reg_num].push_back(reg_info.invalidate_regs[i]);
+ reg_num_collection ®s = m_invalidate_regs_map[reg_num];
+ for (i = 0;; ++i) {
+ regs.push_back(reg_info.invalidate_regs[i]);
+ if (reg_info.invalidate_regs[i] == LLDB_INVALID_REGNUM)
+ break;
+ }
+ reg_info.invalidate_regs = regs.data();
}
if (reg_info.dynamic_size_dwarf_expr_bytes) {
for (i = 0; i < reg_info.dynamic_size_dwarf_len; ++i)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109879.372919.patch
Type: text/x-patch
Size: 3641 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210916/1cc1f1bc/attachment.bin>
More information about the lldb-commits
mailing list