modify-python-lldb.py: clean up __iter__ and __len__ support
Summary:
Instead of modifying the swig-generated code, just add the appropriate
methods to the interface files in order to get the swig to do the
generation for us.
This is a straight-forward move from the python script to the interface
files. The single class which has nontrivial handling in the script
(SBModule) has been left for a separate patch.
For the cases where I did not find any tests exercising the
iteration/length methods (i.e., no tests failed after I stopped emitting
them), I tried to add basic tests for that functionality.
Reviewers: zturner, jingham, amccarth
Subscribers: jdoerfert, lldb-commits
Differential Revision: https://reviews.llvm.org/D60119
llvm-svn: 357572
diff --git a/lldb/scripts/interface/SBProcess.i b/lldb/scripts/interface/SBProcess.i
index 9cb4741..7e00ed3 100644
--- a/lldb/scripts/interface/SBProcess.i
+++ b/lldb/scripts/interface/SBProcess.i
@@ -497,6 +497,15 @@
for idx in range(len(accessor)):
threads.append(accessor[idx])
return threads
+
+ def __iter__(self):
+ '''Iterate over all threads in a lldb.SBProcess object.'''
+ return lldb_iter(self, 'GetNumThreads', 'GetThreadAtIndex')
+
+ def __len__(self):
+ '''Return the number of threads in a lldb.SBProcess object.'''
+ return self.GetNumThreads()
+
__swig_getmethods__["threads"] = get_process_thread_list
if _newclass: threads = property(get_process_thread_list, None, doc='''A read only property that returns a list() of lldb.SBThread objects for this process.''')