From 084f6b1ec65170c2f8e38688bc83ff15b9a963e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thi=C3=A9baud=20Weksteen?= Date: Tue, 30 Jun 2015 14:58:07 -0700 Subject: scripts/gdb: add command to check list consistency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a gdb script to verify the consistency of lists. Signed-off-by: Thiébaud Weksteen Signed-off-by: Jan Kiszka Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/gdb/linux/lists.py | 89 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 scripts/gdb/linux/lists.py (limited to 'scripts/gdb/linux/lists.py') diff --git a/scripts/gdb/linux/lists.py b/scripts/gdb/linux/lists.py new file mode 100644 index 000000000000..2a94b5462d06 --- /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 +# +# 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() -- cgit v1.2.3 From 433296b32b39bd2f8a8717ccb2385b4c8654017d Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Tue, 30 Jun 2015 14:58:10 -0700 Subject: scripts/gdb: also allow list_head pointer as lx-list-check paramter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes the usage more flexible. Signed-off-by: Jan Kiszka Cc: Thiébaud Weksteen Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/gdb/linux/lists.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'scripts/gdb/linux/lists.py') diff --git a/scripts/gdb/linux/lists.py b/scripts/gdb/linux/lists.py index 2a94b5462d06..71fba6afcb55 100644 --- a/scripts/gdb/linux/lists.py +++ b/scripts/gdb/linux/lists.py @@ -20,9 +20,11 @@ list_head = utils.CachedType("struct list_head") def list_check(head): nb = 0 + if (head.type == list_head.get_type().pointer()): + head = head.dereference() + elif (head.type != list_head.get_type()): + raise gdb.GdbError('argument must be of type (struct list_head [*])') 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: -- cgit v1.2.3 From 3328bc9ee47fbf2e35d146bed0d41cff1c68e8f3 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Tue, 30 Jun 2015 14:58:13 -0700 Subject: scripts/gdb: enable completion for lx-list-check parameter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Kiszka Cc: Thiébaud Weksteen Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/gdb/linux/lists.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'scripts/gdb/linux/lists.py') diff --git a/scripts/gdb/linux/lists.py b/scripts/gdb/linux/lists.py index 71fba6afcb55..3a3775bc162b 100644 --- a/scripts/gdb/linux/lists.py +++ b/scripts/gdb/linux/lists.py @@ -80,7 +80,8 @@ class LxListChk(gdb.Command): """Verify a list consistency""" def __init__(self): - super(LxListChk, self).__init__("lx-list-check", gdb.COMMAND_DATA) + super(LxListChk, self).__init__("lx-list-check", gdb.COMMAND_DATA, + gdb.COMPLETE_EXPRESSION) def invoke(self, arg, from_tty): argv = gdb.string_to_argv(arg) -- cgit v1.2.3