From patchwork Wed Nov 19 21:00:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Taylor X-Patchwork-Id: 3805 Received: (qmail 11992 invoked by alias); 19 Nov 2014 21:00:51 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 11961 invoked by uid 89); 19 Nov 2014 21:00:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, NO_DNS_FOR_FROM, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mailuogwdur.emc.com Received: from mailuogwdur.emc.com (HELO mailuogwdur.emc.com) (128.221.224.79) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 19 Nov 2014 21:00:48 +0000 Received: from maildlpprd55.lss.emc.com (maildlpprd55.lss.emc.com [10.106.48.159]) by mailuogwprd54.lss.emc.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.0) with ESMTP id sAJL0ilZ002308 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 19 Nov 2014 16:00:44 -0500 X-DKIM: OpenDKIM Filter v2.4.3 mailuogwprd54.lss.emc.com sAJL0ilZ002308 X-DKIM: OpenDKIM Filter v2.4.3 mailuogwprd54.lss.emc.com sAJL0ilZ002308 Received: from mailsyshubprd06.lss.emc.com (mailsyshubprd06.lss.emc.com [10.253.24.24]) by maildlpprd55.lss.emc.com (RSA Interceptor); Wed, 19 Nov 2014 16:00:15 -0500 Received: from usendtaylorx2l.lss.emc.com (usendtaylorx2l.lss.emc.com [10.243.10.188]) by mailsyshubprd06.lss.emc.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.0) with ESMTP id sAJL0THW030252; Wed, 19 Nov 2014 16:00:29 -0500 Received: by usendtaylorx2l.lss.emc.com (Postfix, from userid 26043) id DA2FC5DAB7A; Wed, 19 Nov 2014 16:00:26 -0500 (EST) Received: from usendtaylorx2l (localhost [127.0.0.1]) by usendtaylorx2l.lss.emc.com (Postfix) with ESMTP id 7EC055D778C; Wed, 19 Nov 2014 16:00:26 -0500 (EST) To: "gdb-patches@sourceware.org" cc: Eli Zaretskii Subject: RFA info macro [-at LOCATION,] (v2) In-reply-to: <83mw7ymmdw.fsf@gnu.org> References: <31913.1415655693@usendtaylorx2l> <83mw7ymmdw.fsf@gnu.org> Comments: In-reply-to Eli Zaretskii message dated "Mon, 10 Nov 2014 22:44:43 -0500." Date: Wed, 19 Nov 2014 16:00:26 -0500 Message-ID: <8085.1416430826@usendtaylorx2l> From: David Taylor X-RSA-Classifications: Source Code, public X-Sentrion-Hostname: mailuogwprd54.lss.emc.com This adds a NEWS entry as requested by Eli and I believe addresses his concerns with regard to gdb/doc/gdb.texinfo. The other two files gdb/macrocmd.c and gdb/testsuite/gdb.base/info-macros.exp are unchanged from the previous submission. I updated the gdb/ChangeLog entry to include the gdb/NEWS addition.. A few releases ago it was possible to set a location that would be used by 'info location' by typing something like: list file.c:42 and then do: info macro MACRONAME . Sometime between release 7.1 and 7.8 that stopped working. The following patch adds the option [-at LOCATION,] to 'info macro' to enable the use of a user selected location as a documented feature. Three files, three change log entries: gdb/ChangeLog: 2014-11-10 David Taylor * macrocmd.c (info_macro_command): Add support for new option '-at LOCATION'. (_initialize_macrocmd): Update doc string for 'info macro' command. * NEWS: Add entry about --reverse option to info macro command. gdb/doc/ChangeLog: 2014-11-10 David Taylor * gdb.texinfo: Document new -at LOCATION option of the 'info macro' command. gdb/testsuite/ChangeLog: 2014-11-10 David Taylor * gdb.base/info-macros.exp: Add testcases for new -at LOCATION option of the 'info macro' command. On an x86-64 Linux platform, there were no testsuite regressions and the new tests passed. The actual patch: Index: gdb/NEWS =================================================================== RCS file: /home/cvsroot/GDB/gdb/NEWS,v retrieving revision 1.1.1.3 diff -u -r1.1.1.3 NEWS --- gdb/NEWS 21 Aug 2014 13:17:24 -0000 1.1.1.3 +++ gdb/NEWS 19 Nov 2014 20:51:59 -0000 @@ -1,6 +1,15 @@ What has changed in GDB? (Organized release by release) +*** Changes since GDB 7.8 + +* New options + +The info macro command now takes an optional location ([-at LOCATION,]) +for determining which definition, if any, of the macro is in scope. If +left unspecified it, as before, uses the source and line associated with +the current program counter. + *** Changes in GDB 7.8 * New command line options Index: gdb/macrocmd.c =================================================================== RCS file: /home/cvsroot/GDB/gdb/macrocmd.c,v retrieving revision 1.1.1.3 diff -u -r1.1.1.3 macrocmd.c --- gdb/macrocmd.c 21 Aug 2014 13:17:23 -0000 1.1.1.3 +++ gdb/macrocmd.c 19 Nov 2014 20:51:59 -0000 @@ -206,21 +206,43 @@ info_macro_command (char *args, int from_tty) { struct macro_scope *ms = NULL; - struct cleanup *cleanup_chain; + struct cleanup *cleanup_chain = NULL; char *name; int show_all_macros_named = 0; char *arg_start = args; int processing_args = 1; - while (processing_args - && arg_start && *arg_start == '-' && *arg_start != '\0') - { - char *p = skip_to_space (arg_start); + int location_specified = 0; - if (strncmp (arg_start, "-a", p - arg_start) == 0 - || strncmp (arg_start, "-all", p - arg_start) == 0) + while (processing_args && args && *args == '-') + { + if (check_for_argument (&args, "-a", sizeof ("-a") - 1) + || check_for_argument (&args, "-all", sizeof ("-all") - 1)) show_all_macros_named = 1; - else if (strncmp (arg_start, "--", p - arg_start) == 0) + else if (check_for_argument (&args, "-at", sizeof ("-at") - 1)) + { + struct linespec_result canonical; + + location_specified = 1; + + args = skip_spaces (args); + init_linespec_result (&canonical); + decode_line_full (&args, DECODE_LINE_FUNFIRSTLINE, + (struct symtab *) NULL, 0, &canonical, + NULL, NULL); + + cleanup_chain = make_cleanup_destroy_linespec_result (&canonical); + args = skip_spaces (args); + if (args[0] == ',') + { + args++; + args = skip_spaces (args); + } + ms = sal_macro_scope (canonical.sals->vec->sals.sals[0]); + do_cleanups (cleanup_chain); + cleanup_chain = make_cleanup (free_current_contents, &ms); + } + else if (check_for_argument (&args, "--", sizeof ("--") - 1)) /* Our macro support seems rather C specific but this would seem necessary for languages allowing - in macro names. e.g. Scheme's (defmacro ->foo () "bar\n") */ @@ -228,24 +250,26 @@ else { /* Relies on modified 'args' not making it in to history */ - *p = '\0'; error (_("Unrecognized option '%s' to info macro command. " - "Try \"help info macro\"."), arg_start); + "Try \"help info macro\"."), args); } - arg_start = skip_spaces (p); + args = skip_spaces (args); } - name = arg_start; + name = skip_spaces (args); if (! name || ! *name) error (_("You must follow the `info macro' command with the name" " of the macro\n" "whose definition you want to see.")); - ms = default_macro_scope (); - cleanup_chain = make_cleanup (free_current_contents, &ms); - + if (! location_specified) + { + ms = default_macro_scope (); + cleanup_chain = make_cleanup (free_current_contents, &ms); + } + if (! ms) macro_inform_no_debuginfo (); else if (show_all_macros_named) @@ -525,10 +549,11 @@ add_cmd ("macro", no_class, info_macro_command, _("Show the definition of MACRO, and it's source location.\n\ -Usage: info macro [-a|-all] [--] MACRO\n\ +Usage: info macro [-a|-all] [-at LOCATION,] [--] MACRO\n\ Options: \n\ -a, --all Output all definitions of MACRO in the current compilation\ unit.\n\ + -at Use LOCATION rather than the current PC for selecting macros.\n\ -- Specify the end of arguments and the beginning of the MACRO."), &infolist); Index: gdb/doc/gdb.texinfo =================================================================== RCS file: /home/cvsroot/GDB/gdb/doc/gdb.texinfo,v retrieving revision 1.3 diff -u -r1.3 gdb.texinfo --- gdb/doc/gdb.texinfo 21 Aug 2014 14:07:17 -0000 1.3 +++ gdb/doc/gdb.texinfo 19 Nov 2014 20:52:00 -0000 @@ -11412,12 +11412,15 @@ @cindex macro definition, showing @cindex definition of a macro, showing @cindex macros, from debug info -@item info macro [-a|-all] [--] @var{macro} +@item info macro [-a|-all] [-at LOCATION,] [--] @var{macro} Show the current definition or all definitions of the named @var{macro}, and describe the source location or compiler command-line where that -definition was established. The optional double dash is to signify the end of -argument processing and the beginning of @var{macro} for non C-like macros where -the macro may begin with a hyphen. +definition was established. The optional double dash is to signify the +end of argument processing and the beginning of @var{macro} for non +C-like macros where the macro may begin with a hyphen. If the optional +@var{location} is specified, it is used to determine which definition, +if any, of the macro is in scope; otherwise, as before, it uses the +source and line asociated with the current program counter. @kindex info macros @item info macros @var{linespec} Index: gdb/testsuite/gdb.base/info-macros.exp =================================================================== RCS file: /home/cvsroot/GDB/gdb/testsuite/gdb.base/info-macros.exp,v retrieving revision 1.1.1.3 diff -u -r1.1.1.3 info-macros.exp --- gdb/testsuite/gdb.base/info-macros.exp 21 Aug 2014 13:17:27 -0000 1.1.1.3 +++ gdb/testsuite/gdb.base/info-macros.exp 19 Nov 2014 20:52:03 -0000 @@ -133,6 +133,30 @@ set testname "$test" gdb_test "$test" "$r1$r2$r3$r4" "$testname" +set test "info macro -at LOCATION, FOO" + +set r5 ".* has no definition .*\r\nat .*$srcfile:\[0-9\]+" +set testname "$test 1" +gdb_test "info macro -at info-macros.c:42, FOO" "$r1" "$testname" + +set testname "$test 2" +gdb_test "info macro -at info-macros.c:46, FOO" "$r2" "$testname" + +set testname "$test 3" +gdb_test "info macro -at info-macros.c:50, FOO" "$r3" "$testname" + +set testname "$test 4" +gdb_test "info macro -at info-macros.c:54, FOO" "$r2" "$testname" + +set testname "$test 5" +gdb_test "info macro -at info-macros.c:58, FOO" "$r1" "$testname" + +set testname "$test 6" +gdb_test "info macro -at info-macros.c:62, FOO" "$r5" "$testname" + +set testname "$test 7" +gdb_test "info macro -at info-macros.c:66, FOO" "$r4" "$testname" + set test "info macros" set r1 ".*#define FOO \"hello\"" set r2 ".*#define ONE"