Add logic to SBValue.linked_list_iter() to detect infinite loop and to bail out early.
Add code to test case to create an evil linked list with:
task_evil -> task_2 -> task_3 -> task_evil ...
and to check that the linked list iterator only iterates 3 times.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@137291 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/scripts/Python/modify-python-lldb.py b/scripts/Python/modify-python-lldb.py
index a6e86c2..3825090 100644
--- a/scripts/Python/modify-python-lldb.py
+++ b/scripts/Python/modify-python-lldb.py
@@ -112,6 +112,8 @@
end-of-list test function which takes an SBValue for an item and returns
True if EOL is reached and False if not.
+ linked_list_iter() also detects infinite loop and bails out early.
+
The end_of_list_test arg, if omitted, defaults to the __eol_test__
function above.
@@ -130,8 +132,10 @@
if end_of_list_test(self):
return
item = self
+ visited = set()
try:
- while not end_of_list_test(item):
+ while not end_of_list_test(item) and not item.GetValueAsUnsigned() in visited:
+ visited.add(item.GetValueAsUnsigned())
yield item
# Prepare for the next iteration.
item = item.GetChildMemberWithName(next_item_name)