[Lldb-commits] [lldb] [LLDB] Move SB API test helpers to separate library (PR #185866)

via lldb-commits lldb-commits at lists.llvm.org
Wed Mar 11 12:50:43 PDT 2026


https://github.com/Nerixyz updated https://github.com/llvm/llvm-project/pull/185866

>From 3f81daa6097696c763745ddf707318ebcc356f10 Mon Sep 17 00:00:00 2001
From: Nerixyz <nerixdev at outlook.de>
Date: Wed, 11 Mar 2026 12:59:29 +0100
Subject: [PATCH 1/4] [LLDB] Link TestingSupport to liblldb

---
 lldb/unittests/TestingSupport/CMakeLists.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lldb/unittests/TestingSupport/CMakeLists.txt b/lldb/unittests/TestingSupport/CMakeLists.txt
index b9affcf41217f..9d5d88ab47fa1 100644
--- a/lldb/unittests/TestingSupport/CMakeLists.txt
+++ b/lldb/unittests/TestingSupport/CMakeLists.txt
@@ -7,6 +7,7 @@ add_lldb_library(lldbUtilityHelpers
     Support
     ObjectYAML
   LINK_LIBS
+    liblldb
     lldbUtility
     llvm_gtest
   )

>From dcd18ac7792d4c6aad9a8458591ebe6ac752cbb1 Mon Sep 17 00:00:00 2001
From: Nerixyz <nerixdev at outlook.de>
Date: Wed, 11 Mar 2026 19:49:42 +0100
Subject: [PATCH 2/4] refactor: Move SB test helpers to separate library

---
 lldb/unittests/CMakeLists.txt                 |  4 ++
 lldb/unittests/DAP/CMakeLists.txt             |  1 +
 lldb/unittests/DAP/TestBase.cpp               |  2 +-
 lldb/unittests/DAP/VariablesTest.cpp          |  1 +
 .../unittests/SBTestingSupport/CMakeLists.txt | 12 ++++
 .../SBTestingSupport/SBTestUtilities.cpp      | 65 +++++++++++++++++++
 .../SBTestingSupport/SBTestUtilities.h        | 28 ++++++++
 .../TestingSupport/TestUtilities.cpp          | 51 ---------------
 lldb/unittests/TestingSupport/TestUtilities.h |  5 --
 9 files changed, 112 insertions(+), 57 deletions(-)
 create mode 100644 lldb/unittests/SBTestingSupport/CMakeLists.txt
 create mode 100644 lldb/unittests/SBTestingSupport/SBTestUtilities.cpp
 create mode 100644 lldb/unittests/SBTestingSupport/SBTestUtilities.h

diff --git a/lldb/unittests/CMakeLists.txt b/lldb/unittests/CMakeLists.txt
index 76d8b7391c5cf..41e1c29c8093b 100644
--- a/lldb/unittests/CMakeLists.txt
+++ b/lldb/unittests/CMakeLists.txt
@@ -24,6 +24,9 @@ function(add_lldb_unittest test_name)
   if ("liblldb" IN_LIST ARG_LINK_LIBS AND NOT ARG_SBAPITEST)
     message(FATAL_ERROR "The ${test_name} are not allowed to link liblldb.")
   endif()
+  if ("lldbSBUtilityHelpers" IN_LIST ARG_LINK_LIBS AND NOT ARG_SBAPITEST)
+    message(FATAL_ERROR "The ${test_name} are not allowed to link lldbSBUtilityHelpers.")
+  endif()
 
   list(APPEND LLVM_LINK_COMPONENTS ${ARG_LINK_COMPONENTS})
 
@@ -51,6 +54,7 @@ function(add_unittest_inputs test_name inputs)
 endfunction()
 
 add_subdirectory(TestingSupport)
+add_subdirectory(SBTestingSupport)
 if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
   # FIXME: Tests linking against libLLDB don't work on Windows.
   add_subdirectory(API)
diff --git a/lldb/unittests/DAP/CMakeLists.txt b/lldb/unittests/DAP/CMakeLists.txt
index 53e0fde5687ec..3b791d9f00ee8 100644
--- a/lldb/unittests/DAP/CMakeLists.txt
+++ b/lldb/unittests/DAP/CMakeLists.txt
@@ -26,6 +26,7 @@ add_lldb_unittest(DAPTests
     liblldb
     lldbDAP
     lldbUtilityHelpers
+    lldbSBUtilityHelpers
     LLVMTestingSupport
   )
 
diff --git a/lldb/unittests/DAP/TestBase.cpp b/lldb/unittests/DAP/TestBase.cpp
index cb9596e6f1637..4f812305688f5 100644
--- a/lldb/unittests/DAP/TestBase.cpp
+++ b/lldb/unittests/DAP/TestBase.cpp
@@ -11,7 +11,7 @@
 #include "DAPLog.h"
 #include "Handler/RequestHandler.h"
 #include "Handler/ResponseHandler.h"
-#include "TestingSupport/TestUtilities.h"
+#include "SBTestingSupport/SBTestUtilities.h"
 #include "lldb/API/SBDefines.h"
 #include "lldb/Host/MainLoop.h"
 #include "lldb/Host/Pipe.h"
diff --git a/lldb/unittests/DAP/VariablesTest.cpp b/lldb/unittests/DAP/VariablesTest.cpp
index 03f5cbf9cccb5..41c1f9c6d2d79 100644
--- a/lldb/unittests/DAP/VariablesTest.cpp
+++ b/lldb/unittests/DAP/VariablesTest.cpp
@@ -10,6 +10,7 @@
 #include "DAPLog.h"
 #include "Protocol/DAPTypes.h"
 #include "Protocol/ProtocolTypes.h"
+#include "SBTestingSupport/SBTestUtilities.h"
 #include "TestUtilities.h"
 #include "TestingSupport/TestUtilities.h"
 #include "lldb/API/SBDebugger.h"
diff --git a/lldb/unittests/SBTestingSupport/CMakeLists.txt b/lldb/unittests/SBTestingSupport/CMakeLists.txt
new file mode 100644
index 0000000000000..84bba60b8528c
--- /dev/null
+++ b/lldb/unittests/SBTestingSupport/CMakeLists.txt
@@ -0,0 +1,12 @@
+set_property(DIRECTORY PROPERTY EXCLUDE_FROM_ALL ON)
+add_lldb_library(lldbSBUtilityHelpers
+  SBTestUtilities.cpp
+
+  LINK_COMPONENTS
+    Support
+  LINK_LIBS
+    liblldb
+    lldbUtility
+    lldbUtilityHelpers
+    llvm_gtest
+  )
diff --git a/lldb/unittests/SBTestingSupport/SBTestUtilities.cpp b/lldb/unittests/SBTestingSupport/SBTestUtilities.cpp
new file mode 100644
index 0000000000000..b22b76b33a265
--- /dev/null
+++ b/lldb/unittests/SBTestingSupport/SBTestUtilities.cpp
@@ -0,0 +1,65 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 "SBTestUtilities.h"
+
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/API/SBStructuredData.h"
+#include "lldb/API/SBTarget.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gtest/gtest.h"
+
+using namespace lldb_private;
+
+bool lldb_private::DebuggerSupportsLLVMTarget(llvm::StringRef target) {
+  lldb::SBStructuredData data = lldb::SBDebugger::GetBuildConfiguration()
+                                    .GetValueForKey("targets")
+                                    .GetValueForKey("value");
+  for (size_t i = 0; i < data.GetSize(); i++) {
+    char buf[100] = {0};
+    size_t size = data.GetItemAtIndex(i).GetStringValue(buf, sizeof(buf));
+    if (llvm::StringRef(buf, size) == target)
+      return true;
+  }
+
+  return false;
+}
+
+std::pair<lldb::SBTarget, lldb::SBProcess>
+lldb_private::LoadCore(lldb::SBDebugger &debugger, llvm::StringRef binary_path,
+                       llvm::StringRef core_path) {
+  EXPECT_TRUE(debugger);
+
+  llvm::Expected<lldb_private::TestFile> binary_yaml =
+      lldb_private::TestFile::fromYamlFile(binary_path);
+  EXPECT_THAT_EXPECTED(binary_yaml, llvm::Succeeded());
+  llvm::Expected<llvm::sys::fs::TempFile> binary_file =
+      binary_yaml->writeToTemporaryFile();
+  EXPECT_THAT_EXPECTED(binary_file, llvm::Succeeded());
+  lldb::SBError error;
+  lldb::SBTarget target = debugger.CreateTarget(
+      /*filename=*/binary_file->TmpName.data(), /*target_triple=*/"",
+      /*platform_name=*/"", /*add_dependent_modules=*/false, /*error=*/error);
+  EXPECT_TRUE(target);
+  EXPECT_TRUE(error.Success()) << error.GetCString();
+  debugger.SetSelectedTarget(target);
+
+  llvm::Expected<lldb_private::TestFile> core_yaml =
+      lldb_private::TestFile::fromYamlFile(core_path);
+  EXPECT_THAT_EXPECTED(core_yaml, llvm::Succeeded());
+  llvm::Expected<llvm::sys::fs::TempFile> core_file =
+      core_yaml->writeToTemporaryFile();
+  EXPECT_THAT_EXPECTED(core_file, llvm::Succeeded());
+  lldb::SBProcess process = target.LoadCore(core_file->TmpName.data());
+  EXPECT_TRUE(process);
+
+  EXPECT_THAT_ERROR(binary_file->discard(), llvm::Succeeded());
+  EXPECT_THAT_ERROR(core_file->discard(), llvm::Succeeded());
+
+  return std::make_pair(target, process);
+}
diff --git a/lldb/unittests/SBTestingSupport/SBTestUtilities.h b/lldb/unittests/SBTestingSupport/SBTestUtilities.h
new file mode 100644
index 0000000000000..2a8f8e12a9633
--- /dev/null
+++ b/lldb/unittests/SBTestingSupport/SBTestUtilities.h
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_UNITTESTS_SBTESTINGSUPPORT_SBTESTUTILITIES_H
+#define LLDB_UNITTESTS_SBTESTINGSUPPORT_SBTESTUTILITIES_H
+
+#include "lldb/API/SBDebugger.h"
+#include "llvm/ADT/StringRef.h"
+
+#include <utility>
+
+namespace lldb_private {
+
+/// Check if the debugger supports the given platform.
+bool DebuggerSupportsLLVMTarget(llvm::StringRef target);
+
+std::pair<lldb::SBTarget, lldb::SBProcess> LoadCore(lldb::SBDebugger &debugger,
+                                                    llvm::StringRef binary_path,
+                                                    llvm::StringRef core_path);
+
+} // namespace lldb_private
+
+#endif
diff --git a/lldb/unittests/TestingSupport/TestUtilities.cpp b/lldb/unittests/TestingSupport/TestUtilities.cpp
index 13092742a4347..f73134ba00e41 100644
--- a/lldb/unittests/TestingSupport/TestUtilities.cpp
+++ b/lldb/unittests/TestingSupport/TestUtilities.cpp
@@ -7,14 +7,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "TestUtilities.h"
-#include "lldb/API/SBStructuredData.h"
-#include "lldb/API/SBTarget.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ObjectYAML/yaml2obj.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/YAMLTraits.h"
-#include "llvm/Testing/Support/Error.h"
 #include "gtest/gtest.h"
 #include <utility>
 
@@ -64,51 +61,3 @@ llvm::Expected<llvm::sys::fs::TempFile> TestFile::writeToTemporaryFile() {
   llvm::raw_fd_ostream(Temp->FD, /*shouldClose=*/false) << Buffer;
   return std::move(*Temp);
 }
-
-bool lldb_private::DebuggerSupportsLLVMTarget(llvm::StringRef target) {
-  lldb::SBStructuredData data = lldb::SBDebugger::GetBuildConfiguration()
-                                    .GetValueForKey("targets")
-                                    .GetValueForKey("value");
-  for (size_t i = 0; i < data.GetSize(); i++) {
-    char buf[100] = {0};
-    size_t size = data.GetItemAtIndex(i).GetStringValue(buf, sizeof(buf));
-    if (llvm::StringRef(buf, size) == target)
-      return true;
-  }
-
-  return false;
-}
-
-std::pair<lldb::SBTarget, lldb::SBProcess>
-lldb_private::LoadCore(lldb::SBDebugger &debugger, llvm::StringRef binary_path,
-                       llvm::StringRef core_path) {
-  EXPECT_TRUE(debugger);
-
-  llvm::Expected<lldb_private::TestFile> binary_yaml =
-      lldb_private::TestFile::fromYamlFile(binary_path);
-  EXPECT_THAT_EXPECTED(binary_yaml, llvm::Succeeded());
-  llvm::Expected<llvm::sys::fs::TempFile> binary_file =
-      binary_yaml->writeToTemporaryFile();
-  EXPECT_THAT_EXPECTED(binary_file, llvm::Succeeded());
-  lldb::SBError error;
-  lldb::SBTarget target = debugger.CreateTarget(
-      /*filename=*/binary_file->TmpName.data(), /*target_triple=*/"",
-      /*platform_name=*/"", /*add_dependent_modules=*/false, /*error=*/error);
-  EXPECT_TRUE(target);
-  EXPECT_TRUE(error.Success()) << error.GetCString();
-  debugger.SetSelectedTarget(target);
-
-  llvm::Expected<lldb_private::TestFile> core_yaml =
-      lldb_private::TestFile::fromYamlFile(core_path);
-  EXPECT_THAT_EXPECTED(core_yaml, llvm::Succeeded());
-  llvm::Expected<llvm::sys::fs::TempFile> core_file =
-      core_yaml->writeToTemporaryFile();
-  EXPECT_THAT_EXPECTED(core_file, llvm::Succeeded());
-  lldb::SBProcess process = target.LoadCore(core_file->TmpName.data());
-  EXPECT_TRUE(process);
-
-  EXPECT_THAT_ERROR(binary_file->discard(), llvm::Succeeded());
-  EXPECT_THAT_ERROR(core_file->discard(), llvm::Succeeded());
-
-  return std::make_pair(target, process);
-}
diff --git a/lldb/unittests/TestingSupport/TestUtilities.h b/lldb/unittests/TestingSupport/TestUtilities.h
index 01ecc15c9606d..42e5614045fce 100644
--- a/lldb/unittests/TestingSupport/TestUtilities.h
+++ b/lldb/unittests/TestingSupport/TestUtilities.h
@@ -9,7 +9,6 @@
 #ifndef LLDB_UNITTESTS_TESTINGSUPPORT_TESTUTILITIES_H
 #define LLDB_UNITTESTS_TESTINGSUPPORT_TESTUTILITIES_H
 
-#include "lldb/API/SBDebugger.h"
 #include "lldb/Core/ModuleSpec.h"
 #include "lldb/Utility/DataBuffer.h"
 #include "llvm/ADT/Twine.h"
@@ -82,10 +81,6 @@ template <typename T> static llvm::Expected<T> roundtripJSON(const T &input) {
   return llvm::json::parse<T>(encoded);
 }
 
-std::pair<lldb::SBTarget, lldb::SBProcess> LoadCore(lldb::SBDebugger &debugger,
-                                                    llvm::StringRef binary_path,
-                                                    llvm::StringRef core_path);
-
 } // namespace lldb_private
 
 #endif

