[Lldb-commits] [lldb] r136975 - in /lldb/trunk: scripts/Python/modify-python-lldb.py test/lldbtest.py test/python_api/type/ test/python_api/type/Makefile test/python_api/type/TestTypeList.py test/python_api/type/main.cpp

Johnny Chen johnny.chen at apple.com
Fri Aug 5 13:17:27 PDT 2011


Author: johnny
Date: Fri Aug  5 15:17:27 2011
New Revision: 136975

URL: http://llvm.org/viewvc/llvm-project?rev=136975&view=rev
Log:
o modify-python-lldb.py:

  Add the rich comparison methods (__eq__, __ne__) to SBType, too.

o lldbtest.py:

  Add debug utility method TestBase.DebugSBType().

o test/python_api/type:

  Add tests for exercising SBType/SBTypeList API, including the SBTarget.FindTypes(type_name)
  API which returns a SBTypeList matching the type_name.

Added:
    lldb/trunk/test/python_api/type/
    lldb/trunk/test/python_api/type/Makefile
    lldb/trunk/test/python_api/type/TestTypeList.py
    lldb/trunk/test/python_api/type/main.cpp
Modified:
    lldb/trunk/scripts/Python/modify-python-lldb.py
    lldb/trunk/test/lldbtest.py

Modified: lldb/trunk/scripts/Python/modify-python-lldb.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/modify-python-lldb.py?rev=136975&r1=136974&r2=136975&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/modify-python-lldb.py (original)
+++ lldb/trunk/scripts/Python/modify-python-lldb.py Fri Aug  5 15:17:27 2011
@@ -1,5 +1,5 @@
 #
-# modify-lldb-python.py
+# modify-python-lldb.py
 #
 # This script modifies the lldb module (which was automatically generated via
 # running swig) to support iteration and/or equality operations for certain lldb
@@ -189,7 +189,8 @@
 e = { 'SBAddress':    ['GetFileAddress', 'GetModule'],
       'SBBreakpoint': ['GetID'],
       'SBFileSpec':   ['GetFilename', 'GetDirectory'],
-      'SBModule':     ['GetFileSpec', 'GetUUIDString']
+      'SBModule':     ['GetFileSpec', 'GetUUIDString'],
+      'SBType':       ['GetByteSize', 'GetName']
       }
 
 def list_to_frag(list):

Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=136975&r1=136974&r2=136975&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Fri Aug  5 15:17:27 2011
@@ -1060,6 +1060,17 @@
         err.write('\t' + "IsPointerType -> " + str(val.TypeIsPointerType()) + '\n')
         err.write('\t' + "Location      -> " + val.GetLocation()            + '\n')
 
+    def DebugSBType(self, type):
+        """Debug print a SBType object, if traceAlways is True."""
+        if not traceAlways:
+            return
+
+        err = sys.stderr
+        err.write(type.GetName() + ":\n")
+        err.write('\t' + "ByteSize        -> " + str(type.GetByteSize())     + '\n')
+        err.write('\t' + "IsPointerType   -> " + str(type.IsPointerType())   + '\n')
+        err.write('\t' + "IsReferenceType -> " + str(type.IsReferenceType()) + '\n')
+
     def DebugPExpect(self, child):
         """Debug the spwaned pexpect object."""
         if not traceAlways:

Added: lldb/trunk/test/python_api/type/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/type/Makefile?rev=136975&view=auto
==============================================================================
--- lldb/trunk/test/python_api/type/Makefile (added)
+++ lldb/trunk/test/python_api/type/Makefile Fri Aug  5 15:17:27 2011
@@ -0,0 +1,5 @@
+LEVEL = ../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules

Added: lldb/trunk/test/python_api/type/TestTypeList.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/type/TestTypeList.py?rev=136975&view=auto
==============================================================================
--- lldb/trunk/test/python_api/type/TestTypeList.py (added)
+++ lldb/trunk/test/python_api/type/TestTypeList.py Fri Aug  5 15:17:27 2011
@@ -0,0 +1,108 @@
+"""
+Test SBType and SBTypeList API.
+"""
+
+import os, time
+import re
+import unittest2
+import lldb, lldbutil
+from lldbtest import *
+
+class TypeAndTypeListTestCase(TestBase):
+
+    mydir = os.path.join("python_api", "type")
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    @python_api_test
+    def test_with_dsym(self):
+        """Exercise SBType and SBTypeList API."""
+        d = {'EXE': self.exe_name}
+        self.buildDsym(dictionary=d)
+        self.setTearDownCleanup(dictionary=d)
+        self.type_and_typelist_api(self.exe_name)
+
+    @python_api_test
+    def test_with_dwarf(self):
+        """Exercise SBType and SBTypeList API."""
+        d = {'EXE': self.exe_name}
+        self.buildDwarf(dictionary=d)
+        self.setTearDownCleanup(dictionary=d)
+        self.type_and_typelist_api(self.exe_name)
+
+    def setUp(self):
+        # Call super's setUp().
+        TestBase.setUp(self)
+        # We'll use the test method name as the exe_name.
+        self.exe_name = self.testMethodName
+        # Find the line number to break at.
+        self.source = 'main.cpp'
+        self.line = line_number(self.source, '// Break at this line')
+
+    def type_and_typelist_api(self, exe_name):
+        """Exercise SBType and SBTypeList API."""
+        exe = os.path.join(os.getcwd(), exe_name)
+
+        # Create a target by the debugger.
+        target = self.dbg.CreateTarget(exe)
+        self.assertTrue(target, VALID_TARGET)
+
+        # Create the breakpoint inside function 'main'.
+        breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
+        self.assertTrue(breakpoint, VALID_BREAKPOINT)
+
+        # Now launch the process, and do not stop at entry point.
+        process = target.LaunchSimple(None, None, os.getcwd())
+        self.assertTrue(process, PROCESS_IS_VALID)
+
+        # Get Frame #0.
+        self.assertTrue(process.GetState() == lldb.eStateStopped)
+        thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
+        self.assertTrue(thread != None, "There should be a thread stopped due to breakpoint condition")
+        frame0 = thread.GetFrameAtIndex(0)
+
+        # Get the type 'Task'.
+        type_list = target.FindTypes('Task')
+        if self.TraceOn():
+            print "Size of type_list from target.FindTypes('Task') query: %d" % type_list.GetSize()
+        self.assertTrue(len(type_list) == 1)
+        for type in type_list:
+            self.assertTrue(type)
+            self.DebugSBType(type)
+
+        # Now use the SBTarget.FindFirstType() API to find 'Task'.
+        task_type = target.FindFirstType('Task')
+        self.assertTrue(task_type)
+        self.DebugSBType(task_type)
+
+        # Get the reference type of 'Task', just for fun.
+        task_ref_type = task_type.GetReferenceType()
+        self.assertTrue(task_ref_type)
+        self.DebugSBType(task_ref_type)
+
+        # Get the pointer type of 'Task', which is the same as task_head's type.
+        task_pointer_type = task_type.GetPointerType()
+        self.assertTrue(task_pointer_type)
+        self.DebugSBType(task_pointer_type)
+
+        # Get variable 'task_head'.
+        task_head = frame0.FindVariable('task_head')
+        self.assertTrue(task_head, VALID_VARIABLE)
+        self.DebugSBValue(task_head)
+        task_head_type = task_head.GetType()
+        self.DebugSBType(task_head_type)
+        self.assertTrue(task_head_type.IsPointerType())
+
+        self.assertTrue(task_head_type == task_pointer_type)
+
+        # Get the pointee type of 'task_head'.
+        task_head_pointee_type = task_head_type.GetPointeeType()
+        self.DebugSBType(task_head_pointee_type)
+
+        self.assertTrue(task_type == task_head_pointee_type)
+
+
+if __name__ == '__main__':
+    import atexit
+    lldb.SBDebugger.Initialize()
+    atexit.register(lambda: lldb.SBDebugger.Terminate())
+    unittest2.main()

Added: lldb/trunk/test/python_api/type/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/type/main.cpp?rev=136975&view=auto
==============================================================================
--- lldb/trunk/test/python_api/type/main.cpp (added)
+++ lldb/trunk/test/python_api/type/main.cpp Fri Aug  5 15:17:27 2011
@@ -0,0 +1,49 @@
+//===-- main.c --------------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include <stdio.h>
+
+class Task {
+public:
+    int id;
+    Task *next;
+    Task(int i, Task *n):
+        id(i),
+        next(n)
+    {}
+};
+
+
+int main (int argc, char const *argv[])
+{
+    Task *task_head = new Task(-1, NULL);
+    Task *task1 = new Task(1, NULL);
+    Task *task2 = new Task(2, NULL);
+    Task *task3 = new Task(3, NULL); // Orphaned.
+    Task *task4 = new Task(4, NULL);
+    Task *task5 = new Task(5, NULL);
+
+    task_head->next = task1;
+    task1->next = task2;
+    task2->next = task4;
+    task4->next = task5;
+
+    int total = 0;
+    Task *t = task_head;
+    while (t != NULL) {
+        if (t->id >= 0)
+            ++total;
+        t = t->next;
+    }
+    printf("We have a total number of %d tasks\n", total);
+
+    // This corresponds to an empty task list.
+    Task *empty_task_head = new Task(-1, NULL);
+
+    return 0; // Break at this line
+}





More information about the lldb-commits mailing list