| 1 |
'\" |
| 2 |
'\" Copyright 1991-1997 by Bell Labs Innovations for Lucent Technologies. |
| 3 |
'\" |
| 4 |
'\" Permission to use, copy, modify, and distribute this software and its |
| 5 |
'\" documentation for any purpose and without fee is hereby granted, provided |
| 6 |
'\" that the above copyright notice appear in all copies and that both that the |
| 7 |
'\" copyright notice and warranty disclaimer appear in supporting documentation, |
| 8 |
'\" and that the names of Lucent Technologies any of their entities not be used |
| 9 |
'\" in advertising or publicity pertaining to distribution of the software |
| 10 |
'\" without specific, written prior permission. |
| 11 |
'\" |
| 12 |
'\" Lucent Technologies disclaims all warranties with regard to this software, |
| 13 |
'\" including all implied warranties of merchantability and fitness. In no event |
| 14 |
'\" shall Lucent Technologies be liable for any special, indirect or |
| 15 |
'\" consequential damages or any damages whatsoever resulting from loss of use, |
| 16 |
'\" data or profits, whether in an action of contract, negligence or other |
| 17 |
'\" tortuous action, arising out of or in connection with the use or performance |
| 18 |
'\" of this software. |
| 19 |
'\" |
| 20 |
'\" |
| 21 |
.so man.macros |
| 22 |
.TH watch n BLT_VERSION BLT "BLT Built-In Commands" |
| 23 |
.BS |
| 24 |
.SH NAME |
| 25 |
watch \- call Tcl procedures before and after each command |
| 26 |
.SH SYNOPSIS |
| 27 |
\fBwatch create\fR \fIwatchName\fR ?\fIoptions\fR? |
| 28 |
.sp |
| 29 |
\fBwatch activate\fR \fIwatchName\fR |
| 30 |
.sp |
| 31 |
\fBwatch deactivate\fR \fIwatchName\fR |
| 32 |
.sp |
| 33 |
\fBwatch delete\fR \fIwatchName\fR |
| 34 |
.sp |
| 35 |
\fBwatch configure\fR \fIwatchName\fR ?\fIoptions\fR |
| 36 |
.sp |
| 37 |
\fBwatch info\fR \fIwatchName\fR |
| 38 |
.sp |
| 39 |
\fBwatch names\fR |
| 40 |
.BE |
| 41 |
.SH DESCRIPTION |
| 42 |
The \fBwatch\fR command arranges for Tcl procedures to be invoked |
| 43 |
before and after the execution of each Tcl command. |
| 44 |
.SH INTRODUCTION |
| 45 |
When an error occurs in Tcl, the global variable \fIerrorInfo\fR will |
| 46 |
contain a stack-trace of the active procedures when the error occured. |
| 47 |
Sometimes, however, the stack trace is insufficient. You may need to |
| 48 |
know exactly where in the program's execution the error occured. In |
| 49 |
cases like this, a more general tracing facility would be useful. |
| 50 |
.PP |
| 51 |
The \fBwatch\fR command lets you designate Tcl procedures to be |
| 52 |
invoked before and after the execution of each Tcl command. This |
| 53 |
means you can display the command line and its results for each |
| 54 |
command as it executes. Another use is to profile your Tcl commands. |
| 55 |
You can profile any Tcl command (like \fBif\fR and \fBset\fR), not just |
| 56 |
Tcl procedures. |
| 57 |
.SH EXAMPLE |
| 58 |
The following example use \fBwatch\fR to trace Tcl commands |
| 59 |
(printing to standard error) both before and after they are executed. |
| 60 |
.CS |
| 61 |
proc preCmd { level command argv } { |
| 62 |
set name [lindex $argv 0] |
| 63 |
puts stderr "$level $name => $command" |
| 64 |
} |
| 65 |
|
| 66 |
proc postCmd { level command argv retcode results } { |
| 67 |
set name [lindex $argv 0] |
| 68 |
puts stderr "$level $name => $argv\n<= ($retcode) $results" |
| 69 |
} |
| 70 |
watch create trace \\ |
| 71 |
-postcmd postCmd -precmd preCmd |
| 72 |
.CE |
| 73 |
.SH "OPERATIONS" |
| 74 |
The following operations are available for the \fBwatch\fR command: |
| 75 |
.TP |
| 76 |
\fBwatch activate \fIwatchName\fR |
| 77 |
Activates the watch, causing Tcl commands the be traced to the |
| 78 |
maximum depth selected. |
| 79 |
.TP |
| 80 |
\fBwatch create \fIwatchName\fR ?\fIoptions\fR?... |
| 81 |
Creates a new watch \fIwatchName\fR. It's an error if another watch |
| 82 |
\fIwatchName\fR already exists and an error message will be returned. |
| 83 |
\fIOptions\fR may have any of the values accepted by the |
| 84 |
\fBwatch configure\fR command. |
| 85 |
This command returns the empty string. |
| 86 |
.TP |
| 87 |
\fBwatch configure \fIwatchName\fR ?\fIoptions...\fR? |
| 88 |
Queries or modifies the configuration options of the watch \fIwatchName\fR. |
| 89 |
\fIWatchName\fR is the name of a watch. |
| 90 |
\fIOptions\fR may have any of the following values: |
| 91 |
.RS |
| 92 |
.TP |
| 93 |
\fB\-active \fIboolean\fR |
| 94 |
Specifies if the watch is active. |
| 95 |
By default, watches are active when created. |
| 96 |
.TP |
| 97 |
\fB\-postcmd \fIstring\fR |
| 98 |
Specifies a Tcl procedure to be called immediately after each Tcl |
| 99 |
command. \fIString\fR is name of a Tcl procedure and any extra |
| 100 |
arguments to be passed to it. Before \fIstring\fR is invoked, five |
| 101 |
more arguments are appended: 1) the current level 2) the current |
| 102 |
command line 3) a list containing the command after substitutions and |
| 103 |
split into words 4) the return code of the command, and 5) the results |
| 104 |
of the command. The return status of the postcmd procedure is always |
| 105 |
ignored. |
| 106 |
.TP |
| 107 |
\fB\-precmd \fIstring\fR |
| 108 |
Specifies a Tcl procedure to be called immediately before each Tcl |
| 109 |
command. \fIString\fR is name of a Tcl procedure and any extra |
| 110 |
arguments to be passed to it. Before \fIstring\fR is invoked, three |
| 111 |
arguments are appended: 1) the current level 2) the current command |
| 112 |
line, and 3) a list containing the command after substitutions and |
| 113 |
split into words. The return status of the \fB\-precmd\fR procedure |
| 114 |
is always ignored. |
| 115 |
.TP |
| 116 |
\fB\-maxlevel \fInumber\fR |
| 117 |
Specifies the maximum evaluation depth to watch Tcl commands. |
| 118 |
The default maximum level is 10000. |
| 119 |
.RE |
| 120 |
.TP |
| 121 |
\fBwatch deactivate \fIwatchName\fR |
| 122 |
Deactivates the watch. The \fB\-precmd\fR and \fB\-postcmd\fR procedures |
| 123 |
will no longer be invoked. |
| 124 |
.TP |
| 125 |
\fBwatch info \fIwatchName\fR |
| 126 |
Returns the configuration information associated with the |
| 127 |
watch \fIwatchName\fR. \fIWatchName\fR is the name of a watch. |
| 128 |
.TP |
| 129 |
\fBwatch names\fR ?\fIstate\fR? |
| 130 |
Lists the names of the watches for a given state. \fIState\fR may be |
| 131 |
one of the following: \fBactive\fR, \fBidle\fR, or \fBignore\fR. If a |
| 132 |
\fIstate\fR argument isn't specified, |
| 133 |
all watches are |
| 134 |
listed. |
| 135 |
.RE |
| 136 |
.SH KEYWORDS |
| 137 |
debug, profile |