m4-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dumpdef output destination


From: Eric Blake
Subject: Re: dumpdef output destination
Date: Tue, 23 Dec 2008 20:28:51 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.18) Gecko/20081105 Thunderbird/2.0.0.18 Mnenhy/0.7.5.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Gary V. Vaughan on 12/20/2008 10:15 PM:
>> Option 3 - add a flag to both 1.6 and 2.0 debugmode that controls where 
>> dumpdef
>> output goes
>> What letter should I consume as the
>> mnemonic for the ability to redirect dumpdef to stderr, remembering that
>> acdefilmpqstxv are already claimed?  Maybe 'o' for 'Output dumpdef to 
>> stderr'?
> 
> I concur on both counts: option 3 with 'o' for output.

Done as follows, on branch-1.6 and master (but not for branch-1.4).

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAklRrHMACgkQ84KuGfSFAYAp6QCeIRlgLEneYIEEaq8BAsILUEr6
zs0AnAt2q//QoAOH4LlS6yMgb8m/Ja2j
=rCbD
-----END PGP SIGNATURE-----
From df6bfeeaac6bdc1ef8e5406c6ac051af2c10d0d8 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Mon, 22 Dec 2008 05:45:40 -0700
Subject: [PATCH] Add debugmode(o) to control dumpdef output location.

* src/m4.h (DEBUG_TRACE_OUTPUT_DUMPDEF): New macro.
(DEBUG_TRACE_VERBOSE): Update.
* src/debug.c (debug_decode): Support new debug option.
* src/builtin.c (m4_dumpdef): When set, force dumpdef to stderr
rather than the debug file.
* src/m4.c (usage): Document it.
* doc/m4.texinfo (Debugmode, Dumpdef, Debugging options)
(Debugfile): Likewise.
* NEWS: Likewise.
Based on an autoconf bug report by Paolo Bonzini.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog      |   12 +++++++++++
 NEWS           |    8 ++++--
 doc/m4.texinfo |   61 +++++++++++++++++++++++++++++++++++++++++++++++--------
 src/builtin.c  |   20 ++++++++++--------
 src/debug.c    |    4 +++
 src/m4.c       |    1 +
 src/m4.h       |    4 ++-
 7 files changed, 88 insertions(+), 22 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4fe6d1f..ef11ce4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2008-12-23  Eric Blake  <address@hidden>
 
+       Add debugmode(o) to control dumpdef output location.
+       * src/m4.h (DEBUG_TRACE_OUTPUT_DUMPDEF): New macro.
+       (DEBUG_TRACE_VERBOSE): Update.
+       * src/debug.c (debug_decode): Support new debug option.
+       * src/builtin.c (m4_dumpdef): When set, force dumpdef to stderr
+       rather than the debug file.
+       * src/m4.c (usage): Document it.
+       * doc/m4.texinfo (Debugmode, Dumpdef, Debugging options)
+       (Debugfile): Likewise.
+       * NEWS: Likewise.
+       Based on an autoconf bug report by Paolo Bonzini.
+
        Make --debugfile argument optional.
        * src/builtin.c (m4_debugfile): Make error message consistent.
        * src/m4.c (long_options): Make the argument optional, to allow
diff --git a/NEWS b/NEWS
index 88f604d..45664c8 100644
--- a/NEWS
+++ b/NEWS
@@ -54,9 +54,11 @@ Foundation, Inc.
    `--debugmode' is added as an alias for `-d'.  The new flag `d' is added
    to control whether dereferencing an undefined macro causes a warning;
    this flag is enabled by default if neither `-d' nor `-E' are specified.
-   When given the empty string, the mode is treated as `+adeq' instead of
-   `aeq'.  Also, the position of `-d' with respect to files on the command
-   line is now significant.
+   The new flag `o' is added to control whether `dumpdef' outputs to stderr
+   or the current `debugfile' location.  When the command line option is
+   given the empty string, the mode is treated as `+adeq' instead of `aeq'.
+   Also, the position of `-d' with respect to files on the command line is
+   now significant.
 
 ** A new predefined text macro, `__m4_version__', expands to the unquoted
    version number of M4, if GNU extensions are enabled.  While you should
