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/unittests/Process/Utility/DynamicRegisterInfoTest.cpp =================================================================== --- /dev/null +++ lldb/unittests/Process/Utility/DynamicRegisterInfoTest.cpp @@ -0,0 +1,91 @@ +//===-- 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" + +#include "lldb/Utility/ArchSpec.h" + +using namespace lldb_private; + +TEST(DynamicRegisterInfoTest, finalize_regs) { + DynamicRegisterInfo info; + ConstString group{"group"}; + + uint32_t regnums[3] = {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, + LLDB_INVALID_REGNUM}; + + // Add regular registers + struct RegisterInfo new_reg { + "b1", nullptr, 8, LLDB_INVALID_INDEX32, lldb::eEncodingUint, + lldb::eFormatUnsigned, + {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, 0, 0}, + nullptr, nullptr, nullptr, 0 + }; + info.AddRegister(new_reg, group); + new_reg.name = "b2"; + new_reg.kinds[lldb::eRegisterKindProcessPlugin]++; + new_reg.kinds[lldb::eRegisterKindLLDB]++; + info.AddRegister(new_reg, group); + + // Add a few sub-registers + new_reg.name = "s1"; + new_reg.byte_size = 4; + new_reg.kinds[lldb::eRegisterKindProcessPlugin]++; + new_reg.kinds[lldb::eRegisterKindLLDB]++; + regnums[0] = 0; + new_reg.value_regs = regnums; + info.AddRegister(new_reg, group); + + new_reg.name = "s2"; + new_reg.kinds[lldb::eRegisterKindProcessPlugin]++; + new_reg.kinds[lldb::eRegisterKindLLDB]++; + regnums[0] = 1; + info.AddRegister(new_reg, group); + + // Add a register with weird invalidation + new_reg.name = "x"; + new_reg.kinds[lldb::eRegisterKindProcessPlugin]++; + new_reg.kinds[lldb::eRegisterKindLLDB]++; + new_reg.value_regs = nullptr; + regnums[0] = 1; + regnums[1] = 0; + new_reg.invalidate_regs = regnums; + info.AddRegister(new_reg, group); + + info.Finalize(lldb_private::ArchSpec()); + + const RegisterInfo *added_reg = info.GetRegisterInfoAtIndex(0); + ASSERT_NE(added_reg, nullptr); + EXPECT_EQ(added_reg->byte_offset, 0U); + + added_reg = info.GetRegisterInfoAtIndex(1); + ASSERT_NE(added_reg, nullptr); + EXPECT_EQ(added_reg->byte_offset, 8U); + + added_reg = info.GetRegisterInfoAtIndex(2); + ASSERT_NE(added_reg, nullptr); + EXPECT_EQ(added_reg->byte_offset, 0U); + EXPECT_EQ(added_reg->value_regs[0], 0U); + EXPECT_EQ(added_reg->value_regs[1], LLDB_INVALID_REGNUM); + + added_reg = info.GetRegisterInfoAtIndex(3); + ASSERT_NE(added_reg, nullptr); + EXPECT_EQ(added_reg->byte_offset, 8U); + EXPECT_EQ(added_reg->value_regs[0], 1U); + EXPECT_EQ(added_reg->value_regs[1], LLDB_INVALID_REGNUM); + + added_reg = info.GetRegisterInfoAtIndex(4); + ASSERT_NE(added_reg, nullptr); + EXPECT_EQ(added_reg->byte_offset, 16U); + EXPECT_EQ(added_reg->invalidate_regs[0], 0U); + EXPECT_EQ(added_reg->invalidate_regs[1], 1U); + EXPECT_EQ(added_reg->invalidate_regs[2], LLDB_INVALID_REGNUM); +}