[Lldb-commits] [lldb] [lldb][PlatformDarwin][NFC] Move logic to emit warning on invalid/conflicting Python script names into helper function (PR #185669)
Michael Buch via lldb-commits
lldb-commits at lists.llvm.org
Wed Mar 11 03:05:14 PDT 2026
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/185669
>From 20292ed0dbb83ed7a444c0d39dd4046248e4aaab Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Tue, 10 Mar 2026 12:58:25 +0000
Subject: [PATCH 1/8] [lldb][PlatformDarwin] Reword warning when locating
scripting resources from dSYM
This patch makes the warning message more concise (in my opinion). We would duplicate the file path multiple times in the message. I'm planning on factoring this logic into a standalone function, and having it rely on fewer parameters helps with that.
Before:
```
warning: the symbol file '/var/folders/r8/d92r4cgj32qfg84671c1974h0000gn/T/lit-tmp-o6d4yrjx/locate-scripts-from-dsym-test-77d136/.dSYM/Contents/Resources/DWARF/import' contains a debug script. However, its name '/var/folders/r8/d92r4cgj32qfg84671c1974h0000gn/T/lit-tmp-o6d4yrjx/locate-scripts-from-dsym-test-77d136/.dSYM/Contents/Resources/DWARF/../Python/import.py' conflicts with a keyword and as such cannot be loaded. LLDB will load '/var/folders/r8/d92r4cgj32qfg84671c1974h0000gn/T/lit-tmp-o6d4yrjx/locate-scripts-from-dsym-test-77d136/.dSYM/Contents/Resources/DWARF/../Python/_import.py' instead. Consider removing the file with the malformed name to eliminate this warning.
```
After:
```
warning: found a debug script '/var/folders/r8/d92r4cgj32qfg84671c1974h0000gn/T/lit-tmp-c2ftoatb/locate-scripts-from-dsym-test-01f130/.dSYM/Contents/Resources/DWARF/../Python/import.py'. However, its name conflicts with a keyword and as such cannot be loaded. LLDB will load '/var/folders/r8/d92r4cgj32qfg84671c1974h0000gn/T/lit-tmp-c2ftoatb/locate-scripts-from-dsym-test-01f130/.dSYM/Contents/Resources/DWARF/../Python/_import.py' instead. Consider removing the file with the malformed name to eliminate this warning.
```
Before:
```
warning: the symbol file '/var/folders/r8/d92r4cgj32qfg84671c1974h0000gn/T/lit-tmp-o6d4yrjx/locate-scripts-from-dsym-test-01765f/.dSYM/Contents/Resources/DWARF/import' contains a debug script. However, its name conflicts with a keyword and as such cannot be loaded. If you intend to have this script loaded, please rename '/var/folders/r8/d92r4cgj32qfg84671c1974h0000gn/T/lit-tmp-o6d4yrjx/locate-scripts-from-dsym-test-01765f/.dSYM/Contents/Resources/DWARF/../Python/import.py' to '/var/folders/r8/d92r4cgj32qfg84671c1974h0000gn/T/lit-tmp-o6d4yrjx/locate-scripts-from-dsym-test-01765f/.dSYM/Contents/Resources/DWARF/../Python/_import.py' and retry."
```
After:
```
warning: found a debug script '/var/folders/r8/d92r4cgj32qfg84671c1974h0000gn/T/lit-tmp-c2ftoatb/locate-scripts-from-dsym-test-0766c6/.dSYM/Contents/Resources/DWARF/../Python/import.py'. However, its name conflicts with a keyword and as such cannot be loaded. If you intend to have this script loaded, please rename it to '/var/folders/r8/d92r4cgj32qfg84671c1974h0000gn/T/lit-tmp-c2ftoatb/locate-scripts-from-dsym-test-0766c6/.dSYM/Contents/Resources/DWARF/../Python/_import.py' and retry.
```
---
.../Platform/MacOSX/PlatformDarwin.cpp | 25 ++++++++---------
.../unittests/Platform/PlatformDarwinTest.cpp | 28 +++++++++----------
2 files changed, 25 insertions(+), 28 deletions(-)
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index 436dc5aa0f684..01b527e5ad8a9 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -286,23 +286,20 @@ FileSpecList PlatformDarwin::LocateExecutableScriptingResourcesFromDSYM(
: "contains reserved characters";
if (FileSystem::Instance().Exists(script_fspec))
feedback_stream.Format(
- "warning: the symbol file '{0}' contains a debug "
- "script. However, its name"
- " '{1}' {2} and as such cannot be loaded. LLDB will"
- " load '{3}' instead. Consider removing the file with "
- "the malformed name to"
- " eliminate this warning.\n",
- symfile_spec.GetPath(), original_path_string.GetString(),
- reason_for_complaint, path_string.GetString());
+ "warning: found a debug script '{0}'. However, its name"
+ " {1} and as such cannot be loaded. LLDB will"
+ " load '{2}' instead. Consider removing the file with"
+ " the malformed name to eliminate this warning.\n",
+ original_path_string.GetString(), reason_for_complaint,
+ path_string.GetString());
else
feedback_stream.Format(
- "warning: the symbol file '{0}' contains a debug "
- "script. However, its name"
+ "warning: found a debug script '{0}'. However, its name"
" {1} and as such cannot be loaded. If you intend"
- " to have this script loaded, please rename '{2}' to "
- "'{3}' and retry.\n",
- symfile_spec.GetPath(), reason_for_complaint,
- original_path_string.GetString(), path_string.GetString());
+ " to have this script loaded, please rename it to "
+ "'{2}' and retry.\n",
+ original_path_string.GetString(), reason_for_complaint,
+ path_string.GetString());
}
if (FileSystem::Instance().Exists(script_fspec)) {
diff --git a/lldb/unittests/Platform/PlatformDarwinTest.cpp b/lldb/unittests/Platform/PlatformDarwinTest.cpp
index f5fd6660069ea..7e17cb66cbd8d 100644
--- a/lldb/unittests/Platform/PlatformDarwinTest.cpp
+++ b/lldb/unittests/Platform/PlatformDarwinTest.cpp
@@ -354,11 +354,11 @@ TEST_F(PlatformDarwinLocateTest,
std::string fixed_script =
(m_tmp_dsym_dwarf_dir + "/../Python/_import.py").str();
std::string expected = llvm::formatv(
- "warning: the symbol file '{0}' contains a debug script. However, its "
+ "warning: found a debug script '{0}'. However, its "
"name conflicts with a keyword and as such cannot be loaded. If you "
- "intend to have this script loaded, please rename '{1}' to '{2}' and "
+ "intend to have this script loaded, please rename it to '{1}' and "
"retry.\n",
- dsym_module_fpec.GetPath(), orig_script, fixed_script);
+ orig_script, fixed_script);
EXPECT_EQ(ss.GetString(), expected);
}
@@ -394,11 +394,11 @@ TEST_F(PlatformDarwinLocateTest,
std::string fixed_script =
(m_tmp_dsym_dwarf_dir + "/../Python/_import.py").str();
std::string expected = llvm::formatv(
- "warning: the symbol file '{0}' contains a debug script. However, its "
- "name '{1}' conflicts with a keyword and as such cannot be loaded. LLDB "
- "will load '{2}' instead. Consider removing the file with the malformed "
+ "warning: found a debug script '{0}'. However, its "
+ "name conflicts with a keyword and as such cannot be loaded. LLDB "
+ "will load '{1}' instead. Consider removing the file with the malformed "
"name to eliminate this warning.\n",
- dsym_module_fpec.GetPath(), orig_script, fixed_script);
+ orig_script, fixed_script);
EXPECT_EQ(ss.GetString(), expected);
}
@@ -461,11 +461,11 @@ TEST_F(
std::string fixed_script =
(m_tmp_dsym_dwarf_dir + "/../Python/TestModule_1_1_1.py").str();
std::string expected = llvm::formatv(
- "warning: the symbol file '{0}' contains a debug script. However, its "
+ "warning: found a debug script '{0}'. However, its "
"name contains reserved characters and as such cannot be loaded. If you "
- "intend to have this script loaded, please rename '{1}' to '{2}' and "
+ "intend to have this script loaded, please rename it to '{1}' and "
"retry.\n",
- dsym_module_fpec.GetPath(), orig_script, fixed_script);
+ orig_script, fixed_script);
EXPECT_EQ(ss.GetString(), expected);
}
@@ -502,11 +502,11 @@ TEST_F(
std::string fixed_script =
(m_tmp_dsym_dwarf_dir + "/../Python/TestModule_1_1_1.py").str();
std::string expected = llvm::formatv(
- "warning: the symbol file '{0}' contains a debug script. However, its "
- "name '{1}' contains reserved characters and as such cannot be loaded. "
- "LLDB will load '{2}' instead. Consider removing the file with the "
+ "warning: found a debug script '{0}'. However, its "
+ "name contains reserved characters and as such cannot be loaded. "
+ "LLDB will load '{1}' instead. Consider removing the file with the "
"malformed name to eliminate this warning.\n",
- dsym_module_fpec.GetPath(), orig_script, fixed_script);
+ orig_script, fixed_script);
EXPECT_EQ(ss.GetString(), expected);
}
>From c62c7bb0164e54144ac626ef3449b832edba5e40 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Wed, 11 Mar 2026 09:13:26 +0000
Subject: [PATCH 2/8] fixup! use filename without path in warning
---
.../Platform/MacOSX/PlatformDarwin.cpp | 22 ++++-----
.../unittests/Platform/PlatformDarwinTest.cpp | 48 +++++++------------
2 files changed, 28 insertions(+), 42 deletions(-)
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index 01b527e5ad8a9..3015acfd5783a 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -286,20 +286,18 @@ FileSpecList PlatformDarwin::LocateExecutableScriptingResourcesFromDSYM(
: "contains reserved characters";
if (FileSystem::Instance().Exists(script_fspec))
feedback_stream.Format(
- "warning: found a debug script '{0}'. However, its name"
- " {1} and as such cannot be loaded. LLDB will"
- " load '{2}' instead. Consider removing the file with"
- " the malformed name to eliminate this warning.\n",
- original_path_string.GetString(), reason_for_complaint,
- path_string.GetString());
+ "warning: debug script '{0}' cannot be loaded because '{1}' {2}. "
+ "Loading '{3}' instead. Consider removing the file with the "
+ "malformed name to eliminate this warning.\n",
+ original_path_string.GetString(), orig_script_fspec.GetFilename(),
+ reason_for_complaint, script_fspec.GetFilename());
else
feedback_stream.Format(
- "warning: found a debug script '{0}'. However, its name"
- " {1} and as such cannot be loaded. If you intend"
- " to have this script loaded, please rename it to "
- "'{2}' and retry.\n",
- original_path_string.GetString(), reason_for_complaint,
- path_string.GetString());
+ "warning: debug script '{0}' cannot be loaded because '{1}' {2}. "
+ "If you intend to have this script loaded, please rename it to "
+ "'{3}' and retry.\n",
+ original_path_string.GetString(), orig_script_fspec.GetFilename(),
+ reason_for_complaint, script_fspec.GetFilename());
}
if (FileSystem::Instance().Exists(script_fspec)) {
diff --git a/lldb/unittests/Platform/PlatformDarwinTest.cpp b/lldb/unittests/Platform/PlatformDarwinTest.cpp
index 7e17cb66cbd8d..641f6478f78c0 100644
--- a/lldb/unittests/Platform/PlatformDarwinTest.cpp
+++ b/lldb/unittests/Platform/PlatformDarwinTest.cpp
@@ -351,14 +351,11 @@ TEST_F(PlatformDarwinLocateTest,
std::string orig_script =
(m_tmp_dsym_dwarf_dir + "/../Python/import.py").str();
- std::string fixed_script =
- (m_tmp_dsym_dwarf_dir + "/../Python/_import.py").str();
std::string expected = llvm::formatv(
- "warning: found a debug script '{0}'. However, its "
- "name conflicts with a keyword and as such cannot be loaded. If you "
- "intend to have this script loaded, please rename it to '{1}' and "
- "retry.\n",
- orig_script, fixed_script);
+ "warning: debug script '{0}' cannot be loaded because 'import.py' "
+ "conflicts with a keyword. If you intend to have this script loaded, "
+ "please rename it to '_import.py' and retry.\n",
+ orig_script);
EXPECT_EQ(ss.GetString(), expected);
}
@@ -391,14 +388,11 @@ TEST_F(PlatformDarwinLocateTest,
std::string orig_script =
(m_tmp_dsym_dwarf_dir + "/../Python/import.py").str();
- std::string fixed_script =
- (m_tmp_dsym_dwarf_dir + "/../Python/_import.py").str();
std::string expected = llvm::formatv(
- "warning: found a debug script '{0}'. However, its "
- "name conflicts with a keyword and as such cannot be loaded. LLDB "
- "will load '{1}' instead. Consider removing the file with the malformed "
- "name to eliminate this warning.\n",
- orig_script, fixed_script);
+ "warning: debug script '{0}' cannot be loaded because 'import.py' "
+ "conflicts with a keyword. Loading '_import.py' instead. Consider "
+ "removing the file with the malformed name to eliminate this warning.\n",
+ orig_script);
EXPECT_EQ(ss.GetString(), expected);
}
@@ -458,14 +452,11 @@ TEST_F(
std::string orig_script =
(m_tmp_dsym_dwarf_dir + "/../Python/TestModule-1.1 1.py").str();
- std::string fixed_script =
- (m_tmp_dsym_dwarf_dir + "/../Python/TestModule_1_1_1.py").str();
std::string expected = llvm::formatv(
- "warning: found a debug script '{0}'. However, its "
- "name contains reserved characters and as such cannot be loaded. If you "
- "intend to have this script loaded, please rename it to '{1}' and "
- "retry.\n",
- orig_script, fixed_script);
+ "warning: debug script '{0}' cannot be loaded because 'TestModule-1.1 "
+ "1.py' contains reserved characters. If you intend to have this script "
+ "loaded, please rename it to 'TestModule_1_1_1.py' and retry.\n",
+ orig_script);
EXPECT_EQ(ss.GetString(), expected);
}
@@ -499,14 +490,12 @@ TEST_F(
std::string orig_script =
(m_tmp_dsym_dwarf_dir + "/../Python/TestModule-1.1 1.py").str();
- std::string fixed_script =
- (m_tmp_dsym_dwarf_dir + "/../Python/TestModule_1_1_1.py").str();
std::string expected = llvm::formatv(
- "warning: found a debug script '{0}'. However, its "
- "name contains reserved characters and as such cannot be loaded. "
- "LLDB will load '{1}' instead. Consider removing the file with the "
- "malformed name to eliminate this warning.\n",
- orig_script, fixed_script);
+ "warning: debug script '{0}' cannot be loaded because 'TestModule-1.1 "
+ "1.py' contains reserved characters. Loading 'TestModule_1_1_1.py' "
+ "instead. Consider removing the file with the malformed name to "
+ "eliminate this warning.\n",
+ orig_script);
EXPECT_EQ(ss.GetString(), expected);
}
@@ -564,8 +553,7 @@ TEST_F(
->LocateExecutableScriptingResourcesFromDSYM(
ss, module_fspec, *m_target_sp, dsym_module_fpec);
EXPECT_EQ(fspecs.GetSize(), 0u);
- EXPECT_TRUE(ss.GetString().contains(
- "its name conflicts with a keyword and as such cannot be loaded"));
+ EXPECT_TRUE(ss.GetString().contains("conflicts with a keyword"));
}
TEST_F(
>From eb30539a7c7e0799d0e3e897cb0112e4d6f751de Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Wed, 11 Mar 2026 09:22:24 +0000
Subject: [PATCH 3/8] fixup! print conflicting keyword in error message
---
.../Platform/MacOSX/PlatformDarwin.cpp | 26 ++++++++++++-------
.../unittests/Platform/PlatformDarwinTest.cpp | 9 ++++---
2 files changed, 22 insertions(+), 13 deletions(-)
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index 3015acfd5783a..ef697982e5162 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -105,14 +105,14 @@ class SanitizedScriptingModuleName {
if (script_interpreter &&
script_interpreter->IsReservedWord(m_sanitized_name.c_str())) {
+ m_conflicting_keyword = m_sanitized_name;
m_sanitized_name.insert(m_sanitized_name.begin(), '_');
- m_name_is_keyword = true;
}
}
/// Returns \c true if this name is a keyword in the associated scripting
/// language.
- bool IsKeyword() const { return m_name_is_keyword; }
+ bool IsKeyword() const { return !m_conflicting_keyword.empty(); }
/// Returns \c true if the original name has been sanitized (i.e., required
/// changes).
@@ -122,14 +122,16 @@ class SanitizedScriptingModuleName {
llvm::StringRef GetSanitizedName() const { return m_sanitized_name; }
llvm::StringRef GetOriginalName() const { return m_original_name; }
+ llvm::StringRef GetConflictingKeyword() const { return m_conflicting_keyword; }
private:
llvm::StringRef m_original_name;
std::string m_sanitized_name;
- /// \c true if m_sanitized_name is a keyword for the ScriptInterpreter
- /// language associated with this SanitizedScriptingModuleName.
- bool m_name_is_keyword = false;
+ /// If the m_sanitized_name conflicts with a keyword for the ScriptInterpreter
+ /// language associated with this SanitizedScriptingModuleName, is set to the
+ /// conflicting keyword. Empty otherwise.
+ std::string m_conflicting_keyword;
};
} // namespace
@@ -281,23 +283,27 @@ FileSpecList PlatformDarwin::LocateExecutableScriptingResourcesFromDSYM(
// that the file as-is shall not be loaded
if (sanitized_name.RequiredSanitization() &&
FileSystem::Instance().Exists(orig_script_fspec)) {
- const char *reason_for_complaint = sanitized_name.IsKeyword()
- ? "conflicts with a keyword"
- : "contains reserved characters";
+ std::string reason_for_complaint =
+ sanitized_name.IsKeyword()
+ ? llvm::formatv("conflicts with the keyword '{0}'",
+ sanitized_name.GetConflictingKeyword())
+ .str()
+ : "contains reserved characters";
+
if (FileSystem::Instance().Exists(script_fspec))
feedback_stream.Format(
"warning: debug script '{0}' cannot be loaded because '{1}' {2}. "
"Loading '{3}' instead. Consider removing the file with the "
"malformed name to eliminate this warning.\n",
original_path_string.GetString(), orig_script_fspec.GetFilename(),
- reason_for_complaint, script_fspec.GetFilename());
+ std::move(reason_for_complaint), script_fspec.GetFilename());
else
feedback_stream.Format(
"warning: debug script '{0}' cannot be loaded because '{1}' {2}. "
"If you intend to have this script loaded, please rename it to "
"'{3}' and retry.\n",
original_path_string.GetString(), orig_script_fspec.GetFilename(),
- reason_for_complaint, script_fspec.GetFilename());
+ std::move(reason_for_complaint), script_fspec.GetFilename());
}
if (FileSystem::Instance().Exists(script_fspec)) {
diff --git a/lldb/unittests/Platform/PlatformDarwinTest.cpp b/lldb/unittests/Platform/PlatformDarwinTest.cpp
index 641f6478f78c0..1b9f70bd46eea 100644
--- a/lldb/unittests/Platform/PlatformDarwinTest.cpp
+++ b/lldb/unittests/Platform/PlatformDarwinTest.cpp
@@ -353,7 +353,8 @@ TEST_F(PlatformDarwinLocateTest,
(m_tmp_dsym_dwarf_dir + "/../Python/import.py").str();
std::string expected = llvm::formatv(
"warning: debug script '{0}' cannot be loaded because 'import.py' "
- "conflicts with a keyword. If you intend to have this script loaded, "
+ "conflicts with the keyword 'import'. If you intend to have this script "
+ "loaded, "
"please rename it to '_import.py' and retry.\n",
orig_script);
EXPECT_EQ(ss.GetString(), expected);
@@ -390,7 +391,8 @@ TEST_F(PlatformDarwinLocateTest,
(m_tmp_dsym_dwarf_dir + "/../Python/import.py").str();
std::string expected = llvm::formatv(
"warning: debug script '{0}' cannot be loaded because 'import.py' "
- "conflicts with a keyword. Loading '_import.py' instead. Consider "
+ "conflicts with the keyword 'import'. Loading '_import.py' instead. "
+ "Consider "
"removing the file with the malformed name to eliminate this warning.\n",
orig_script);
EXPECT_EQ(ss.GetString(), expected);
@@ -553,7 +555,8 @@ TEST_F(
->LocateExecutableScriptingResourcesFromDSYM(
ss, module_fspec, *m_target_sp, dsym_module_fpec);
EXPECT_EQ(fspecs.GetSize(), 0u);
- EXPECT_TRUE(ss.GetString().contains("conflicts with a keyword"));
+ EXPECT_TRUE(
+ ss.GetString().contains("conflicts with the keyword 'mykeyword_1_1_1'"));
}
TEST_F(
>From e22641cc919146b0fd03920a0ed1930309f44e0f Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Wed, 11 Mar 2026 09:29:45 +0000
Subject: [PATCH 4/8] fixup! formatting
---
lldb/unittests/Platform/PlatformDarwinTest.cpp | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/lldb/unittests/Platform/PlatformDarwinTest.cpp b/lldb/unittests/Platform/PlatformDarwinTest.cpp
index 1b9f70bd46eea..0abb7a56cdaef 100644
--- a/lldb/unittests/Platform/PlatformDarwinTest.cpp
+++ b/lldb/unittests/Platform/PlatformDarwinTest.cpp
@@ -354,8 +354,7 @@ TEST_F(PlatformDarwinLocateTest,
std::string expected = llvm::formatv(
"warning: debug script '{0}' cannot be loaded because 'import.py' "
"conflicts with the keyword 'import'. If you intend to have this script "
- "loaded, "
- "please rename it to '_import.py' and retry.\n",
+ "loaded, please rename it to '_import.py' and retry.\n",
orig_script);
EXPECT_EQ(ss.GetString(), expected);
}
@@ -392,8 +391,8 @@ TEST_F(PlatformDarwinLocateTest,
std::string expected = llvm::formatv(
"warning: debug script '{0}' cannot be loaded because 'import.py' "
"conflicts with the keyword 'import'. Loading '_import.py' instead. "
- "Consider "
- "removing the file with the malformed name to eliminate this warning.\n",
+ "Consider removing the file with the malformed name to eliminate this "
+ "warning.\n",
orig_script);
EXPECT_EQ(ss.GetString(), expected);
}
>From 5c25049aca78f1eb4b79ccaad9336d5e0b0fe9ec Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Wed, 11 Mar 2026 09:51:16 +0000
Subject: [PATCH 5/8] fixup! clang-format
---
lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index ef697982e5162..a1de158610c41 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -122,7 +122,9 @@ class SanitizedScriptingModuleName {
llvm::StringRef GetSanitizedName() const { return m_sanitized_name; }
llvm::StringRef GetOriginalName() const { return m_original_name; }
- llvm::StringRef GetConflictingKeyword() const { return m_conflicting_keyword; }
+ llvm::StringRef GetConflictingKeyword() const {
+ return m_conflicting_keyword;
+ }
private:
llvm::StringRef m_original_name;
>From 8e4de72634fa93bc3496b1311f3e7abb77e3d485 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Tue, 10 Mar 2026 14:17:59 +0000
Subject: [PATCH 6/8] [lldb][PlatformDarwin][NFC] Move logic to emit warning on
invalid/conflicting Python script names into helper function
Depends on:
* https://github.com/llvm/llvm-project/pull/185666
* https://github.com/llvm/llvm-project/pull/185627
I'm planning on re-using this logic for a different API. Hence move it into a common helper.
---
.../Platform/MacOSX/PlatformDarwin.cpp | 62 +++++++++++--------
1 file changed, 35 insertions(+), 27 deletions(-)
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index a1de158610c41..2b3ee1a46a1fa 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -126,6 +126,39 @@ class SanitizedScriptingModuleName {
return m_conflicting_keyword;
}
+ /// If we did some replacements of reserved characters, and a
+ /// file with the untampered name exists, then warn the user
+ /// that the file as-is shall not be loaded.
+ void WarnIfInvalidUnsanitizedScriptExists(Stream &os,
+ const FileSpec &original_fspec,
+ const FileSpec &fspec) const {
+ if (!RequiredSanitization())
+ return;
+
+ // Path to unsanitized script name doesn't exist. Nothing to warn about.
+ if (!FileSystem::Instance().Exists(original_fspec))
+ return;
+
+ llvm::StringRef reason_for_complaint = IsKeyword()
+ ? "conflicts with a keyword"
+ : "contains reserved characters";
+
+ if (FileSystem::Instance().Exists(fspec))
+ os.Format("warning: found a debug script '{0}'. However, its name"
+ " {1} and as such cannot be loaded. LLDB will"
+ " load '{2}' instead. Consider removing the file with"
+ " the malformed name to eliminate this warning.\n",
+ original_fspec.GetPath(), reason_for_complaint,
+ fspec.GetPath());
+ else
+ os.Format("warning: found a debug script '{0}'. However, its name"
+ " {1} and as such cannot be loaded. If you intend"
+ " to have this script loaded, please rename it to "
+ "'{2}' and retry.\n",
+ original_fspec.GetPath(), reason_for_complaint,
+ fspec.GetPath());
+ }
+
private:
llvm::StringRef m_original_name;
std::string m_sanitized_name;
@@ -280,33 +313,8 @@ FileSpecList PlatformDarwin::LocateExecutableScriptingResourcesFromDSYM(
FileSpec orig_script_fspec(original_path_string.GetString());
FileSystem::Instance().Resolve(orig_script_fspec);
- // if we did some replacements of reserved characters, and a
- // file with the untampered name exists, then warn the user
- // that the file as-is shall not be loaded
- if (sanitized_name.RequiredSanitization() &&
- FileSystem::Instance().Exists(orig_script_fspec)) {
- std::string reason_for_complaint =
- sanitized_name.IsKeyword()
- ? llvm::formatv("conflicts with the keyword '{0}'",
- sanitized_name.GetConflictingKeyword())
- .str()
- : "contains reserved characters";
-
- if (FileSystem::Instance().Exists(script_fspec))
- feedback_stream.Format(
- "warning: debug script '{0}' cannot be loaded because '{1}' {2}. "
- "Loading '{3}' instead. Consider removing the file with the "
- "malformed name to eliminate this warning.\n",
- original_path_string.GetString(), orig_script_fspec.GetFilename(),
- std::move(reason_for_complaint), script_fspec.GetFilename());
- else
- feedback_stream.Format(
- "warning: debug script '{0}' cannot be loaded because '{1}' {2}. "
- "If you intend to have this script loaded, please rename it to "
- "'{3}' and retry.\n",
- original_path_string.GetString(), orig_script_fspec.GetFilename(),
- std::move(reason_for_complaint), script_fspec.GetFilename());
- }
+ sanitized_name.WarnIfInvalidUnsanitizedScriptExists(
+ feedback_stream, orig_script_fspec, script_fspec);
if (FileSystem::Instance().Exists(script_fspec)) {
file_list.Append(script_fspec);
>From d1eeee0f8ede81c0d5a9377c587362e31029a756 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Wed, 11 Mar 2026 09:50:16 +0000
Subject: [PATCH 7/8] fixup! rebase
---
.../Platform/MacOSX/PlatformDarwin.cpp | 32 ++++++++++---------
1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index 2b3ee1a46a1fa..4a8b35a34ae89 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -139,24 +139,26 @@ class SanitizedScriptingModuleName {
if (!FileSystem::Instance().Exists(original_fspec))
return;
- llvm::StringRef reason_for_complaint = IsKeyword()
- ? "conflicts with a keyword"
- : "contains reserved characters";
+ std::string reason_for_complaint =
+ IsKeyword() ? llvm::formatv("conflicts with the keyword '{0}'",
+ GetConflictingKeyword())
+ .str()
+ : "contains reserved characters";
if (FileSystem::Instance().Exists(fspec))
- os.Format("warning: found a debug script '{0}'. However, its name"
- " {1} and as such cannot be loaded. LLDB will"
- " load '{2}' instead. Consider removing the file with"
- " the malformed name to eliminate this warning.\n",
- original_fspec.GetPath(), reason_for_complaint,
- fspec.GetPath());
+ os.Format(
+ "warning: debug script '{0}' cannot be loaded because '{1}' {2}. "
+ "Loading '{3}' instead. Consider removing the file with the "
+ "malformed name to eliminate this warning.\n",
+ original_fspec.GetPath(), original_fspec.GetFilename(),
+ std::move(reason_for_complaint), fspec.GetFilename());
else
- os.Format("warning: found a debug script '{0}'. However, its name"
- " {1} and as such cannot be loaded. If you intend"
- " to have this script loaded, please rename it to "
- "'{2}' and retry.\n",
- original_fspec.GetPath(), reason_for_complaint,
- fspec.GetPath());
+ os.Format(
+ "warning: debug script '{0}' cannot be loaded because '{1}' {2}. "
+ "If you intend to have this script loaded, please rename it to "
+ "'{3}' and retry.\n",
+ original_fspec.GetPath(), original_fspec.GetFilename(),
+ std::move(reason_for_complaint), fspec.GetFilename());
}
private:
>From d5ad7fb677307a395f7997021dd2decad375811c Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Wed, 11 Mar 2026 10:04:58 +0000
Subject: [PATCH 8/8] fixup! fix tests
---
.../unittests/Platform/PlatformDarwinTest.cpp | 45 ++++++++++---------
1 file changed, 23 insertions(+), 22 deletions(-)
diff --git a/lldb/unittests/Platform/PlatformDarwinTest.cpp b/lldb/unittests/Platform/PlatformDarwinTest.cpp
index 0abb7a56cdaef..3d2e65f55dd0c 100644
--- a/lldb/unittests/Platform/PlatformDarwinTest.cpp
+++ b/lldb/unittests/Platform/PlatformDarwinTest.cpp
@@ -340,7 +340,8 @@ TEST_F(PlatformDarwinLocateTest,
// Keywords are not permitted in module names.
// See MockScriptInterpreterPython::IsReservedWord
- CreateFile("import.py", m_tmp_dsym_python_dir);
+ FileSpec script_fspec(CreateFile("import.py", m_tmp_dsym_python_dir));
+ ASSERT_TRUE(script_fspec);
StreamString ss;
FileSpecList fspecs =
@@ -349,13 +350,11 @@ TEST_F(PlatformDarwinLocateTest,
ss, module_fspec, *m_target_sp, dsym_module_fpec);
EXPECT_EQ(fspecs.GetSize(), 0u);
- std::string orig_script =
- (m_tmp_dsym_dwarf_dir + "/../Python/import.py").str();
std::string expected = llvm::formatv(
"warning: debug script '{0}' cannot be loaded because 'import.py' "
"conflicts with the keyword 'import'. If you intend to have this script "
"loaded, please rename it to '_import.py' and retry.\n",
- orig_script);
+ script_fspec.GetPath());
EXPECT_EQ(ss.GetString(), expected);
}
@@ -376,7 +375,9 @@ TEST_F(PlatformDarwinLocateTest,
// Keywords are not permitted in module names.
// See MockScriptInterpreterPython::IsReservedWord
CreateFile("_import.py", m_tmp_dsym_python_dir);
- CreateFile("import.py", m_tmp_dsym_python_dir);
+
+ FileSpec orig_fspec(CreateFile("import.py", m_tmp_dsym_python_dir));
+ ASSERT_TRUE(orig_fspec);
StreamString ss;
FileSpecList fspecs =
@@ -386,14 +387,12 @@ TEST_F(PlatformDarwinLocateTest,
EXPECT_EQ(fspecs.GetSize(), 1u);
EXPECT_EQ(fspecs.GetFileSpecAtIndex(0).GetFilename(), "_import.py");
- std::string orig_script =
- (m_tmp_dsym_dwarf_dir + "/../Python/import.py").str();
std::string expected = llvm::formatv(
"warning: debug script '{0}' cannot be loaded because 'import.py' "
"conflicts with the keyword 'import'. Loading '_import.py' instead. "
"Consider removing the file with the malformed name to eliminate this "
"warning.\n",
- orig_script);
+ orig_fspec.GetPath());
EXPECT_EQ(ss.GetString(), expected);
}
@@ -442,7 +441,9 @@ TEST_F(
CreateFile("TestModule-1.1 1.o", m_tmp_dsym_dwarf_dir));
ASSERT_TRUE(dsym_module_fpec);
- CreateFile("TestModule-1.1 1.py", m_tmp_dsym_python_dir);
+ FileSpec script_fspec(
+ CreateFile("TestModule-1.1 1.py", m_tmp_dsym_python_dir));
+ ASSERT_TRUE(script_fspec);
StreamString ss;
FileSpecList fspecs =
@@ -451,13 +452,12 @@ TEST_F(
ss, module_fspec, *m_target_sp, dsym_module_fpec);
EXPECT_EQ(fspecs.GetSize(), 0u);
- std::string orig_script =
- (m_tmp_dsym_dwarf_dir + "/../Python/TestModule-1.1 1.py").str();
std::string expected = llvm::formatv(
- "warning: debug script '{0}' cannot be loaded because 'TestModule-1.1 "
- "1.py' contains reserved characters. If you intend to have this script "
- "loaded, please rename it to 'TestModule_1_1_1.py' and retry.\n",
- orig_script);
+ "warning: debug script '{0}' cannot be loaded because"
+ " 'TestModule-1.1 1.py' contains reserved characters. If you intend to"
+ " have this script loaded, please rename it to 'TestModule_1_1_1.py' and "
+ "retry.\n",
+ script_fspec.GetPath());
EXPECT_EQ(ss.GetString(), expected);
}
@@ -478,7 +478,9 @@ TEST_F(
CreateFile("TestModule-1.1 1.o", m_tmp_dsym_dwarf_dir));
ASSERT_TRUE(dsym_module_fpec);
- CreateFile("TestModule-1.1 1.py", m_tmp_dsym_python_dir);
+ FileSpec orig_fspec(CreateFile("TestModule-1.1 1.py", m_tmp_dsym_python_dir));
+ ASSERT_TRUE(orig_fspec);
+
CreateFile("TestModule_1_1_1.py", m_tmp_dsym_python_dir);
StreamString ss;
@@ -489,14 +491,13 @@ TEST_F(
EXPECT_EQ(fspecs.GetSize(), 1u);
EXPECT_EQ(fspecs.GetFileSpecAtIndex(0).GetFilename(), "TestModule_1_1_1.py");
- std::string orig_script =
- (m_tmp_dsym_dwarf_dir + "/../Python/TestModule-1.1 1.py").str();
std::string expected = llvm::formatv(
- "warning: debug script '{0}' cannot be loaded because 'TestModule-1.1 "
- "1.py' contains reserved characters. Loading 'TestModule_1_1_1.py' "
- "instead. Consider removing the file with the malformed name to "
+ "warning: debug script '{0}' cannot be loaded because"
+ " 'TestModule-1.1 1.py' contains reserved characters. Loading"
+ " 'TestModule_1_1_1.py' instead. Consider removing the file with the "
+ "malformed name to "
"eliminate this warning.\n",
- orig_script);
+ orig_fspec.GetPath());
EXPECT_EQ(ss.GetString(), expected);
}
More information about the lldb-commits
mailing list