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.
llvm-svn: 130452
diff --git a/lldb/test/class_static/TestStaticVariables.py b/lldb/test/class_static/TestStaticVariables.py
index c9f9fc3..12ff778 100644
--- a/lldb/test/class_static/TestStaticVariables.py
+++ b/lldb/test/class_static/TestStaticVariables.py
@@ -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()
diff --git a/lldb/test/class_types/TestClassTypesDisassembly.py b/lldb/test/class_types/TestClassTypesDisassembly.py
index fedefc8..5c144dc 100644
--- a/lldb/test/class_types/TestClassTypesDisassembly.py
+++ b/lldb/test/class_types/TestClassTypesDisassembly.py
@@ -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():
diff --git a/lldb/test/foundation/TestSymbolTable.py b/lldb/test/foundation/TestSymbolTable.py
index 7e80ee7..c86d90c 100644
--- a/lldb/test/foundation/TestSymbolTable.py
+++ b/lldb/test/foundation/TestSymbolTable.py
@@ -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()
diff --git a/lldb/test/lldbutil.py b/lldb/test/lldbutil.py
index 7bc0eef..eb983fe 100644
--- a/lldb/test/lldbutil.py
+++ b/lldb/test/lldbutil.py
@@ -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
diff --git a/lldb/test/python_api/frame/TestFrames.py b/lldb/test/python_api/frame/TestFrames.py
index 2ce9fd9..038264e 100644
--- a/lldb/test/python_api/frame/TestFrames.py
+++ b/lldb/test/python_api/frame/TestFrames.py
@@ -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(),
diff --git a/lldb/test/python_api/lldbutil/TestLLDBIterator.py b/lldb/test/python_api/lldbutil/TestLLDBIterator.py
index 06e9a9a..890c018 100644
--- a/lldb/test/python_api/lldbutil/TestLLDBIterator.py
+++ b/lldb/test/python_api/lldbutil/TestLLDBIterator.py
@@ -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