From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1456 invoked by alias); 13 May 2013 20:21:08 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 1445 invoked by uid 89); 13 May 2013 20:21:08 -0000 X-Spam-SWARE-Status: No, score=-3.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,RP_MATCHES_RCVD,SPF_PASS,TW_BJ,TW_RG autolearn=ham version=3.3.1 Received: from mail-gh0-f201.google.com (HELO mail-gh0-f201.google.com) (209.85.160.201) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Mon, 13 May 2013 20:21:06 +0000 Received: by mail-gh0-f201.google.com with SMTP id r14so189501ghr.2 for ; Mon, 13 May 2013 13:21:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:date:message-id:from:to:subject:x-gm-message-state; bh=6xSSa5tR3AetJc0I5n8zkAKyCjBBhW1kxc8DSWIxI8I=; b=p4wR3r5A8wVPQ34tHOn2/2VIbR3CeiyS7xgWarXPj1pycxVUzGwFiA1iZXxyTkwwKx U77odo0Bdg6LaVpC2ebrgEaKxvJlV0JGA1KThHZrC6PUIOfVlkFxmIS0WMnkia/aBGh7 TJ++QDyFhowW2gl2dQYysioUl6devcRX47tijlZ/zPVSErB1124YtP84rGpJH+BtKgtl Lmp9CryUgGD+4SD6huTVb9VnOGRSxrD2BJU/H7wZdbRQhUWzZkrYyGpo1Dpc0bmEb9SX JOfEOD3UxDAo9YTrKx93WBtm/1o1u6WFWzswKzfW7p7kJQ/GjCQZCh3uQ/AhFBr0gf+M knWQ== X-Received: by 10.236.198.168 with SMTP id v28mr7892532yhn.10.1368476465053; Mon, 13 May 2013 13:21:05 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id o42si808200yhe.5.2013.05.13.13.21.05 for (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Mon, 13 May 2013 13:21:05 -0700 (PDT) Received: from ruffy2.mtv.corp.google.com (ruffy2.mtv.corp.google.com [172.17.128.107]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id ABAD35A40E5 for ; Mon, 13 May 2013 13:21:04 -0700 (PDT) Date: Mon, 13 May 2013 20:21:00 -0000 Message-Id: From: Doug Evans To: gdb-patches@sourceware.org Subject: [RFA 1/2, doc RFA] maint check-symtabs, maint expand-symtabs X-Gm-Message-State: ALoCoQn0EYWrrSjeihn1hgEh65TJ64R8IwZuXJ6kmpGfL9gxMfPQq9ldo3hF1U3VZAir5uf9tI4HXA0q2AvQi5CUk/I1meZnnE1docLouxA+79V77gTg51eI8yTFdSHS9q4ALKvqgcMqW5e9Qw/Xzrp/Zp1IZKZcY95eqO7vt5Azu3bhQMiyNwnpZwzi0Bu9EiuKfhtwB4htqBNFx26K5BPFxNeGfPBqjghR3+6mNvaBAvpjCf5v/k4= X-SW-Source: 2013-05/txt/msg00454.txt.bz2 Hi. This is a revised version of this patch: http://sourceware.org/ml/gdb-patches/2013-05/msg00261.html It makes "check-psymtabs" only check already expanded symtabs, and adds new maint commands check-symtabs and expand-symtabs. Regression tested on amd64-linux. Ok to check in? 2013-05-13 Doug Evans * NEWS: Mention new maintenance commands check-symtabs, and expand-symtabs, and renamed check-psymtabs. * psymtab.c (maintenance_check_psymtabs): Renamed from maintenance_check_symtabs. Only process already-expanded symbol tables. (_initialize_psymtab): Update. * symmisc.c (maintenance_check_symtabs): New function. (maintenance_expand_name_matcher): New function (maintenance_expand_file_matcher): New function (maintenance_expand_symtabs): New function. (_initialize_symmisc): Add "mt check-symtabs" and "mt expand-symtabs" commands. doc/ * gdb.texinfo (Maintenance Commands): Update doc for "maint check-psymtabs". Add doc for "maint check-symtabs", "maint expand-symtabs". testsuite/ * gdb.base/maint.exp: Update test for "maint check-psymtabs". Add tests for "maint check-symtabs", "maint expand-symtabs". Index: NEWS =================================================================== RCS file: /cvs/src/src/gdb/NEWS,v retrieving revision 1.594 diff -u -p -r1.594 NEWS --- NEWS 7 May 2013 01:09:27 -0000 1.594 +++ NEWS 9 May 2013 20:45:40 -0000 @@ -11,6 +11,12 @@ Nios II GNU/Linux nios2*-*-linux * New commands: catch rethrow Like "catch throw", but catches a re-thrown exception. +maint check-psymtabs + Renamed from old "maint check-symtabs". +maint check-symtabs + Perform consistency checks on symtabs. +maint expand-symtabs + Expand symtabs matching an optional regexp. show configuration Display the details of GDB configure-time options. Index: psymtab.c =================================================================== RCS file: /cvs/src/src/gdb/psymtab.c,v retrieving revision 1.75 diff -u -p -r1.75 psymtab.c --- psymtab.c 8 May 2013 22:38:19 -0000 1.75 +++ psymtab.c 9 May 2013 20:58:19 -0000 @@ -2007,10 +2012,10 @@ maintenance_info_psymtabs (char *regexp, } } -/* Check consistency of psymtabs and symtabs. */ +/* Check consistency of currently expanded psymtabs vs symtabs. */ static void -maintenance_check_symtabs (char *ignore, int from_tty) +maintenance_check_psymtabs (char *ignore, int from_tty) { struct symbol *sym; struct partial_symbol **psym; @@ -2025,7 +2030,25 @@ maintenance_check_symtabs (char *ignore, { struct gdbarch *gdbarch = get_objfile_arch (objfile); - s = psymtab_to_symtab (objfile, ps); + /* We don't call psymtab_to_symtab here because that may cause symtab + expansion. When debugging a problem it helps if checkers leave + things unchanged. */ + s = ps->symtab; + + /* First do some checks that don't require the associated symtab. */ + if (ps->texthigh < ps->textlow) + { + printf_filtered ("Psymtab "); + puts_filtered (ps->filename); + printf_filtered (" covers bad range "); + fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout); + printf_filtered (" - "); + fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout); + printf_filtered ("\n"); + continue; + } + + /* Now do checks requiring the associated symtab. */ if (s == NULL) continue; bv = BLOCKVECTOR (s); @@ -2063,20 +2086,8 @@ maintenance_check_symtabs (char *ignore, } psym++; } - if (ps->texthigh < ps->textlow) - { - printf_filtered ("Psymtab "); - puts_filtered (ps->filename); - printf_filtered (" covers bad range "); - fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout); - printf_filtered (" - "); - fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout); - printf_filtered ("\n"); - continue; - } - if (ps->texthigh == 0) - continue; - if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b)) + if (ps->texthigh != 0 + && (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))) { printf_filtered ("Psymtab "); puts_filtered (ps->filename); @@ -2140,7 +2151,8 @@ This does not include information about just the symbol table structures themselves."), &maintenanceinfolist); - add_cmd ("check-symtabs", class_maintenance, maintenance_check_symtabs, - _("Check consistency of psymtabs and symtabs."), + add_cmd ("check-psymtabs", class_maintenance, maintenance_check_psymtabs, + _("\ +Check consistency of currently expanded psymtabs versus symtabs."), &maintenancelist); } Index: symmisc.c =================================================================== RCS file: /cvs/src/src/gdb/symmisc.c,v retrieving revision 1.96 diff -u -p -r1.96 symmisc.c --- symmisc.c 9 Apr 2013 02:17:17 -0000 1.96 +++ symmisc.c 9 May 2013 20:45:40 -0000 @@ -771,6 +771,134 @@ maintenance_info_symtabs (char *regexp, printf_filtered ("}\n"); } } + +/* Check consistency of symtabs. + An example of what this checks for is NULL blockvectors. + They can happen if there's a bug during debug info reading. + GDB assumes they are always non-NULL. + + Note: This does not check for psymtab vs symtab consistency. + Use "maint check-psymtabs" for that. */ + +static void +maintenance_check_symtabs (char *ignore, int from_tty) +{ + struct program_space *pspace; + struct objfile *objfile; + + ALL_PSPACES (pspace) + ALL_PSPACE_OBJFILES (pspace, objfile) + { + struct symtab *symtab; + + /* We don't want to print anything for this objfile until we + actually find something worth printing. */ + int printed_objfile_start = 0; + + ALL_OBJFILE_SYMTABS (objfile, symtab) + { + int found_something = 0; + + QUIT; + + if (symtab->blockvector == NULL) + found_something = 1; + /* Add more checks here. */ + + if (found_something) + { + if (! printed_objfile_start) + { + printf_filtered ("{ objfile %s ", objfile->name); + wrap_here (" "); + printf_filtered ("((struct objfile *) %s)\n", + host_address_to_string (objfile)); + printed_objfile_start = 1; + } + printf_filtered (" { symtab %s\n", + symtab_to_filename_for_display (symtab)); + if (symtab->blockvector == NULL) + printf_filtered (" NULL blockvector\n"); + printf_filtered (" }\n"); + } + } + + if (printed_objfile_start) + printf_filtered ("}\n"); + } +} + +/* Helper function for maintenance_expand_symtabs. + This is the name_matcher function for expand_symtabs_matching. */ + +static int +maintenance_expand_name_matcher (const char *symname, void *data) +{ + /* Since we're not searching on symbols, just return TRUE. */ + return 1; +} + +/* Helper function for maintenance_expand_symtabs. + This is the file_matcher function for expand_symtabs_matching. */ + +static int +maintenance_expand_file_matcher (const char *filename, void *data, + int basenames) +{ + const char *regexp = data; + + QUIT; + + /* KISS: Only apply the regexp to the complete file name. */ + if (basenames) + return 0; + + if (regexp == NULL || re_exec (filename)) + return 1; + + return 0; +} + +/* Expand all symbol tables whose name matches an optional regexp. */ + +static void +maintenance_expand_symtabs (char *args, int from_tty) +{ + struct program_space *pspace; + struct objfile *objfile; + struct cleanup *cleanups; + char **argv; + char *regexp = NULL; + + /* We use buildargv here so that we handle spaces in the regexp + in a way that allows adding more arguments later. */ + argv = gdb_buildargv (args); + cleanups = make_cleanup_freeargv (argv); + + if (argv != NULL) + { + if (argv[0] != NULL) + { + regexp = argv[0]; + if (argv[1] != NULL) + error (_("Extra arguments after regexp.")); + } + } + + if (regexp) + re_comp (regexp); + + ALL_PSPACES (pspace) + ALL_PSPACE_OBJFILES (pspace, objfile) + { + if (objfile->sf) + { + objfile->sf->qf->expand_symtabs_matching + (objfile, maintenance_expand_file_matcher, + maintenance_expand_name_matcher, ALL_DOMAIN, regexp); + } + } +} /* Return the nexting depth of a block within other blocks in its symtab. */ @@ -819,4 +947,14 @@ This does not include information about linetables --- just the symbol table structures themselves.\n\ With an argument REGEXP, list the symbol tables whose names that match that."), &maintenanceinfolist); + + add_cmd ("check-symtabs", class_maintenance, maintenance_check_symtabs, + _("\ +Check consistency of currently expanded symtabs."), + &maintenancelist); + + add_cmd ("expand-symtabs", class_maintenance, maintenance_expand_symtabs, + _("Expand symbol tables.\n\ +With an argument REGEXP, only expand the symbol tables with matching names."), + &maintenancelist); } Index: doc/gdb.texinfo =================================================================== RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v retrieving revision 1.1086 diff -u -p -r1.1086 gdb.texinfo --- doc/gdb.texinfo 8 May 2013 05:40:44 -0000 1.1086 +++ doc/gdb.texinfo 9 May 2013 20:45:40 -0000 @@ -35512,9 +35512,20 @@ only if non-stop mode is active (@pxref{ architecture supports displaced stepping. @end table +@kindex maint check-psymtabs +@item maint check-psymtabs +Check the consistency of currently expanded psymtabs versus symtabs. +Use this to check, for example, whether a symbol is in one but not the other. + @kindex maint check-symtabs @item maint check-symtabs -Check the consistency of psymtabs and symtabs. +Check the consistency of currently expanded symtabs. + +@kindex maint expand-symtabs +@item maint expand-symtabs [@var{regexp}] +Expand symbol tables. +If @var{regexp} is specified, only expand symbol tables for file +names matching @var{regexp}. @kindex maint cplus first_component @item maint cplus first_component @var{name} Index: testsuite/gdb.base/maint.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.base/maint.exp,v retrieving revision 1.63 diff -u -p -r1.63 maint.exp --- testsuite/gdb.base/maint.exp 29 Mar 2013 00:11:10 -0000 1.63 +++ testsuite/gdb.base/maint.exp 13 May 2013 19:22:19 -0000 @@ -20,7 +20,9 @@ # source file used is break.c -#maintenance check-symtabs -- Check consistency of psymtabs and symtabs +#maintenance check-psymtabs -- Check consistency of psymtabs vs symtabs +#maintenance check-symtabs -- Check consistency of symtabs +#maintenance expand-symtabs -- Expand symtabs matching a file regexp #maintenance set -- Set GDB internal variables used by the GDB maintainer #maintenance show -- Show GDB internal variables used by the GDB maintainer #maintenance demangle -- Demangle a C++ mangled name @@ -82,6 +84,18 @@ gdb_file_cmd ${binfile} # program wasn't running. gdb_test "maint print registers" "Name.*Nr.*Rel.*Offset.*Size.*Type.*" +# Test "mt expand-symtabs" here as it's easier to verify before we +# run the program. +gdb_test_no_output "mt set per on" "mt set per on for expand-symtabs" +gdb_test_multiple "mt expand-symtabs $subdir/break\[.\]c$" \ + "mt expand-symtabs" { + -re "#primary symtabs: 1 \\(\[+\]1\\),.*$gdb_prompt $" { + # This should expand exactly one (primary) symtab. + pass "mt expand-symtabs" + } + } +gdb_test "mt set per off" ".*" "mt set per off for expand-symtabs" + # Tests that can or should be done with a running program gdb_load ${binfile} @@ -110,20 +124,25 @@ gdb_test_multiple "maint info sections . # guo: on linux this command output is huge. for some reason splitting up # the regexp checks works. # -send_gdb "maint check-symtabs\n" +send_gdb "maint check-psymtabs\n" gdb_expect { - -re "^maint check-symtabs" { + -re "^maint check-psymtabs" { gdb_expect { -re "$gdb_prompt $" { - pass "maint check-symtabs" + pass "maint check-psymtabs" } - timeout { fail "(timeout) maint check-symtabs" } + timeout { fail "(timeout) maint check-psymtabs" } } } - -re ".*$gdb_prompt $" { fail "maint check-symtabs" } - timeout { fail "(timeout) maint check-symtabs" } + -re ".*$gdb_prompt $" { fail "maint check-psymtabs" } + timeout { fail "(timeout) maint check-psymtabs" } } +# This command does not produce any output unless there is some problem +# with the symtabs, so that branch will really never be covered in the +# tests here!! +gdb_test_no_output "maint check-symtabs" + gdb_test_no_output "maint set per-command on" gdb_test "maint set per-command off" \