Re: dumpdef a pushdef'd stack

Eric Blake <[email protected]>
Newsgroups gmane.comp.gnu.m4.patches
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Eric Blake on 9/27/2006 7:25 AM:
> Another followup patch that I just thought of - it would be nice if the
> 'm' debug flag altered the dumpdef output to show WHICH module provided
> the various builtins.

Wow, this turned out rather nice when playing with modules!  -dm is
turning out to be rather useful.

2006-09-27  Eric Blake  <[email protected]>

	* m4/m4module.h (m4_symbol_value_print, m4_symbol_print): Add
	another parameter to print module info.
	* m4/macro.c (trace_pre): Adjust caller.
	* modules/m4.c (M4BUILTIN_HANDLER): Likewise.
	* doc/m4.texinfo (Dumpdef, Debug Levels): Document this.
	* NEWS: Document this.

- --
Life is short - so eat dessert first!

Eric Blake             [email protected]
-----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

iD8DBQFFG02+84KuGfSFAYARAp3PAKCYku5/rfLMSRMNHBRdGcGUhK6dkgCgrAkU
5Q8Xlb6X4klE90MlA0xbJFo=
=0myZ
-----END PGP SIGNATURE-----

_______________________________________________
M4-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/m4-patches
m4.patch167 (text/plain, 8.2 KB)
Index: NEWS
===================================================================
RCS file: /sources/m4/m4/NEWS,v
retrieving revision 1.21
diff -u -p -r1.21 NEWS
--- NEWS	27 Sep 2006 13:21:05 -0000	1.21
+++ NEWS	28 Sep 2006 03:47:18 -0000
@@ -59,10 +59,11 @@ promoted to 2.0.
   standard error are terminals.
 
 * New `m' flag to `-d'/`--debug' option or `debugmode' macro traces
-  actions related to module loading and unloading.  New `s' flag shows the
-  entire stack of `pushdef' definitions during `dumpdef'.  Also, the
-  `--debug' option now understands `-' and `+' modifiers, the way
-  `debugmode' has always done.
+  actions related to module loading and unloading, and affects `dumpdef'
+  output to show where builtins come from.  New `s' flag shows the entire
+  stack of `pushdef' definitions during `dumpdef'.  Also, the `--debug'
+  option now understands `-' and `+' modifiers, the way `debugmode' has
+  always done.
 
 * The semantics of `traceon' and `traceoff' now match traditional
   implementations: when called without arguments, they affect global state
