From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1973 invoked by alias); 9 Mar 2009 00:17:29 -0000 Received: (qmail 1958 invoked by uid 22791); 9 Mar 2009 00:17:28 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_37,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 09 Mar 2009 00:17:21 +0000 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n290EU0N030184; Sun, 8 Mar 2009 20:14:32 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n290EU8c031731; Sun, 8 Mar 2009 20:14:30 -0400 Received: from host0.dyn.jankratochvil.net (sebastian-int.corp.redhat.com [172.16.52.221]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n290EQZR002651; Sun, 8 Mar 2009 20:14:29 -0400 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.14.3/8.14.3) with ESMTP id n290ENID028443; Mon, 9 Mar 2009 01:14:24 +0100 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.14.3/8.14.2/Submit) id n290EM26028438; Mon, 9 Mar 2009 01:14:22 +0100 Date: Mon, 09 Mar 2009 00:17:00 -0000 From: Jan Kratochvil To: Eli Zaretskii Cc: gdb-patches@sourceware.org, Joel Brobecker Subject: [patch] Better display command-line macros + doc addon [Re: [patch] doc: Document macros defined from command-line] Message-ID: <20090309001422.GA29150@host0.dyn.jankratochvil.net> References: <20090306204631.GA27092@host0.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) X-IsSubscribed: yes 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 X-SW-Source: 2009-03/txt/msg00104.txt.bz2 Hi, this patch is unrelated to the discussed compiler/DWARF changes. http://sourceware.org/ml/gdb-patches/2009-02/threads.html#00397 http://sourceware.org/ml/gdb-patches/2009-03/threads.html#00026 Just moved the testcase from it into this patch. On Sat, 07 Mar 2009 10:16:10 +0100, Eli Zaretskii wrote: > . Tell about the way of defining macros before describing what GDB > does in that case. > . Don't qualify the -Dfoo=bar feature by "Unix", since on non-Unix > platforms GDB supports only GCC-produced debug info. > . Use @var for meta-syntactic variables that stand for something > else. Understood, used your text. > > +Defined at /home/jimb/gdb/macros/play/sample.c:0 > > +#define __STDC__ 1 > > Should we perhaps show "-D__STDC__=1" here? Good idea, a code patch attached. > Also, perhaps add a short notice of this feature at the beginning of > the section, where "info macro" is described. Made there the change. Thanks, Jan gdb/ 2009-03-09 Jan Kratochvil * macrocmd.c (info_macro_command): Print -Dname=value if LINE is zero. gdb/doc/ 2009-03-09 Jan Kratochvil * gdb.texinfo (Macros): Note command-line for `info macro'. Append a new part on command-line defined macros. gdb/testsuite/ 2009-03-09 Jan Kratochvil * gdb.base/macscp.exp: New `options' parameter `-DFROM_COMMANDLINE'. (info_macro): Remova `decimal' declaration. New variable `nonzero'. Replace all uses of `decimal' by `nonzero'. (info macro FROM_COMMANDLINE): New test. --- gdb/macrocmd.c 3 Jan 2009 05:57:52 -0000 1.19 +++ gdb/macrocmd.c 9 Mar 2009 00:05:45 -0000 @@ -158,7 +158,10 @@ info_macro_command (char *name, int from fprintf_filtered (gdb_stdout, "Defined at "); show_pp_source_pos (gdb_stdout, file, line); - fprintf_filtered (gdb_stdout, "#define %s", name); + if (line != 0) + fprintf_filtered (gdb_stdout, "#define %s", name); + else + fprintf_filtered (gdb_stdout, "-D%s", name); if (d->kind == macro_function_like) { int i; @@ -172,7 +175,10 @@ info_macro_command (char *name, int from } fputs_filtered (")", gdb_stdout); } - fprintf_filtered (gdb_stdout, " %s\n", d->replacement); + if (line != 0) + fprintf_filtered (gdb_stdout, " %s\n", d->replacement); + else + fprintf_filtered (gdb_stdout, "=%s\n", d->replacement); } else { --- gdb/doc/gdb.texinfo 5 Mar 2009 23:11:11 -0000 1.561 +++ gdb/doc/gdb.texinfo 9 Mar 2009 00:05:56 -0000 @@ -8341,7 +8341,7 @@ can be any string of tokens. @cindex definition, showing a macro's @item info macro @var{macro} Show the definition of the macro named @var{macro}, and describe the -source location where that definition was established. +source location or compiler command-line where that definition was established. @kindex macro define @cindex user-defined macros @@ -8506,6 +8506,18 @@ $2 = 0 (@value{GDBP}) @end smallexample +In addition to source files, macros can be defined on the compilation command +line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in +such a way, @value{GDBN} displays the location of their definition as line zero +of the source file submitted to the compiler. + +@smallexample +(@value{GDBP}) info macro __STDC__ +Defined at /home/jimb/gdb/macros/play/sample.c:0 +-D__STDC__=1 +(@value{GDBP}) +@end smallexample + @node Tracepoints @chapter Tracepoints --- gdb/testsuite/gdb.base/macscp.exp 18 Feb 2009 22:24:37 -0000 1.20 +++ gdb/testsuite/gdb.base/macscp.exp 9 Mar 2009 00:05:57 -0000 @@ -26,7 +26,7 @@ set testfile "macscp" set objfile ${objdir}/${subdir}/${testfile}.o set binfile ${objdir}/${subdir}/${testfile} -set options { debug } +set options { debug additional_flags=-DFROM_COMMANDLINE=ARG} get_compiler_info ${binfile} if [test_compiler_info gcc*] { @@ -67,19 +67,22 @@ gdb_load ${binfile} proc info_macro {macro} { global gdb_prompt - global decimal set filepat {macscp[0-9]+\.[ch]} set definition {} set location {} + # Line number zero is set for macros defined from the compiler command-line. + # Such macros are not being tested by this function. + set nonzero {[1-9][0-9]*} + send_gdb "info macro ${macro}\n" set debug_me 0 if {$debug_me} {exp_internal 1} gdb_expect { - -re "Defined at \[^\r\n\]*(${filepat}):${decimal}\[\r\n\]" { + -re "Defined at \[^\r\n\]*(${filepat}):${nonzero}\[\r\n\]" { # `location' and `definition' should be empty when we see # this message. if {[llength $location] == 0 && [llength $definition] == 0} { @@ -101,7 +104,7 @@ proc info_macro {macro} { set definition {} } } - -re "^\[\r\n\]* included at \[^\r\n\]*(${filepat}):${decimal}\[\r\n\]" { + -re "^\[\r\n\]* included at \[^\r\n\]*(${filepat}):${nonzero}\[\r\n\]" { # `location' should *not* be empty when we see this # message. It should have recorded at least the initial # `Defined at ' message (for definitions) or ` at' message @@ -114,7 +117,7 @@ proc info_macro {macro} { set definition {} } } - -re "^\[\r\n\]*at \[^\r\n\]*(${filepat}):${decimal}\[\r\n\]" { + -re "^\[\r\n\]*at \[^\r\n\]*(${filepat}):${nonzero}\[\r\n\]" { # This appears after a `has no definition' message. # `location' should be empty when we see it. if {[string compare $definition undefined] == 0 \ @@ -205,6 +208,11 @@ list_and_check_macro macscp2_2 WHERE {ma list_and_check_macro macscp3_2 WHERE {macscp3.h macscp1.c {before macscp3_2}} +# Assuming the current position inside program by `list' from above. +gdb_test "info macro FROM_COMMANDLINE" \ + "Defined at \[^\r\n\]*:0\r\n-DFROM_COMMANDLINE=ARG" + + # Although GDB's macro table structures distinguish between multiple # #inclusions of the same file, GDB's other structures don't. So the # `list' command here doesn't reliably select one #inclusion or the