================
@@ -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);
----------------
DavidSpickett wrote:

Is comparing CompilerType enough to prove that we are reusing the type? I 
looked a bit into it but am not sure what the thing underlying the CompilerType 
is.

Of course you can prove this another way, if you disable caching, this test 
should fail. Does it?

https://github.com/llvm/llvm-project/pull/215874
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to