Index: doc/m4.texinfo
===================================================================
RCS file: /sources/m4/m4/doc/m4.texinfo,v
retrieving revision 1.53
diff -u -p -r1.53 m4.texinfo
--- doc/m4.texinfo	27 Sep 2006 13:21:05 -0000	1.53
+++ doc/m4.texinfo	28 Sep 2006 03:47:20 -0000
@@ -2642,12 +2642,12 @@ f(popdef(`f')dumpdef(`f'))
 @result{}f1
 @end example
 
-@xref{Debug Levels}, for information on how the @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.
+@xref{Debug Levels}, 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.
 
 @comment options: -ds -l3
 @example
@@ -2658,8 +2658,15 @@ pushdef(`foo', defn(`divnum'))
 @result{}
 pushdef(`foo', `3')
 @result{}
-dumpdef(`foo')
-@error{}foo:@tabchar{}3, <div...>, 1 l...
+debugmode(`+m')
+@result{}
+dumpdef(`foo', `dnl', `indir', `__gnu__')
+@error{}__gnu__:@tabchar{}@{gnu@}
+@error{}dnl:@tabchar{}<dnl>@{m4@}
+@error{}foo:@tabchar{}3, <div...>@{m4@}, 1 l...
+@error{}indir:@tabchar{}<ind...>@{gnu@}
+@result{}
+debugmode(`-m')
 @result{}
 @end example
 
@@ -2919,7 +2926,8 @@ output line.
 
 @item m
 In debug output, print a message each time a module is manipulated
-(@pxref{Modules}).
+(@pxref{Modules}).  In dumpdef output, follow builtin macros with their
+module name, surrounded by braces (@samp{@{@}}).
 
 @item p
 In debug output, print a message when a named file is found through the
Index: m4/m4module.h
===================================================================
RCS file: /sources/m4/m4/m4/m4module.h,v
retrieving revision 1.88
diff -u -p -r1.88 m4module.h
--- m4/m4module.h	27 Sep 2006 13:21:05 -0000	1.88
+++ m4/m4module.h	28 Sep 2006 03:47:20 -0000
@@ -217,10 +217,11 @@ extern bool		m4_get_symbol_traced	  (m4_
 extern bool		m4_set_symbol_name_traced (m4_symbol_table*,
 						   const char *, bool);
 extern void	m4_symbol_value_print	(m4_symbol_value *, m4_obstack *, bool,
-					 const char *, const char *, size_t);
+					 const char *, const char *, size_t,
+					 bool);
 extern void	m4_symbol_print		(m4_symbol *, m4_obstack *, bool,
 					 const char *, const char *, bool,
-					 size_t);
+					 size_t, bool);
 
 #define m4_is_symbol_void(symbol)					\
 	(m4_is_symbol_value_void (m4_get_symbol_value (symbol)))
Index: m4/macro.c
===================================================================
RCS file: /sources/m4/m4/m4/macro.c,v
retrieving revision 1.55
diff -u -p -r1.55 macro.c
--- m4/macro.c	27 Sep 2006 13:21:05 -0000	1.55
+++ m4/macro.c	28 Sep 2006 03:47:20 -0000
@@ -618,6 +618,7 @@ trace_pre (m4 *context, const char *name
       const char *lquote = m4_get_syntax_lquote (M4SYNTAX);
       const char *rquote = m4_get_syntax_rquote (M4SYNTAX);
       size_t arg_length = m4_get_max_debug_arg_length_opt (context);
+      bool module = m4_is_debug_bit (context, M4_DEBUG_TRACE_MODULE);
 
       trace_format (context, "(");
       for (i = 1; i < argc; i++)
@@ -626,7 +627,7 @@ trace_pre (m4 *context, const char *name
 	    trace_format (context, ", ");
 
 	  m4_symbol_value_print (argv[i], &context->trace_messages,
-				 quote, lquote, rquote, arg_length);
+				 quote, lquote, rquote, arg_length, module);
 	}
       trace_format (context, ")");
     }
Index: m4/symtab.c
===================================================================
RCS file: /sources/m4/m4/m4/symtab.c,v
retrieving revision 1.62
diff -u -p -r1.62 symtab.c
--- m4/symtab.c	27 Sep 2006 13:21:05 -0000	1.62
+++ m4/symtab.c	28 Sep 2006 03:47:20 -0000
@@ -464,11 +464,12 @@ m4_set_symbol_name_traced (m4_symbol_tab
 
 /* Grow OBS with a text representation of VALUE.  If QUOTE, then
    surround a text definition by LQUOTE and RQUOTE.  If ARG_LENGTH is
-   non-zero, then truncate text definitions to that length.  */
+   non-zero, then truncate text definitions to that length.  If
+   MODULE, then include which module defined a builtin.  */
 void
 m4_symbol_value_print (m4_symbol_value *value, m4_obstack *obs, bool quote,
 		       const char *lquote, const char *rquote,
-		       size_t arg_length)
+		       size_t arg_length, bool module)
 {
   const char *text;
   size_t len;
@@ -509,17 +510,25 @@ m4_symbol_value_print (m4_symbol_value *
     obstack_grow (obs, "...", 3);
   if (quote)
     obstack_grow (obs, rquote, strlen (rquote));
+  if (module && VALUE_HANDLE (value))
+    {
+      obstack_1grow (obs, '{');
+      text = m4_get_module_name (VALUE_HANDLE (value));
+      obstack_grow (obs, text, strlen (text));
+      obstack_1grow (obs, '}');
+    }
 }
 
 /* Grow OBS with a text representation of SYMBOL.  If QUOTE, then
    surround each text definition by LQUOTE and RQUOTE.  If STACK, then
    append all pushdef'd values, rather than just the top.  If
    ARG_LENGTH is non-zero, then truncate text definitions to that
-   length.  */
+   length.  If MODULE, then include which module defined a
+   builtin.  */
 void
 m4_symbol_print (m4_symbol *symbol, m4_obstack *obs, bool quote,
 		 const char *lquote, const char *rquote, bool stack,
-		 size_t arg_length)
+		 size_t arg_length, bool module)
 {
   m4_symbol_value *value;
 
@@ -527,7 +536,8 @@ m4_symbol_print (m4_symbol *symbol, m4_o
   assert (obs);
 
   value = m4_get_symbol_value (symbol);
-  m4_symbol_value_print (value, obs, quote, lquote, rquote, arg_length);
+  m4_symbol_value_print (value, obs, quote, lquote, rquote, arg_length,
+			 module);
   if (stack)
     {
       value = VALUE_NEXT (value);
@@ -536,7 +546,7 @@ m4_symbol_print (m4_symbol *symbol, m4_o
 	  obstack_1grow (obs, ',');
 	  obstack_1grow (obs, ' ');
 	  m4_symbol_value_print (value, obs, quote, lquote, rquote,
-				 arg_length);
+				 arg_length, module);
 	  value = VALUE_NEXT (value);
 	}
     }
Index: modules/m4.c
===================================================================
RCS file: /sources/m4/m4/modules/m4.c,v
retrieving revision 1.75
diff -u -p -r1.75 m4.c
--- modules/m4.c	27 Sep 2006 13:21:05 -0000	1.75
+++ modules/m4.c	28 Sep 2006 03:47:20 -0000
@@ -371,6 +371,7 @@ M4BUILTIN_HANDLER (dumpdef)
   const char *rquote = m4_get_syntax_rquote (M4SYNTAX);
   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);
 
   data.obs = obs;
   m4_dump_symbols (context, &data, argc, argv, true);
@@ -383,7 +384,8 @@ M4BUILTIN_HANDLER (dumpdef)
       obstack_grow (obs, data.base[0], strlen (data.base[0]));
       obstack_1grow (obs, ':');
       obstack_1grow (obs, '\t');
-      m4_symbol_print (symbol, obs, quote, lquote, rquote, stack, arg_length);
+      m4_symbol_print (symbol, obs, quote, lquote, rquote, stack, arg_length,
+		       module);
       obstack_1grow (obs, '\n');
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.