OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [doc/] [trace.n] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
'\"
2
'\" Copyright (c) 1993 The Regents of the University of California.
3
'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
4
'\"
5
'\" See the file "license.terms" for information on usage and redistribution
6
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7
'\"
8
'\" RCS: @(#) $Id: trace.n,v 1.1.1.1 2002-01-16 10:25:25 markom Exp $
9
'\"
10
.so man.macros
11
.TH trace n "" Tcl "Tcl Built-In Commands"
12
.BS
13
'\" Note:  do not modify the .SH NAME line immediately below!
14
.SH NAME
15
trace \- Monitor variable accesses
16
.SH SYNOPSIS
17
\fBtrace \fIoption\fR ?\fIarg arg ...\fR?
18
.BE
19
 
20
.SH DESCRIPTION
21
.PP
22
This command causes Tcl commands to be executed whenever certain operations are
23
invoked.  At present, only variable tracing is implemented. The
24
legal \fIoption\fR's (which may be abbreviated) are:
25
.TP
26
\fBtrace variable \fIname ops command\fR
27
Arrange for \fIcommand\fR to be executed whenever variable \fIname\fR
28
is accessed in one of the ways given by \fIops\fR.  \fIName\fR may
29
refer to a normal variable, an element of an array, or to an array
30
as a whole (i.e. \fIname\fR may be just the name of an array, with no
31
parenthesized index).  If \fIname\fR refers to a whole array, then
32
\fIcommand\fR is invoked whenever any element of the array is
33
manipulated.
34
.RS
35
.PP
36
\fIOps\fR indicates which operations are of interest, and consists of
37
one or more of the following letters:
38
.TP
39
\fBr\fR
40
Invoke \fIcommand\fR whenever the variable is read.
41
.TP
42
\fBw\fR
43
Invoke \fIcommand\fR whenever the variable is written.
44
.TP
45
\fBu\fR
46
Invoke \fIcommand\fR whenever the variable is unset.  Variables
47
can be unset explicitly with the \fBunset\fR command, or
48
implicitly when procedures return (all of their local variables
49
are unset).  Variables are also unset when interpreters are
50
deleted, but traces will not be invoked because there is no
51
interpreter in which to execute them.
52
.PP
53
When the trace triggers, three arguments are appended to
54
\fIcommand\fR so that the actual command is as follows:
55
.CS
56
\fIcommand name1 name2 op\fR
57
.CE
58
\fIName1\fR and \fIname2\fR give the name(s) for the variable
59
being accessed:  if the variable is a scalar then \fIname1\fR
60
gives the variable's name and \fIname2\fR is an empty string;
61
if the variable is an array element then \fIname1\fR gives the
62
name of the array and name2 gives the index into the array;
63
if an entire array is being deleted and the trace was registered
64
on the overall array, rather than a single element, then \fIname1\fR
65
gives the array name and \fIname2\fR is an empty string.
66
\fIName1\fR and \fIname2\fR are not necessarily the same as the
67
name used in the \fBtrace variable\fR command:  the \fBupvar\fR
68
command allows a procedure to reference a variable under a
69
different name.
70
\fIOp\fR indicates what operation is being performed on the
71
variable, and is one of \fBr\fR, \fBw\fR, or \fBu\fR as
72
defined above.
73
.PP
74
\fICommand\fR executes in the same context as the code that invoked
75
the traced operation:  if the variable was accessed as part of a
76
Tcl procedure, then \fIcommand\fR will have access to the same
77
local variables as code in the procedure.  This context may be
78
different than the context in which the trace was created.
79
If \fIcommand\fR invokes a procedure (which it normally does) then
80
the procedure will have to use \fBupvar\fR or \fBuplevel\fR if it
81
wishes to access the traced variable.
82
Note also that \fIname1\fR may not necessarily be the same as the name
83
used to set the trace on the variable;  differences can occur if
84
the access is made through a variable defined with the \fBupvar\fR
85
command.
86
.PP
87
For read and write traces, \fIcommand\fR can modify
88
the variable to affect the result of the traced operation.
89
If \fIcommand\fR modifies the value of a variable during a
90
read or write trace, then the new value will be returned as the
91
result of the traced operation.
92
The return value from  \fIcommand\fR is ignored except that
93
if it returns an error of any sort then the traced operation
94
also returns an error with
95
the same error message returned by the trace command
96
(this mechanism can be used to implement read-only variables, for
97
example).
98
For write traces, \fIcommand\fR is invoked after the variable's
99
value has been changed; it can write a new value into the variable
100
to override the original value specified in the write operation.
101
To implement read-only variables, \fIcommand\fR will have to restore
102
the old value of the variable.
103
.PP
104
While \fIcommand\fR is executing during a read or write trace, traces
105
on the variable are temporarily disabled.
106
This means that reads and writes invoked by
107
\fIcommand\fR will occur directly, without invoking \fIcommand\fR
108
(or any other traces) again.
109
However, if \fIcommand\fR unsets the variable then unset traces
110
will be invoked.
111
.PP
112
When an unset trace is invoked, the variable has already been
113
deleted:  it will appear to be undefined with no traces.
114
If an unset occurs because of a procedure return, then the
115
trace will be invoked in the variable context of the procedure
116
being returned to:  the stack frame of the returning procedure
117
will no longer exist.
118
Traces are not disabled during unset traces, so if an unset trace
119
command creates a new trace and accesses the variable, the
120
trace will be invoked.
121
Any errors in unset traces are ignored.
122
.PP
123
If there are multiple traces on a variable they are invoked
124
in order of creation, most-recent first.
125
If one trace returns an error, then no further traces are
126
invoked for the variable.
127
If an array element has a trace set, and there is also a trace
128
set on the array as a whole, the trace on the overall array
129
is invoked before the one on the element.
130
.PP
131
Once created, the trace remains in effect either until the
132
trace is removed with the \fBtrace vdelete\fR command described
133
below, until the variable is unset, or until the interpreter
134
is deleted.
135
Unsetting an element of array will remove any traces on that
136
element, but will not remove traces on the overall array.
137
.PP
138
This command returns an empty string.
139
.RE
140
.TP
141
\fBtrace vdelete \fIname ops command\fR
142
If there is a trace set on variable \fIname\fR with the
143
operations and command given by \fIops\fR and \fIcommand\fR,
144
then the trace is removed, so that \fIcommand\fR will never
145
again be invoked.
146
Returns an empty string.
147
.TP
148
\fBtrace vinfo \fIname\fR
149
Returns a list containing one element for each trace
150
currently set on variable \fIname\fR.
151
Each element of the list is itself a list containing two
152
elements, which are the \fIops\fR and \fIcommand\fR associated
153
with the trace.
154
If \fIname\fR doesn't exist or doesn't have any traces set, then
155
the result of the command will be an empty string.
156
 
157
.SH KEYWORDS
158
read, variable, write, trace, unset

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.