The SBValue.linked_list_iter() API failed for an empty list.

Fix the bug and add a test case.

llvm-svn: 136265
This commit is contained in:
Johnny Chen 2011-07-27 21:14:01 +00:00
parent 03f56d9de6
commit bfdf9a36d9
3 changed files with 25 additions and 5 deletions

View File

@ -129,12 +129,10 @@ linked_list_iter_def = '''
"""
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

View File

@ -91,6 +91,10 @@ class ValueAsLinkedListTestCase(TestBase):
# 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 @@ class ValueAsLinkedListTestCase(TestBase):
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()

View File

@ -33,7 +33,7 @@ int main (int argc, char const *argv[])
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 @@ int main (int argc, char const *argv[])
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
}