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
}
}
+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)
{
#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"
// 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)
{
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
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;
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());
}