home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tcl2-73c.zip / tcl7.3 / doc / trace.n < prev    next >
Text File  |  1993-06-16  |  7KB  |  176 lines

  1. '\"
  2. '\" Copyright (c) 1993 The Regents of the University of California.
  3. '\" All rights reserved.
  4. '\"
  5. '\" Permission is hereby granted, without written agreement and without
  6. '\" license or royalty fees, to use, copy, modify, and distribute this
  7. '\" documentation for any purpose, provided that the above copyright
  8. '\" notice and the following two paragraphs appear in all copies.
  9. '\"
  10. '\" IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
  11. '\" FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  12. '\" ARISING OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  13. '\" CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. '\"
  15. '\" THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16. '\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17. '\" AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  18. '\" ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  19. '\" PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20. '\" 
  21. '\" $Header: /user6/ouster/tcl/man/RCS/trace.n,v 1.3 93/06/16 16:36:39 ouster Exp $ SPRITE (Berkeley)
  22. '\" 
  23. .so man.macros
  24. .HS trace tcl
  25. .BS
  26. '\" Note:  do not modify the .SH NAME line immediately below!
  27. .SH NAME
  28. trace \- Monitor variable accesses
  29. .SH SYNOPSIS
  30. \fBtrace \fIoption\fR ?\fIarg arg ...\fR?
  31. .BE
  32.  
  33. .SH DESCRIPTION
  34. .PP
  35. This command causes Tcl commands to be executed whenever certain operations are
  36. invoked.  At present, only variable tracing is implemented. The
  37. legal \fIoption\fR's (which may be abbreviated) are:
  38. .TP
  39. \fBtrace variable \fIname ops command\fR
  40. Arrange for \fIcommand\fR to be executed whenever variable \fIname\fR
  41. is accessed in one of the ways given by \fIops\fR.  \fIName\fR may
  42. refer to a normal variable, an element of an array, or to an array
  43. as a whole (i.e. \fIname\fR may be just the name of an array, with no
  44. parenthesized index).  If \fIname\fR refers to a whole array, then
  45. \fIcommand\fR is invoked whenever any element of the array is
  46. manipulated.
  47. .RS
  48. .LP
  49. \fIOps\fR indicates which operations are of interest, and consists of
  50. one or more of the following letters:
  51. .RS
  52. .TP
  53. \fBr\fR
  54. Invoke \fIcommand\fR whenever the variable is read.
  55. .TP
  56. \fBw\fR
  57. Invoke \fIcommand\fR whenever the variable is written.
  58. .TP
  59. \fBu\fR
  60. Invoke \fIcommand\fR whenever the variable is unset.  Variables
  61. can be unset explicitly with the \fBunset\fR command, or
  62. implicitly when procedures return (all of their local variables
  63. are unset).  Variables are also unset when interpreters are
  64. deleted, but traces will not be invoked because there is no
  65. interpreter in which to execute them.
  66. .RE
  67. .LP
  68. When the trace triggers, three arguments are appended to
  69. \fIcommand\fR so that the actual command is as follows:
  70. .DS C
  71. \fIcommand name1 name2 op\fR
  72. .DE
  73. \fIName1\fR and \fIname2\fR give the name(s) for the variable
  74. being accessed:  if the variable is a scalar then \fIname1\fR
  75. gives the variable's name and \fIname2\fR is an empty string;
  76. if the variable is an array element then \fIname1\fR gives the
  77. name of the array and name2 gives the index into the array;
  78. if an entire array is being deleted and the trace was registered
  79. on the overall array, rather than a single element, then \fIname1\fR
  80. gives the array name and \fIname2\fR is an empty string.
  81. \fIOp\fR indicates what operation is being performed on the
  82. variable, and is one of \fBr\fR, \fBw\fR, or \fBu\fR as
  83. defined above.
  84. .LP
  85. \fICommand\fR executes in the same context as the code that invoked
  86. the traced operation:  if the variable was accessed as part of a
  87. Tcl procedure, then \fIcommand\fR will have access to the same
  88. local variables as code in the procedure.  This context may be
  89. different than the context in which the trace was created.
  90. If \fIcommand\fR invokes a procedure (which it normally does) then
  91. the procedure will have to use \fBupvar\fR or \fBuplevel\fR if it
  92. wishes to access the traced variable.
  93. Note also that \fIname1\fR may not necessarily be the same as the name
  94. used to set the trace on the variable;  differences can occur if
  95. the access is made through a variable defined with the \fBupvar\fR
  96. command.
  97. .LP
  98. For read and write traces, \fIcommand\fR can modify
  99. the variable to affect the result of the traced operation.
  100. If \fIcommand\fR modifies the value of a variable during a
  101. read or write trace, then the new value will be returned as the
  102. result of the traced operation.
  103. The return value from  \fIcommand\fR is ignored except that
  104. if it returns an error of any sort then the traced operation
  105. also returns an error with
  106. .VS
  107. the same error message returned by the trace command
  108. .VE
  109. (this mechanism can be used to implement read-only variables, for
  110. example).
  111. For write traces, \fIcommand\fR is invoked after the variable's
  112. value has been changed; it can write a new value into the variable
  113. to override the original value specified in the write operation.
  114. To implement read-only variables, \fIcommand\fR will have to restore
  115. the old value of the variable.
  116. .LP
  117. While \fIcommand\fR is executing during a read or write trace, traces
  118. on the variable are temporarily disabled.
  119. This means that reads and writes invoked by
  120. \fIcommand\fR will occur directly, without invoking \fIcommand\fR
  121. (or any other traces) again.
  122. .VS
  123. However, if \fIcommand\fR unsets the variable then unset traces
  124. will be invoked.
  125. .VE
  126. .LP
  127. When an unset trace is invoked, the variable has already been
  128. deleted:  it will appear to be undefined with no traces.
  129. If an unset occurs because of a procedure return, then the
  130. trace will be invoked in the variable context of the procedure
  131. being returned to:  the stack frame of the returning procedure
  132. will no longer exist.
  133. Traces are not disabled during unset traces, so if an unset trace
  134. command creates a new trace and accesses the variable, the
  135. trace will be invoked.
  136. .VS
  137. Any errors in unset traces are ignored.
  138. .VE
  139. .LP
  140. If there are multiple traces on a variable they are invoked
  141. in order of creation, most-recent first.
  142. If one trace returns an error, then no further traces are
  143. invoked for the variable.
  144. If an array element has a trace set, and there is also a trace
  145. set on the array as a whole, the trace on the overall array
  146. is invoked before the one on the element.
  147. .LP
  148. Once created, the trace remains in effect either until the
  149. trace is removed with the \fBtrace vdelete\fR command described
  150. below, until the variable is unset, or until the interpreter
  151. is deleted.
  152. Unsetting an element of array will remove any traces on that
  153. element, but will not remove traces on the overall array.
  154. .LP
  155. This command returns an empty string.
  156. .RE
  157. .TP
  158. \fBtrace vdelete \fIname ops command\fR
  159. If there is a trace set on variable \fIname\fR with the
  160. operations and command given by \fIops\fR and \fIcommand\fR,
  161. then the trace is removed, so that \fIcommand\fR will never
  162. again be invoked.
  163. Returns an empty string.
  164. .TP
  165. \fBtrace vinfo \fIname\fR
  166. Returns a list containing one element for each trace
  167. currently set on variable \fIname\fR.
  168. Each element of the list is itself a list containing two
  169. elements, which are the \fIops\fR and \fIcommand\fR associated
  170. with the trace.
  171. If \fIname\fR doesn't exist or doesn't have any traces set, then
  172. the result of the command will be an empty string.
  173.  
  174. .SH KEYWORDS
  175. read, variable, write, trace, unset
  176.