summaryrefslogtreecommitdiffstats
path: root/tmac/trace.tmac
blob: a119ae79c945f0cf01c9a922a94591b4f9a06fbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
.\" trace.tmac
.\"
.\" Load this before a macro package that you want to trace.
.\"
.\"
.\" Copyright (C) 1989-2020 Free Software Foundation, Inc.
.\"      Written by James Clark (jjc@jclark.com)
.\"
.\" This file is part of groff.
.\"
.\" groff is free software; you can redistribute it and/or modify it
.\" under the terms of the GNU General Public License as published by
.\" the Free Software Foundation, either version 3 of the License, or
.\" (at your option) any later version.
.\"
.\" groff is distributed in the hope that it will be useful, but WITHOUT
.\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
.\" or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
.\" License for more details.
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with this program.  If not, see
.\" <http://www.gnu.org/licenses/>.
.\"
.
.
.\" Tracing within groff means replacing the original macros or requests
.\" with special versions which act as wrappers to emit tracing
.\" information.  A natural consequence of creating such wrappers is
.\" that arguments must be expanded once more.  In most cases it doesn't
.\" matter, however, sometimes it makes a difference.
.\"
.\" To limit side effects, only macros are traced by default, together
.\" with some requests like '.return' which don't take (user) arguments.
.\" If you want more tracing, especially of number and string register
.\" assignments, add the '-r trace-full=1' command-line option.
.
.
.\" Regarding the usage of '.do': All lines of macros which should work
.\" in compatibility mode must be protected if they contain GNU troff
.\" extensions and are defined with '.de'.  Example: '.ds', but not
.\" '.ds1', since the latter can't be called in compatibility mode.
.
.
.do if d !!!sp \
.  nx
.
.do nr *groff_trace_tmac_C \n[.cp]
.cp 0
.
.ds !!!sp " \"
.
.de !!c
..
.
.
.eo
.
.rn return !!return
.
.de1 return
.  tm1 "\*[!!!sp]*** return
.  !!return twice
..
.
.ec
.
.ie r trace-full \{\
.  eo
.
.  rn nr !!nr
.
.  de nr
.    do ecs
.    ec
.    do !!nr \$*
.    do tm1 "\*[!!!sp]*** .nr \$* (-> \n[\$1])
.    do ecr
.  .
.
.  rn ds !!ds
.  rn ds1 !!ds1
.  rn as !!as
.  rn as1 !!as1
.
.  de ds
.    do ecs
.    ec
.    do tm1 "\*[!!!sp]*** .ds \$^
.    do !!ds \$^\"
.    do ecr
.  .
.
.  de1 ds1
.    ecs
.    ec
.    tm1 "\*[!!!sp]*** .ds1 \$^
.    !!ds1 \$^\"
.    ecr
.  .
.
.  de as
.    do ecs
.    ec
.    do tm1 "\*[!!!sp]*** .as \$^
.    do !!as \$^\"
.    do ecr
.  .
.
.  de1 as1
.    ecs
.    ec
.    tm1 "\*[!!!sp]*** .as1 \$^
.    !!as1 \$^\"
.    ecr
.  .
.
.  rn substring !!substring
.
.  de1 substring
.    ecs
.    ec
.    !!substring \$*
.    tm1 "\*[!!!sp]*** .substring \$* (-> '\*[\$1]')
.    ecr
.  .
.
.  rn so !!so
.
.  de so
.    do ecs
.    ec
.    do tm1 "\*[!!!sp]*** .so \$* {
.    do !!as !!!sp " \"
.    do ecr
.    do !!so \$*
.    do ecs
.    ec
.    do !!substring !!!sp 1
.    do tm1 "\*[!!!sp]*** }
.    do ecr
.  .
.
.  !!c We must use '.de' for the redefinition of .mso to avoid
.  !!c side effects; for example, it might be called with
.  !!c '.do mso ...'.
.
.  rn mso !!mso
.
.  de mso
.    do ecs
.    ec
.    do tm1 "\*[!!!sp]*** .mso \$* {
.    do !!as !!!sp " \"
.    do ecr
.    do !!mso \$*
.    do ecs
.    ec
.    do !!substring !!!sp 1
.    do tm1 "\*[!!!sp]*** }
.    do ecr
.  .
.
.  ec
.\}
.el \{\
.  als !!ds ds
.  als !!as as
.  als !!substring substring
.\}
.
.
.eo
.
.rn als !!als
.
.de1 als
.  ecs
.  ec
.  !!als \$*
.  if d !!\$2 \
.    !!als !!\$1 !!\$2
.  tm1 "\*[!!!sp]*** .als \$*
.  ecr
..
.
.rn rm !!rm
.
.de1 rm
.  ecs
.  ec
.  !!rm \$*
.  if d !!\$1 \
.    !!rm !!\$1
.  tm1 "\*[!!!sp]*** .rm \$*
.  ecr
..
.
.rn rn !!rn
.
.de rn
.  do ecs
.  ec
.  do !!rn \$*
.  do if d !!\$1 \
.    !!rn !!\$1 !!\$2
.  do tm1 "\*[!!!sp]*** .rn \$*
.  do ecr
..
.
.!!c Now the central tracing macros.  The redefined 'de' macros
.!!c create wrapper macros 'foo' which emit tracing messages
.!!c before and after the call to the traced macro '!!foo'.
.!!c
.!!c Note that we define '!!foo' in advance so that an alias to
.!!c '!!!!foo' is possible.  The latter occurs if 'foo' is
.!!c called as \\[foo].
.!!c
.!!c The call to 'dei' must be the last instruction in the macro
.!!c (since it continues the definition of the macro to trace).
.
.!!rn de !!de
.!!rn de1 !!de1
.
.!!de de
.  do ecs
.  ec
.  do !!de \$1
.    do ie \\n[.br] .do !!ds !!!br .\"
.    el             .do !!ds !!!br '\"
.    ie "\$1"\\$0" .do tm1 "\\*[!!!sp]*** de trace enter: \\*[!!!br]\\$0 \\$@
.    el            .do tm1 "\\*[!!!sp]*** de trace enter \$1: \\*[!!!br]\\$0 \\$@
.    do !!as !!!sp " \"
.
.    do nop \\*[!!\\$0]\\
.
.    do !!substring !!!sp 1
.    do ie \\n[.br] .do !!ds !!!br .\"
.    el             .do !!ds !!!br '\"
.    ie "\$1"\\$0" .do tm1 "\\*[!!!sp]*** trace exit: \\*[!!!br]\\$0 \\$@
.    el            .do tm1 "\\*[!!!sp]*** trace exit \$1: \\*[!!!br]\\$0 \\$@
\..
.
.  do tm1 "\*[!!!sp]*** .de \$*
.
.  do !!ds !!d1 !!\$1\"
.  do !!ds !!d2 \$2\"
.  do ecr
.  do dei !!d1 !!d2
..
.
.!!de1 de1
.  ecs
.  ec
.  !!de1 \$1
.    ie \\n[.br] .!!ds !!!br .\"
.    el          .!!ds !!!br '\"
.    ie "\$1"\\$0" .tm1 "\\*[!!!sp]*** de1 trace enter: \\*[!!!br]\\$0 \\$@
.    el            .tm1 "\\*[!!!sp]*** de1 trace enter \$1: \\*[!!!br]\\$0 \\$@
.    !!as !!!sp " \"
.
.    nop \\*[!!\\$0]\\
.
.    !!substring !!!sp 1
.    ie \\n[.br] .!!ds !!!br .\"
.    el          .!!ds !!!br '\"
.    ie "\$1"\\$0" .tm1 "\\*[!!!sp]*** trace exit: \\*[!!!br]\\$0 \\$@
.    el            .tm1 "\\*[!!!sp]*** trace exit \$1: \\*[!!!br]\\$0 \\$@
\..
.
.  tm1 "\*[!!!sp]*** .de1 \$*
.
.  !!ds !!d1 !!\$1\"
.  !!ds !!d2 \$2\"
.  ecr
.  dei1 !!d1 !!d2
..
.
.!!rn am !!am
.!!rn am1 !!am1
.
.!!de am
.  do ecs
.  ec
.  do !!de \$1
.    do ie \\n[.br] .do !!ds !!!br .\"
.    el             .do !!ds !!!br '\"
.    ie "\$1"\\$0" .do tm1 "\\*[!!!sp]*** am trace enter: \\*[!!!br]\\$0 \\$@
.    el            .do tm1 "\\*[!!!sp]*** am trace enter \$1: \\*[!!!br]\\$0 \\$@
.    do !!as !!!sp " \"
.
.    do nop \\*[!!\\$0]\\
.
.    do !!substring !!!sp 1
.    do ie \\n[.br] .do !!ds !!!br .\"
.    el             .do !!ds !!!br '\"
.    ie "\$1"\\$0" .do tm1 "\\*[!!!sp]*** trace exit: \\*[!!!br]\\$0 \\$@
.    el            .do tm1 "\\*[!!!sp]*** trace exit \$1: \\*[!!!br]\\$0 \\$@
\..
.
.  do tm1 "\*[!!!sp]*** .am \$*
.
.  do !!ds !!a1 !!\$1\"
.  do !!ds !!a2 \$2\"
.  do ecr
.  do ami !!a1 !!a2
..
.
.!!de1 am1
.  ecs
.  ec
.  !!de1 \$1
.    ie \\n[.br] .!!ds !!!br .\"
.    el          .!!ds !!!br '\"
.    ie "\$1"\\$0" .tm1 "\\*[!!!sp]*** am1 trace enter: \\*[!!!br]\\$0 \\$@
.    el            .tm1 "\\*[!!!sp]*** am1 trace enter \$1: \\*[!!!br]\\$0 \\$@
.    !!as !!!sp " \"
.
.    nop \\*[!!\\$0]\\
.
.    !!substring !!!sp 1
.    ie \\n[.br] .!!ds !!!br .\"
.    el          .!!ds !!!br '\"
.    ie "\$1"\\$0" .tm1 "\\*[!!!sp]*** trace exit: \\*[!!!br]\\$0 \\$@
.    el            .tm1 "\\*[!!!sp]*** trace exit \$1: \\*[!!!br]\\$0 \\$@
\..
.
.  tm1 "\*[!!!sp]*** .am1 \$*
.
.  !!ds !!a1 !!\$1\"
.  !!ds !!a2 \$2\"
.  ecr
.  ami1 !!a1 !!a2
..
.
.
.ec
.
.cp \n[*groff_trace_tmac_C]
.do rr *groff_trace_tmac_C
.
.\" Local Variables:
.\" mode: nroff
.\" fill-column: 72
.\" End:
.\" vim: set filetype=groff textwidth=72: