[Lldb-commits] [lldb] r112247 - in /lldb/trunk/test: array_types/TestArrayTypes.py bitfields/TestBitfields.py lldbtest.py

Johnny Chen johnny.chen at apple.com
Thu Aug 26 17:15:48 PDT 2010


Author: johnny
Date: Thu Aug 26 19:15:48 2010
New Revision: 112247

URL: http://llvm.org/viewvc/llvm-project?rev=112247&view=rev
Log:
Added a test case to bitfields which uses the Python APIs from lldb.py.
Added a utility method to TestBase class to debug print an SBValue object.

Modified:
    lldb/trunk/test/array_types/TestArrayTypes.py
    lldb/trunk/test/bitfields/TestBitfields.py
    lldb/trunk/test/lldbtest.py

Modified: lldb/trunk/test/array_types/TestArrayTypes.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/array_types/TestArrayTypes.py?rev=112247&r1=112246&r2=112247&view=diff
==============================================================================
--- lldb/trunk/test/array_types/TestArrayTypes.py (original)
+++ lldb/trunk/test/array_types/TestArrayTypes.py Thu Aug 26 19:15:48 2010
@@ -77,34 +77,42 @@
         # Lookup the "strings" string array variable.
         frame = thread.GetFrameAtIndex(0)
         variable = frame.LookupVar("strings")
+        self.DebugSBValue(frame, variable)
         self.assertTrue(variable.GetNumChildren() == 4,
                         "Variable 'strings' should have 4 children")
 
         child3 = variable.GetChildAtIndex(3)
+        self.DebugSBValue(frame, child3)
         self.assertTrue(child3.GetSummary(frame) == '"Guten Tag"',
                         'strings[3] == "Guten Tag"')
 
         # Lookup the "char_16" char array variable.
         variable = frame.LookupVar("char_16")
+        self.DebugSBValue(frame, variable)
         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.DebugSBValue(frame, variable)
         self.assertTrue(variable.GetNumChildren() == 2,
                         "Variable 'ushort_matrix' should have 2 children")
         child0 = variable.GetChildAtIndex(0)
+        self.DebugSBValue(frame, child0)
         self.assertTrue(child0.GetNumChildren() == 3,
                         "Variable 'ushort_matrix[0]' should have 3 children")
         child0_2 = child0.GetChildAtIndex(2)
+        self.DebugSBValue(frame, child0_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.DebugSBValue(frame, variable)
         self.assertTrue(variable.GetNumChildren() == 6,
                         "Variable 'long_6' should have 6 children")
         child5 = variable.GetChildAtIndex(5)
+        self.DebugSBValue(frame, child5)
         self.assertTrue(long(child5.GetValue(frame)) == 6,
                         "long_6[5] == 6")
 

Modified: lldb/trunk/test/bitfields/TestBitfields.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/bitfields/TestBitfields.py?rev=112247&r1=112246&r2=112247&view=diff
==============================================================================
--- lldb/trunk/test/bitfields/TestBitfields.py (original)
+++ lldb/trunk/test/bitfields/TestBitfields.py Thu Aug 26 19:15:48 2010
@@ -53,6 +53,61 @@
                        '(uint32_t:7) b7 = 0x0000007f,',
                        '(uint32_t:4) four = 0x0000000f'])
 
+    def test_bitfields_variable_python(self):
+        """Use Python APIs to inspect a bitfields variable."""
+        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)
+        # This does not work, and results in the process stopped at dyld_start?
+        #process = target.LaunchProcess([''], [''], os.ctermid(), False)
+
+        # 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 "bits" variable which contains 8 bitfields.
+        frame = thread.GetFrameAtIndex(0)
+        bits = frame.LookupVar("bits")
+        self.DebugSBValue(frame, bits)
+        self.assertTrue(bits.GetTypeName() == "Bits" and
+                        bits.GetNumChildren() == 8 and
+                        bits.GetByteSize() == 4,
+                        "(Bits)bits with byte size of 4 and 8 children")
+
+        b1 = bits.GetChildAtIndex(0)
+        self.DebugSBValue(frame, b1)
+        self.assertTrue(b1.GetName() == "b1" and
+                        b1.GetTypeName() == "uint32_t:1" and
+                        b1.IsInScope(frame) and
+                        int(b1.GetValue(frame), 16) == 0x01,
+                        'bits.b1 has type uint32_t:1, is in scope, and == 0x01')
+
+        b7 = bits.GetChildAtIndex(6)
+        self.DebugSBValue(frame, b7)
+        self.assertTrue(b7.GetName() == "b7" and
+                        b7.GetTypeName() == "uint32_t:7" and
+                        b7.IsInScope(frame) and
+                        int(b7.GetValue(frame), 16) == 0x7f,
+                        'bits.b7 has type uint32_t:7, is in scope, and == 0x7f')
+
+        four = bits.GetChildAtIndex(7)
+        self.DebugSBValue(frame, four)
+        self.assertTrue(four.GetName() == "four" and
+                        four.GetTypeName() == "uint32_t:4" and
+                        four.IsInScope(frame) and
+                        int(four.GetValue(frame), 16) == 0x0f,
+                        'bits.four has type uint32_t:4, is in scope, and == 0x0f')
+
 
 if __name__ == '__main__':
     import atexit

Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=112247&r1=112246&r2=112247&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Thu Aug 26 19:15:48 2010
@@ -177,6 +177,7 @@
 def EnvArray():
     return map(lambda k,v: k+"="+v, os.environ.keys(), os.environ.values())
 
+
 class TestBase(unittest2.TestCase):
     """This LLDB abstract base class is meant to be subclassed."""
 
@@ -337,3 +338,20 @@
         if self.traceAlways:
             print str(method) + ":",  result
         return result
+
+    def DebugSBValue(self, frame, val):
+        """Debug print a SBValue object, if self.traceAlways is True."""
+        if not self.traceAlways:
+            return
+
+        err = sys.stderr
+        err.write(val.GetName() + ":\n")
+        err.write('\t' + "TypeName    -> " + val.GetTypeName()          + '\n')
+        err.write('\t' + "ByteSize    -> " + str(val.GetByteSize())     + '\n')
+        err.write('\t' + "NumChildren -> " + str(val.GetNumChildren())  + '\n')
+        err.write('\t' + "Value       -> " + str(val.GetValue(frame))   + '\n')
+        err.write('\t' + "Summary     -> " + str(val.GetSummary(frame)) + '\n')
+        err.write('\t' + "IsPtrType   -> " + str(val.TypeIsPtrType())   + '\n')
+        err.write('\t' + "Location    -> " + val.GetLocation(frame)     + '\n')
+
+





More information about the lldb-commits mailing list