Skip to contentSkip to conversation

scripts/gdb: fix list_for_each

PATCH Applied George Prekas 2 participants 3 messages Sep 24, 2020 – Jan 5, 2021 GDB kernel debugging helper scripts

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 scripts/gdb: fix list_for_each

If the list is uninitialized (next pointer is NULL), list_for_each gets stuck in an infinite loop. Print a message and treat list as empty.

---
 scripts/gdb/linux/lists.py | 5 +++++

 1 file changed, 5 insertions(+)
scripts/gdb/linux/lists.py +0 -0
index c487ddf09d38..bae4d70b7eae 100644
@@ -27,6 +27,11 @@ def list_for_each(head):

         raise TypeError("Must be struct list_head not {}" .format(head.type))

+    if head['next'] == 0:
+        gdb.write("list_for_each: Uninitialized list '{}' treated as empty\n" +                     .format(head.address))
+        return
+
     node = head['next'].dereference()
     while node.address != head.address:
         yield node.address

Signature · 1 line
2.16.6
#1 lore raw
Quoted 16 lines · George Prekas

If the list is uninitialized (next pointer is NULL), list_for_each gets stuck in an infinite loop. Print a message and treat list as empty.

---
 scripts/gdb/linux/lists.py | 5 +++++

 1 file changed, 5 insertions(+)
scripts/gdb/linux/lists.py +0 -0
index c487ddf09d38..bae4d70b7eae 100644
@@ -27,6 +27,11 @@ def list_for_each(head):

         raise TypeError("Must be struct list_head not {}" .format(head.type))

Quoted 9 lines

+    if head['next'] == 0:
+        gdb.write("list_for_each: Uninitialized list '{}' treated as empty\n"
+                     .format(head.address))
+        return
+
     node = head['next'].dereference()
     while node.address != head.address:
         yield node.address

Happy New Year!

Any updates on this?

Thanks,
George

maintainer Reviewed-by
#2 lore raw
Quoted 17 lines · George Prekas
Quoted 16 lines · George Prekas

If the list is uninitialized (next pointer is NULL), list_for_each gets stuck in an infinite loop. Print a message and treat list as empty.

---
 scripts/gdb/linux/lists.py | 5 +++++

 1 file changed, 5 insertions(+)
scripts/gdb/linux/lists.py +0 -0
index c487ddf09d38..bae4d70b7eae 100644
@@ -27,6 +27,11 @@ def list_for_each(head):

         raise TypeError("Must be struct list_head not {}" .format(head.type))

Quoted 11 lines
Quoted 9 lines

+    if head['next'] == 0:
+        gdb.write("list_for_each: Uninitialized list '{}' treated as empty\n"
+                     .format(head.address))
+        return
+
     node = head['next'].dereference()
     while node.address != head.address:
         yield node.address

Happy New Year!

Same to you!

Quoted 3 lines

Any updates on this?

Sorry, slipped through.

Andrew, please pick this up.

Jan

Signature · 2 lines
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux