forked from OSchip/llvm-project
If we are trying to load the scripting resource for a module whose name happens to be a Python keyword, then prefix the filename with an _ (e.g. a module named def will load _def.py)
Fixes rdar://13893506 llvm-svn: 230602
This commit is contained in:
parent
5017ab5d0e
commit
99b0a9cdd7
|
@ -601,6 +601,12 @@ public:
|
|||
error.SetErrorString("loading unimplemented");
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool
|
||||
IsReservedWord (const char* word)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual lldb::ScriptInterpreterObjectSP
|
||||
MakeScriptObject (void* object)
|
||||
|
|
|
@ -248,6 +248,9 @@ public:
|
|||
lldb_private::Error& error,
|
||||
lldb::ScriptInterpreterObjectSP* module_sp = nullptr) override;
|
||||
|
||||
bool
|
||||
IsReservedWord (const char* word) override;
|
||||
|
||||
lldb::ScriptInterpreterObjectSP
|
||||
MakeScriptObject (void* object) override;
|
||||
|
||||
|
|
|
@ -195,7 +195,7 @@ ScriptInterpreterPython::ScriptInterpreterPython (CommandInterpreter &interprete
|
|||
|
||||
int old_count = Debugger::TestDebuggerRefCount();
|
||||
|
||||
run_string.Printf ("run_one_line (%s, 'import copy, os, re, sys, uuid, lldb')", m_dictionary_name.c_str());
|
||||
run_string.Printf ("run_one_line (%s, 'import copy, keyword, os, re, sys, uuid, lldb')", m_dictionary_name.c_str());
|
||||
PyRun_SimpleString (run_string.GetData());
|
||||
|
||||
// WARNING: temporary code that loads Cocoa formatters - this should be done on a per-platform basis rather than loading the whole set
|
||||
|
@ -2582,6 +2582,21 @@ ScriptInterpreterPython::LoadScriptingModule (const char* pathname,
|
|||
}
|
||||
}
|
||||
|
||||
bool
|
||||
ScriptInterpreterPython::IsReservedWord (const char* word)
|
||||
{
|
||||
StreamString command_stream;
|
||||
command_stream.Printf("keyword.iskeyword('%s')", word);
|
||||
bool result;
|
||||
ExecuteScriptOptions options;
|
||||
options.SetEnableIO(false);
|
||||
options.SetMaskoutErrors(true);
|
||||
options.SetSetLLDBGlobals(false);
|
||||
if (ExecuteOneLineWithReturn(command_stream.GetData(), ScriptInterpreter::eScriptReturnTypeBool, &result, options))
|
||||
return result;
|
||||
return false;
|
||||
}
|
||||
|
||||
lldb::ScriptInterpreterObjectSP
|
||||
ScriptInterpreterPython::MakeScriptObject (void* object)
|
||||
{
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "lldb/Host/HostInfo.h"
|
||||
#include "lldb/Host/FileSystem.h"
|
||||
#include "lldb/Host/Symbols.h"
|
||||
#include "lldb/Interpreter/CommandInterpreter.h"
|
||||
#include "lldb/Symbol/ObjectFile.h"
|
||||
#include "lldb/Symbol/SymbolFile.h"
|
||||
#include "lldb/Symbol/SymbolVendor.h"
|
||||
|
@ -67,6 +68,8 @@ PlatformDarwin::LocateExecutableScriptingResources (Target *target,
|
|||
// should not lose ".file" but GetFileNameStrippingExtension() will do precisely that.
|
||||
// Ideally, we should have a per-platform list of extensions (".exe", ".app", ".dSYM", ".framework")
|
||||
// which should be stripped while leaving "this.binary.file" as-is.
|
||||
ScriptInterpreter *script_interpreter = target->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
|
||||
|
||||
FileSpec module_spec = module.GetFileSpec();
|
||||
|
||||
if (module_spec)
|
||||
|
@ -87,6 +90,8 @@ PlatformDarwin::LocateExecutableScriptingResources (Target *target,
|
|||
{
|
||||
std::string module_basename (module_spec.GetFilename().GetCString());
|
||||
std::string original_module_basename (module_basename);
|
||||
|
||||
bool was_keyword = false;
|
||||
|
||||
// FIXME: for Python, we cannot allow certain characters in module
|
||||
// filenames we import. Theoretically, different scripting languages may
|
||||
|
@ -97,7 +102,11 @@ PlatformDarwin::LocateExecutableScriptingResources (Target *target,
|
|||
std::replace(module_basename.begin(), module_basename.end(), '.', '_');
|
||||
std::replace(module_basename.begin(), module_basename.end(), ' ', '_');
|
||||
std::replace(module_basename.begin(), module_basename.end(), '-', '_');
|
||||
|
||||
if (script_interpreter && script_interpreter->IsReservedWord(module_basename.c_str()))
|
||||
{
|
||||
module_basename.insert(module_basename.begin(), '_');
|
||||
was_keyword = true;
|
||||
}
|
||||
|
||||
StreamString path_string;
|
||||
StreamString original_path_string;
|
||||
|
@ -115,19 +124,22 @@ PlatformDarwin::LocateExecutableScriptingResources (Target *target,
|
|||
if (module_basename != original_module_basename
|
||||
&& orig_script_fspec.Exists())
|
||||
{
|
||||
const char* reason_for_complaint = was_keyword ? "conflicts with a keyword" : "contains reserved characters";
|
||||
if (script_fspec.Exists())
|
||||
feedback_stream->Printf("warning: the symbol file '%s' contains a debug script. However, its name"
|
||||
" '%s' contains reserved characters and as such cannot be loaded. LLDB will"
|
||||
" '%s' %s and as such cannot be loaded. LLDB will"
|
||||
" load '%s' instead. Consider removing the file with the malformed name to"
|
||||
" eliminate this warning.\n",
|
||||
symfile_spec.GetPath().c_str(),
|
||||
original_path_string.GetData(),
|
||||
reason_for_complaint,
|
||||
path_string.GetData());
|
||||
else
|
||||
feedback_stream->Printf("warning: the symbol file '%s' contains a debug script. However, its name"
|
||||
" contains reserved characters and as such cannot be loaded. If you intend"
|
||||
" %s and as such cannot be loaded. If you intend"
|
||||
" to have this script loaded, please rename '%s' to '%s' and retry.\n",
|
||||
symfile_spec.GetPath().c_str(),
|
||||
reason_for_complaint,
|
||||
original_path_string.GetData(),
|
||||
path_string.GetData());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue