<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Not really a test case proper - just an example to make “load packages” more explicative<div><br><div>
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div style="font-size: medium; orphans: 2; widows: 2; border-collapse: separate; border-spacing: 0px;"><span style="font-size: 12px; orphans: auto; widows: auto;">Enrico Granata</span><br style="font-size: 12px; orphans: auto; widows: auto;"><span style="font-size: 12px; orphans: auto; widows: auto;">✉ egranata@</span><font color="#ff2600" style="font-size: 12px; orphans: auto; widows: auto;"></font><span style="font-size: 12px; orphans: auto; widows: auto;">.com</span><br style="font-size: 12px; orphans: auto; widows: auto;"><span style="font-size: 12px; orphans: auto; widows: auto;">✆ 27683</span></div></div>
</div>
<br><div><div>On May 3, 2013, at 10:54 AM, "Malea, Daniel" <<a href="mailto:daniel.malea@intel.com">daniel.malea@intel.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Can you please put test cases in the 'test' directory, instead of the<br>commit message. It's not exactly convenient to run it this way.<br><br><br>Dan<br><br>On 2013-05-02 7:57 PM, "Enrico Granata" <<a href="mailto:egranata@apple.com">egranata@apple.com</a>> wrote:<br><br><blockquote type="cite">Author: enrico<br>Date: Thu May  2 18:57:33 2013<br>New Revision: 180975<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=180975&view=rev">http://llvm.org/viewvc/llvm-project?rev=180975&view=rev</a><br>Log:<br><<a href="rdar://problem/11558812">rdar://problem/11558812</a>><br><br>Allow command script import to load packages.<br><br>e.g.:<br>egranata$ ./lldb<br>(lldb) command script import lldb.macosx.crashlog<br>"crashlog" and "save_crashlog" command installed, use the "--help" option<br>for detailed help<br>"malloc_info", "ptr_refs", "cstr_refs", and "objc_refs" commands have<br>been installed, use the "--help" options on these commands for detailed<br>help.<br>The "unwind-diagnose" command has been installed, type "help<br>unwind-diagnose" for detailed help.<br>(lldb)<span class="Apple-converted-space"> </span><br><br>./lldb<br>(lldb) command script import theFoo<br>I am happy<br>(lldb) fbc<br>àèìòù<br>(lldb)<br><br>egranata$ ls theFoo/<br>__init__.py theBar.py<br><br>egranata$ cat theFoo/__init__.py<br>import lldb<br>import theBar<br><br>def __lldb_init_module(debugger, internal_dict):<br><span class="Apple-tab-span" style="white-space: pre;">        </span>print "I am happy"<br><span class="Apple-tab-span" style="white-space: pre;">    </span>debugger.HandleCommand("command script add -f theFoo.theBar.theCommand<br>fbc")<br><span class="Apple-tab-span" style="white-space: pre;"> </span>return None<br><br>egranata$ cat theFoo/theBar.py<br>#encoding=utf-8<br><br>def theCommand(debugger, command, result, internal_dict):<br><span class="Apple-tab-span" style="white-space: pre;">     </span>result.PutCString(u"àèìòù")<br><span class="Apple-tab-span" style="white-space: pre;">      </span>return None<br><br><br>Modified:<br>  lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp<br><br>Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp<br>URL:<span class="Apple-converted-space"> </span><br><a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptIn">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptIn</a><br>terpreterPython.cpp?rev=180975&r1=180974&r2=180975&view=diff<br>==========================================================================<br>====<br>--- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original)<br>+++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Thu May  2<br>18:57:33 2013<br>@@ -2594,42 +2594,47 @@ ScriptInterpreterPython::LoadScriptingMo<br>   {<br>       FileSpec target_file(pathname, true);<br><br>-        // TODO: would we want to reject any other value?<br>-        if (target_file.GetFileType() == FileSpec::eFileTypeInvalid ||<br>-            target_file.GetFileType() == FileSpec::eFileTypeUnknown)<br>-        {<br>-            error.SetErrorString("invalid pathname");<br>-            return false;<br>-        }<br>-        <br>-        const char* directory = target_file.GetDirectory().GetCString();<br>-        std::string basename(target_file.GetFilename().GetCString());<br>+        std::string basename;<br>+        StreamString command_stream;<br><br>       // Before executing Pyton code, lock the GIL.<br>       Locker py_lock (this,<br>                       Locker::AcquireLock      | (init_session ?<br>Locker::InitSession     : 0),<br>                       Locker::FreeAcquiredLock | (init_session ?<br>Locker::TearDownSession : 0));<br><br>-        // now make sure that Python has "directory" in the search path<br>-        StreamString command_stream;<br>-        command_stream.Printf("if not (sys.path.__contains__('%s')):\n<br>sys.path.insert(1,'%s');\n\n",<br>-                              directory,<br>-                              directory);<br>-        bool syspath_retval =<br>ExecuteMultipleLines(command_stream.GetData(),<br>ScriptInterpreter::ExecuteScriptOptions().SetEnableIO(false).SetSetLLDBGlo<br>bals(false));<br>-        if (!syspath_retval)<br>+        if (target_file.GetFileType() == FileSpec::eFileTypeInvalid ||<br>+            target_file.GetFileType() == FileSpec::eFileTypeUnknown ||<br>+            target_file.GetFileType() == FileSpec::eFileTypeDirectory )<br>       {<br>-            error.SetErrorString("Python sys.path handling failed");<br>-            return false;<br>+            // if not a filename, try to just plain import<br>+            basename = pathname;<br>       }<br>-        <br>-        // strip .py or .pyc extension<br>-        ConstString extension = target_file.GetFileNameExtension();<br>-        if (extension)<br>+        else<br>       {<br>-            if (::strcmp(extension.GetCString(), "py") == 0)<br>-                basename.resize(basename.length()-3);<br>-            else if(::strcmp(extension.GetCString(), "pyc") == 0)<br>-                basename.resize(basename.length()-4);<br>+            const char* directory =<br>target_file.GetDirectory().GetCString();<br>+            std::string basename(target_file.GetFilename().GetCString());<br>+            <br>+            // now make sure that Python has "directory" in the search<br>path<br>+            StreamString command_stream;<br>+            command_stream.Printf("if not<br>(sys.path.__contains__('%s')):\n    sys.path.insert(1,'%s');\n\n",<br>+                                  directory,<br>+                                  directory);<br>+            bool syspath_retval =<br>ExecuteMultipleLines(command_stream.GetData(),<br>ScriptInterpreter::ExecuteScriptOptions().SetEnableIO(false).SetSetLLDBGlo<br>bals(false));<br>+            if (!syspath_retval)<br>+            {<br>+                error.SetErrorString("Python sys.path handling failed");<br>+                return false;<br>+            }<br>+            <br>+            // strip .py or .pyc extension<br>+            ConstString extension = target_file.GetFileNameExtension();<br>+            if (extension)<br>+            {<br>+                if (::strcmp(extension.GetCString(), "py") == 0)<br>+                    basename.resize(basename.length()-3);<br>+                else if(::strcmp(extension.GetCString(), "pyc") == 0)<br>+                    basename.resize(basename.length()-4);<br>+            }<br>       }<br><br>       // check if the module is already import-ed<br><br><br>_______________________________________________<br>lldb-commits mailing list<br>lldb-commits@cs.uiuc.edu<br>http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits</blockquote></div></blockquote></div><br></div></body></html>