https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/185057

>From c7650c394a3c4996765bed5eb33da1163b3922c0 Mon Sep 17 00:00:00 2001
From: Michael Buch <[email protected]>
Date: Fri, 6 Mar 2026 16:10:57 +0000
Subject: [PATCH 1/4] [lldb][PlatformDarwin] Make
 LocateExecutableScriptingResourcesFromDSYM a public static

This will allow us to unit-test it in a follow-up patch. We could test 
`LocateExecutableScriptingResources` directly, but that requires a valid 
`Module`/`ObjectFile`/`SymbolFile`. That's a lot of boilerplate/set to 
ultimately just test the `dSYM` logic. The helper just takes `FileSpec`s, which 
are much easier to construct in a test.
---
 .../Platform/MacOSX/PlatformDarwin.cpp        |  2 +-
 .../Plugins/Platform/MacOSX/PlatformDarwin.h  | 22 +++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp 
b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index 3d12f9f815661..2c5b10c07ee26 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -200,7 +200,7 @@ PlatformDarwin::PutFile(const lldb_private::FileSpec 
&source,
   return PlatformPOSIX::PutFile(source, destination, uid, gid);
 }
 
-static FileSpecList LocateExecutableScriptingResourcesFromDSYM(
+FileSpecList PlatformDarwin::LocateExecutableScriptingResourcesFromDSYM(
     Stream &feedback_stream, FileSpec module_spec, const Target &target,
     const FileSpec &symfile_spec) {
   FileSpecList file_list;
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h 
b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
index dc81a9baf5e51..e884bcba5c2cc 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
@@ -133,6 +133,28 @@ class PlatformDarwin : public PlatformPOSIX {
   llvm::Expected<std::string>
   ResolveSDKPathFromDebugInfo(CompileUnit &unit) override;
 
+  /// Helper function for \c LocateExecutableScriptingResources
+  /// which gathers FileSpecs for executable scripts (currently
+  /// just Python) from a .dSYM Python directory.
+  ///
+  /// \param[out] feedback_stream Any warnings/errors are printed into this
+  /// stream.
+  ///
+  /// \param[in] module_spec FileSpec of the Module for which to locate
+  /// scripting resources.
+  ///
+  /// \param[in] target Target which owns the ScriptInterpreter which is
+  /// eventually used for loading the scripting resources.
+  ///
+  /// \param[in] symfile_spec FileSpec for the SymbolFile inside the Module's
+  /// dSYM directory. The scripting resources are loaded from the adjacent
+  /// Resources directory in the same dSYM.
+  /// E.g., \c /path/to/.dSYM/Contents/Resources/DWARF/a.out
+  ///
+  static FileSpecList LocateExecutableScriptingResourcesFromDSYM(
+      Stream &feedback_stream, FileSpec module_spec, const Target &target,
+      const FileSpec &symfile_spec);
+
 protected:
   static const char *GetCompatibleArch(ArchSpec::Core core, size_t idx);
 

>From 04e9ef59548ba9274ef42cfbfc6bce28f7924d47 Mon Sep 17 00:00:00 2001
From: Michael Buch <[email protected]>
Date: Fri, 6 Mar 2026 16:13:26 +0000
Subject: [PATCH 2/4] [lldb][PlatformDarwin][test] Add unit-test for
 LocateExecutableScriptingResourcesFromDSYM

---
 lldb/unittests/Platform/CMakeLists.txt        |   1 +
 .../unittests/Platform/PlatformDarwinTest.cpp | 138 +++++++++++++++++-
 2 files changed, 138 insertions(+), 1 deletion(-)

diff --git a/lldb/unittests/Platform/CMakeLists.txt 
b/lldb/unittests/Platform/CMakeLists.txt
index 9a4fd8b3cd0c6..a96636fc3fd59 100644
--- a/lldb/unittests/Platform/CMakeLists.txt
+++ b/lldb/unittests/Platform/CMakeLists.txt
@@ -12,6 +12,7 @@ add_lldb_unittest(LLDBPlatformTests
     lldbPluginPlatformLinux
     lldbPluginPlatformMacOSX
     lldbPluginPlatformNetBSD
+    lldbUtilityHelpers
   )
 
 add_subdirectory(Android)
diff --git a/lldb/unittests/Platform/PlatformDarwinTest.cpp 
b/lldb/unittests/Platform/PlatformDarwinTest.cpp
index 72494d0a2667b..fa7153b455e78 100644
--- a/lldb/unittests/Platform/PlatformDarwinTest.cpp
+++ b/lldb/unittests/Platform/PlatformDarwinTest.cpp
@@ -9,15 +9,94 @@
 #include "gtest/gtest.h"
 
 #include "Plugins/Platform/MacOSX/PlatformDarwin.h"
+#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Interpreter/ScriptInterpreter.h"
 
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FileSystem.h"
 
+#include <memory>
 #include <tuple>
 
 using namespace lldb;
 using namespace lldb_private;
 
-TEST(PlatformDarwinTest, TestParseVersionBuildDir) {
+namespace {
+class MockScriptInterpreterPython : public ScriptInterpreter {
+public:
+  MockScriptInterpreterPython(Debugger &debugger)
+      : ScriptInterpreter(debugger,
+                          lldb::ScriptLanguage::eScriptLanguagePython) {}
+
+  ~MockScriptInterpreterPython() override = default;
+
+  bool ExecuteOneLine(llvm::StringRef command, CommandReturnObject *,
+                      const ExecuteScriptOptions &) override {
+    return false;
+  }
+
+  void ExecuteInterpreterLoop() override {}
+
+  static void Initialize() {
+    PluginManager::RegisterPlugin(GetPluginNameStatic(),
+                                  GetPluginDescriptionStatic(),
+                                  lldb::eScriptLanguagePython, CreateInstance);
+  }
+
+  static void Terminate() {}
+
+  static lldb::ScriptInterpreterSP CreateInstance(Debugger &debugger) {
+    return std::make_shared<MockScriptInterpreterPython>(debugger);
+  }
+
+  static llvm::StringRef GetPluginNameStatic() {
+    return "MockScriptInterpreterPython";
+  }
+
+  static llvm::StringRef GetPluginDescriptionStatic() {
+    return "MockScriptInterpreterPython";
+  }
+
+  // PluginInterface protocol
+  llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
+};
+
+LLDB_PLUGIN_DEFINE(MockScriptInterpreterPython)
+} // namespace
+
+struct PlatformDarwinTest : public testing::Test {
+protected:
+  void SetUp() override {
+    std::call_once(TestUtilities::g_debugger_initialize_flag,
+                   []() { Debugger::Initialize(nullptr); });
+  };
+
+  DebuggerSP m_debugger_sp;
+  PlatformSP m_platform_sp;
+  SubsystemRAII<FileSystem, HostInfo, PlatformMacOSX,
+                MockScriptInterpreterPython>
+      subsystems;
+};
+
+static std::string CreateFile(llvm::StringRef filename,
+                              llvm::SmallString<128> parent_dir) {
+  llvm::SmallString<128> path(parent_dir);
+  llvm::sys::path::append(path, filename);
+  int fd;
+  std::error_code ret = llvm::sys::fs::openFileForWrite(path, fd);
+  assert(!ret && "Failed to create test file.");
+  ::close(fd);
+
+  return path.c_str();
+}
+
+TEST_F(PlatformDarwinTest, TestParseVersionBuildDir) {
   llvm::VersionTuple V;
   llvm::StringRef D;
 
@@ -44,3 +123,60 @@ TEST(PlatformDarwinTest, TestParseVersionBuildDir) {
   std::tie(V, D) = PlatformDarwin::ParseVersionBuildDir("3.4.5");
   EXPECT_EQ(llvm::VersionTuple(3, 4, 5), V);
 }
+
+TEST_F(PlatformDarwinTest, LocateExecutableScriptingResourcesFromDSYM) {
+  TargetSP target_sp;
+  ArchSpec arch("x86_64-apple-macosx-");
+  auto platform_sp = PlatformRemoteMacOSX::CreateInstance(true, &arch);
+  // Platform::SetHostPlatform(platform_sp);
+
+  m_debugger_sp = Debugger::CreateInstance();
+
+  m_debugger_sp->GetTargetList().CreateTarget(*m_debugger_sp, "", arch,
+                                              lldb_private::eLoadDependentsNo,
+                                              m_platform_sp, target_sp);
+
+  ASSERT_TRUE(target_sp);
+
+  llvm::SmallString<128> tmp_dir;
+  ASSERT_FALSE(llvm::sys::fs::createUniqueDirectory(
+      "locate-scripts-from-dsym-test", tmp_dir))
+      << "Failed to create test directory.";
+
+  // Create dummy module file at <test-root>/TestModule.o
+  FileSpec module_fspec(CreateFile("TestModule.o", tmp_dir));
+  ASSERT_TRUE(module_fspec);
+
+  // Create <test-root>/.dSYM/Contents/Resources
+  llvm::SmallString<128> dsym_resource_dir(tmp_dir);
+  llvm::sys::path::append(tmp_dir, ".dSYM", "Contents", "Resources");
+  ASSERT_FALSE(llvm::sys::fs::create_directory(dsym_resource_dir))
+      << "Failed to create test dSYM root directory.";
+
+  // Create .dSYM/Contents/Resources/DWARF
+  llvm::SmallString<128> dwarf_dir(dsym_resource_dir);
+  llvm::sys::path::append(dwarf_dir, "DWARF");
+  ASSERT_FALSE(llvm::sys::fs::create_directory(dwarf_dir))
+      << "Failed to create test dSYM DWARF directory.";
+
+  // Create dummy module file at
+  // <test-root>/.dSYM/Contents/Resources/DWARF/TestModule.o
+  FileSpec dsym_module_fpec(CreateFile("TestModule.o", dwarf_dir));
+  ASSERT_TRUE(dsym_module_fpec);
+
+  // Create .dSYM/Contents/Resources/Python
+  llvm::SmallString<128> python_dir(dsym_resource_dir);
+  llvm::sys::path::append(python_dir, "Python");
+  ASSERT_FALSE(llvm::sys::fs::create_directory(python_dir))
+      << "Failed to create test dSYM Python directory.";
+
+  CreateFile("TestModule.py", python_dir);
+  CreateFile("TestModule.txt", python_dir);
+  CreateFile("TestModule.sh", python_dir);
+
+  StreamString ss;
+  FileSpecList fspecs = std::static_pointer_cast<PlatformDarwin>(platform_sp)
+                            ->LocateExecutableScriptingResourcesFromDSYM(
+                                ss, module_fspec, *target_sp, 
dsym_module_fpec);
+  EXPECT_EQ(fspecs.GetSize(), 1u);
+}

>From f4765e910f5068193e783b97e9b1ea59e1d44f2f Mon Sep 17 00:00:00 2001
From: Michael Buch <[email protected]>
Date: Fri, 6 Mar 2026 17:33:47 +0000
Subject: [PATCH 3/4] fixup! remove leftover debug comment

---
 lldb/unittests/Platform/PlatformDarwinTest.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/lldb/unittests/Platform/PlatformDarwinTest.cpp 
b/lldb/unittests/Platform/PlatformDarwinTest.cpp
index fa7153b455e78..7ddaab8f8ab05 100644
--- a/lldb/unittests/Platform/PlatformDarwinTest.cpp
+++ b/lldb/unittests/Platform/PlatformDarwinTest.cpp
@@ -128,7 +128,6 @@ TEST_F(PlatformDarwinTest, 
LocateExecutableScriptingResourcesFromDSYM) {
   TargetSP target_sp;
   ArchSpec arch("x86_64-apple-macosx-");
   auto platform_sp = PlatformRemoteMacOSX::CreateInstance(true, &arch);
-  // Platform::SetHostPlatform(platform_sp);
 
   m_debugger_sp = Debugger::CreateInstance();
 

>From cc352a24464e7496a9f87aa8bfb34e6570a2d156 Mon Sep 17 00:00:00 2001
From: Michael Buch <[email protected]>
Date: Sat, 7 Mar 2026 11:13:59 +0000
Subject: [PATCH 4/4] fixup! set platform

---
 lldb/unittests/Platform/PlatformDarwinTest.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lldb/unittests/Platform/PlatformDarwinTest.cpp 
b/lldb/unittests/Platform/PlatformDarwinTest.cpp
index 7ddaab8f8ab05..5947ea6428f54 100644
--- a/lldb/unittests/Platform/PlatformDarwinTest.cpp
+++ b/lldb/unittests/Platform/PlatformDarwinTest.cpp
@@ -128,6 +128,7 @@ TEST_F(PlatformDarwinTest, 
LocateExecutableScriptingResourcesFromDSYM) {
   TargetSP target_sp;
   ArchSpec arch("x86_64-apple-macosx-");
   auto platform_sp = PlatformRemoteMacOSX::CreateInstance(true, &arch);
+  Platform::SetHostPlatform(platform_sp);
 
   m_debugger_sp = Debugger::CreateInstance();
 

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

Reply via email to