[Lldb-commits] [lldb] [lldb][PlatformDarwin] Make PlatformDarwin define a safe-path for auto-loading scripting resources (PR #191454)
Michael Buch via lldb-commits
lldb-commits at lists.llvm.org
Sat Apr 18 02:52:12 PDT 2026
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/191454
>From 8738f83917c5fbe8df1c63af9af30262b97a8850 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Fri, 17 Apr 2026 17:55:45 +0100
Subject: [PATCH 1/3] [lldb][Target] Move Debugger::GetSafeAutoLoadPaths into
Target
Required for https://github.com/llvm/llvm-project/pull/191454
We want to make the `Target`/`Platform` define commonly used default paths (without configuring them in CMake). This is easiest if this logic lived in `Target` (since then we have access to the associated `Platform`).
---
lldb/include/lldb/Core/Debugger.h | 11 +++--------
lldb/include/lldb/Target/Target.h | 6 ++++++
lldb/source/Core/Debugger.cpp | 14 +-------------
lldb/source/Target/Platform.cpp | 2 +-
lldb/source/Target/Target.cpp | 12 ++++++++++++
5 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h
index 421f8b04bc13d..e53e916d78cc1 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -69,7 +69,6 @@ class Process;
class Stream;
class SymbolContext;
class Target;
-class Debugger;
#ifndef NDEBUG
/// Global properties used in the LLDB testsuite.
@@ -85,7 +84,7 @@ struct TestingProperties : public Properties {
void AppendSafeAutoLoadPaths(FileSpec path);
private:
- friend Debugger;
+ friend Target;
/// Callers should use Debugger::GetSafeAutoLoadPaths since it
/// accounts for default paths configured via CMake.
@@ -145,12 +144,6 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
static void AssertCallback(llvm::StringRef message, llvm::StringRef backtrace,
llvm::StringRef prompt);
- /// Get the list of paths that LLDB will consider automatically loading
- /// scripting resources from. Currently whether to load scripts
- /// unconditionally is controlled via the
- /// `target.load-script-from-symbol-file` setting.
- static FileSpecList GetSafeAutoLoadPaths();
-
void Clear();
void DispatchClientTelemetry(const lldb_private::StructuredDataImpl &entry);
@@ -659,6 +652,8 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
};
std::optional<ProgressReport> GetCurrentProgressReport() const;
+ static const FileSpecList &GetDefaultSafeAutoLoadPaths();
+
protected:
friend class CommandInterpreter;
friend class REPL;
diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h
index 67f373aa5a325..f8ca5197a385a 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -1721,6 +1721,12 @@ class Target : public std::enable_shared_from_this<Target>,
void SaveScriptedLaunchInfo(lldb_private::ProcessInfo &process_info);
+ /// Get the list of paths that LLDB will consider automatically loading
+ /// scripting resources from. Currently whether to load scripts
+ /// unconditionally is controlled via the
+ /// `target.load-script-from-symbol-file` setting.
+ FileSpecList GetSafeAutoLoadPaths() const;
+
/// Add a signal for the target. This will get copied over to the process
/// if the signal exists on that target. Only the values with Yes and No are
/// set, Calculate values will be ignored.
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 1701f063fc061..48e03881fa3b5 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -213,7 +213,7 @@ enum {
};
#endif
-static const FileSpecList &GetDefaultSafeAutoLoadPaths() {
+const FileSpecList &Debugger::GetDefaultSafeAutoLoadPaths() {
static const FileSpecList sSafePaths = [] {
// FIXME: in c++20 this could be a std::array (with CTAD deduced size)
// and we could statically assert that all members are non-empty.
@@ -2618,15 +2618,3 @@ StructuredData::DictionarySP Debugger::GetBuildConfiguration() {
AddLLVMTargets(*config_up);
return config_up;
}
-
-FileSpecList Debugger::GetSafeAutoLoadPaths() {
- FileSpecList fspecs = GetDefaultSafeAutoLoadPaths();
-
-#ifndef NDEBUG
- for (const auto &fspec :
- TestingProperties::GetGlobalTestingProperties().GetSafeAutoLoadPaths())
- fspecs.Append(fspec);
-#endif
-
- return fspecs;
-}
diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index eaf461392d669..4786674c6ec36 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -190,7 +190,7 @@ Platform::LocateExecutableScriptingResourcesFromSafePaths(
->GetSanitizedScriptingModuleName(
module_spec.GetFileNameStrippingExtension().GetStringRef());
- FileSpecList paths = Debugger::GetSafeAutoLoadPaths();
+ FileSpecList paths = target.GetSafeAutoLoadPaths();
// Iterate in reverse so we consider the latest appended path first.
for (FileSpec path : llvm::reverse(paths)) {
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 4673e325a13a6..a30011216260d 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -5431,6 +5431,18 @@ void Target::NotifyBreakpointChanged(
BroadcastEvent(Target::eBroadcastBitBreakpointChanged, breakpoint_data_sp);
}
+FileSpecList Target::GetSafeAutoLoadPaths() const {
+ FileSpecList fspecs = Debugger::GetDefaultSafeAutoLoadPaths();
+
+#ifndef NDEBUG
+ for (const auto &fspec :
+ TestingProperties::GetGlobalTestingProperties().GetSafeAutoLoadPaths())
+ fspecs.Append(fspec);
+#endif
+
+ return fspecs;
+}
+
// FIXME: the language plugin should expression options dynamically and
// we should validate here (by asking the language plugin) that the options
// being set/retrieved are actually valid options.
>From 28a0912941e4a52bb428c1e6ccf00a39370ef02b Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Fri, 27 Mar 2026 12:02:01 +0000
Subject: [PATCH 2/3] [lldb][Platform] Allow Platform to define safe-paths for
auto-loading scripting resources
Depends on:
* https://github.com/llvm/llvm-project/pull/191446
Assisted-by: Claude
- Used Claude to write the skeleton of the test before manually cleaning it up.
---
lldb/include/lldb/Target/Platform.h | 7 ++++
.../Host/macosx/objcxx/HostInfoMacOSX.mm | 1 +
.../Platform/MacOSX/PlatformDarwin.cpp | 33 +++++++++++++++++++
.../Plugins/Platform/MacOSX/PlatformDarwin.h | 3 ++
lldb/source/Target/Target.cpp | 12 +++++++
lldb/unittests/Platform/CMakeLists.txt | 1 +
.../unittests/Platform/PlatformDarwinTest.cpp | 18 ++++++++++
7 files changed, 75 insertions(+)
diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h
index 001ff7e112909..4db1cd328bc08 100644
--- a/lldb/include/lldb/Target/Platform.h
+++ b/lldb/include/lldb/Target/Platform.h
@@ -1009,6 +1009,13 @@ class Platform : public PluginInterface {
LocateModuleCallback GetLocateModuleCallback() const;
+ /// Returns a \c FileSpecList of safe paths to auto-load scripting resources
+ /// from for a particular platform.
+ virtual llvm::Expected<FileSpecList>
+ GetSafeAutoLoadPaths(const Target &target) const {
+ return FileSpecList();
+ }
+
protected:
/// Create a list of ArchSpecs with the given OS and a architectures. The
/// vendor field is left as an "unspecified unknown".
diff --git a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
index 2214678d392b5..9f1335ee2946d 100644
--- a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
+++ b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
@@ -14,6 +14,7 @@
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/DataBuffer.h"
#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/FileSpecList.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Timer.h"
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index e2d8670a6acae..6e1a359ffe595 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -1564,3 +1564,36 @@ PlatformDarwin::ResolveSDKPathFromDebugInfo(CompileUnit &unit) {
return path_or_err->str();
}
+
+llvm::Expected<FileSpecList>
+PlatformDarwin::GetSafeAutoLoadPaths(const Target &target) const {
+ Log *log = GetLog(LLDBLog::Modules | LLDBLog::Platform);
+
+ XcodeSDK::Type sdk_type =
+ XcodeSDK::GetSDKTypeForTriple(target.GetArchitecture().GetTriple());
+ XcodeSDK sdk(XcodeSDK::Info{sdk_type, {}});
+
+ auto sdk_root_or_err = HostInfo::GetSDKRoot(HostInfo::SDKOptions{sdk});
+ if (!sdk_root_or_err) {
+ LLDB_LOG_ERROR(log, sdk_root_or_err.takeError(),
+ "Failed to resolve SDK root for triple '{1}': {0}",
+ target.GetArchitecture().GetTriple().str());
+
+ // Fall back to any macOS SDK.
+ sdk = XcodeSDK::GetAnyMacOS();
+ LLDB_LOG(log, "Falling back to SDK '{0}'", sdk.GetString());
+ sdk_root_or_err = HostInfo::GetSDKRoot(HostInfo::SDKOptions{sdk});
+ }
+
+ if (!sdk_root_or_err)
+ return sdk_root_or_err.takeError();
+
+ // $SDKROOT/usr/share/lldb is an auto-loadable path.
+ llvm::SmallString<256> resolved(*sdk_root_or_err);
+ llvm::sys::path::append(resolved, "usr", "share", "lldb");
+
+ FileSpecList fspecs;
+ fspecs.Append(FileSpec(resolved));
+
+ return fspecs;
+}
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
index fd5207e82b6db..f3c176f09cb68 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
@@ -159,6 +159,9 @@ class PlatformDarwin : public PlatformPOSIX {
const Target &target,
const FileSpec &symfile_spec);
+ llvm::Expected<FileSpecList>
+ GetSafeAutoLoadPaths(const Target &target) const override;
+
protected:
static const char *GetCompatibleArch(ArchSpec::Core core, size_t idx);
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index a30011216260d..1117f3680db43 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -5434,6 +5434,18 @@ void Target::NotifyBreakpointChanged(
FileSpecList Target::GetSafeAutoLoadPaths() const {
FileSpecList fspecs = Debugger::GetDefaultSafeAutoLoadPaths();
+ // Add platform-specific safe-paths.
+ if (m_platform_sp) {
+ if (auto platform_fspecs_or_err =
+ m_platform_sp->GetSafeAutoLoadPaths(*this))
+ fspecs.Append(*platform_fspecs_or_err);
+ else
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Modules | LLDBLog::Platform),
+ platform_fspecs_or_err.takeError(),
+ "Skipping safe auto-load path: {0}");
+ }
+
+ // Properties for testing get added last so they take priority.
#ifndef NDEBUG
for (const auto &fspec :
TestingProperties::GetGlobalTestingProperties().GetSafeAutoLoadPaths())
diff --git a/lldb/unittests/Platform/CMakeLists.txt b/lldb/unittests/Platform/CMakeLists.txt
index f8755432bf6d7..b3c87b33527bd 100644
--- a/lldb/unittests/Platform/CMakeLists.txt
+++ b/lldb/unittests/Platform/CMakeLists.txt
@@ -14,6 +14,7 @@ add_lldb_unittest(LLDBPlatformTests
lldbPluginPlatformMacOSX
lldbPluginPlatformNetBSD
lldbUtilityHelpers
+ LLVMTestingSupport
)
add_subdirectory(Android)
diff --git a/lldb/unittests/Platform/PlatformDarwinTest.cpp b/lldb/unittests/Platform/PlatformDarwinTest.cpp
index 16920c13b46a5..04af8081a274e 100644
--- a/lldb/unittests/Platform/PlatformDarwinTest.cpp
+++ b/lldb/unittests/Platform/PlatformDarwinTest.cpp
@@ -22,6 +22,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Testing/Support/Error.h"
#include <memory>
#include <tuple>
@@ -767,3 +768,20 @@ INSTANTIATE_TEST_SUITE_P(PlatformDarwinLocateWithSpecialCharsTest,
PlatformDarwinLocateWithSpecialCharsTestFixture,
testing::ValuesIn(std::vector<SpecialCharTestCase>{
{' ', '_'}, {'.', '_'}, {'-', '_'}, {'+', 'x'}}));
+
+TEST_F(PlatformDarwinLocateTest, GetSafeAutoLoadPaths) {
+ // Tests PlatformDarwin::GetSafeAutoLoadPaths returns a path into the SDK on
+ // Darwin platforms.
+
+ auto paths_or_err = std::static_pointer_cast<PlatformDarwin>(m_platform_sp)
+ ->GetSafeAutoLoadPaths(*m_target_sp);
+
+ ASSERT_THAT_EXPECTED(paths_or_err, llvm::Succeeded());
+
+ ASSERT_EQ(paths_or_err->GetSize(), 1u);
+
+ // The returned path should be $SDKROOT/usr/share/lldb.
+ FileSpec path = paths_or_err->GetFileSpecAtIndex(0);
+ EXPECT_TRUE(llvm::StringRef(path.GetPath()).ends_with("/usr/share/lldb"))
+ << "Unexpected path: " << path.GetPath();
+}
>From f337a39ec6c4c1572377ac7c65379c754c4e1ccf Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Sat, 18 Apr 2026 10:51:42 +0100
Subject: [PATCH 3/3] fixup! adjust error message
---
lldb/source/Target/Target.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 1117f3680db43..261dc21873aec 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -5442,7 +5442,7 @@ FileSpecList Target::GetSafeAutoLoadPaths() const {
else
LLDB_LOG_ERROR(GetLog(LLDBLog::Modules | LLDBLog::Platform),
platform_fspecs_or_err.takeError(),
- "Skipping safe auto-load path: {0}");
+ "Skipping safe auto-load: {0}");
}
// Properties for testing get added last so they take priority.
More information about the lldb-commits
mailing list