>From 31937bbf975cd6d8ad69665d58234410adf5f523 Mon Sep 17 00:00:00 2001
From: Nerixyz <nerixdev at outlook.de>
Date: Wed, 11 Mar 2026 20:50:02 +0100
Subject: [PATCH 3/4] fix: remove `liblldb` from utility helpers

---
 lldb/unittests/TestingSupport/CMakeLists.txt | 1 -
 1 file changed, 1 deletion(-)

diff --git a/lldb/unittests/TestingSupport/CMakeLists.txt b/lldb/unittests/TestingSupport/CMakeLists.txt
index 9d5d88ab47fa1..b9affcf41217f 100644
--- a/lldb/unittests/TestingSupport/CMakeLists.txt
+++ b/lldb/unittests/TestingSupport/CMakeLists.txt
@@ -7,7 +7,6 @@ add_lldb_library(lldbUtilityHelpers
     Support
     ObjectYAML
   LINK_LIBS
-    liblldb
     lldbUtility
     llvm_gtest
   )

>From 88d64e598298252529a6917698f5c0ff7657e37b Mon Sep 17 00:00:00 2001
From: Nerixyz <nerixdev at outlook.de>
Date: Wed, 11 Mar 2026 20:50:22 +0100
Subject: [PATCH 4/4] fix: remove `lldbUtility` from SB utility helpers

---
 lldb/unittests/SBTestingSupport/CMakeLists.txt | 1 -
 1 file changed, 1 deletion(-)

diff --git a/lldb/unittests/SBTestingSupport/CMakeLists.txt b/lldb/unittests/SBTestingSupport/CMakeLists.txt
index 84bba60b8528c..4e259e4870a64 100644
--- a/lldb/unittests/SBTestingSupport/CMakeLists.txt
+++ b/lldb/unittests/SBTestingSupport/CMakeLists.txt
@@ -6,7 +6,6 @@ add_lldb_library(lldbSBUtilityHelpers
     Support
   LINK_LIBS
     liblldb
-    lldbUtility
     lldbUtilityHelpers
     llvm_gtest
   )



More information about the lldb-commits mailing list