[Lldb-commits] [lldb] r112210 - in /lldb/trunk: scripts/Python/build-swig-Python.sh scripts/lldb.swig test/array_types/TestArrayTypes.py test/lldbtest.py

Johnny Chen johnny.chen at apple.com
Thu Aug 26 13:04:17 PDT 2010


Author: johnny
Date: Thu Aug 26 15:04:17 2010
New Revision: 112210

URL: http://llvm.org/viewvc/llvm-project?rev=112210&view=rev
Log:
o Added a test case for array_types which uses the Python APIs from lldb.py,
  with the only exception of launching the process from SBTarget which is under
  investigation.

o build-swig-Python.sh should also checks the timestamp of ${swig_input_file}
  for update eligibility.  Also, once an update is in order, there's no need
  to check the remaining header files for timestamps.

o Coaches swig to treat StopReason as an int type, instead of a C++ class.

Modified:
    lldb/trunk/scripts/Python/build-swig-Python.sh
    lldb/trunk/scripts/lldb.swig
    lldb/trunk/test/array_types/TestArrayTypes.py
    lldb/trunk/test/lldbtest.py

Modified: lldb/trunk/scripts/Python/build-swig-Python.sh
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/build-swig-Python.sh?rev=112210&r1=112209&r2=112210&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/build-swig-Python.sh (original)
+++ lldb/trunk/scripts/Python/build-swig-Python.sh Thu Aug 26 15:04:17 2010
@@ -67,7 +67,7 @@
 NeedToUpdate=0
 
 
-if [ ! -f $swig_output_file ]
+if [ ! -f ${swig_output_file} ]
 then
     NeedToUpdate=1
     if [ $Debug == 1 ]
@@ -80,7 +80,7 @@
 then
     for hdrfile in ${HEADER_FILES}
     do
-        if [ $hdrfile -nt $swig_output_file ]
+        if [ $hdrfile -nt ${swig_output_file} ]
         then
             NeedToUpdate=1
             if [ $Debug == 1 ]
@@ -88,10 +88,24 @@
                 echo "${hdrfile} is newer than ${swig_output_file}"
                 echo "swig file will need to be re-built."
             fi
+            break
         fi
     done
 fi
 
+if [ $NeedToUpdate == 0 ]
+then
+    if [ ${swig_input_file} -nt ${swig_output_file} ]
+    then
+        NeedToUpdate=1
+        if [ $Debug == 1 ]
+        then
+            echo "${swig_input_file} is newer than ${swig_output_file}"
+            echo "swig file will need to be re-built."
+        fi
+    fi
+fi
+
 os_name=`uname -s`
 python_version=`/usr/bin/python --version 2>&1 | sed -e 's,Python ,,' -e 's,[.][0-9],,2' -e 's,[a-z][a-z][0-9],,'`
 

Modified: lldb/trunk/scripts/lldb.swig
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/lldb.swig?rev=112210&r1=112209&r2=112210&view=diff
==============================================================================
--- lldb/trunk/scripts/lldb.swig (original)
+++ lldb/trunk/scripts/lldb.swig Thu Aug 26 15:04:17 2010
@@ -121,6 +121,7 @@
 typedef lldb::SBStringList SBStringList;
 typedef lldb::RegisterKind RegisterKind;
 const RegisterKind kNumRegisterKinds = lldb::kNumRegisterKinds ;
+typedef int StopReason;
 
 
 %include "lldb/API/SBAddress.h"

Modified: lldb/trunk/test/array_types/TestArrayTypes.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/array_types/TestArrayTypes.py?rev=112210&r1=112209&r2=112210&view=diff
==============================================================================
--- lldb/trunk/test/array_types/TestArrayTypes.py (original)
+++ lldb/trunk/test/array_types/TestArrayTypes.py Thu Aug 26 15:04:17 2010
@@ -52,6 +52,64 @@
         self.expect("variable list long_6", VARIABLES_DISPLAYED_CORRECTLY,
             startstr = '(long [6])')
 
