mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Thiébaud Weksteen" <thiebaud@weksteen.fr>
To: linux-kernel@vger.kernel.org
Cc: Jan Kiszka <jan.kiszka@siemens.com>
Subject: [PATCH] scripts/gdb: Add command to check list consistency
Date: Wed, 22 Apr 2015 17:32:27 +1000	[thread overview]
Message-ID: <55374E8B.1040408@weksteen.fr> (raw)

Add a gdb script to verify the consistency of lists.

Signed-off-by: Thiébaud Weksteen <thiebaud@weksteen.fr>
---
 scripts/gdb/linux/lists.py | 78 ++++++++++++++++++++++++++++++++++++++++++++++
 scripts/gdb/vmlinux-gdb.py |  1 +
 2 files changed, 79 insertions(+)
 create mode 100644 scripts/gdb/linux/lists.py

diff --git a/scripts/gdb/linux/lists.py b/scripts/gdb/linux/lists.py
new file mode 100644
index 0000000..d512f62
--- /dev/null
+++ b/scripts/gdb/linux/lists.py
@@ -0,0 +1,78 @@
+#
+# gdb helper commands and functions for Linux kernel debugging
+#
+#  list tools
+#
+# Authors:
+#  Thiebaud Weksteen <thiebaud@weksteen.fr>
+#
+# This work is licensed under the terms of the GNU GPL version 2.
+#
+
+import gdb
+
+from linux import utils
+
+list_head = utils.CachedType("struct list_head")
+
+def check_list(head):
+    nb = 0
+    list_head_ptr_type = list_head.get_type().pointer()
+    c = head.cast(list_head_ptr_type)
+    try:
+        gdb.write("Starting with: {} {}\n".format(c, c.dereference()))
+    except gdb.MemoryError:
+        gdb.write('head is not accessible\n')
+        return
+    while True:
+        p = c['prev']
+        n = c['next']
+        try:
+            if p['next'] != c:
+                gdb.write('prev.next != current: current={current} '
+                          'prev={p} prev.next={pnext}\n'.format(
+                          current=c,
+                          p=p,
+                          pnext=p['next']
+                          ))
+                return
+        except gdb.MemoryError:
+            gdb.write('prev is not accessible: current={current} '
+                      'current.prev={p}\n'.format(
+                      current=c,
+                      p=p
+                      ))
+            return
+        try:
+            if n['prev'] != c:
+                gdb.write('next.prev != current: current={current} '
+                          'next={n}, next.prev={nprev}\n'.format(
+                          current=c,
+                          n=n,
+                          nprev=n['prev']
+                          ))
+                return
+        except gdb.MemoryError:
+            gdb.write('next is not accessible: current={current} '
+                      'current.next={n}\n'.format(
+                      current=c,
+                      n=n
+                      ))
+            return
+        c = n
+        nb += 1
+        if c == head:
+            gdb.write("list is consistent: {} node(s)\n".format(nb))
+            return
+
+class LxChkList(gdb.Command):
+    """Verify a list consistency"""
+
+    def __init__(self):
+        super(LxChkList, self).__init__("lx-check-list", gdb.COMMAND_DATA)
+
+    def invoke(self, arg, from_tty):
+        argv = gdb.string_to_argv(arg)
+        check_list(gdb.parse_and_eval(argv[0]))
+
+LxChkList()
diff --git a/scripts/gdb/vmlinux-gdb.py b/scripts/gdb/vmlinux-gdb.py
index 4848928..ce82bf5 100644
--- a/scripts/gdb/vmlinux-gdb.py
+++ b/scripts/gdb/vmlinux-gdb.py
@@ -28,3 +28,4 @@ else:
     import linux.dmesg
     import linux.tasks
     import linux.cpus
+    import linux.lists
-- 
2.1.0

             reply	other threads:[~2015-04-22  9:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-22  7:32 Thiébaud Weksteen [this message]
2015-04-23 12:10 ` Jan Kiszka
2015-04-23 12:20   ` Jan Kiszka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55374E8B.1040408@weksteen.fr \
    --to=thiebaud@weksteen.fr \
    --cc=jan.kiszka@siemens.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome