[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: dumpdef a pushdef'd stack
From: |
Eric Blake |
Subject: |
Re: dumpdef a pushdef'd stack |
Date: |
Fri, 06 Oct 2006 09:22:58 -0600 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Thunderbird/1.5.0.7 Mnenhy/0.7.4.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi Gary,
According to Gary V. Vaughan on 10/5/2006 2:09 AM:
> Hi Eric,
>
> On 27 Sep 2006, at 14:20, Eric Blake wrote:
>>> [[...]] now that --arglength can affect dumpdef output as well as trace
>>> output, we should be able to tweak it on the fly. I'm thinking a macro
>>> named debuglen is the best fit here (fitting in with the naming of other
>>> debug* builtins), but I could also be persuaded to name the macro
>>> arglength to match the command-line option. Or maybe name it debuglen,
>>> deprecate --arglength (as that name isn't quite descriptive of what is
>>> really being length-limited), and introduce --debuglen as a synonym to
>>> -l.
>>> Thoughts?
>
> I think the latter is more in keeping with my notional 2.0 theme of
> clean and complete integration between command line options and run
> time control of the same.
Done (well, the int parsing of m4_numeric_arg in macros still needs an
overhaul to use xstrtol/xstrtoumax, but that is a later patch because it
affects more than just debuglen).
2006-10-06 Eric Blake <address@hidden>
* m4/utility.c (m4_numeric_arg): Merge from branch.
* modules/gnu.c (debuglen): New builtin.
* src/main.c (usage, ARGLENGTH_OPTION, long_options, main):
Rename --arglength to --debuglen.
* tests/options.at (--arglength): Rename to --debuglen.
(deprecated options): Augment test.
* doc/m4.texinfo (Invoking m4): Document the name change.
(Debugmode): Rename from Debug Levels.
(Debugfile): Rename from Debug Output.
(Debuglen): New node.
* NEWS: Document these changes.
- --
Life is short - so eat dessert first!
Eric Blake address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFFJnTS84KuGfSFAYARAuWaAJ4vWY7kWdnHC9lCmDd0g59vU8cedgCg0O75
uZAC90slvjlEYB3Kt5PdD7M=
=DJrA
-----END PGP SIGNATURE-----
Index: NEWS
===================================================================
RCS file: /sources/m4/m4/NEWS,v
retrieving revision 1.24
diff -u -p -r1.24 NEWS
--- NEWS 29 Sep 2006 18:20:12 -0000 1.24
+++ NEWS 6 Oct 2006 15:19:53 -0000
@@ -95,9 +95,14 @@ promoted to 2.0.
either be blind (ie. be unrecognized without arguments), or begin with
the prefix `m4' or `__'.
-* The `-l'/`--arglength' command line argument now affects dumpdef
- output as well as trace output. Also, it now performs argument
- validation and accepts an optional multiplier suffix.
+* A new builtin `debuglen' is introduced which allows runtime setting
+ of debug output length, previously controlled only by the `-l' command
+ line argument. A new command line argument `--debuglen' matches the
+ spelling of the new macro, and the old spelling `--arglength' now issues
+ a warning that it might be withdrawn in the future. Additionally,
+ whether using the new macro or the command line argument, the length
+ limitation now affects dumpdef output as well as trace output, undergoes
+ argument validation, and accepts an optional multiplier suffix.
* The `-L'/`--nesting-limit' command line option can now be set to 0
to remove the default limit. However, it is still possible that heavily
Index: doc/m4.texinfo
===================================================================
RCS file: /sources/m4/m4/doc/m4.texinfo,v
retrieving revision 1.58
diff -u -p -r1.58 m4.texinfo
--- doc/m4.texinfo 4 Oct 2006 03:57:00 -0000 1.58
+++ doc/m4.texinfo 6 Oct 2006 15:19:54 -0000
@@ -191,8 +191,9 @@ How to debug macros and input
* Dumpdef:: Displaying macro definitions
* Trace:: Tracing macro calls
-* Debug Levels:: Controlling debugging output
-* Debug Output:: Saving debugging output
+* Debugmode:: Controlling debugging options
+* Debuglen:: Limiting debug output
+* Debugfile:: Saving debugging output
Input control
@@ -496,7 +497,7 @@ format and meaning of @var{RESYNTAX-SPEC
@item --safer
Cripple the builtins @code{maketemp} (@pxref{Maketemp}),
address@hidden (@pxref{Debug Output}), @code{syscmd} (@pxref{Syscmd}),
address@hidden (@pxref{Debugfile}), @code{syscmd} (@pxref{Syscmd}),
and @code{esyscmd} (@pxref{Esyscmd}), since they can perform potentially
unsafe actions. An attempt to use these macros will result in an error.
This option is intended to make it safer to preprocess an input file of
@@ -679,7 +680,7 @@ scripts.
@itemx address@hidden@address@hidden
Set the debug-level according to the flags @var{FLAGS}. The debug-level
controls the format and amount of information presented by the debugging
-functions. @xref{Debug Levels}, for more details on the format and
+functions. @xref{Debugmode}, for more details on the format and
meaning of @var{FLAGS}. If omitted, @var{FLAGS} defaults to
@samp{aeq}. When the option is presented multiple times, if later
@var{FLAGS} starts with @samp{-} or @samp{+}, they are cumulative,
@@ -692,22 +693,25 @@ Redirect debug and trace output to the n
error messages, and the output of @code{errprint} and @code{dumpdef},
are still printed to standard error. If this option is not given, debug
output goes to standard error; if @var{FILE} is the empty string, debug
-output is discarded. @xref{Debug Output}, for more details. The
+output is discarded. @xref{Debugfile}, for more details. The
spellings @option{-o} and @option{--error-output} are misleading and
inconsistent with other @acronym{GNU} tools; using those spellings will
evoke a warning, and they may be withdrawn or change semantics in a
future release.
@item -l @var{NUM}
address@hidden address@hidden
@itemx address@hidden
Restrict the size of the output generated by macro tracing or by
@code{dumpdef} to @var{NUM} characters per string. If unspecified or
-zero, output is unlimited. @xref{Debug Levels}, for more details.
address@hidden can have an optional scaling suffix.
address@hidden FIXME - should we add a debuglen macro that can alter this
address@hidden setting on the fly? Also, should we add an option that
address@hidden controls whether output strings are sanitized with escape
address@hidden sequences, so that dumpdef is truly one line per macro?
+zero, output is unlimited. @xref{Debuglen}, for more details.
address@hidden can have an optional scaling suffix. The spelling
address@hidden is deprecated, since it does not match the
address@hidden macro; using it will evoke a warning, and it may be
+withdrawn in a future release.
address@hidden FIXME - Should we add an option that controls whether output
address@hidden strings are sanitized with escape sequences, so that dumpdef is
address@hidden truly one line per macro?
@comment FIXME - see comment on --nesting-limit about NUM.
@item -t @var{NAME}
@@ -2596,8 +2600,9 @@ Fortunately, there is support for macro
@menu
* Dumpdef:: Displaying macro definitions
* Trace:: Tracing macro calls
-* Debug Levels:: Controlling debugging output
-* Debug Output:: Saving debugging output
+* Debugmode:: Controlling debugging options
+* Debuglen:: Limiting debug output
+* Debugfile:: Saving debugging output
@end menu
@node Dumpdef
@@ -2650,12 +2655,12 @@ f(popdef(`f')dumpdef(`f'))
@result{}f1
@end example
address@hidden Levels}, for information on how the @samp{m}, @samp{q}, and
address@hidden, for information on how the @samp{m}, @samp{q}, and
@samp{s} flags affect the details of the display. Remember, the
@samp{q} flag is implied when the @option{--debug} option (@option{-d},
@pxref{Invoking m4}) is used in the command line without arguments.
-Also, the @option{--arglength} option (@option{-l}) can affect output,
-by truncating longer strings.
+Also, @code{--debuglen} (@pxref{Debuglen}) can affect output, by
+truncating longer strings.
@comment options: -ds -l3
@example
@@ -2691,7 +2696,7 @@ It is possible to trace macro calls and
@deffnx {Builtin (m4)} traceoff (@address@hidden)
When called without any arguments, @code{traceon} and @code{traceoff}
will turn tracing on and off, respectively, for all macros, identical to
-using the @samp{t} flag of @code{debugmode} (@pxref{Debug Levels}).
+using the @samp{t} flag of @code{debugmode} (@pxref{Debugmode}).
When called with arguments, only the named macros are affected, whether
or not they are currently defined. A macro's expansion will be traced
if global tracing is on, or if the individual macro tracing flag is
@@ -2704,8 +2709,8 @@ The expansion of @code{traceon} and @cod
Whenever a traced macro is called and the arguments have been collected,
the call is displayed. If the expansion of the macro call is not void,
the expansion can be displayed after the call. The output is printed
-to the current debug file (defaulting to standard error, @pxref{Debug
-Output}).
+to the current debug file (defaulting to standard error,
address@hidden).
@example
$ @kbd{m4 -d}
@@ -2882,11 +2887,11 @@ a b
@result{}1 2
@end example
address@hidden Levels}, for information on controlling the details of the
address@hidden, for information on controlling the details of the
display.
address@hidden Debug Levels
address@hidden Controlling debugging output
address@hidden Debugmode
address@hidden Controlling debugging options
@cindex controlling debugging output
@cindex debugging output, controlling
@@ -2906,8 +2911,7 @@ following:
@item a
In trace output, show the actual arguments that were collected before
invoking the macro. Arguments are subject to length truncation
-specified by the command line option @option{--arglength}
-(@option{-l}).
+specified by @code{debuglen} (@pxref{Debuglen}).
@item c
In trace output, show several trace lines for each macro call. A line
@@ -2917,8 +2921,8 @@ after the call has completed.
@item e
In trace output, show the expansion of each macro call, if it is not
-void. The expansion is subject to length truncation specified by the
-command line option @option{--arglength} (@option{-l}).
+void. The expansion is subject to length truncation specified by
address@hidden (@pxref{Debuglen}).
@item f
In debug and trace output, include the name of the current input file in
@@ -2978,26 +2982,6 @@ If no flags are specified with the @opti
@samp{aeq}. Many examples in this manual show their output using
default flags.
address@hidden FIXME - add a new macro debuglen (or some other spelling) that
address@hidden allows changing the -l/--arglength option on the fly? If so,
address@hidden add a new node here describing it.
-Also, the option @option{--arglength} (@option{-l}) can affect trace
-and dumpdef output. If the option is specified to a non-zero value,
-then strings longer than that length are truncated, and @samp{...}
-included in the output to show that truncation took place. This allows
-reducing the size of the debug output in the face of arbitrarily long
-macro arguments or definitions.
-
address@hidden options: -l4 -techo
address@hidden
-$ @kbd{m4 -d -l 4 -t echo}
-define(`echo', `$@')
address@hidden
-echo(`long string')
address@hidden: -1- echo(`long...') -> ``lon...'
address@hidden string
address@hidden example
-
@cindex @acronym{GNU} extensions
There is a builtin macro @code{debugmode}, which allows on-the-fly control of
the debugging output format:
@@ -3034,7 +3018,64 @@ foo
@result{}FOO
@end example
address@hidden Debug Output
address@hidden Debuglen
address@hidden Limiting debug output
+
address@hidden @acronym{GNU} extensions
address@hidden arglength
address@hidden debuglen
address@hidden limiting trace output length
address@hidden trace output, limiting length
address@hidden dumpdef output, limiting length
+When debugging, sometimes it is desirable to reduce the clutter of
+arbitrary-length strings, because the prefix carries enough information
+to understand the issues. The builtin macro @code{debuglen}, along with
+the command line option counterpart @option{--debuglen} (or @option{-l},
address@hidden m4}), allow on-the-fly control of debugging string
+lengths:
+
address@hidden {Builtin (gnu)} debuglen (@var{len})
+The argument @var{len} is an integer that controls how much of
+arbitrary-length strings should be output during trace and dumpdef
+output. If specified to a non-zero value, then strings longer than that
+length are truncated, and @samp{...} included in the output to show that
+truncation took place. A warning is issued if @var{len} cannot be
+parsed as an integer.
address@hidden FIXME - make this understand an optional suffix, similar to how
address@hidden --debuglen does. Also, we need a section documenting scaling
address@hidden suffixes.
address@hidden FIXME - should we allow len to be `?', meaning expand to the
address@hidden current value?
+
+The macro @code{debuglen} is recognized only with parameters.
address@hidden deffn
+
address@hidden options: -l4 -techo
address@hidden
+$ @kbd{m4 -d -l 4 -t echo}
+debuglen(`oops')
address@hidden:stdin:1: Warning: debuglen: non-numeric argument `oops'
address@hidden
+define(`echo', `$@')
address@hidden
+echo(`long string')
address@hidden: -1- echo(`long...') -> ``lon...'
address@hidden string
+debuglen
address@hidden
+debuglen(`0')
address@hidden
+echo(`long string')
address@hidden: -1- echo(`long string') -> ``long string''
address@hidden string
+debuglen(`12')
address@hidden
+echo(`long string')
address@hidden: -1- echo(`long string') -> ``long string...'
address@hidden string
address@hidden example
+
address@hidden Debugfile
@section Saving debugging output
@cindex saving debugging output
@@ -3860,7 +3901,7 @@ the @env{M4PATH} environment variable is
a colon-separated list of directories, which will be searched in order.
If the automatic search for include-files causes trouble, the @samp{p}
-debug flag (@pxref{Debug Levels}) can help isolate the problem.
+debug flag (@pxref{Debugmode}) can help isolate the problem.
@node Diversions
@chapter Diverting and undiverting output
@@ -5080,7 +5121,7 @@ Line numbers start at 1 for each file.
reflected in the file name. Synclines, via @code{syncoutput}
(@pxref{Syncoutput}) or the command line option @option{--synclines}
(or @option{-s}, @pxref{Invoking m4}), and the
address@hidden and @samp{l} flags of @code{debugmode} (@pxref{Debug Levels}),
address@hidden and @samp{l} flags of @code{debugmode} (@pxref{Debugmode}),
also use this notion of current file and line. Redefining the three
location macros has no effect on syncline, debug, warning, or error
message output.
@@ -5454,11 +5495,11 @@ The generation of sync lines can be cont
@item
The format of the output from @code{dumpdef} and macro tracing can be
-controlled with @code{debugmode} (@pxref{Debug Levels}).
+controlled with @code{debugmode} (@pxref{Debugmode}).
@item
The destination of trace and debug output can be controlled with
address@hidden (@pxref{Debug Output}).
address@hidden (@pxref{Debugfile}).
@end itemize
Additionally, @acronym{POSIX} only requires support for the command line
Index: m4/utility.c
===================================================================
RCS file: /sources/m4/m4/m4/utility.c,v
retrieving revision 1.50
diff -u -p -r1.50 utility.c
--- m4/utility.c 4 Oct 2006 03:57:00 -0000 1.50
+++ m4/utility.c 6 Oct 2006 15:19:54 -0000
@@ -76,13 +76,20 @@ m4_numeric_arg (m4 *context, int argc, m
{
char *endp;
- if (*M4ARG (arg) == 0
- || (*valuep = strtol (skip_space (context, M4ARG (arg)), &endp, 10),
- *skip_space (context, endp) != 0))
+ if (*M4ARG (arg) == '\0')
{
- m4_warn (context, 0, _("%s: argument %d non-numeric: %s"),
- M4ARG (0), arg - 1, M4ARG (arg));
- return false;
+ *valuep = 0;
+ m4_warn (context, 0, _("%s: empty string treated as 0"), M4ARG (0));
+ }
+ else
+ {
+ *valuep = strtol (skip_space (context, M4ARG (arg)), &endp, 10);
+ if (*skip_space (context, endp) != 0)
+ {
+ m4_warn (context, 0, _("%s: non-numeric argument `%s'"),
+ M4ARG (0), M4ARG (arg));
+ return false;
+ }
}
return true;
}
Index: modules/gnu.c
===================================================================
RCS file: /sources/m4/m4/modules/gnu.c,v
retrieving revision 1.61
diff -u -p -r1.61 gnu.c
--- modules/gnu.c 4 Oct 2006 03:57:01 -0000 1.61
+++ modules/gnu.c 6 Oct 2006 15:19:54 -0000
@@ -49,8 +49,9 @@
BUILTIN (builtin, false, true, false, 1, -1 ) \
BUILTIN (changeresyntax,false,true, false, 1, 1 ) \
BUILTIN (changesyntax,false, true, false, 1, -1 ) \
- BUILTIN (debugmode, false, false, false, 0, 1 ) \
BUILTIN (debugfile, false, false, false, 0, 1 ) \
+ BUILTIN (debuglen, false, true, false, 1, 1 ) \
+ BUILTIN (debugmode, false, false, false, 0, 1 ) \
BUILTIN (esyscmd, false, true, true, 1, 1 ) \
BUILTIN (format, false, true, false, 1, -1 ) \
BUILTIN (indir, false, true, false, 1, -1 ) \
@@ -419,6 +420,22 @@ M4BUILTIN_HANDLER (debugfile)
}
+/* On-the-fly control of debug length. It takes one integer
+ argument. */
+
+/**
+ * debuglen(LEN)
+ **/
+M4BUILTIN_HANDLER (debuglen)
+{
+ int i;
+ if (!m4_numeric_arg (context, argc, argv, 1, &i))
+ return;
+ /* FIXME - make m4_numeric_arg more powerful - we want to accept
+ suffixes, and limit the result to size_t. */
+ m4_set_max_debug_arg_length_opt (context, i);
+}
+
/* On-the-fly control of the format of the tracing output. It takes one
argument, which is a character string like given to the -d option, or
none in which case the debug_level is zeroed. */
Index: src/main.c
===================================================================
RCS file: /sources/m4/m4/src/main.c,v
retrieving revision 1.93
diff -u -p -r1.93 main.c
--- src/main.c 5 Oct 2006 23:07:28 -0000 1.93
+++ src/main.c 6 Oct 2006 15:19:55 -0000
@@ -132,7 +132,7 @@ Frozen state files:\n\
Debugging:\n\
-d, --debug[=FLAGS] set debug level (no FLAGS implies `aeq')\n\
--debugfile=FILE redirect debug and trace output\n\
- -l, --arglength=NUM restrict macro tracing size\n\
+ -l, --debuglen=NUM restrict macro tracing size\n\
-t, --trace=NAME trace NAME when it is defined\n\
"), stdout);
fputs (_("\
@@ -175,7 +175,8 @@ mismatch, or whatever value was passed t
non-character as a pseudo short option, starting with CHAR_MAX + 1. */
enum
{
- DEBUGFILE_OPTION = CHAR_MAX + 1, /* no short opt */
+ ARGLENGTH_OPTION = CHAR_MAX + 1, /* not quite -l, because of message */
+ DEBUGFILE_OPTION, /* no short opt */
DIVERSIONS_OPTION, /* not quite -N, because of message */
ERROR_OUTPUT_OPTION, /* not quite -o, because of message */
HASHSIZE_OPTION, /* not quite -H, because of message */
@@ -190,9 +191,9 @@ enum
/* Decode options and launch execution. */
static const struct option long_options[] =
{
- {"arglength", required_argument, NULL, 'l'},
{"batch", no_argument, NULL, 'b'},
{"debug", optional_argument, NULL, 'd'},
+ {"debuglen", required_argument, NULL, 'l'},
{"define", required_argument, NULL, 'D'},
{"discard-comments", no_argument, NULL, 'c'},
{"fatal-warnings", no_argument, NULL, 'E'},
@@ -213,6 +214,7 @@ static const struct option long_options[
{"undefine", required_argument, NULL, 'U'},
{"word-regexp", required_argument, NULL, 'W'},
+ {"arglength", required_argument, NULL, ARGLENGTH_OPTION},
{"debugfile", required_argument, NULL, DEBUGFILE_OPTION},
{"diversions", required_argument, NULL, DIVERSIONS_OPTION},
{"hashsize", required_argument, NULL, HASHSIZE_OPTION},
@@ -448,6 +450,10 @@ main (int argc, char *const *argv, char
interactive = INTERACTIVE_YES;
break;
+ case ARGLENGTH_OPTION:
+ error (0, 0, _("Warning: `%s' is deprecated, use `%s' instead"),
+ "--arglength", "--debuglen");
+ /* fall through */
case 'l':
size = size_opt (optarg,
N_("debug argument length"));
Index: tests/options.at
===================================================================
RCS file: /sources/m4/m4/tests/options.at,v
retrieving revision 1.16
diff -u -p -r1.16 options.at
--- tests/options.at 3 Oct 2006 12:57:18 -0000 1.16
+++ tests/options.at 6 Oct 2006 15:19:55 -0000
@@ -68,6 +68,11 @@ AT_CHECK_M4([-e], [0], [],
[[m4: Warning: `-e' is deprecated, use `-i' instead
]])
+dnl --arglength is an older spelling for --debuglen
+AT_CHECK_M4([--arglength=10], [0], [],
+[[m4: Warning: `--arglength' is deprecated, use `--debuglen' instead
+]])
+
AT_CLEANUP
@@ -133,53 +138,6 @@ m@&address@hidden()
AT_CLEANUP
-## --------- ##
-## arglength ##
-## --------- ##
-
-AT_SETUP([--arglength])
-
-dnl Check for argument validation.
-
-AT_DATA([in],
-[[define(`echo', `$@')dnl
-traceon(`echo')dnl
-echo(`long string')
-]])
-
-AT_CHECK_M4([--arglength=-1 in], [1], [],
-[[m4: invalid debug argument length `-1'
-]])
-
-AT_CHECK_M4([--arglength oops in], [1], [],
-[[m4: invalid debug argument length `oops'
-]])
-
-AT_CHECK_M4([-l 10oops in], [1], [],
-[[m4: invalid character following debug argument length in `10oops'
-]])
-
-dnl MiB is the suffix to implict 1, resulting in 1048576
-AT_CHECK_M4([-lMiB in], [0], [[long string
-]], [[m4trace: -1- echo(`long string') -> ``long string''
-]])
-
-dnl this assumes size_t is no bigger than 64 bits
-AT_CHECK_M4([-l 123456789012345678901234567890 in], [1], [],
-[[m4: debug argument length `123456789012345678901234567890' too large
-]])
-
-AT_CHECK_M4([-l 3 in], [0], [[long string
-]], [[m4trace: -1- echo(`lon...') -> ``lo...'
-]])
-
-AT_CHECK_M4([--arglength=3 -l0 in], [0], [[long string
-]], [[m4trace: -1- echo(`long string') -> ``long string''
-]])
-
-AT_CLEANUP
-
-
## ----------- ##
## debug flags ##
## ----------- ##
@@ -285,6 +243,53 @@ AT_CHECK([cat trace4], [0], [expout])
AT_CLEANUP
+## -------- ##
+## debuglen ##
+## -------- ##
+
+AT_SETUP([--debuglen])
+
+dnl Check for argument validation.
+
+AT_DATA([in],
+[[define(`echo', `$@')dnl
+traceon(`echo')dnl
+echo(`long string')
+]])
+
+AT_CHECK_M4([--debuglen=-1 in], [1], [],
+[[m4: invalid debug argument length `-1'
+]])
+
+AT_CHECK_M4([--debuglen oops in], [1], [],
+[[m4: invalid debug argument length `oops'
+]])
+
+AT_CHECK_M4([-l 10oops in], [1], [],
+[[m4: invalid character following debug argument length in `10oops'
+]])
+
+dnl MiB is the suffix to implict 1, resulting in 1048576
+AT_CHECK_M4([-lMiB in], [0], [[long string
+]], [[m4trace: -1- echo(`long string') -> ``long string''
+]])
+
+dnl this assumes size_t is no bigger than 64 bits
+AT_CHECK_M4([-l 123456789012345678901234567890 in], [1], [],
+[[m4: debug argument length `123456789012345678901234567890' too large
+]])
+
+AT_CHECK_M4([-l 3 in], [0], [[long string
+]], [[m4trace: -1- echo(`lon...') -> ``lo...'
+]])
+
+AT_CHECK_M4([--debuglen=3 -l0 in], [0], [[long string
+]], [[m4trace: -1- echo(`long string') -> ``long string''
+]])
+
+AT_CLEANUP
+
+
## ---------------- ##
## discard comments ##
## ---------------- ##