+    def test_array_types_python(self):
+        """
+        Test 'variable list var_name' on some variables with array types.
+
+        Use the Python APIs from lldb.py.
+        """
+        exe = os.path.join(os.getcwd(), "a.out")
+
+        target = self.dbg.CreateTarget(exe)
+        self.assertTrue(target.IsValid(), VALID_TARGET)
+
+        breakpoint = target.BreakpointCreateByLocation("main.c", 42)
+        self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT)
+
+        self.runCmd("run", RUN_STOPPED)
+
+        # The stop reason of the thread should be breakpoint.
+        thread = target.GetProcess().GetThreadAtIndex(0)
+        self.assertTrue(thread.GetStopReason() == Enum("Breakpoint"),
+                        STOPPED_DUE_TO_BREAKPOINT)
+
+        # The breakpoint should have a hit count of 1.
+        self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE)
+
+        # Lookup the "strings" string array variable.
+        frame = thread.GetFrameAtIndex(0)
+        variable = frame.LookupVar("strings")
+        self.assertTrue(variable.GetNumChildren() == 4,
+                        "Variable 'strings' should have 4 children")
+
+        child3 = variable.GetChildAtIndex(3)
+        self.assertTrue(child3.GetSummary(frame) == '"Guten Tag"',
+                        'strings[3] == "Guten Tag"')
+
+        # Lookup the "char_16" char array variable.
+        variable = frame.LookupVar("char_16")
+        self.assertTrue(variable.GetNumChildren() == 16,
+                        "Variable 'char_16' should have 16 children")
+
+        # Lookup the "ushort_matrix" ushort[] array variable.
+        variable = frame.LookupVar("ushort_matrix")
+        self.assertTrue(variable.GetNumChildren() == 2,
+                        "Variable 'ushort_matrix' should have 2 children")
+        child0 = variable.GetChildAtIndex(0)
+        self.assertTrue(child0.GetNumChildren() == 3,
+                        "Variable 'ushort_matrix[0]' should have 3 children")
+        child0_2 = child0.GetChildAtIndex(2)
+        self.assertTrue(int(child0_2.GetValue(frame), 16) == 3,
+                        "ushort_matrix[0][2] == 3")
+
+        # Lookup the "long_6" char array variable.
+        variable = frame.LookupVar("long_6")
+        self.assertTrue(variable.GetNumChildren() == 6,
+                        "Variable 'long_6' should have 6 children")
+        child5 = variable.GetChildAtIndex(5)
+        self.assertTrue(long(child5.GetValue(frame)) == 6,
+                        "long_6[5] == 6")
+
 
 if __name__ == '__main__':
     import atexit

Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=112210&r1=112209&r2=112210&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Thu Aug 26 15:04:17 2010
@@ -133,14 +133,43 @@
 
 DATA_TYPES_DISPLAYED_CORRECTLY = "Data type(s) displayed correctly"
 
+VALID_BREAKPOINT = "Got a valid breakpoint"
+
+VALID_PROCESS = "Got a valid process"
+
+VALID_TARGET = "Got a valid target"
+
 VARIABLES_DISPLAYED_CORRECTLY = "Variable(s) displayed correctly"
 
+
 #
 # And a generic "Command '%s' returns successfully" message generator.
 #
 def CMD_MSG(command):
     return "Command '%s' returns successfully" % (command)
 
+#
+# Returns the enum from the input string stopReason.
+#
+def Enum(stopReason):
+    if stopReason == "Invalid":
+        return 0
+    elif stopReason == "None":
+        return 1
+    elif stopReason == "Trace":
+        return 2
+    elif stopReason == "Breakpoint":
+        return 3
+    elif stopReason == "Watchpoint":
+        return 4
+    elif stopReason == "Signal":
+        return 5
+    elif stopReason == "Exception":
+        return 6
+    elif stopReason == "PlanComplete":
+        return 7
+    else:
+        raise Exception("Unknown stopReason string")
 
 class TestBase(unittest2.TestCase):
     """This LLDB abstract base class is meant to be subclassed."""





More information about the lldb-commits mailing list