Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965458AbbDWMKq (ORCPT ); Thu, 23 Apr 2015 08:10:46 -0400 Received: from david.siemens.de ([192.35.17.14]:58696 "EHLO david.siemens.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753260AbbDWMKp (ORCPT ); Thu, 23 Apr 2015 08:10:45 -0400 Message-ID: <5538E142.2090507@siemens.com> Date: Thu, 23 Apr 2015 14:10:42 +0200 From: Jan Kiszka User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: =?UTF-8?B?VGhpw6liYXVkIFdla3N0ZWVu?= , linux-kernel@vger.kernel.org Subject: Re: [PATCH] scripts/gdb: Add command to check list consistency References: <55374E8B.1040408@weksteen.fr> In-Reply-To: <55374E8B.1040408@weksteen.fr> 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: 4542 Lines: 141 On 2015-04-22 09:32, ThiƩbaud Weksteen wrote: > Add a gdb script to verify the consistency of lists. > > Signed-off-by: ThiƩbaud Weksteen > --- > 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 Who is the copyright holder, also you, your employer etc.? Please clarify, ideally by just having a copyright line like in the other scripts. > +# > +# 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): In general - applies to internal naming as well as the command itself - I would prefer "list check". That would create a namespace under which we may add further list helpers later on. > + nb = 0 > + list_head_ptr_type = list_head.get_type().pointer() > + c = head.cast(list_head_ptr_type) Why casting? Is it a common use case to not have the list head as a variable at hand? The user could still do lx_list_check (struct list_head *)0x... when needed. > + 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'] > + )) This is not pep8-conforming. Please fix (even if the exiting scripts have some issues as well - just noticed...). > + 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 > Looks useful! As indicated, I could imagine extending this module by further helpers, for the other list types or for walking a list, executing some gdb command for each element. Thanks, Jan -- Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux -- 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/