The SBValue.linked_list_iter() API failed for an empty list.
Fix the bug and add a test case.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@136265 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/scripts/Python/modify-python-lldb.py b/scripts/Python/modify-python-lldb.py
index 3cd3126..9f5f8c9 100644
--- a/scripts/Python/modify-python-lldb.py
+++ b/scripts/Python/modify-python-lldb.py
@@ -129,12 +129,10 @@
"""
try:
item = self.GetChildMemberWithName(next_item_name)
- while item:
+ while not end_of_list_test(item):
yield item
# Prepare for the next iteration.
item = item.GetChildMemberWithName(next_item_name)
- if end_of_list_test(item):
- break
except:
# Exception occurred. Stop the generator.
pass
diff --git a/test/python_api/value/linked_list/TestValueAPILinkedList.py b/test/python_api/value/linked_list/TestValueAPILinkedList.py
index 6456a2e..f07ed1b 100644
--- a/test/python_api/value/linked_list/TestValueAPILinkedList.py
+++ b/test/python_api/value/linked_list/TestValueAPILinkedList.py
@@ -91,6 +91,10 @@
# or it corresponds to a null pointer.
if not val or int(val.GetValue(), 16) == 0:
return True
+ # Also check the "id" for correct semantics. If id <= 0, the item
+ # is corrupted, let's return True to signify end of list.
+ if int(val.GetChildMemberWithName("id").GetValue(), 0) <= 0:
+ return True
# Otherwise, return False.
return False
@@ -109,6 +113,20 @@
print "visited IDs:", list
self.assertTrue(visitedIDs == list)
+ # Get variable 'empty_task_head'.
+ empty_task_head = frame0.FindVariable('empty_task_head')
+ self.assertTrue(empty_task_head, VALID_VARIABLE)
+ self.DebugSBValue(empty_task_head)
+
+ list = []
+ # There is no iterable item from empty_task_head.linked_list_iter().
+ for t in empty_task_head.linked_list_iter('next', eol):
+ if self.TraceOn():
+ print cvf.format(t)
+ list.append(int(t.GetChildMemberWithName("id").GetValue()))
+
+ self.assertTrue(len(list) == 0)
+
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
diff --git a/test/python_api/value/linked_list/main.cpp b/test/python_api/value/linked_list/main.cpp
index 772d5ed..db0e249 100644
--- a/test/python_api/value/linked_list/main.cpp
+++ b/test/python_api/value/linked_list/main.cpp
@@ -33,7 +33,7 @@
task2->next = task4;
task4->next = task5;
- int total = 0; // Break at this line
+ int total = 0;
Task *t = task_head;
while (t != NULL) {
if (t->id >= 0)
@@ -41,5 +41,9 @@
t = t->next;
}
printf("We have a total number of %d tasks\n", total);
- return 0;
+
+ // This corresponds to an empty task list.
+ Task *empty_task_head = new Task(-1, NULL);
+
+ return 0; // Break at this line
}