Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756572AbbEVF6p (ORCPT ); Fri, 22 May 2015 01:58:45 -0400 Received: from goliath.siemens.de ([192.35.17.28]:51537 "EHLO goliath.siemens.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755688AbbEVF6Y (ORCPT ); Fri, 22 May 2015 01:58:24 -0400 From: Jan Kiszka To: Andrew Morton Cc: linux-kernel@vger.kernel.org, =?UTF-8?q?Thi=C3=A9baud=20Weksteen?= Subject: [PATCH 1/7] scripts/gdb: Add command to check list consistency Date: Fri, 22 May 2015 07:58:11 +0200 Message-Id: <9ed2578d34b10419d4fcf28d03e264fc9ce1ab3b.1432274297.git.jan.kiszka@siemens.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3960 Lines: 124 From: ThiƩbaud Weksteen Add a gdb script to verify the consistency of lists. Signed-off-by: ThiƩbaud Weksteen Signed-off-by: Jan Kiszka --- 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 +# +# 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.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/