m4-patches
[Top][All Lists]
Advanced

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

Re: freezing trace status


From: Eric Blake
Subject: Re: freezing trace status
Date: Wed, 28 May 2008 20:26:36 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080421 Thunderbird/2.0.0.14 Mnenhy/0.7.5.666

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

According to Eric Blake on 5/17/2008 10:16 PM:
| This is because -d is currently acted on during option parsing, then
| frozen file is reloaded, then --traceon/--traceoff are used in their
| location interleaved with input files.  I like the action of --traceon/-t
| better, since both files and command line can override each other, merely
| by choosing the correct order for listing the commands.  But interleaving
| -d with command-line files means that 'm4 file -dV' no longer turns on
| debugging before parsing file, and this might break existing m4 clients
| (for 2.0, that's probably okay, as long as it is documented in NEWS).  So
| is it worth a followup patch that defers command-line action on -d to
| match the behavior of -t?

I committed the following:

- --
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

iEYEARECAAYFAkg+FFsACgkQ84KuGfSFAYD4FwCeIVOZvcMfO3a8DTmghll6mT6L
XQMAoLc5/yI79pI9L84nTxsm1RhFclVU
=cqd4
-----END PGP SIGNATURE-----
>From b365ac707f78650ff719f3a295ac0d4c1a6521a2 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Wed, 28 May 2008 20:16:23 -0600
Subject: [PATCH] Improve frozen debugmode behavior.

* m4/debug.c (m4_debug_decode): Make empty debugmode additive.
* src/main.c (main): Interleave -d with files.
* tests/options.at (--debugmode): Update test.
* tests/freeze.at (reloading debugmode): New test.
* doc/m4.texinfo (Debugging options, Debugmode): Document the
change.
* NEWS: Likewise.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog        |   11 +++++++++++
 NEWS             |    9 +++++++--
 doc/m4.texinfo   |   47 ++++++++++++++++++++++++-----------------------
 m4/debug.c       |    2 +-
 src/main.c       |   28 +++++++++++++++++++++++-----
 tests/freeze.at  |   39 +++++++++++++++++++++++++++++++++++++++
 tests/options.at |   15 ++++++++++++++-
 7 files changed, 119 insertions(+), 32 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b0f13a2..d5eec17 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2008-05-28  Eric Blake  <address@hidden>
+
+       Improve frozen debugmode behavior.
+       * m4/debug.c (m4_debug_decode): Make empty debugmode additive.
+       * src/main.c (main): Interleave -d with files.
+       * tests/options.at (--debugmode): Update test.
+       * tests/freeze.at (reloading debugmode): New test.
+       * doc/m4.texinfo (Debugging options, Debugmode): Document the
+       change.
+       * NEWS: Likewise.
+
 2008-05-27  Eric Blake  <address@hidden>
 
        Fix some testsuite failures on Solaris 8.
diff --git a/NEWS b/NEWS
index 1391e36..9aa47db 100644
--- a/NEWS
+++ b/NEWS
@@ -30,8 +30,13 @@ promoted to 2.0.
     the include path, rather than always searching `.' first.
 
 *** The `-d'/`--debug' command-line option now understands `-' and `+'
-     modifiers, the way `debugmode' has always done.  The option
-    `--debugmode' is added as an alias for `-d'.
+    modifiers, the way the builtin `debugmode' has always done; this allows
+    `-d-V' to disable prior debug settings from the command line, similar
+    to using the builtin `debugmode' without arguments.  The option
+    `--debugmode' is added as an alias for `-d'.  When given the empty
+    string, the mode is treated as `+aeq' instead of `aeq'.  Also, the
+    position of `-d' with respect to files on the command line is now
+    significant.
 
 *** New `--debuglen' command-line option matches the spelling of a new
     macro, and the old spelling `--arglength' now issues a warning that it
diff --git a/doc/m4.texinfo b/doc/m4.texinfo
index 2048483..3540710 100644
--- a/doc/m4.texinfo
+++ b/doc/m4.texinfo
@@ -946,13 +946,16 @@ 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{Debugmode}, for more details on the format and
 meaning of @var{FLAGS}.  If omitted, @var{FLAGS} defaults to
address@hidden  When the option is presented multiple times, if later
address@hidden  When the option is presented multiple times, if later
 @var{FLAGS} starts with @samp{-} or @samp{+}, they are cumulative,
-otherwise the later flags override all earlier occurrences.  The
+otherwise the later flags override all earlier occurrences.  Therefore,
+to disable all previously set flags, specify an explicit @var{FLAGS} of
address@hidden  The
 spelling @option{--debug} is recognized as an unambiguous option for
 compatibility with earlier versions of @acronym{GNU} M4, but for
 consistency with the builtin name, you can also use the spelling
address@hidden
address@hidden  Order is significant with respect to
+file names.
 
 @item address@hidden
 @itemx -o @var{FILE}
@@ -4155,7 +4158,7 @@ the previous setting.
 @comment currently enabled?
 
 If no flags are specified with the @option{--debug} option, the default is
address@hidden  Many examples in this manual show their output using
address@hidden  Many examples in this manual show their output using
 default flags.
 
 @cindex @acronym{GNU} extensions
@@ -4164,10 +4167,10 @@ the debugging output format:
 
 @deffn {Builtin (gnu)} debugmode (@ovar{flags})
 The argument @var{flags} should be a subset of the letters listed above.
-If no argument is present, all debugging flags are cleared
-(as if no @option{--debug} was given), and with an empty argument the flags
-are reset to the default of @samp{aeq}.  If an unknown flag is
-encountered, an error is issued.
+If no argument is present, all debugging flags are cleared (as if
address@hidden were an explicit @samp{-V}).  With an empty argument, the
+most common flags are enabled (as if @var{flags} were an explicit
address@hidden).  If an unknown flag is encountered, an error is issued.
 
 The expansion of @code{debugmode} is void.
 @end deffn
@@ -4179,34 +4182,32 @@ define(`foo', `FOO$1')
 @result{}
 traceon(`foo', `divnum')
 @result{}
-debugmode()
address@hidden
+debugmode()dnl same as debugmode(`+aeq')
 foo
 @error{}m4trace: -1- foo -> `FOO'
 @result{}FOO
 debugmode(`V')debugmode(`-q')
address@hidden:stdin:5: -1- id 6: debugmode ... = <debugmode>@address@hidden
address@hidden:stdin:5: -1- id 6: debugmode(`-q') -> `'
address@hidden:stdin:5: -1- id 7: debugmode ... = <debugmode>@address@hidden
address@hidden:stdin:5: -1- id 7: debugmode(`-q') -> `'
 @result{}
 foo(
 `BAR')
address@hidden:stdin:6: -1- id 7: foo ... = FOO$1
address@hidden:stdin:6: -1- id 7: foo(BAR) -> FOOBAR
address@hidden:stdin:6: -1- id 8: foo ... = FOO$1
address@hidden:stdin:6: -1- id 8: foo(BAR) -> FOOBAR
 @result{}FOOBAR
-debugmode
address@hidden:stdin:8: -1- id 8: debugmode ... = <debugmode>@address@hidden
address@hidden:stdin:8: -1- id 8: debugmode ->@w{ }
address@hidden
+debugmode`'dnl same as debugmode(`-V')
address@hidden:stdin:8: -1- id 9: debugmode ... = <debugmode>@address@hidden
address@hidden:stdin:8: -1- id 9: debugmode ->@w{ }
 foo
 @error{}m4trace: -1- foo
 @result{}FOO
 debugmode(`+clmx')
 @result{}
 foo(divnum)
address@hidden:11: -1- id 11: foo ... = FOO$1
address@hidden:11: -2- id 12: divnum ... = <divnum>@address@hidden
address@hidden:11: -2- id 12: divnum
address@hidden:11: -1- id 11: foo
address@hidden:11: -1- id 13: foo ... = FOO$1
address@hidden:11: -2- id 14: divnum ... = <divnum>@address@hidden
address@hidden:11: -2- id 14: divnum
address@hidden:11: -1- id 13: foo
 @result{}FOO0
 debugmode(`-m')
 @result{}
@@ -8409,7 +8410,7 @@ comment delimiters.
 @item d @var{len} @key{NL} @var{str} @key{NL}
 Sets the debug flags, using @var{str} as the argument to
 @code{debugmode}.  If omitted, then the debug flags start in their
-default state.
+default disabled state.
 
 @item D @var{number} , @var{len} @key{NL} @var{str} @key{NL}
 Selects diversion @var{number}, making it current, then copy @var{str}
diff --git a/m4/debug.c b/m4/debug.c
index 5b54c4a..e6c8ffb 100644
--- a/m4/debug.c
+++ b/m4/debug.c
@@ -39,7 +39,7 @@ m4_debug_decode (m4 *context, int previous, const char *opts)
   char mode = '\0';
 
   if (opts == NULL || *opts == '\0')
-    level = M4_DEBUG_TRACE_DEFAULT;
+    level = M4_DEBUG_TRACE_DEFAULT | previous;
   else
     {
       if (*opts == '-' || *opts == '+')
diff --git a/src/main.c b/src/main.c
index 7690147..104c256 100644
--- a/src/main.c
+++ b/src/main.c
@@ -427,11 +427,11 @@ main (int argc, char *const *argv, char *const *envp)
        case 'p':
        case 'r':
        case 't':
-       case '\1':
        case POPDEF_OPTION:
        case SYNCOUTPUT_OPTION:
        case TRACEOFF_OPTION:
        case UNLOAD_MODULE_OPTION:
+       defer:
          /* Arguments that cannot be handled until later are accumulated.  */
 
          defn = (deferred *) xmalloc (sizeof *defn);
@@ -444,12 +444,12 @@ main (int argc, char *const *argv, char *const *envp)
          else
            tail->next = defn;
          tail = defn;
-
-         if (optchar == '\1')
-           seen_file = true;
-
          break;
 
+       case '\1':
+         seen_file = true;
+         goto defer;
+
        case 'B':
          /* In 1.4.x, -B<num> was a no-op option for compatibility with
             Solaris m4.  Warn if optarg is all numeric.  FIXME -
@@ -537,6 +537,11 @@ main (int argc, char *const *argv, char *const *envp)
          break;
 
        case 'd':
+          /* Staggered handling of 'd', since -dm is useful prior to
+             first file and prior to reloading, but other -d must also
+             have effect between files.  */
+         if (seen_file || frozen_file_to_read)
+           goto defer;
          {
            int old = m4_get_debug_level_opt (context);
            m4_set_debug_level_opt (context, m4_debug_decode (context, old,
@@ -702,6 +707,19 @@ main (int argc, char *const *argv, char *const *envp)
          m4_symbol_delete (M4SYMTAB, arg);
          break;
 
+       case 'd':
+         {
+           int old = m4_get_debug_level_opt (context);
+           m4_set_debug_level_opt (context, m4_debug_decode (context, old,
+                                                             arg));
+         }
+         if (m4_get_debug_level_opt (context) < 0)
+           {
+             error (0, 0, _("bad debug flags: `%s'"), arg);
+             m4_set_debug_level_opt (context, 0);
+           }
+         break;
+
        case 'm':
          /* FIXME - should loading a module result in output?  */
          m4_module_load (context, arg, NULL);
diff --git a/tests/freeze.at b/tests/freeze.at
index fd1981b..44de59d 100644
--- a/tests/freeze.at
+++ b/tests/freeze.at
@@ -338,6 +338,45 @@ define{`a.b', `hello $1'}dnl
 ]])
 
 ## --------- ##
+## debugmode ##
+## --------- ##
+
+# Check that debugmode can be preserved, and how it interacts with -d
+AT_SETUP([reloading debugmode])
+AT_KEYWORDS([frozen])
+
+AT_DATA([frozen.m4],
+[[debugmode(`fl')dnl
+]])
+AT_DATA([unfrozen.m4],
+[[traceon(`len')len(`a')
+]])
+
+AT_CHECK_M4([-F frozen.m4f -d-V frozen.m4], [0])
+
+dnl With no -d option, use the frozen file
+AT_CHECK_M4([-R frozen.m4f unfrozen.m4], [0], [[1
+]], [[m4trace:unfrozen.m4:1: -1- len
+]], [], [ ])
+
+dnl With plain -d before -R, use the frozen file
+AT_CHECK_M4([-R frozen.m4f unfrozen.m4], [0], [[1
+]], [[m4trace:unfrozen.m4:1: -1- len
+]])
+
+dnl With plain -d after -R, add +aeq to the frozen file
+AT_CHECK_M4([-R frozen.m4f -d unfrozen.m4], [0], [[1
+]], [[m4trace:unfrozen.m4:1: -1- len(`a') -> `1'
+]], [], [ ])
+
+dnl With explicit -d option, override frozen file
+AT_CHECK_M4([-R frozen.m4f -de unfrozen.m4], [0], [[1
+]], [[m4trace: -1- len -> 1
+]])
+
+AT_CLEANUP
+
+## --------- ##
 ## nul bytes ##
 ## --------- ##
 
diff --git a/tests/options.at b/tests/options.at
index 19b8874..5484f14 100644
--- a/tests/options.at
+++ b/tests/options.at
@@ -371,12 +371,25 @@ AT_DATA([[nested]],
 ')dnl
 ]])
 
-dnl AT_CHECK_M4 starts life with -d.  Make sure it looks like -daeq.
+dnl AT_CHECK_M4 starts life with -d.  Make sure it looks like -d+aeq.
 AT_CHECK_M4([-tlen in], [0], [[3
 0
 ]], [[m4trace: -1- len(`abc') -> `3'
 ]])
 
+AT_CHECK_M4([-tlen -dfl -d in], [0], [[3
+0
+]], [[m4trace:in:2: -1- len(`abc') -> `3'
+]])
+
+dnl -d after file is deferred (but this is still useful for some flags).
+AT_CHECK_M4([-tlen in -dfli], [0], [[3
+0
+]], [[m4trace: -1- len(`abc') -> `3'
+m4debug: input from m4wrap recursion level 1
+m4debug: input from m4wrap exhausted
+]])
+
 dnl Test all flags.
 AT_CHECK_M4([-dV in], [0], [[3
 0
-- 
1.5.5.1


reply via email to

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