diff options
| author | Johnny Chen <johnny.chen@apple.com> | 2011-04-28 22:57:01 +0000 |
|---|---|---|
| committer | Johnny Chen <johnny.chen@apple.com> | 2011-04-28 22:57:01 +0000 |
| commit | e69c74832884db8166b379a04a87c9db91b2814e (patch) | |
| tree | 40a9fe3ff26903bad945b260ab7f862275a62a7e | |
| parent | 8409bce4aca162fad81e43f84cece1b9b13cde77 (diff) | |
| download | bcm5719-llvm-e69c74832884db8166b379a04a87c9db91b2814e.tar.gz bcm5719-llvm-e69c74832884db8166b379a04a87c9db91b2814e.zip | |
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
| -rw-r--r-- | lldb/test/class_static/TestStaticVariables.py | 3 | ||||
| -rw-r--r-- | lldb/test/class_types/TestClassTypesDisassembly.py | 5 | ||||
| -rw-r--r-- | lldb/test/foundation/TestSymbolTable.py | 3 | ||||
| -rw-r--r-- | lldb/test/lldbutil.py | 83 | ||||
| -rw-r--r-- | lldb/test/python_api/frame/TestFrames.py | 3 | ||||
| -rw-r--r-- | lldb/test/python_api/lldbutil/TestLLDBIterator.py | 3 |
6 files changed, 8 insertions, 92 deletions
diff --git a/lldb/test/class_static/TestStaticVariables.py b/lldb/test/class_static/TestStaticVariables.py index c9f9fc3bcd8..12ff77853a5 100644 --- a/lldb/test/class_static/TestStaticVariables.py +++ b/lldb/test/class_static/TestStaticVariables.py @@ -101,8 +101,7 @@ class StaticVariableTestCase(TestBase): # 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 fedefc8ddad..5c144dc3297 100644 --- a/lldb/test/class_types/TestClassTypesDisassembly.py +++ b/lldb/test/class_types/TestClassTypesDisassembly.py @@ -103,9 +103,8 @@ class IterateFrameAndDisassembleTestCase(TestBase): 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 7e80ee73105..c86d90cf85e 100644 --- a/lldb/test/foundation/TestSymbolTable.py +++ b/lldb/test/foundation/TestSymbolTable.py @@ -60,8 +60,7 @@ class FoundationSymtabTestCase(TestBase): # 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 7bc0eef65df..eb983fee236 100644 --- a/lldb/test/lldbutil.py +++ b/lldb/test/lldbutil.py @@ -27,85 +27,6 @@ def which(program): 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 @@ def disassemble(target, function_or_symbol): """ 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 value_type_to_str(enum): 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 2ce9fd90d1e..038264ea2c1 100644 --- a/lldb/test/python_api/frame/TestFrames.py +++ b/lldb/test/python_api/frame/TestFrames.py @@ -80,8 +80,7 @@ class FrameAPITestCase(TestBase): # 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 06e9a9ac863..890c01881b6 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 |

