summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2008-12-23 14:40:57 -0700
committerEric Blake <ebb9@byu.net>2008-12-23 14:40:57 -0700
commit268aa74a4cd66160d4c589572294e50f455c2069 (patch)
treeed560de5f6814e4b88600cd17ef4d546c3c8b1c9
parent180376508cd4345812278d896024a3f3cd5746d1 (diff)
downloadm4-268aa74a4cd66160d4c589572294e50f455c2069.tar.gz
Add debugmode(o) to control dumpdef output location.
* m4/m4module.h (M4_DEBUG_TRACE_OUTPUT_DUMPDEF): New enumerator. (M4_DEBUG_TRACE_VERBOSE): Update. * m4/debug.c (m4_debug_decode): Support new debug option. * src/freeze.c (produce_debugmode_state): Likewise. * modules/m4.c (dumpdef): When set, force dumpdef to stderr rather than the debug file. * src/main.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 <ebb9@byu.net> (cherry picked from commit df6bfeeaac6bdc1ef8e5406c6ac051af2c10d0d8)
-rw-r--r--ChangeLog13
-rw-r--r--NEWS12
-rw-r--r--doc/m4.texinfo72
-rw-r--r--m4/debug.c4
-rw-r--r--m4/m4module.h4
-rw-r--r--modules/m4.c6
-rw-r--r--src/freeze.c4
-rw-r--r--src/main.c1
8 files changed, 90 insertions, 26 deletions
diff --git a/ChangeLog b/ChangeLog
index c042e0c7..43213844 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2008-12-23 Eric Blake <ebb9@byu.net>
+ Add debugmode(o) to control dumpdef output location.
+ * m4/m4module.h (M4_DEBUG_TRACE_OUTPUT_DUMPDEF): New enumerator.
+ (M4_DEBUG_TRACE_VERBOSE): Update.
+ * m4/debug.c (m4_debug_decode): Support new debug option.
+ * src/freeze.c (produce_debugmode_state): Likewise.
+ * modules/m4.c (dumpdef): When set, force dumpdef to stderr rather
+ than the debug file.
+ * src/main.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/main.c (long_options): Make the argument optional, to allow
setting debug file back to stderr.
diff --git a/NEWS b/NEWS
index 2e9a8c24..4180190d 100644
--- a/NEWS
+++ b/NEWS
@@ -157,10 +157,6 @@ promoted to 2.0.
`dumpdef'. The `c' flag has been updated to add information to the
first line to show the definition of the macro being expanded.
-*** The `dumpdef' builtin now always outputs to standard error, rather than
- the debug file specified by the `--debugfile' option or `debugfile'
- macro.
-
*** The `eval' and `mpeval' builtins now support the following new
operators: `>>>', `\', `?:', and `,'.
@@ -253,9 +249,11 @@ promoted to 2.0.
`--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 121300f6..3d039f6d 100644
--- a/doc/m4.texinfo
+++ b/doc/m4.texinfo
@@ -1027,9 +1027,11 @@ len(`123')
@item --debugfile@r{[}=@var{file}@r{]}
@itemx -o @var{file}
@itemx --error-output=@var{file}
-Redirect debug and trace output to the named @var{file}. Warnings,
-error messages, and the output of @code{errprint} and @code{dumpdef},
-are still printed to standard error. If these options are not used, or
+Redirect debug messages and trace output to the
+named @var{file}. Warnings, error messages, and @code{errprint} output
+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
@@ -4074,14 +4076,13 @@ If you want to see what a name expands into, you can use the builtin
@code{dumpdef}:
@deffn {Builtin (m4)} dumpdef (@ovar{name@dots{}})
-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
-directly to standard error, independently of the @option{--debugfile}
-option (@pxref{Debugging options, , Invoking m4}), or @code{debugfile} macro.
-The output 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
@@ -4491,6 +4492,11 @@ In debug output, print a message each time a module is manipulated
and in dumpdef output, follow builtin macros with their module name,
surrounded by braces (@samp{@{@}}).
+@item 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
@@ -4691,11 +4697,13 @@ Invoking m4}), or with the builtin macro @code{debugfile}:
@deffn {Builtin (gnu)} debugfile (@ovar{file})
Send 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 warnings, error messages, or @code{errprint} and @code{dumpdef}
-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.
+discarded. If @code{debugfile} is called without any arguments, debug
+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.
When the @option{--safer} option (@pxref{Operation modes, , Invoking
m4}) is in effect, @var{file} must be empty or omitted, since otherwise
@@ -4753,6 +4761,38 @@ undivert(`trace')dnl
@result{}m4trace:3: -1- foo -> `bar'
@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
+@code{dumpdef} 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.
+
+@example
+$ @kbd{m4 -d}
+traceon(`divnum')
+@result{}
+divnum
+@error{}m4trace: -1- divnum -> `0'
+@result{}0
+dumpdef(`divnum')
+@error{}divnum:@tabchar{}<divnum>
+@result{}
+debugfile(`')
+@result{}
+divnum
+@result{}0
+dumpdef(`divnum')
+@result{}
+debugmode(`+o')
+@result{}
+divnum
+@result{}0
+dumpdef(`divnum')
+@error{}divnum:@tabchar{}<divnum>
+@result{}
+@end example
+
@node Input Control
@chapter Input control
diff --git a/m4/debug.c b/m4/debug.c
index f4005ebf..f5cb4e25 100644
--- a/m4/debug.c
+++ b/m4/debug.c
@@ -101,6 +101,10 @@ m4_debug_decode (m4 *context, const char *opts)
level |= M4_DEBUG_TRACE_DEREF;
break;
+ case 'o':
+ level |= M4_DEBUG_TRACE_OUTPUT_DUMPDEF;
+ break;
+
case 'V':
level |= M4_DEBUG_TRACE_VERBOSE;
break;
diff --git a/m4/m4module.h b/m4/m4module.h
index 1f3b7bcf..d5ad5135 100644
--- a/m4/m4module.h
+++ b/m4/m4module.h
@@ -404,9 +404,11 @@ enum {
M4_DEBUG_TRACE_STACK = (1 << 11),
/* d: warn if dereferencing undefined macro */
M4_DEBUG_TRACE_DEREF = (1 << 12),
+ /* o: output dumpdef to stderr, not debug file */
+ M4_DEBUG_TRACE_OUTPUT_DUMPDEF = (1 << 13),
/* V: very verbose -- print everything */
- M4_DEBUG_TRACE_VERBOSE = ((1 << 13) - 1)
+ M4_DEBUG_TRACE_VERBOSE = ((1 << 14) - 1)
};
/* initial flags, used if no -d or -E -- equiv: d */
diff --git a/modules/m4.c b/modules/m4.c
index f78a177d..f578261a 100644
--- a/modules/m4.c
+++ b/modules/m4.c
@@ -341,7 +341,11 @@ M4BUILTIN_HANDLER (dumpdef)
bool stack = m4_is_debug_bit (context, M4_DEBUG_TRACE_STACK);
size_t arg_length = m4_get_max_debug_arg_length_opt (context);
bool module = m4_is_debug_bit (context, M4_DEBUG_TRACE_MODULE);
+ FILE *output = (m4_is_debug_bit (context, M4_DEBUG_TRACE_OUTPUT_DUMPDEF)
+ ? stderr : m4_get_debug_file (context));
+ if (!output)
+ return;
if (m4_is_debug_bit (context, M4_DEBUG_TRACE_QUOTE))
quotes = m4_get_syntax_quotes (M4SYNTAX);
data.obs = m4_arg_scratch (context);
@@ -365,7 +369,7 @@ M4BUILTIN_HANDLER (dumpdef)
obstack_1grow (obs, '\n');
len = obstack_object_size (obs);
value = (char *) obstack_finish (obs);
- fwrite (value, 1, len, stderr);
+ fwrite (value, 1, len, output);
obstack_free (obs, value);
}
}
diff --git a/src/freeze.c b/src/freeze.c
index 3008f272..0394d4c2 100644
--- a/src/freeze.c
+++ b/src/freeze.c
@@ -111,7 +111,7 @@ static void
produce_debugmode_state (FILE *file, int flags)
{
/* This code tracks the number of bits in M4_DEBUG_TRACE_VERBOSE. */
- char str[14];
+ char str[15];
int offset = 0;
verify ((1 << (sizeof str - 1)) - 1 == M4_DEBUG_TRACE_VERBOSE);
if (flags & M4_DEBUG_TRACE_ARGS)
@@ -140,6 +140,8 @@ produce_debugmode_state (FILE *file, int flags)
str[offset++] = 's';
if (flags & M4_DEBUG_TRACE_DEREF)
str[offset++] = 'd';
+ if (flags & M4_DEBUG_TRACE_OUTPUT_DUMPDEF)
+ str[offset++] = 'o';
str[offset] = '\0';
if (offset)
xfprintf (file, "d%d\n%s\n", offset, str);
diff --git a/src/main.c b/src/main.c
index f8ab98ea..c04c5491 100644
--- a/src/main.c
+++ b/src/main.c
@@ -170,6 +170,7 @@ FLAGS is any of:\n\
"), stdout);
fputs (_("\
m show module information in trace, debug, and dumpdef\n\
+ 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\
s show full stack of pushdef values in dumpdef\n\