aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2020-10-13 21:08:37 -0700
committerJonas Devlieghere <jonas@devlieghere.com>2020-10-13 23:50:57 -0700
commit1197ee35b84e1fe1c1884b3228b95351719fbb09 (patch)
tree7173c2346d4470d70f16514e9763a7797e4242dd /lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
parent625fa47617022b2d1ed7b940f9621162874175ee (diff)
downloadllvm-1197ee35b84e1fe1c1884b3228b95351719fbb09.zip
llvm-1197ee35b84e1fe1c1884b3228b95351719fbb09.tar.gz
llvm-1197ee35b84e1fe1c1884b3228b95351719fbb09.tar.bz2
[lldb] Unconditionally strip the `.py(c)` extension when loading a module
Currently we only strip the Python extension when the file exists on disk because we assumed that if it didn't exist it was a module. However, with the change from D89334 this is no longer the case as we want to be able to import a relative path to a .py as a module. Since we always import a scripting module as a "python module" we should always strip the extension if present. Differential revision: https://reviews.llvm.org/D89352
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp')
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index f67572c..17ba2db 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -2797,19 +2797,20 @@ bool ScriptInterpreterPythonImpl::LoadScriptingModule(
return false;
}
- // strip .py or .pyc extension
- ConstString extension = target_file.GetFileNameExtension();
- if (extension) {
- if (llvm::StringRef(extension.GetCString()) == ".py")
- basename.resize(basename.length() - 3);
- else if (llvm::StringRef(extension.GetCString()) == ".pyc")
- basename.resize(basename.length() - 4);
- }
} else {
error.SetErrorString("no known way to import this module specification");
return false;
}
+ // Strip .py or .pyc extension
+ llvm::StringRef extension = target_file.GetFileNameExtension().GetCString();
+ if (!extension.empty()) {
+ if (extension == ".py")
+ basename.resize(basename.length() - 3);
+ else if (extension == ".pyc")
+ basename.resize(basename.length() - 4);
+ }
+
// check if the module is already import-ed
command_stream.Clear();
command_stream.Printf("sys.modules.__contains__('%s')", basename.c_str());