[Lldb-commits] [lldb] r136144 - in /lldb/trunk: scripts/Python/modify-python-lldb.py test/python_api/value/linked_list/TestValueAPILinkedList.py
Johnny Chen
johnny.chen at apple.com
Tue Jul 26 13:57:10 PDT 2011
Author: johnny
Date: Tue Jul 26 15:57:10 2011
New Revision: 136144
URL: http://llvm.org/viewvc/llvm-project?rev=136144&view=rev
Log:
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.
Modified:
lldb/trunk/scripts/Python/modify-python-lldb.py
lldb/trunk/test/python_api/value/linked_list/TestValueAPILinkedList.py
Modified: lldb/trunk/scripts/Python/modify-python-lldb.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/modify-python-lldb.py?rev=136144&r1=136143&r2=136144&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/modify-python-lldb.py (original)
+++ lldb/trunk/scripts/Python/modify-python-lldb.py Tue Jul 26 15:57:10 2011
@@ -89,10 +89,21 @@
# 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 @@
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 @@
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:
Modified: lldb/trunk/test/python_api/value/linked_list/TestValueAPILinkedList.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/value/linked_list/TestValueAPILinkedList.py?rev=136144&r1=136143&r2=136144&view=diff
==============================================================================
--- lldb/trunk/test/python_api/value/linked_list/TestValueAPILinkedList.py (original)
+++ lldb/trunk/test/python_api/value/linked_list/TestValueAPILinkedList.py Tue Jul 26 15:57:10 2011
@@ -54,16 +54,6 @@
process = target.LaunchSimple(None, None, os.getcwd())
self.assertTrue(process, PROCESS_IS_VALID)
- 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
-
- # Otherwise, return False.
- return False
-
# Get Frame #0.
self.assertTrue(process.GetState() == lldb.eStateStopped)
thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
@@ -80,6 +70,32 @@
list = []
cvf = lldbutil.ChildVisitingFormatter(indent_child=2)
+ for t in task_head.linked_list_iter('next'):
+ self.assertTrue(t, VALID_VARIABLE)
+ # Make sure that 'next' corresponds to an SBValue with pointer type.
+ self.assertTrue(t.TypeIsPointerType())
+ if self.TraceOn():
+ print cvf.format(t)
+ list.append(int(t.GetChildMemberWithName("id").GetValue()))
+
+ # Sanity checks that the we visited all the items (no more, no less).
+ if self.TraceOn():
+ print "visited IDs:", list
+ self.assertTrue(visitedIDs == list)
+
+ # Let's exercise the linked_list_iter() API again, this time supplying
+ # our end of list test function.
+ 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
+
+ # Otherwise, return False.
+ return False
+
+ list = []
for t in task_head.linked_list_iter('next', eol):
self.assertTrue(t, VALID_VARIABLE)
# Make sure that 'next' corresponds to an SBValue with pointer type.
More information about the lldb-commits
mailing list