diff --git a/doc/m4.texinfo b/doc/m4.texinfo
index 0910d1a..9e5b07c 100644
--- a/doc/m4.texinfo
+++ b/doc/m4.texinfo
@@ -926,9 +926,11 @@ Debugging options
 @item address@hidden@address@hidden
 @itemx -o @var{file}
 @itemx address@hidden
-Redirect @code{dumpdef} output, debug messages, and trace output to the
+Redirect debug messages and trace output to the
 named @var{file}.  Warnings, error messages, and @code{errprint} output
-are still printed to standard error.  If these options are not used, or
+are still printed to standard error.  Output from @code{dumpdef} goes to
+this file when the debug level @code{o} is not set (@pxref{Debugmode}).
+If these options are not used, or
 if @var{file} is unspecified (only possible for @option{--debugfile}),
 debug output goes to standard error; if @var{file} is the empty string,
 debug output is discarded.  @xref{Debugfile}, for more details.  The
@@ -938,6 +940,7 @@ Debugging options
 @acronym{GNU} tools; for now they are silently accepted as synonyms of
 @option{--debugfile} and only recognized once, but in a future version
 of M4, using them will cause a warning to be issued.
address@hidden FIXME make them warn in m4 1.6
 
 @ignore
 @comment not worth including in the manual, but provides a good test
@@ -3993,12 +3996,13 @@ Dumpdef
 @code{dumpdef}:
 
 @deffn Builtin dumpdef (@address@hidden)
-Accepts any number of arguments.  If called without any arguments,
-it displays the definitions of all known names, otherwise it displays
-the definitions of each @var{name} given.  The output is printed to the
-current debug file (usually standard error), and is sorted by name.  If
-a @var{name} is undefined, the @samp{d} debug level controls whether a
-warning is issued (@pxref{Debugmode}).
+Accepts any number of arguments.  If called without any arguments, it
+displays the definitions of all known names, otherwise it displays the
+definitions of each @var{name} given, sorted by name.  If a @var{name}
+is undefined, the @samp{d} debug level controls whether a warning is
+issued (@pxref{Debugmode}).  Likewise, the @samp{o} debug level controls
+whether the output is issued to standard error or the current debug
+file (@pxref{Debugfile}).
 
 The expansion of @code{dumpdef} is void.
 @end deffn
@@ -4309,6 +4313,11 @@ Debugmode
 In debug and trace output, include the current input line number in the
 output line.
 
address@hidden o
+Output @code{dumpdef} data to standard error instead of the current
+debug file.  This can be useful when post-processing trace output, where
+interleaving dumpdef and trace output can cause ambiguities.
+
 @item p
 In debug output, print a message when a named file is found through the
 path search mechanism (@pxref{Search Path}), giving the actual file name
@@ -4440,7 +4449,9 @@ Debugfile
 Sends all further debug and trace output to @var{file}, opened in append
 mode.  If @var{file} is the empty string, debug and trace output are
 discarded.  If @code{debugfile} is called without any arguments, debug
-and trace output are sent to standard error.  This does not affect
+and trace output are sent to standard error.  Output from @code{dumpdef}
+is sent to this file if the debug level @code{o} is not set
+(@pxref{Debugmode}).  This does not affect
 warnings, error messages, or @code{errprint} output, which are
 always sent to standard error.  If @var{file} cannot be opened, the
 current debug file is unchanged, and an error is issued.
@@ -4468,6 +4479,38 @@ Debugfile
 @result{}0
 @end example
 
+Sometimes it is useful to post-process trace output, even though there
+is no standardized format for trace output.  In this situation, forcing
address@hidden to output to standard error instead of the default of the
+current debug file will avoid any ambiguities between the two types of
+output; it also allows debugging via @code{dumpdef} when debug output is
+discarded.
+
address@hidden
+$ @kbd{m4 -d}
+traceon(`divnum')
address@hidden
+divnum
address@hidden: -1- divnum -> `0'
address@hidden
+dumpdef(`divnum')
address@hidden:@tabchar{}<divnum>
address@hidden
+debugfile(`')
address@hidden
+divnum
address@hidden
+dumpdef(`divnum')
address@hidden
+debugmode(`+o')
address@hidden
+divnum
address@hidden
+dumpdef(`divnum')
address@hidden:@tabchar{}<divnum>
address@hidden
address@hidden example
+
 @node Input Control
 @chapter Input control
 
diff --git a/src/builtin.c b/src/builtin.c
index e9e08da..33ef9e5 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -885,9 +885,11 @@ m4_dumpdef (struct obstack *obs, int argc, macro_arguments 
*argv)
   int i;
   struct dump_symbol_data data;
   const builtin *bp;
+  FILE *output = (debug_level & DEBUG_TRACE_OUTPUT_DUMPDEF) ? stderr : debug;
+
 
   /* If there's no debug stream to dump to, skip all of this work.  */
-  if (!debug)
+  if (!output)
     return;
 
   data.obs = obs;
@@ -925,19 +927,19 @@ m4_dumpdef (struct obstack *obs, int argc, 
macro_arguments *argv)
     {
       /* TODO - add debugmode(b) option to control quoting style?  */
       fwrite (SYMBOL_NAME (data.base[0]), 1, SYMBOL_NAME_LEN (data.base[0]),
-             debug);
-      fputc (':', debug);
-      fputc ('\t', debug);
+             output);
+      fputc (':', output);
+      fputc ('\t', output);
 
       switch (SYMBOL_TYPE (data.base[0]))
        {
        case TOKEN_TEXT:
          if (debug_level & DEBUG_TRACE_QUOTE)
-           fwrite (curr_quote.str1, 1, curr_quote.len1, debug);
+           fwrite (curr_quote.str1, 1, curr_quote.len1, output);
          fwrite (SYMBOL_TEXT (data.base[0]), 1,
-                 SYMBOL_TEXT_LEN (data.base[0]), debug);
+                 SYMBOL_TEXT_LEN (data.base[0]), output);
          if (debug_level & DEBUG_TRACE_QUOTE)
-           fwrite (curr_quote.str2, 1, curr_quote.len2, debug);
+           fwrite (curr_quote.str2, 1, curr_quote.len2, output);
          break;
 
        case TOKEN_FUNC:
@@ -947,7 +949,7 @@ m4_dumpdef (struct obstack *obs, int argc, macro_arguments 
*argv)
              assert (!"m4_dumpdef");
              abort ();
            }
-         xfprintf (debug, "<%s>", bp->name);
+         xfprintf (output, "<%s>", bp->name);
          break;
 
        default:
@@ -955,7 +957,7 @@ m4_dumpdef (struct obstack *obs, int argc, macro_arguments 
*argv)
          abort ();
          break;
        }
-      fputc ('\n', debug);
+      fputc ('\n', output);
     }
 }
 
diff --git a/src/debug.c b/src/debug.c
index babaf87..b97fca3 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -109,6 +109,10 @@ debug_decode (const char *opts)
              level |= DEBUG_TRACE_DEREF;
              break;
 
+           case 'o':
+             level |= DEBUG_TRACE_OUTPUT_DUMPDEF;
+             break;
+
            case 'V':
              level |= DEBUG_TRACE_VERBOSE;
              break;
diff --git a/src/m4.c b/src/m4.c
index 06b200c..1206761 100644
--- a/src/m4.c
+++ b/src/m4.c
@@ -275,6 +275,7 @@ FLAGS is any of:\n\
   l   include current input line number in trace and debug\n\
 "), stdout);
       fputs (_("\
+  o   output dumpdef to stderr rather than debug file\n\
   p   show results of path searches in debug\n\
   q   quote values in dumpdef and trace, useful with a or e\n\
   t   trace all macro calls, regardless of per-macro traceon state\n\
diff --git a/src/m4.h b/src/m4.h
index 76c697b..0611db4 100644
--- a/src/m4.h
+++ b/src/m4.h
@@ -196,9 +196,11 @@ extern FILE *debug;
 #define DEBUG_TRACE_CALLID 0x200
 /* d: warn if dereferencing undefined macro */
 #define DEBUG_TRACE_DEREF 0x400
+/* o: output dumpdef to stderr, not debug file */
+#define DEBUG_TRACE_OUTPUT_DUMPDEF 0x800
 
 /* V: very verbose --  print everything */
-#define DEBUG_TRACE_VERBOSE 0x7FF
+#define DEBUG_TRACE_VERBOSE 0xFFF
 /* default flags -- equiv: adeq */
 #define DEBUG_TRACE_DEFAULT 0x407
 
-- 
1.6.0.4


reply via email to

[Prev in Thread] Current Thread [Next in Thread]