aboutsummaryrefslogtreecommitdiff
path: root/lldb/scripts/Python/modify-python-lldb.py
diff options
context:
space:
mode:
authorJohnny Chen <johnny.chen@apple.com>2011-07-26 20:57:10 +0000
committerJohnny Chen <johnny.chen@apple.com>2011-07-26 20:57:10 +0000
commite33b166da1586296b44d609c9edd1d9d89a4e54e (patch)
tree20f82a3d10823913253b856431c7ad2f45b583c4 /lldb/scripts/Python/modify-python-lldb.py
parent2aedba6c5e18fa3e62a0eca95d50c6ab77abd109 (diff)
downloadllvm-e33b166da1586296b44d609c9edd1d9d89a4e54e.zip
llvm-e33b166da1586296b44d609c9edd1d9d89a4e54e.tar.gz
llvm-e33b166da1586296b44d609c9edd1d9d89a4e54e.tar.bz2
We can do better with the SBValue.linked_list_iter() API by supplying a default
end of list test function as __eol_test__. The simple example can be reduced to: for t in task_head.linked_list_iter('next'): print t Modify the test program to exercise the API for both cases: supplying or not supplying an end of list test function. llvm-svn: 136144
Diffstat (limited to 'lldb/scripts/Python/modify-python-lldb.py')
-rw-r--r--lldb/scripts/Python/modify-python-lldb.py28
1 files changed, 16 insertions, 12 deletions
diff --git a/lldb/scripts/Python/modify-python-lldb.py b/lldb/scripts/Python/modify-python-lldb.py
index 3a784a6..3cd3126 100644
--- a/lldb/scripts/Python/modify-python-lldb.py
+++ b/lldb/scripts/Python/modify-python-lldb.py
@@ -89,10 +89,21 @@ def lldb_iter(obj, getsize, getelem):
# which takes an SBValue and returns True if EOL is reached and False if not.
#
linked_list_iter_def = '''
+ def __eol_test__(val):
+ """Default function for end of list test takes an SBValue object.
+
+ Return True if val is invalid or it corresponds to a null pointer.
+ Otherwise, return False.
+ """
+ if not val or int(val.GetValue(), 0) == 0:
+ return True
+ else:
+ return False
+
# ==================================================
# Iterator for lldb.SBValue treated as a linked list
# ==================================================
- def linked_list_iter(self, next_item_name, end_of_list_test):
+ def linked_list_iter(self, next_item_name, end_of_list_test=__eol_test__):
"""Generator adaptor to support iteration for SBValue as a linked list.
linked_list_iter() is a special purpose iterator to treat the SBValue as
@@ -101,17 +112,10 @@ linked_list_iter_def = '''
end-of-list test function which takes an SBValue for an item and returns
True if EOL is reached and False if not.
- For example,
-
- def eol(val):
- \'\'\'Test function to determine end of list.\'\'\'
- # End of list is reached if either the value object is invalid
- # or it corresponds to a null pointer.
- if not val or int(val.GetValue(), 16) == 0:
- return True
+ The end_of_list_test arg, if omitted, defaults to the __eol_test__
+ function above.
- # Otherwise, return False.
- return False
+ For example,
# Get Frame #0.
...
@@ -120,7 +124,7 @@ linked_list_iter_def = '''
task_head = frame0.FindVariable('task_head')
...
- for t in task_head.linked_list_iter('next', eol):
+ for t in task_head.linked_list_iter('next'):
print t
"""
try: