[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 02:50:46 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/6] [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/6] 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/6] 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/6] 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 ad16fc7b422636829a5a1511c630774942bb45f3 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 5/6] [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 ef697982e5162..329ef8d857a7b 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -124,6 +124,39 @@ class SanitizedScriptingModuleName {
   llvm::StringRef GetOriginalName() const { return m_original_name; }
   llvm::StringRef GetConflictingKeyword() const { 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;
@@ -278,33 +311,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 4b81145e96b92dd66b023de847e760783736175c 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 6/6] 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 329ef8d857a7b..75ca0196e5051 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -137,24 +137,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:



More information about the lldb-commits mailing list