[Lldb-commits] [lldb] [lldb] Cache register types by object UID and register size (PR #215874)
Bar Soloveychik via lldb-commits
lldb-commits at lists.llvm.org
Thu Aug 13 11:54:47 PDT 2026
================
@@ -0,0 +1,161 @@
+//===-- RegisterTypeBuilderClangTest.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 "Plugins/RegisterTypeBuilder/RegisterTypeBuilderClang.h"
+#include "Plugins/Platform/Linux/PlatformLinux.h"
+#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Utility/ArchSpec.h"
+#include "lldb/Utility/RegisterInfo.h"
+#include "lldb/Utility/RegisterTypeFlags.h"
+#include "gtest/gtest.h"
+
+#include <mutex>
+#include <optional>
+
+using namespace lldb;
+using namespace lldb_private;
+
+namespace {
+
+class RegisterTypeBuilderClangTest : public testing::Test {
+public:
+ SubsystemRAII<FileSystem, HostInfo, TypeSystemClang,
+ platform_linux::PlatformLinux>
+ subsystems;
+
+protected:
+ void SetUp() override {
+ std::call_once(TestUtilities::g_debugger_initialize_flag,
+ []() { Debugger::Initialize(nullptr); });
+ ArchSpec host_arch("x86_64-pc-linux");
+ Platform::SetHostPlatform(
+ platform_linux::PlatformLinux::CreateInstance(true, &host_arch));
+ m_debugger_sp = Debugger::CreateInstance();
+ }
+
+ static RegisterInfo MakeRegisterInfo(const RegisterType &type,
+ uint32_t byte_size) {
+ RegisterInfo info{};
+ info.name = "test";
+ info.byte_size = byte_size;
+ info.register_type = &type;
+ return info;
+ }
+
+ DebuggerSP m_debugger_sp;
+};
+
+TEST_F(RegisterTypeBuilderClangTest, ReusesCachedType) {
+ Target &target = m_debugger_sp->GetDummyTarget();
+ RegisterTypeFlags flags("flags", 4,
+ {RegisterTypeFlags::Field("field", 0, 31)});
+ RegisterInfo info = MakeRegisterInfo(flags, 4);
+ RegisterTypeBuilderClang builder(target);
+
+ CompilerType first = builder.GetRegisterType(info);
+ CompilerType second = builder.GetRegisterType(info);
+
+ ASSERT_TRUE(first);
+ ASSERT_TRUE(second);
+ EXPECT_EQ(first, second);
+}
+
+TEST_F(RegisterTypeBuilderClangTest, DistinguishesTypesWithTheSameID) {
+ Target &target = m_debugger_sp->GetDummyTarget();
+ RegisterTypeFlags first_flags("flags", 4,
----------------
barsolo2000 wrote:
Done.
https://github.com/llvm/llvm-project/pull/215874
More information about the lldb-commits
mailing list