[Lldb-commits] [lldb] r146584 - in /lldb/trunk: scripts/Python/python-wrapper.swig test/functionalities/command_script/TestCommandScript.py test/functionalities/command_script/bug11569.py test/functionalities/command_script/py_import

Johnny Chen johnny.chen at apple.com
Wed Dec 14 12:40:27 PST 2011


Author: johnny
Date: Wed Dec 14 14:40:27 2011
New Revision: 146584

URL: http://llvm.org/viewvc/llvm-project?rev=146584&view=rev
Log:
http://llvm.org/bugs/show_bug.cgi?id=11569
LLDBSwigPythonCallCommand crashes when a command script returns an object 

Add more robustness to LLDBSwigPythonCallCommand.  It should check whether the returned Python object
is a string, and only assign it as the error msg when the check holds.
Also add a regression test.

Added:
    lldb/trunk/test/functionalities/command_script/bug11569.py
Modified:
    lldb/trunk/scripts/Python/python-wrapper.swig
    lldb/trunk/test/functionalities/command_script/TestCommandScript.py
    lldb/trunk/test/functionalities/command_script/py_import

Modified: lldb/trunk/scripts/Python/python-wrapper.swig
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-wrapper.swig?rev=146584&r1=146583&r2=146584&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/python-wrapper.swig (original)
+++ lldb/trunk/scripts/Python/python-wrapper.swig Wed Dec 14 14:40:27 2011
@@ -645,9 +645,11 @@
                         err_msg.clear();
                         retval = true;
                     }
-                    else // return value is an error string
+                    else
                     {
-                        err_msg.assign(PyString_AsString(pvalue));
+                        // return value is an error string
+                        if (PyString_CheckExact(pvalue))
+                            err_msg.assign(PyString_AsString(pvalue));
                         retval = false;
                     }
                     Py_DECREF (pvalue);

Modified: lldb/trunk/test/functionalities/command_script/TestCommandScript.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/command_script/TestCommandScript.py?rev=146584&r1=146583&r2=146584&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/command_script/TestCommandScript.py (original)
+++ lldb/trunk/test/functionalities/command_script/TestCommandScript.py Wed Dec 14 14:40:27 2011
@@ -37,6 +37,7 @@
             self.runCmd('command script delete tell_sync', check=False)
             self.runCmd('command script delete tell_async', check=False)
             self.runCmd('command script delete tell_curr', check=False)
+            self.runCmd('command script delete bug11569', check=False)
 
         # Execute the cleanup function during test case tear down.
         self.addTearDownHook(cleanup)
@@ -115,6 +116,12 @@
         self.expect('command script add -f foobar frame', error=True,
                     substrs = ['cannot add command'])
 
+        # http://llvm.org/bugs/show_bug.cgi?id=11569
+        # LLDBSwigPythonCallCommand crashes when a command script returns an object 
+        self.runCmd('command script add -f bug11569 bug11569')
+        # This should not crash.
+        self.runCmd('bug11569', check=False)
+
 if __name__ == '__main__':
     import atexit
     lldb.SBDebugger.Initialize()

Added: lldb/trunk/test/functionalities/command_script/bug11569.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/command_script/bug11569.py?rev=146584&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/command_script/bug11569.py (added)
+++ lldb/trunk/test/functionalities/command_script/bug11569.py Wed Dec 14 14:40:27 2011
@@ -0,0 +1,7 @@
+def bug11569(debugger, args, result, dict):
+    """
+    http://llvm.org/bugs/show_bug.cgi?id=11569
+    LLDBSwigPythonCallCommand crashes when a command script returns an object.
+    """
+    return ["return", "a", "non-string", "should", "not", "crash", "LLDB"];
+

Modified: lldb/trunk/test/functionalities/command_script/py_import
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/command_script/py_import?rev=146584&r1=146583&r2=146584&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/command_script/py_import (original)
+++ lldb/trunk/test/functionalities/command_script/py_import Wed Dec 14 14:40:27 2011
@@ -1,6 +1,7 @@
 script import sys, os
 script sys.path.append(os.path.join(os.getcwd(), os.pardir))
 script import welcome
+script import bug11569
 command script add welcome --function welcome.welcome_impl
 command script add targetname --function welcome.target_name_impl
 command script add longwait --function welcome.print_wait_impl





More information about the lldb-commits mailing list