The -d option to m4 (or --debug,
see Invoking m4) controls the amount of details
presented in three
categories of output. Trace output is requested by traceon
(see Trace), and each line is prefixed by ‘m4trace:’ in
relation to a macro invocation. Debug output tracks useful events not
associated with a macro invocation, and each line is prefixed by
‘m4debug:’. Finally, dumpdef (see Dumpdef) output is
affected, with no prefix added to the output lines.
The flags following the option can be one or more of the following:
atraceon. Arguments are subject to length truncation specified by
the command line option --arglength (or -l).
cetraceon. The
expansion is subject to length truncation specified by the command line
option --arglength (or -l).
filpqtm4, regardless of the settings of traceon.
xVIf no flags are specified with the -d option, the default is ‘aeq’. The examples throughout this manual assume the default flags.
There is a builtin macro debugmode, which allows on-the-fly control of
the debugging output format:
The argument flags should be a subset of the letters listed above. As special cases, if the argument starts with a ‘+’, the flags are added to the current debug flags, and if it starts with a ‘-’, they are removed. If no argument is present, all debugging flags are cleared (as if no -d was given), and with an empty argument the flags are reset to the default of ‘aeq’.
The expansion of
debugmodeis void.
$ m4
define(`foo', `FOO')
⇒
traceon(`foo')
⇒
debugmode()
⇒
foo
error-->m4trace: -1- foo -> `FOO'
⇒FOO
debugmode
⇒
foo
error-->m4trace: -1- foo
⇒FOO
debugmode(`+l')
⇒
foo
error-->m4trace:8: -1- foo
⇒FOO
The following example demonstrates the behavior of length truncation, when specified on the command line. Note that each argument and the final result are individually truncated. Also, the special tokens for builtin functions are not truncated.
$ m4 -d -l 6
define(`echo', `$@')debugmode(`+t')
⇒
echo(`1', `long string')
error-->m4trace: -1- echo(`1', `long s...') -> ``1',`l...'
⇒1,long string
indir(`echo', defn(`changequote'))
error-->m4trace: -2- defn(`change...')
error-->m4trace: -1- indir(`echo', <changequote>) -> ``''
⇒
This example shows the effects of the debug flags that are not related to macro tracing.
$ m4 -dip -I examples
error-->m4debug: input read from stdin
include(`foo')dnl
error-->m4debug: path search for `foo' found `examples/foo'
error-->m4debug: input read from examples/foo
⇒bar
error-->m4debug: input reverted to stdin, line 1
^D
error-->m4debug: input exhausted