[Lldb-commits] [lldb] 57c1fe9 - [lldb][test] PlatformDarwinTest.cpp: add more test-cases for script name sanitization
Michael Buch via lldb-commits
lldb-commits at lists.llvm.org
Tue Mar 10 05:32:07 PDT 2026
Author: Michael Buch
Date: 2026-03-10T12:31:43Z
New Revision: 57c1fe926451ddd5d7b2c089a71692cb36a6fb39
URL: https://github.com/llvm/llvm-project/commit/57c1fe926451ddd5d7b2c089a71692cb36a6fb39
DIFF: https://github.com/llvm/llvm-project/commit/57c1fe926451ddd5d7b2c089a71692cb36a6fb39.diff
LOG: [lldb][test] PlatformDarwinTest.cpp: add more test-cases for script name sanitization
Adds more test-cases since I'm making changes around this area (see https://github.com/llvm/llvm-project/pull/185627).
Added:
Modified:
lldb/unittests/Platform/PlatformDarwinTest.cpp
Removed:
################################################################################
diff --git a/lldb/unittests/Platform/PlatformDarwinTest.cpp b/lldb/unittests/Platform/PlatformDarwinTest.cpp
index 48836ad89b14d..fc99dd9e44ada 100644
--- a/lldb/unittests/Platform/PlatformDarwinTest.cpp
+++ b/lldb/unittests/Platform/PlatformDarwinTest.cpp
@@ -52,7 +52,8 @@ class MockScriptInterpreterPython : public ScriptInterpreter {
static void Terminate() { PluginManager::UnregisterPlugin(CreateInstance); }
bool IsReservedWord(const char *word) override {
- return llvm::is_contained({"import"}, llvm::StringRef(word));
+ return llvm::is_contained({"import", "mykeyword_1_1_1"},
+ llvm::StringRef(word));
}
static lldb::ScriptInterpreterSP CreateInstance(Debugger &debugger) {
@@ -495,3 +496,96 @@ TEST_F(
EXPECT_EQ(fspecs.GetFileSpecAtIndex(0).GetFilename(), "TestModule_1_1_1.py");
EXPECT_TRUE(ss.GetString().empty());
}
+
+TEST_F(
+ PlatformDarwinLocateTest,
+ LocateExecutableScriptingResourcesFromDSYM_ModuleNameIsKeywordAfterReplacement) {
+ // Test case where the module name contains "special characters" but after
+ // LLDB replaces those the filename is still a keyword. We ensure this by a
+ // special case in MockScriptInterpreterPython::IsReservedWord.
+
+ // Create dummy module file at <test-root>/mykeyword-1.1 1.o
+ FileSpec module_fspec(CreateFile("mykeyword-1.1 1.o", m_tmp_root_dir));
+ ASSERT_TRUE(module_fspec);
+
+ // Create dummy module file at
+ // <test-root>/.dSYM/Contents/Resources/DWARF/mykeyword-1.1 1.o
+ FileSpec dsym_module_fpec(
+ CreateFile("mykeyword-1.1 1.o", m_tmp_dsym_dwarf_dir));
+ ASSERT_TRUE(dsym_module_fpec);
+
+ CreateFile("mykeyword-1.1 1.py", m_tmp_dsym_python_dir);
+
+ StreamString ss;
+ FileSpecList fspecs =
+ std::static_pointer_cast<PlatformDarwin>(m_platform_sp)
+ ->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"));
+}
+
+TEST_F(
+ PlatformDarwinLocateTest,
+ LocateExecutableScriptingResourcesFromDSYM_ModuleNameIsKeywordAfterReplacement_Match_Warning) {
+ // Like
+ // LocateExecutableScriptingResourcesFromDSYM_ModuleNameIsKeywordAfterReplacement
+ // but we place a script with all the replacement characters into the module
+ // directory so LLDB loads it. That will still produce a warning.
+
+ // Create dummy module file at <test-root>/mykeyword-1.1 1.o
+ FileSpec module_fspec(CreateFile("mykeyword-1.1 1.o", m_tmp_root_dir));
+ ASSERT_TRUE(module_fspec);
+
+ // Create dummy module file at
+ // <test-root>/.dSYM/Contents/Resources/DWARF/mykeyword-1.1 1.o
+ FileSpec dsym_module_fpec(
+ CreateFile("mykeyword-1.1 1.o", m_tmp_dsym_dwarf_dir));
+ ASSERT_TRUE(dsym_module_fpec);
+
+ CreateFile("mykeyword-1.1 1.py", m_tmp_dsym_python_dir);
+ CreateFile("_mykeyword_1_1_1.py", m_tmp_dsym_python_dir);
+
+ StreamString ss;
+ FileSpecList fspecs =
+ std::static_pointer_cast<PlatformDarwin>(m_platform_sp)
+ ->LocateExecutableScriptingResourcesFromDSYM(
+ ss, module_fspec, *m_target_sp, dsym_module_fpec);
+ EXPECT_EQ(fspecs.GetSize(), 1u);
+ EXPECT_EQ(fspecs.GetFileSpecAtIndex(0).GetFilename(), "_mykeyword_1_1_1.py");
+ EXPECT_TRUE(
+ ss.GetString().contains("Consider removing the file with the malformed "
+ "name to eliminate this warning."));
+}
+
+TEST_F(
+ PlatformDarwinLocateTest,
+ LocateExecutableScriptingResourcesFromDSYM_ModuleNameIsKeywordAfterReplacement_Match_NoWarning) {
+ // Like
+ // LocateExecutableScriptingResourcesFromDSYM_ModuleNameIsKeywordAfterReplacement_Match_Warning
+ // but we place a script with all the replacement characters into the module
+ // directory so LLDB loads it (but no script that matches the original module
+ // name, and hence generates no warning).
+
+ // Create dummy module file at <test-root>/mykeyword-1.1 1.o
+ FileSpec module_fspec(CreateFile("mykeyword-1.1 1.o", m_tmp_root_dir));
+ ASSERT_TRUE(module_fspec);
+
+ // Create dummy module file at
+ // <test-root>/.dSYM/Contents/Resources/DWARF/mykeyword-1.1 1.o
+ FileSpec dsym_module_fpec(
+ CreateFile("mykeyword-1.1 1.o", m_tmp_dsym_dwarf_dir));
+ ASSERT_TRUE(dsym_module_fpec);
+
+ CreateFile("_mykeyword_1_1_1.py", m_tmp_dsym_python_dir);
+
+ StreamString ss;
+ FileSpecList fspecs =
+ std::static_pointer_cast<PlatformDarwin>(m_platform_sp)
+ ->LocateExecutableScriptingResourcesFromDSYM(
+ ss, module_fspec, *m_target_sp, dsym_module_fpec);
+ EXPECT_EQ(fspecs.GetSize(), 1u);
+ EXPECT_EQ(fspecs.GetFileSpecAtIndex(0).GetFilename(), "_mykeyword_1_1_1.py");
+ EXPECT_TRUE(ss.Empty());
+}
More information about the lldb-commits
mailing list