summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/ScriptInterpreter/Python
diff options
context:
space:
mode:
authorAdrian McCarthy <amccarth@google.com>2016-04-07 22:52:12 +0000
committerAdrian McCarthy <amccarth@google.com>2016-04-07 22:52:12 +0000
commitf9f3609704c1f5cdcdc8ef04dfdf5234217d6686 (patch)
tree75ed48ce2bfb60e3f131f899964421f7a20440f2 /lldb/source/Plugins/ScriptInterpreter/Python
parent3a41be277a761d7687a2b860fa045ef5227d6e2d (diff)
downloadbcm5719-llvm-f9f3609704c1f5cdcdc8ef04dfdf5234217d6686.tar.gz
bcm5719-llvm-f9f3609704c1f5cdcdc8ef04dfdf5234217d6686.zip
Fix TestImport for Windows by ensuring backslashes in the directory paths are properly escaped in Python.
The Python import works by ensuring the directory of the module or package is in sys.path, and then it does a Python `import foo`. The original code was not escaping the backslashes in the directory path, so this wasn't working. Differential Revision: http://reviews.llvm.org/D18873 llvm-svn: 265738
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python')
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 4ca7cd01177..0af1fd53ac8 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -2548,7 +2548,7 @@ ScriptInterpreterPython::LoadScriptingModule(const char *pathname, bool can_relo
StreamString command_stream;
- // Before executing Pyton code, lock the GIL.
+ // Before executing Python code, lock the GIL.
Locker py_lock (this,
Locker::AcquireLock | (init_session ? Locker::InitSession : 0) | Locker::NoSTDIN,
Locker::FreeAcquiredLock | (init_session ? Locker::TearDownSession : 0));
@@ -2569,9 +2569,10 @@ ScriptInterpreterPython::LoadScriptingModule(const char *pathname, bool can_relo
target_file.GetFileType() == FileSpec::eFileTypeRegular ||
target_file.GetFileType() == FileSpec::eFileTypeSymbolicLink)
{
- std::string directory(target_file.GetDirectory().GetCString());
- replace_all(directory,"'","\\'");
-
+ std::string directory = target_file.GetDirectory().GetCString();
+ replace_all(directory, "\\", "\\\\");
+ replace_all(directory, "'", "\\'");
+
// now make sure that Python has "directory" in the search path
StreamString command_stream;
command_stream.Printf("if not (sys.path.__contains__('%s')):\n sys.path.insert(1,'%s');\n\n",
@@ -2583,7 +2584,7 @@ ScriptInterpreterPython::LoadScriptingModule(const char *pathname, bool can_relo
error.SetErrorString("Python sys.path handling failed");
return false;
}
-
+
// strip .py or .pyc extension
ConstString extension = target_file.GetFileNameExtension();
if (extension)
@@ -2634,8 +2635,8 @@ ScriptInterpreterPython::LoadScriptingModule(const char *pathname, bool can_relo
command_stream.Printf("reload_module(%s)",basename.c_str());
}
else
- command_stream.Printf("import %s",basename.c_str());
-
+ command_stream.Printf("import %s", basename.c_str());
+
error = ExecuteMultipleLines(command_stream.GetData(), ScriptInterpreter::ExecuteScriptOptions().SetEnableIO(false).SetSetLLDBGlobals(false));
if (error.Fail())
return false;
OpenPOWER on IntegriCloud