Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / man / mann / trace.n
CommitLineData
86530b38
AT
1'\"
2'\" Copyright (c) 1993 The Regents of the University of California.
3'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
4'\" Copyright (c) 2000 Ajuba Solutions.
5'\"
6'\" See the file "license.terms" for information on usage and redistribution
7'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
8'\"
9'\" RCS: @(#) $Id: trace.n,v 1.13.2.2 2004/10/27 14:43:14 dkf Exp $
10'\"
11'\" The definitions below are for supplemental macros used in Tcl/Tk
12'\" manual entries.
13'\"
14'\" .AP type name in/out ?indent?
15'\" Start paragraph describing an argument to a library procedure.
16'\" type is type of argument (int, etc.), in/out is either "in", "out",
17'\" or "in/out" to describe whether procedure reads or modifies arg,
18'\" and indent is equivalent to second arg of .IP (shouldn't ever be
19'\" needed; use .AS below instead)
20'\"
21'\" .AS ?type? ?name?
22'\" Give maximum sizes of arguments for setting tab stops. Type and
23'\" name are examples of largest possible arguments that will be passed
24'\" to .AP later. If args are omitted, default tab stops are used.
25'\"
26'\" .BS
27'\" Start box enclosure. From here until next .BE, everything will be
28'\" enclosed in one large box.
29'\"
30'\" .BE
31'\" End of box enclosure.
32'\"
33'\" .CS
34'\" Begin code excerpt.
35'\"
36'\" .CE
37'\" End code excerpt.
38'\"
39'\" .VS ?version? ?br?
40'\" Begin vertical sidebar, for use in marking newly-changed parts
41'\" of man pages. The first argument is ignored and used for recording
42'\" the version when the .VS was added, so that the sidebars can be
43'\" found and removed when they reach a certain age. If another argument
44'\" is present, then a line break is forced before starting the sidebar.
45'\"
46'\" .VE
47'\" End of vertical sidebar.
48'\"
49'\" .DS
50'\" Begin an indented unfilled display.
51'\"
52'\" .DE
53'\" End of indented unfilled display.
54'\"
55'\" .SO
56'\" Start of list of standard options for a Tk widget. The
57'\" options follow on successive lines, in four columns separated
58'\" by tabs.
59'\"
60'\" .SE
61'\" End of list of standard options for a Tk widget.
62'\"
63'\" .OP cmdName dbName dbClass
64'\" Start of description of a specific option. cmdName gives the
65'\" option's name as specified in the class command, dbName gives
66'\" the option's name in the option database, and dbClass gives
67'\" the option's class in the option database.
68'\"
69'\" .UL arg1 arg2
70'\" Print arg1 underlined, then print arg2 normally.
71'\"
72'\" RCS: @(#) $Id: man.macros,v 1.4 2000/08/25 06:18:32 ericm Exp $
73'\"
74'\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
75.if t .wh -1.3i ^B
76.nr ^l \n(.l
77.ad b
78'\" # Start an argument description
79.de AP
80.ie !"\\$4"" .TP \\$4
81.el \{\
82. ie !"\\$2"" .TP \\n()Cu
83. el .TP 15
84.\}
85.ta \\n()Au \\n()Bu
86.ie !"\\$3"" \{\
87\&\\$1 \\fI\\$2\\fP (\\$3)
88.\".b
89.\}
90.el \{\
91.br
92.ie !"\\$2"" \{\
93\&\\$1 \\fI\\$2\\fP
94.\}
95.el \{\
96\&\\fI\\$1\\fP
97.\}
98.\}
99..
100'\" # define tabbing values for .AP
101.de AS
102.nr )A 10n
103.if !"\\$1"" .nr )A \\w'\\$1'u+3n
104.nr )B \\n()Au+15n
105.\"
106.if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
107.nr )C \\n()Bu+\\w'(in/out)'u+2n
108..
109.AS Tcl_Interp Tcl_CreateInterp in/out
110'\" # BS - start boxed text
111'\" # ^y = starting y location
112'\" # ^b = 1
113.de BS
114.br
115.mk ^y
116.nr ^b 1u
117.if n .nf
118.if n .ti 0
119.if n \l'\\n(.lu\(ul'
120.if n .fi
121..
122'\" # BE - end boxed text (draw box now)
123.de BE
124.nf
125.ti 0
126.mk ^t
127.ie n \l'\\n(^lu\(ul'
128.el \{\
129.\" Draw four-sided box normally, but don't draw top of
130.\" box if the box started on an earlier page.
131.ie !\\n(^b-1 \{\
132\h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
133.\}
134.el \}\
135\h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
136.\}
137.\}
138.fi
139.br
140.nr ^b 0
141..
142'\" # VS - start vertical sidebar
143'\" # ^Y = starting y location
144'\" # ^v = 1 (for troff; for nroff this doesn't matter)
145.de VS
146.if !"\\$2"" .br
147.mk ^Y
148.ie n 'mc \s12\(br\s0
149.el .nr ^v 1u
150..
151'\" # VE - end of vertical sidebar
152.de VE
153.ie n 'mc
154.el \{\
155.ev 2
156.nf
157.ti 0
158.mk ^t
159\h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
160.sp -1
161.fi
162.ev
163.\}
164.nr ^v 0
165..
166'\" # Special macro to handle page bottom: finish off current
167'\" # box/sidebar if in box/sidebar mode, then invoked standard
168'\" # page bottom macro.
169.de ^B
170.ev 2
171'ti 0
172'nf
173.mk ^t
174.if \\n(^b \{\
175.\" Draw three-sided box if this is the box's first page,
176.\" draw two sides but no top otherwise.
177.ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
178.el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
179.\}
180.if \\n(^v \{\
181.nr ^x \\n(^tu+1v-\\n(^Yu
182\kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
183.\}
184.bp
185'fi
186.ev
187.if \\n(^b \{\
188.mk ^y
189.nr ^b 2
190.\}
191.if \\n(^v \{\
192.mk ^Y
193.\}
194..
195'\" # DS - begin display
196.de DS
197.RS
198.nf
199.sp
200..
201'\" # DE - end display
202.de DE
203.fi
204.RE
205.sp
206..
207'\" # SO - start of list of standard options
208.de SO
209.SH "STANDARD OPTIONS"
210.LP
211.nf
212.ta 5.5c 11c
213.ft B
214..
215'\" # SE - end of list of standard options
216.de SE
217.fi
218.ft R
219.LP
220See the \\fBoptions\\fR manual entry for details on the standard options.
221..
222'\" # OP - start of full description for a single option
223.de OP
224.LP
225.nf
226.ta 4c
227Command-Line Name: \\fB\\$1\\fR
228Database Name: \\fB\\$2\\fR
229Database Class: \\fB\\$3\\fR
230.fi
231.IP
232..
233'\" # CS - begin code excerpt
234.de CS
235.RS
236.nf
237.ta .25i .5i .75i 1i
238..
239'\" # CE - end code excerpt
240.de CE
241.fi
242.RE
243..
244.de UL
245\\$1\l'|0\(ul'\\$2
246..
247.TH trace n "8.4" Tcl "Tcl Built-In Commands"
248.BS
249'\" Note: do not modify the .SH NAME line immediately below!
250.SH NAME
251trace \- Monitor variable accesses, command usages and command executions
252.SH SYNOPSIS
253\fBtrace \fIoption\fR ?\fIarg arg ...\fR?
254.BE
255
256.SH DESCRIPTION
257.PP
258This command causes Tcl commands to be executed whenever certain operations are
259invoked. The legal \fIoption\fR's (which may be abbreviated) are:
260.TP
261\fBtrace add \fItype name ops ?args?\fR
262Where \fItype\fR is \fBcommand\fR, \fBexecution\fR, or \fBvariable\fR.
263.RS
264.TP
265\fBtrace add command\fR \fIname ops command\fR
266Arrange for \fIcommand\fR to be executed whenever command \fIname\fR
267is modified in one of the ways given by the list \fIops\fR. \fIName\fR will be
268resolved using the usual namespace resolution rules used by
269procedures. If the command does not exist, an error will be thrown.
270.RS
271.PP
272\fIOps\fR indicates which operations are of interest, and is a list of
273one or more of the following items:
274.TP
275\fBrename\fR
276Invoke \fIcommand\fR whenever the command is renamed. Note that
277renaming to the empty string is considered deletion, and will not
278be traced with '\fBrename\fR'.
279.TP
280\fBdelete\fR
281Invoke \fIcommand\fR when the command is deleted. Commands can be
282deleted explicitly by using the \fBrename\fR command to rename the
283command to an empty string. Commands are also deleted when the
284interpreter is deleted, but traces will not be invoked because there is no
285interpreter in which to execute them.
286.PP
287When the trace triggers, depending on the operations being traced, a
288number of arguments are appended to \fIcommand\fR so that the actual
289command is as follows:
290.CS
291\fIcommand oldName newName op\fR
292.CE
293\fIOldName\fR and \fInewName\fR give the traced command's current
294(old) name, and the name to which it is being renamed (the empty
295string if this is a 'delete' operation).
296\fIOp\fR indicates what operation is being performed on the
297command, and is one of \fBrename\fR or \fBdelete\fR as
298defined above. The trace operation cannot be used to stop a command
299from being deleted. Tcl will always remove the command once the trace
300is complete. Recursive renaming or deleting will not cause further traces
301of the same type to be evaluated, so a delete trace which itself
302deletes the command, or a rename trace which itself renames the
303command will not cause further trace evaluations to occur.
304Both \fIoldName\fR and \fInewName\fR are fully qualified with any namespace(s)
305in which they appear.
306.RE
307.TP
308\fBtrace add execution\fR \fIname ops command\fR
309Arrange for \fIcommand\fR to be executed whenever command \fIname\fR
310is executed, with traces occurring at the points indicated by the list
311\fIops\fR. \fIName\fR will be
312resolved using the usual namespace resolution rules used by
313procedures. If the command does not exist, an error will be thrown.
314.RS
315.PP
316\fIOps\fR indicates which operations are of interest, and is a list of
317one or more of the following items:
318.TP
319\fBenter\fR
320Invoke \fIcommand\fR whenever the command \fIname\fR is executed,
321just before the actual execution takes place.
322.TP
323\fBleave\fR
324Invoke \fIcommand\fR whenever the command \fIname\fR is executed,
325just after the actual execution takes place.
326.TP
327\fBenterstep\fR
328Invoke \fIcommand\fR for every Tcl command which is executed
329inside the procedure \fIname\fR, just before the actual execution
330takes place. For example if we have 'proc foo {} { puts "hello" }',
331then an \fIenterstep\fR trace would be
332invoked just before \fIputs "hello"\fR is executed.
333Setting an \fIenterstep\fR trace on a \fIcommand\fR
334will not result in an error and is simply ignored.
335.TP
336\fBleavestep\fR
337Invoke \fIcommand\fR for every Tcl command which is executed
338inside the procedure \fIname\fR, just after the actual execution
339takes place.
340Setting a \fIleavestep\fR trace on a \fIcommand\fR
341will not result in an error and is simply ignored.
342.PP
343When the trace triggers, depending on the operations being traced, a
344number of arguments are appended to \fIcommand\fR so that the actual
345command is as follows:
346.PP
347For \fBenter\fR and \fBenterstep\fR operations:
348.CS
349\fIcommand command-string op\fR
350.CE
351\fICommand-string\fR gives the complete current command being
352executed (the traced command for a \fBenter\fR operation, an
353arbitrary command for a \fBenterstep\fR operation), including
354all arguments in their fully expanded form.
355\fIOp\fR indicates what operation is being performed on the
356command execution, and is one of \fBenter\fR or \fBenterstep\fR as
357defined above. The trace operation can be used to stop the
358command from executing, by deleting the command in question. Of
359course when the command is subsequently executed, an 'invalid command'
360error will occur.
361.PP
362For \fBleave\fR and \fBleavestep\fR operations:
363.CS
364\fIcommand command-string code result op\fR
365.CE
366\fICommand-string\fR gives the complete current command being
367executed (the traced command for a \fBenter\fR operation, an
368arbitrary command for a \fBenterstep\fR operation), including
369all arguments in their fully expanded form.
370\fICode\fR gives the result code of that execution, and \fIresult\fR
371the result string.
372\fIOp\fR indicates what operation is being performed on the
373command execution, and is one of \fBleave\fR or \fBleavestep\fR as
374defined above.
375Note that the creation of many \fBenterstep\fR or
376\fBleavestep\fR traces can lead to unintuitive results, since the
377invoked commands from one trace can themselves lead to further
378command invocations for other traces.
379.PP
380\fICommand\fR executes in the same context as the code that invoked
381the traced operation: thus the \fIcommand\fR, if invoked from a procedure,
382will have access to the same local variables as code in the procedure.
383This context may be different than the context in which the trace was
384created. If \fIcommand\fR invokes a procedure (which it normally does)
385then the procedure will have to use upvar or uplevel commands if it wishes
386to access the local variables of the code which invoked the trace operation.
387.PP
388While \fIcommand\fR is executing during an execution trace, traces
389on \fIname\fR are temporarily disabled. This allows the \fIcommand\fR
390to execute \fIname\fR in its body without invoking any other traces again.
391If an error occurs while executing the \fIcommand\fR body, then the
392command \fIname\fR as a whole will return that same error.
393.PP
394When multiple traces are set on \fIname\fR, then for \fIenter\fR
395and \fIenterstep\fR operations, the traced commands are invoked
396in the reverse order of how the traces were originally created;
397and for \fIleave\fR and \fIleavestep\fR operations, the traced
398commands are invoked in the original order of creation.
399.PP
400The behavior of execution traces is currently undefined for a command
401\fIname\fR imported into another namespace.
402.RE
403.TP
404\fBtrace add variable\fI name ops command\fR
405Arrange for \fIcommand\fR to be executed whenever variable \fIname\fR
406is accessed in one of the ways given by the list \fIops\fR. \fIName\fR may
407refer to a normal variable, an element of an array, or to an array
408as a whole (i.e. \fIname\fR may be just the name of an array, with no
409parenthesized index). If \fIname\fR refers to a whole array, then
410\fIcommand\fR is invoked whenever any element of the array is
411manipulated. If the variable does not exist, it will be created but
412will not be given a value, so it will be visible to \fBnamespace which\fR
413queries, but not to \fBinfo exists\fR queries.
414.RS
415.PP
416\fIOps\fR indicates which operations are of interest, and is a list of
417one or more of the following items:
418.TP
419\fBarray\fR
420Invoke \fIcommand\fR whenever the variable is accessed or modified via
421the \fBarray\fR command, provided that \fIname\fR is not a scalar
422variable at the time that the \fBarray\fR command is invoked. If
423\fIname\fR is a scalar variable, the access via the \fBarray\fR
424command will not trigger the trace.
425.TP
426\fBread\fR
427Invoke \fIcommand\fR whenever the variable is read.
428.TP
429\fBwrite\fR
430Invoke \fIcommand\fR whenever the variable is written.
431.TP
432\fBunset\fR
433Invoke \fIcommand\fR whenever the variable is unset. Variables
434can be unset explicitly with the \fBunset\fR command, or
435implicitly when procedures return (all of their local variables
436are unset). Variables are also unset when interpreters are
437deleted, but traces will not be invoked because there is no
438interpreter in which to execute them.
439.PP
440When the trace triggers, three arguments are appended to
441\fIcommand\fR so that the actual command is as follows:
442.CS
443\fIcommand name1 name2 op\fR
444.CE
445\fIName1\fR and \fIname2\fR give the name(s) for the variable
446being accessed: if the variable is a scalar then \fIname1\fR
447gives the variable's name and \fIname2\fR is an empty string;
448if the variable is an array element then \fIname1\fR gives the
449name of the array and name2 gives the index into the array;
450if an entire array is being deleted and the trace was registered
451on the overall array, rather than a single element, then \fIname1\fR
452gives the array name and \fIname2\fR is an empty string.
453\fIName1\fR and \fIname2\fR are not necessarily the same as the
454name used in the \fBtrace variable\fR command: the \fBupvar\fR
455command allows a procedure to reference a variable under a
456different name.
457\fIOp\fR indicates what operation is being performed on the
458variable, and is one of \fBread\fR, \fBwrite\fR, or \fBunset\fR as
459defined above.
460.PP
461\fICommand\fR executes in the same context as the code that invoked
462the traced operation: if the variable was accessed as part of a Tcl
463procedure, then \fIcommand\fR will have access to the same local
464variables as code in the procedure. This context may be different
465than the context in which the trace was created. If \fIcommand\fR
466invokes a procedure (which it normally does) then the procedure will
467have to use \fBupvar\fR or \fBuplevel\fR if it wishes to access the
468traced variable. Note also that \fIname1\fR may not necessarily be
469the same as the name used to set the trace on the variable;
470differences can occur if the access is made through a variable defined
471with the \fBupvar\fR command.
472.PP
473For read and write traces, \fIcommand\fR can modify the variable to
474affect the result of the traced operation. If \fIcommand\fR modifies
475the value of a variable during a read or write trace, then the new
476value will be returned as the result of the traced operation. The
477return value from \fIcommand\fR is ignored except that if it returns
478an error of any sort then the traced operation also returns an error
479with the same error message returned by the trace command (this
480mechanism can be used to implement read-only variables, for example).
481For write traces, \fIcommand\fR is invoked after the variable's value
482has been changed; it can write a new value into the variable to
483override the original value specified in the write operation. To
484implement read-only variables, \fIcommand\fR will have to restore the
485old value of the variable.
486.PP
487While \fIcommand\fR is executing during a read or write trace, traces
488on the variable are temporarily disabled. This means that reads and
489writes invoked by \fIcommand\fR will occur directly, without invoking
490\fIcommand\fR (or any other traces) again. However, if \fIcommand\fR
491unsets the variable then unset traces will be invoked.
492.PP
493When an unset trace is invoked, the variable has already been deleted:
494it will appear to be undefined with no traces. If an unset occurs
495because of a procedure return, then the trace will be invoked in the
496variable context of the procedure being returned to: the stack frame
497of the returning procedure will no longer exist. Traces are not
498disabled during unset traces, so if an unset trace command creates a
499new trace and accesses the variable, the trace will be invoked. Any
500errors in unset traces are ignored.
501.PP
502If there are multiple traces on a variable they are invoked in order
503of creation, most-recent first. If one trace returns an error, then
504no further traces are invoked for the variable. If an array element
505has a trace set, and there is also a trace set on the array as a
506whole, the trace on the overall array is invoked before the one on the
507element.
508.PP
509Once created, the trace remains in effect either until the trace is
510removed with the \fBtrace remove variable\fR command described below,
511until the variable is unset, or until the interpreter is deleted.
512Unsetting an element of array will remove any traces on that element,
513but will not remove traces on the overall array.
514.PP
515This command returns an empty string.
516.RE
517.RE
518.TP
519\fBtrace remove \fItype name opList command\fR
520Where \fItype\fR is either \fBcommand\fR, \fBexecution\fR or \fBvariable\fR.
521.RS
522.TP
523\fBtrace remove command\fI name opList command\fR
524If there is a trace set on command \fIname\fR with the operations and
525command given by \fIopList\fR and \fIcommand\fR, then the trace is
526removed, so that \fIcommand\fR will never again be invoked. Returns
527an empty string. If \fIname\fR doesn't exist, the command will throw
528an error.
529.TP
530\fBtrace remove execution\fI name opList command\fR
531If there is a trace set on command \fIname\fR with the operations and
532command given by \fIopList\fR and \fIcommand\fR, then the trace is
533removed, so that \fIcommand\fR will never again be invoked. Returns
534an empty string. If \fIname\fR doesn't exist, the command will throw
535an error.
536.TP
537\fBtrace remove variable\fI name opList command\fR
538If there is a trace set on variable \fIname\fR with the operations and
539command given by \fIopList\fR and \fIcommand\fR, then the trace is
540removed, so that \fIcommand\fR will never again be invoked. Returns
541an empty string.
542.RE
543.TP
544\fBtrace info \fItype name\fR
545Where \fItype\fR is either \fBcommand\fR, \fBexecution\fR or \fBvariable\fR.
546.RS
547.TP
548\fBtrace info command\fI name\fR
549Returns a list containing one element for each trace currently set on
550command \fIname\fR. Each element of the list is itself a list
551containing two elements, which are the \fIopList\fR and \fIcommand\fR
552associated with the trace. If \fIname\fR doesn't have any traces set,
553then the result of the command will be an empty string. If \fIname\fR
554doesn't exist, the command will throw an error.
555.TP
556\fBtrace info execution\fI name\fR
557Returns a list containing one element for each trace currently set on
558command \fIname\fR. Each element of the list is itself a list
559containing two elements, which are the \fIopList\fR and \fIcommand\fR
560associated with the trace. If \fIname\fR doesn't have any traces set,
561then the result of the command will be an empty string. If \fIname\fR
562doesn't exist, the command will throw an error.
563.TP
564\fBtrace info variable\fI name\fR
565Returns a list containing one element for each trace currently set on
566variable \fIname\fR. Each element of the list is itself a list
567containing two elements, which are the \fIopList\fR and \fIcommand\fR
568associated with the trace. If \fIname\fR doesn't exist or doesn't
569have any traces set, then the result of the command will be an empty
570string.
571.RE
572.PP
573For backwards compatibility, three other subcommands are available:
574.RS
575.TP
576\fBtrace variable \fIname ops command\fR
577This is equivalent to \fBtrace add variable \fIname ops command\fR.
578.TP
579\fBtrace vdelete \fIname ops command\fR
580This is equivalent to \fBtrace remove variable \fIname ops command\fR
581.TP
582\fBtrace vinfo \fIname\fR
583This is equivalent to \fBtrace info variable \fIname\fR
584.RE
585.PP
586These subcommands are deprecated and will likely be removed in a
587future version of Tcl. They use an older syntax in which \fBarray\fR,
588\fBread\fR, \fBwrite\fR, \fBunset\fR are replaced by \fBa\fR, \fBr\fR,
589\fBw\fR and \fBu\fR respectively, and the \fIops\fR argument is not a
590list, but simply a string concatenation of the operations, such as
591\fBrwua\fR.
592.SH EXAMPLES
593Print a message whenever either of the global variables \fBfoo\fR and
594\fBbar\fR are updated, even if they have a different local name at the
595time (which can be done with the \fBupvar\fR command):
596.CS
597proc tracer {varname args} {
598 upvar #0 $varname var
599 puts "$varname was updated to be \e"$var\e""
600}
601\fBtrace add\fR variable foo write "tracer foo"
602\fBtrace add\fR variable bar write "tracer bar"
603.CE
604.PP
605Ensure that the global variable \fBfoobar\fR always contains the
606product of the global variables \fBfoo\fR and \fBbar\fR:
607.CS
608proc doMult args {
609 global foo bar foobar
610 set foobar [expr {$foo * $bar}]
611}
612\fBtrace add\fR variable foo write doMult
613\fBtrace add\fR variable bar write doMult
614.CE
615
616.SH "SEE ALSO"
617set(n), unset(n)
618
619.SH KEYWORDS
620read, command, rename, variable, write, trace, unset