[Lldb-commits] [lldb] r182977 - <rdar://problem/11109316>

Enrico Granata egranata at apple.com
Thu May 30 18:03:09 PDT 2013


Author: enrico
Date: Thu May 30 20:03:09 2013
New Revision: 182977

URL: http://llvm.org/viewvc/llvm-project?rev=182977&view=rev
Log:
<rdar://problem/11109316>

command script import now does reloads - for real
If you invoke command script import foo and it detects that foo has already been imported, it will
 - invoke reload(foo) to reload the module in Python
 - re-invoke foo.__lldb_init_module
 This second step is necessary to ensure that LLDB does not keep cached copies of any formatter, command, ... that the module is providing

Usual caveats with Python imports persist. Among these:
 - if you have objects lurking around, reloading the module won't magically update them to reflect changes
 - if module A imports module B, reloading A won't reload B
These are Python-specific issues independent of LLDB that would require more extensive design work

The --allow-reload (-r) option is maintained for compatibility with existing scripts, but is clearly documented as redundant - reloading is always enabled whether you use it or not


Modified:
    lldb/trunk/source/Commands/CommandObjectCommands.cpp
    lldb/trunk/source/Core/Module.cpp
    lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
    lldb/trunk/test/functionalities/command_script/import/TestImport.py

Modified: lldb/trunk/source/Commands/CommandObjectCommands.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectCommands.cpp?rev=182977&r1=182976&r2=182977&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectCommands.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectCommands.cpp Thu May 30 20:03:09 2013
@@ -1355,7 +1355,7 @@ protected:
         void
         OptionParsingStarting ()
         {
-            m_allow_reload = false;
+            m_allow_reload = true;
         }
         
         const OptionDefinition*
@@ -1426,7 +1426,7 @@ protected:
 OptionDefinition
 CommandObjectCommandsScriptImport::CommandOptions::g_option_table[] =
 {
-    { LLDB_OPT_SET_1, false, "allow-reload", 'r', no_argument, NULL, 0, eArgTypeNone,        "Allow the script to be loaded even if it was already loaded before (for Python, the __lldb_init_module function will be called again, but the module will not be reloaded from disk)."},
+    { LLDB_OPT_SET_1, false, "allow-reload", 'r', no_argument, NULL, 0, eArgTypeNone,        "Allow the script to be loaded even if it was already loaded before. This argument exists for backwards compatibility, but reloading is always allowed, whether you specify it or not."},
     { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
 };
 

Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=182977&r1=182976&r2=182977&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Thu May 30 20:03:09 2013
@@ -1287,7 +1287,7 @@ Module::LoadScriptingResourceInTarget (T
                         }
                         StreamString scripting_stream;
                         scripting_fspec.Dump(&scripting_stream);
-                        const bool can_reload = false;
+                        const bool can_reload = true;
                         const bool init_lldb_globals = false;
                         bool did_load = script_interpreter->LoadScriptingModule(scripting_stream.GetData(), can_reload, init_lldb_globals, error);
                         if (!did_load)

Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=182977&r1=182976&r2=182977&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original)
+++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Thu May 30 20:03:09 2013
@@ -2672,7 +2672,10 @@ ScriptInterpreterPython::LoadScriptingMo
 
         // now actually do the import
         command_stream.Clear();
-        command_stream.Printf("import %s",basename.c_str());
+        if (was_imported)
+            command_stream.Printf("reload(%s)",basename.c_str());
+        else
+            command_stream.Printf("import %s",basename.c_str());
         bool import_retval = ExecuteMultipleLines(command_stream.GetData(), ScriptInterpreter::ExecuteScriptOptions().SetEnableIO(false).SetSetLLDBGlobals(false).SetMaskoutErrors(false));
         PyObject* py_error = PyErr_Occurred(); // per Python docs: "you do not need to Py_DECREF()" the return of this function
         

Modified: lldb/trunk/test/functionalities/command_script/import/TestImport.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/command_script/import/TestImport.py?rev=182977&r1=182976&r2=182977&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/command_script/import/TestImport.py (original)
+++ lldb/trunk/test/functionalities/command_script/import/TestImport.py Thu May 30 20:03:09 2013
@@ -45,17 +45,15 @@ class ImportTestCase(TestBase):
                 error=True, startstr='error: module importing failed')
         self.expect("command script import ./nosuchfolder/",
                 error=True, startstr='error: module importing failed')
-        self.expect("command script import ./foo/foo.py",
-                error=True, startstr='error: module importing failed')
+        self.expect("command script import ./foo/foo.py", error=False)
 
         self.runCmd("command script import --allow-reload ./thepackage")
         self.expect("TPcommandA",substrs=["hello world A"])
         self.expect("TPcommandB",substrs=["hello world B"])
 
         self.runCmd("script import dummymodule")
-        self.expect("command script import ./dummymodule.py",
-                error=True, startstr='error: module importing failed')
-        self.runCmd("command script import --allow-reload ./dummymodule.py")
+        self.expect("command script import ./dummymodule.py", error=False)
+        self.expect("command script import --allow-reload ./dummymodule.py", error=False)
 
         self.runCmd("command script add -f foo.foo_function foocmd")
         self.runCmd("command script add -f foobar.foo_function foobarcmd")





More information about the lldb-commits mailing list