summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/include/lldb/Interpreter/ScriptInterpreter.h6
-rw-r--r--lldb/include/lldb/Interpreter/ScriptInterpreterPython.h3
-rw-r--r--lldb/source/Interpreter/ScriptInterpreterPython.cpp17
-rw-r--r--lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp18
4 files changed, 40 insertions, 4 deletions
diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
index 1b4b8816192..18a3c0024d1 100644
--- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h
+++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
@@ -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)
diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreterPython.h b/lldb/include/lldb/Interpreter/ScriptInterpreterPython.h
index 94ed16e02ca..1ff7311f479 100644
--- a/lldb/include/lldb/Interpreter/ScriptInterpreterPython.h
+++ b/lldb/include/lldb/Interpreter/ScriptInterpreterPython.h
@@ -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;
diff --git a/lldb/source/Interpreter/ScriptInterpreterPython.cpp b/lldb/source/Interpreter/ScriptInterpreterPython.cpp
index 84472411e0f..c28dcf99b4d 100644
--- a/lldb/source/Interpreter/ScriptInterpreterPython.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreterPython.cpp
@@ -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)
{
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index 14d157312fc..dc0a1dd0cd1 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -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());
}
OpenPOWER on IntegriCloud