Author: enrico
Date: Wed Feb 25 19:37:26 2015
New Revision: 230602

URL: http://llvm.org/viewvc/llvm-project?rev=230602&view=rev
Log:
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


Modified:
    lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
    lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h
    lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
    lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp

Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h?rev=230602&r1=230601&r2=230602&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h Wed Feb 25 19:37:26 
2015
@@ -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)

Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h?rev=230602&r1=230601&r2=230602&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h (original)
+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h Wed Feb 25 
19:37:26 2015
@@ -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;
     

Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=230602&r1=230601&r2=230602&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original)
+++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Wed Feb 25 
19:37:26 2015
@@ -195,7 +195,7 @@ ScriptInterpreterPython::ScriptInterpret
     
     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::LoadScriptingMo
     }
 }
 
+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)
 {

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp?rev=230602&r1=230601&r2=230602&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp Wed Feb 25 
19:37:26 2015
@@ -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::LocateExecutableScriptin
         // 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::LocateExecutableScriptin
                             {
                                 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::LocateExecutableScriptin
                                 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::LocateExecutableScriptin
                                     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());
                                     }


_______________________________________________
lldb-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits

Reply via email to