This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit e0bea987d1c8e2dccadf9094fbb27828f0a9121e
Author: anjiahao <anjia...@xiaomi.com>
AuthorDate: Fri Apr 19 11:41:21 2024 +0800

    gdb python plugin:support dump list member
    
    Signed-off-by: anjiahao <anjia...@xiaomi.com>
---
 tools/gdb/lists.py | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/tools/gdb/lists.py b/tools/gdb/lists.py
index 067058042b..62c74a35bd 100644
--- a/tools/gdb/lists.py
+++ b/tools/gdb/lists.py
@@ -241,3 +241,33 @@ class Nxlistcheck(gdb.Command):
 
 
 Nxlistcheck()
+
+
+class Nxlistforentry(gdb.Command):
+    """Dump list members for a given list"""
+
+    def __init__(self):
+        super(Nxlistforentry, self).__init__(
+            "listforentry", gdb.COMMAND_DATA, gdb.COMPLETE_EXPRESSION
+        )
+
+    def invoke(self, arg, from_tty):
+        argv = gdb.string_to_argv(arg)
+
+        if len(argv) != 3:
+            gdb.write("listforentry takes three arguments"
+                      "head, type, member\n")
+            gdb.write("eg: listforentry &g_list 'struct type' 'node '\n")
+            return
+
+        i = 0
+        for entry in list_for_each_entry(
+                gdb.parse_and_eval(argv[0]),
+                gdb.lookup_type(argv[1]).pointer(),
+                argv[2]):
+            gdb.write(f"{i}: ({argv[1]} *){entry}\n")
+            gdb.execute(f"print *({argv[1]} *){entry}")
+            i += 1
+
+
+Nxlistforentry()

Reply via email to