[Lldb-commits] [lldb] r130452 - in /lldb/trunk/test: class_static/TestStaticVariables.py class_types/TestClassTypesDisassembly.py foundation/TestSymbolTable.py lldbutil.py python_api/frame/TestFrames.py python_api/lldbutil/TestLLDBIterator.py

Johnny Chen johnny.chen at apple.com
Thu Apr 28 15:57:01 PDT 2011


Author: johnny
Date: Thu Apr 28 17:57:01 2011
New Revision: 130452

URL: http://llvm.org/viewvc/llvm-project?rev=130452&view=rev
Log:
Modify the test suite and lldbutil.py to utilize the Python iteration pattern now that
the lldb iteration protocol has been added to lldb.py module.

Modified:
    lldb/trunk/test/class_static/TestStaticVariables.py
    lldb/trunk/test/class_types/TestClassTypesDisassembly.py
    lldb/trunk/test/foundation/TestSymbolTable.py
    lldb/trunk/test/lldbutil.py
    lldb/trunk/test/python_api/frame/TestFrames.py
    lldb/trunk/test/python_api/lldbutil/TestLLDBIterator.py

Modified: lldb/trunk/test/class_static/TestStaticVariables.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/class_static/TestStaticVariables.py?rev=130452&r1=130451&r2=130452&view=diff
==============================================================================
--- lldb/trunk/test/class_static/TestStaticVariables.py (original)
+++ lldb/trunk/test/class_static/TestStaticVariables.py Thu Apr 28 17:57:01 2011
@@ -101,8 +101,7 @@
         # in_scope_only => False
         valList = frame.GetVariables(False, False, True, False)
 
-        from lldbutil import lldb_iter
-        for val in lldb_iter(valList, 'GetSize', 'GetValueAtIndex'):
+        for val in valList:
             self.DebugSBValue(frame, val)
             self.assertTrue(val.GetValueType() == lldb.eValueTypeVariableGlobal)
             name = val.GetName()

Modified: lldb/trunk/test/class_types/TestClassTypesDisassembly.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/class_types/TestClassTypesDisassembly.py?rev=130452&r1=130451&r2=130452&view=diff
==============================================================================
--- lldb/trunk/test/class_types/TestClassTypesDisassembly.py (original)
+++ lldb/trunk/test/class_types/TestClassTypesDisassembly.py Thu Apr 28 17:57:01 2011
@@ -103,9 +103,8 @@
             if function.IsValid():
                 # Get all instructions for this function and print them out.
                 insts = function.GetInstructions(target)
-                from lldbutil import lldb_iter
-                for inst in lldb_iter(insts, 'GetSize', 'GetInstructionAtIndex'):
-                    # It could simply be 'print inst' to print out the disassembly.
+                for inst in insts:
+                    # We could simply do 'print inst' to print out the disassembly.
                     # But we want to print to stdout only if self.TraceOn() is True.
                     disasm = str(inst)
                     if self.TraceOn():

Modified: lldb/trunk/test/foundation/TestSymbolTable.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/foundation/TestSymbolTable.py?rev=130452&r1=130451&r2=130452&view=diff
==============================================================================
--- lldb/trunk/test/foundation/TestSymbolTable.py (original)
+++ lldb/trunk/test/foundation/TestSymbolTable.py Thu Apr 28 17:57:01 2011
@@ -60,8 +60,7 @@
         # Create the set of known symbols.  As we iterate through the symbol
         # table, remove the symbol from the set if it is a known symbol.
         expected_symbols = set(self.symbols_list)
-        from lldbutil import lldb_iter
-        for symbol in lldb_iter(module, 'GetNumSymbols', 'GetSymbolAtIndex'):
+        for symbol in module:
             self.assertTrue(symbol.IsValid(), VALID_SYMBOL)
             #print "symbol:", symbol
             name = symbol.GetName()

Modified: lldb/trunk/test/lldbutil.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbutil.py?rev=130452&r1=130451&r2=130452&view=diff
==============================================================================
--- lldb/trunk/test/lldbutil.py (original)
+++ lldb/trunk/test/lldbutil.py Thu Apr 28 17:57:01 2011
@@ -27,85 +27,6 @@
                 return exe_file
     return None
 
-# ===========================================
-# Iterator for lldb aggregate data structures
-# ===========================================
-
-def lldb_iter(obj, getsize, getelem):
-    """A generator adaptor for lldb aggregate data structures.
-
-    API clients pass in an aggregate object or a container of it, the name of
-    the method to get the size of the aggregate, and the name of the method to
-    get the element by index.
-
-    Example usages:
-
-    1. Pass an aggregate as the first argument:
-
-    def disassemble_instructions (insts):
-        from lldbutil import lldb_iter
-        for i in lldb_iter(insts, 'GetSize', 'GetInstructionAtIndex'):
-            print i
-
-    2. Pass a container of aggregate which provides APIs to get to the size and
-       the element of the aggregate:
-
-    # Module is a container of symbol table 
-    module = target.FindModule(filespec)
-    for symbol in lldb_iter(module, 'GetNumSymbols', 'GetSymbolAtIndex'):
-        name = symbol.GetName()
-        ...
-    """
-    #import traceback
-    #traceback.print_stack()
-    size = getattr(obj, getsize)
-    elem = getattr(obj, getelem)
-    for i in range(size()):
-        yield elem(i)
-
-def smart_iter(obj):
-    """Returns an iterator for eligible lldb objects, or None otherwise.
-
-    An example of eligible lldb container object is SBModule, which contains
-    SBSymbols.  While SBTarget contains SBModules and SBBreakpoints, because it
-    is ambiguous which containee type to iterate on, the best we can do is to
-    return None.  API clients can use lldb_iter() to clarify their intentions.
-
-    SBSymbol does not have the notion of containee objects and is not eligible
-    for smart iterator.
-
-    Example usage:
-
-    from lldb_util import smart_iter
-    for thread in smart_iter(process):
-        ID = thread.GetThreadID()
-        if thread.GetStopReason() == lldb.eStopReasonBreakpoint:
-            stopped_due_to_breakpoint = True
-        for frame in smart_iter(thread):
-            self.assertTrue(frame.GetThread().GetThreadID() == ID)
-        ...
-    """
-    d = { lldb.SBBreakpoint:  ('GetNumLocations',   'GetLocationAtIndex'),
-          lldb.SBCompileUnit: ('GetNumLineEntries', 'GetLineEntryAtIndex'),
-          lldb.SBDebugger:    ('GetNumTargets',     'GetTargetAtIndex'),
-          lldb.SBModule:      ('GetNumSymbols',     'GetSymbolAtIndex'),
-          lldb.SBProcess:     ('GetNumThreads',     'GetThreadAtIndex'),
-          lldb.SBThread:      ('GetNumFrames',      'GetFrameAtIndex'),
-
-          lldb.SBInstructionList:   ('GetSize', 'GetInstructionAtIndex'),
-          lldb.SBStringList:        ('GetSize', 'GetStringAtIndex',),
-          lldb.SBSymbolContextList: ('GetSize', 'GetContextAtIndex'),
-          lldb.SBValueList:         ('GetSize',  'GetValueAtIndex'),
-
-          lldb.SBType:  ('GetNumberChildren', 'GetChildAtIndex'),
-          lldb.SBValue: ('GetNumChildren',    'GetChildAtIndex')
-          }
-    if obj.__class__ in d:
-        val = d.get(obj.__class__)
-        return lldb_iter(obj, val[0], val[1])
-    else:
-        return None
-
 # ===================================================
 # Disassembly for an SBFunction or an SBSymbol object
 # ===================================================
@@ -117,7 +38,7 @@
     """
     buf = StringIO.StringIO()
     insts = function_or_symbol.GetInstructions(target)
-    for i in lldb_iter(insts, 'GetSize', 'GetInstructionAtIndex'):
+    for i in insts:
         print >> buf, i
     return buf.getvalue()
 
@@ -289,7 +210,7 @@
 def get_stopped_threads(process, reason):
     """Returns the thread(s) with the specified stop reason in a list."""
     threads = []
-    for t in lldb_iter(process, 'GetNumThreads', 'GetThreadAtIndex'):
+    for t in process:
         if t.GetStopReason() == reason:
             threads.append(t)
     return threads

Modified: lldb/trunk/test/python_api/frame/TestFrames.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/frame/TestFrames.py?rev=130452&r1=130451&r2=130452&view=diff
==============================================================================
--- lldb/trunk/test/python_api/frame/TestFrames.py (original)
+++ lldb/trunk/test/python_api/frame/TestFrames.py Thu Apr 28 17:57:01 2011
@@ -80,8 +80,7 @@
                 # in_scope_only => True
                 valList = frame.GetVariables(True, False, False, True)
                 argList = []
-                from lldbutil import lldb_iter
-                for val in lldb_iter(valList, 'GetSize', 'GetValueAtIndex'):
+                for val in valList:
                     #self.DebugSBValue(frame, val)
                     argList.append("(%s)%s=%s" % (val.GetTypeName(),
                                                   val.GetName(),

Modified: lldb/trunk/test/python_api/lldbutil/TestLLDBIterator.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/lldbutil/TestLLDBIterator.py?rev=130452&r1=130451&r2=130452&view=diff
==============================================================================
--- lldb/trunk/test/python_api/lldbutil/TestLLDBIterator.py (original)
+++ lldb/trunk/test/python_api/lldbutil/TestLLDBIterator.py Thu Apr 28 17:57:01 2011
@@ -1,6 +1,5 @@
 """
-Test lldb_iter/smart_iter() which returns an iterator object for lldb container
-objects.
+Test the iteration protocol for some lldb container objects.
 """
 
 import os, time





More information about the lldb-commits mailing list