Imported Upstream version 1.22.4
[platform/upstream/groff.git] / tmac / groff_trace.7.man
1 .TH GROFF_TRACE @MAN7EXT@ "@MDATE@" "groff @VERSION@"
2 .SH NAME
3 groff_trace \- groff macro package trace.tmac
4 .
5 .\" groff_trace.7
6 .\" File position: <groff-source>/tmac/groff_trace.man
7 .
8 .
9 .\" Save and disable compatibility mode (for, e.g., Solaris 10/11).
10 .do nr groff_trace_C \n[.C]
11 .cp 0
12 .
13 .
14 .\" ====================================================================
15 .\" Legal Terms
16 .\" ====================================================================
17 .\"
18 .\" Copyright (C) 2002-2018 Free Software Foundation, Inc.
19 .\"
20 .\" This file is part of groff, the GNU roff type-setting system.
21 .\"
22 .\" Permission is granted to copy, distribute and/or modify this
23 .\" document under the terms of the GNU Free Documentation License,
24 .\" Version 1.3 or any later version published by the Free Software
25 .\" Foundation; with no Invariant Sections, with no Front-Cover Texts,
26 .\" and with no Back-Cover Texts.
27 .\"
28 .\" A copy of the Free Documentation License is included as a file
29 .\" called FDL in the main directory of the groff source package.
30 .
31 .
32 .\" ====================================================================
33 .SH SYNOPSIS
34 .\" ====================================================================
35 .
36 .SY "groff \-m trace"
37 .RI [ option
38 \&.\|.\|.\&]
39 .RI [ input-file
40 \&.\|.\|.\&]
41 .YS
42 .
43 .
44 .\" ====================================================================
45 .SH DESCRIPTION
46 .\" ====================================================================
47 .
48 The
49 .I trace
50 macro package of
51 .BR groff (@MAN1EXT@)
52 can be a valuable tool for debugging documents written in the roff
53 formatting language.
54 .
55 A call stack trace is protocolled on standard error, this is, a
56 diagnostic message is emitted on entering and exiting of a macro call.
57 .
58 This greatly eases to track down an error in some macro.
59 .
60 .
61 .P
62 This tracing process is activated by specifying the groff or troff
63 command-line option
64 .BR \-m\ trace .
65 .
66 This works also with the
67 .BR groffer (@MAN1EXT@)
68 viewer program.
69 .
70 A finer control can be obtained by including the macro file within the
71 document by the groff macro call
72 .BR .mso\ trace.tmac .
73 .
74 Only macros that are defined after this line are traced.
75 .
76 .
77 .P
78 If the command-line option
79 .B \-r\ trace-full=1
80 is given (or if this register is set in the document), number and
81 string register assignments together with some other requests are
82 traced also.
83 .
84 .
85 .P
86 If some other macro package should be traced as well it must be
87 specified after
88 .B \-m\ trace
89 on the command line.
90 .
91 .
92 .P
93 The macro file
94 .B trace.tmac
95 is unusual because it does not contain any macros to be called by a
96 user.
97 .
98 Instead, the existing macro definition and appending facilities are
99 modified such that they display diagnostic messages.
100 .
101 .
102 .\" ====================================================================
103 .SH EXAMPLES
104 .\" ====================================================================
105 .
106 In the following examples, a roff fragment is fed into groff via
107 standard input.
108 .
109 As we are only interested in the diagnostic messages (standard error)
110 on the terminal, the normal formatted output (standard output) is
111 redirected to the nirvana device
112 .IR /dev/null .
113 .
114 The resulting diagnostic messages are displayed directly below the
115 corresponding example.
116 .
117 .
118 .\" ====================================================================
119 .SS "Command line option"
120 Example:
121 .
122 .RS
123 .P
124 .EX
125 \fIsh#\fP echo \[aq].
126 > .de test_macro
127 > ..
128 > .test_macro
129 > .test_macro some dummy arguments
130 > \[aq] | groff \-m trace > /dev/null
131
132 *** .de test_macro
133 *** de trace enter: .test_macro
134 *** trace exit: .test_macro
135 *** de trace enter: .test_macro "some" "dummy" "arguments"
136 *** trace exit: .test_macro "some" "dummy" "arguments"
137 .EE
138 .RE
139 .
140 .P
141 The entry and the exit of each macro call is displayed on the terminal
142 (standard output) \[em] together with the arguments (if any).
143 .
144 .
145 .\" ====================================================================
146 .SS "Nested macro calls"
147 Example:
148 .
149 .RS
150 .P
151 .EX
152 \fIsh#\fP echo \[aq].
153 > .de child
154 > ..
155 > .de parent
156 > .child
157 > ..
158 > .parent
159 > \[aq] | groff \-m trace > /dev/null
160
161 *** .de child
162 *** .de parent
163 *** de trace enter: .parent
164  *** de trace enter: .child
165  *** trace exit: .child
166 *** trace exit: .parent
167 .EE
168 .RE
169 .
170 .P
171 This shows that macro calls can be nested.
172 .
173 This powerful feature can help to tack down quite complex call stacks.
174 .
175 .
176 .\" ====================================================================
177 .SS "Activating with .mso"
178 Example:
179 .
180 .RS
181 .P
182 .EX
183 \fIsh#\fP echo \[aq].
184 > .de before
185 > ..
186 > .mso trace.tmac
187 > .de after
188 > ..
189 > .before
190 > .after
191 > .before
192 > \[aq] | groff > /dev/null
193
194 *** de trace enter: .after
195 *** trace exit: .after
196 .EE
197 .RE
198 .
199 .P
200 Here, the tracing is activated within the document, not by a
201 command-line option.
202 .
203 As tracing was not active when macro
204 .I before
205 was defined, no call of this macro is protocolled; on the other hand,
206 the macro
207 .I after
208 is fully protocolled.
209 .
210 .
211 .\" ====================================================================
212 .SH PROBLEMS
213 .\" ====================================================================
214 .
215 Because
216 .B trace.tmac
217 wraps the
218 .B .de
219 request (and its cousins), macro arguments are expanded one level more.
220 .
221 This causes problems if an argument contains four backslashes or more
222 to prevent too early expansion of the backslash.
223 .
224 For example, this macro call
225 .
226 .IP
227 .EX
228 \&.foo \e\e\e\en[bar]
229 .EE
230 .
231 .
232 .P
233 normally passes \[oq]\e\en[bar]\[cq] to macro \[oq].foo\[cq], but with
234 the redefined
235 .B .de
236 request it passes \[oq]\en[bar]\[cq] instead.
237 .
238 .
239 .P
240 The solution to this problem is to use groff's
241 .B \eE
242 escape which is an escape character not interpreted in copy mode, for
243 example
244 .
245 .IP
246 .EX
247 \&.foo \eEn[bar]
248 .EE
249 .
250 .
251 .\" ====================================================================
252 .SH FILES
253 .\" ====================================================================
254 .
255 The
256 .I trace
257 macros are kept in the file
258 .B trace.tmac
259 located in the
260 .IR "tmac directory" ;
261 see
262 .BR groff_tmac (@MAN5EXT@)
263 for details.
264 .
265 .
266 .\" ====================================================================
267 .SH ENVIRONMENT
268 .\" ====================================================================
269 .
270 .TP
271 .I GROFF_TMAC_PATH
272 A colon-separated list of additional tmac directories in which to
273 search for macro files; see
274 .BR groff_tmac (@MAN5EXT@)
275 for details.
276 .
277 .
278 .\" ====================================================================
279 .SH AUTHORS
280 .\" ====================================================================
281 .
282 The
283 .I trace
284 macro packages was written by James Clark.
285 .
286 This document was written by
287 .MT groff\-bernd.warken\-72@\:web.de
288 Bernd Warken
289 .ME .
290 .
291 .
292 .\" ====================================================================
293 .SH "SEE ALSO"
294 .\" ====================================================================
295 .
296 .IR "Groff: The GNU Implementation of troff" ,
297 by Trent A.\& Fisher and Werner Lemberg,
298 is the primary
299 .I groff
300 manual.
301 .
302 You can browse it interactively with \[lq]info groff\[rq].
303 .
304 .
305 .TP
306 .BR groff (@MAN1EXT@)
307 An overview of the groff system.
308 .
309 .TP
310 .BR troff (@MAN1EXT@)
311 For details on option
312 .BR \-m .
313 .
314 .TP
315 .BR groffer (@MAN1EXT@)
316 A viewer program for all kinds of roff documents.
317 .
318 .TP
319 .BR groff_tmac (@MAN5EXT@)
320 A general description of groff macro packages.
321 .
322 .TP
323 .BR groff (@MAN7EXT@)
324 A short reference for the groff formatting language.
325 .
326 .\" Restore compatibility mode (for, e.g., Solaris 10/11).
327 .cp \n[groff_trace_C]
328 .
329 .
330 .\" Local Variables:
331 .\" mode: nroff
332 .\" End:
333 .\" vim: set filetype=groff: