From: "Thiébaud Weksteen" <thiebaud@weksteen.fr>
To: linux-kernel@vger.kernel.org
Cc: Jan Kiszka <jan.kiszka@siemens.com>
Subject: [PATCH v2] scripts/gdb: Add command to check list consistency
Date: Fri, 24 Apr 2015 11:57:30 +1000 [thread overview]
Message-ID: <5539A30A.8010600@weksteen.fr> (raw)
Add a gdb script to verify the consistency of lists.
Signed-off-by: Thiébaud Weksteen <thiebaud@weksteen.fr>
---
Implement suggestions from Jan.
Changes in v2:
- Add copyright line
- Rename check_list to list_check
- Remove casting and only accept (struct list_head) object
- Add error message if argument is missing
- Reformat error messages to include address of nodes
Example of use:
(gdb) lx-list-check workqueues
Starting with: {next = 0xf3aea5a8, prev = 0xf580e668}
list is consistent: 30 node(s)
(gdb) set *((int *) 0xf3934908) = 0x0
(gdb) lx-list-check workqueues
Starting with: {next = 0xf3aea5a8, prev = 0xf580e668}
next is not accessible: current@0xf3934908={next = 0x0, prev = 0xf3aea5a8}
(gdb) set *((int *) 0xf3934908) = 0xdeadbeef
(gdb) lx-list-check workqueues
Starting with: {next = 0xf3aea5a8, prev = 0xf580e668}
next.prev != current: current@0xf3934908={next = 0xdeadbeef, prev = 0xf3aea5a8}
next@0xdeadbeef={next = 0x0, prev = 0x0}
(gdb) set *((int *) 0xf3934908) = 0xf537f188
(gdb) lx-list-check workqueues
Starting with: {next = 0xf3aea5a8, prev = 0xf580e668}
list is consistent: 30 node(s)
scripts/gdb/linux/lists.py | 89 ++++++++++++++++++++++++++++++++++++++++++++++
scripts/gdb/vmlinux-gdb.py | 1 +
2 files changed, 90 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..2a94b54
--- /dev/null
+++ b/scripts/gdb/linux/lists.py
@@ -0,0 +1,89 @@
+#
+# gdb helper commands and functions for Linux kernel debugging
+#
+# list tools
+#
+# Copyright (c) Thiebaud Weksteen, 2015
+#
+# 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 list_check(head):
+ nb = 0
+ c = head
+ if (c.type != list_head.get_type()):
+ raise gdb.GdbError('The argument should be of type (struct list_head)')
+ try:
+ gdb.write("Starting with: {}\n".format(c))
+ except gdb.MemoryError:
+ gdb.write('head is not accessible\n')
+ return
+ while True:
+ p = c['prev'].dereference()
+ n = c['next'].dereference()
+ try:
+ if p['next'] != c.address:
+ gdb.write('prev.next != current: '
+ 'current@{current_addr}={current} '
+ 'prev@{p_addr}={p}\n'.format(
+ current_addr=c.address,
+ current=c,
+ p_addr=p.address,
+ p=p,
+ ))
+ return
+ except gdb.MemoryError:
+ gdb.write('prev is not accessible: '
+ 'current@{current_addr}={current}\n'.format(
+ current_addr=c.address,
+ current=c
+ ))
+ return
+ try:
+ if n['prev'] != c.address:
+ gdb.write('next.prev != current: '
+ 'current@{current_addr}={current} '
+ 'next@{n_addr}={n}\n'.format(
+ current_addr=c.address,
+ current=c,
+ n_addr=n.address,
+ n=n,
+ ))
+ return
+ except gdb.MemoryError:
+ gdb.write('next is not accessible: '
+ 'current@{current_addr}={current}\n'.format(
+ current_addr=c.address,
+ current=c
+ ))
+ return
+ c = n
+ nb += 1
+ if c == head:
+ gdb.write("list is consistent: {} node(s)\n".format(nb))
+ return
+
+
+class LxListChk(gdb.Command):
+ """Verify a list consistency"""
+
+ def __init__(self):
+ super(LxListChk, self).__init__("lx-list-check", gdb.COMMAND_DATA)
+
+ def invoke(self, arg, from_tty):
+ argv = gdb.string_to_argv(arg)
+ if len(argv) != 1:
+ raise gdb.GdbError("lx-list-check takes one argument")
+ list_check(gdb.parse_and_eval(argv[0]))
+
+LxListChk()
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
next reply other threads:[~2015-04-24 1:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-24 1:57 Thiébaud Weksteen [this message]
2015-05-01 6:50 ` [PATCH v2] scripts/gdb: Add command to check list consistency 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=5539A30A.8010600@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.