| 1 |
'\" |
| 2 |
'\" Copyright (c) 1989-1993 The Regents of the University of California. |
| 3 |
'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. |
| 4 |
'\" Copyright (c) 2002 Kevin B. Kenny <[email protected]>. All rights reserved. |
| 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 |
.TH Tcl_CreateTrace 3 "" Tcl "Tcl Library Procedures" |
| 10 |
.so man.macros |
| 11 |
.BS |
| 12 |
.SH NAME |
| 13 |
Tcl_CreateTrace, Tcl_CreateObjTrace, Tcl_DeleteTrace \- arrange for command execution to be traced |
| 14 |
.SH SYNOPSIS |
| 15 |
.nf |
| 16 |
\fB#include <tcl.h>\fR |
| 17 |
.sp |
| 18 |
Tcl_Trace |
| 19 |
\fBTcl_CreateTrace\fR(\fIinterp, level, proc, clientData\fR) |
| 20 |
.sp |
| 21 |
Tcl_Trace |
| 22 |
\fBTcl_CreateObjTrace\fR(\fIinterp, level, flags, objProc, clientData, deleteProc\fR) |
| 23 |
.sp |
| 24 |
\fBTcl_DeleteTrace\fR(\fIinterp, trace\fR) |
| 25 |
.SH ARGUMENTS |
| 26 |
.AS Tcl_CmdObjTraceDeleteProc *deleteProc |
| 27 |
.AP Tcl_Interp *interp in |
| 28 |
Interpreter containing command to be traced or untraced. |
| 29 |
.AP int level in |
| 30 |
Only commands at or below this nesting level will be traced unless |
| 31 |
0 is specified. 1 means |
| 32 |
top-level commands only, 2 means top-level commands or those that are |
| 33 |
invoked as immediate consequences of executing top-level commands |
| 34 |
(procedure bodies, bracketed commands, etc.) and so on. |
| 35 |
A value of 0 means that commands at any level are traced. |
| 36 |
.AP int flags in |
| 37 |
Flags governing the trace execution. See below for details. |
| 38 |
.AP Tcl_CmdObjTraceProc *objProc in |
| 39 |
Procedure to call for each command that is executed. See below for |
| 40 |
details of the calling sequence. |
| 41 |
.AP Tcl_CmdTraceProc *proc in |
| 42 |
Procedure to call for each command that is executed. See below for |
| 43 |
details on the calling sequence. |
| 44 |
.AP ClientData clientData in |
| 45 |
Arbitrary one-word value to pass to \fIobjProc\fR or \fIproc\fR. |
| 46 |
.AP Tcl_CmdObjTraceDeleteProc *deleteProc in |
| 47 |
Procedure to call when the trace is deleted. See below for details of |
| 48 |
the calling sequence. A NULL pointer is permissible and results in no |
| 49 |
callback when the trace is deleted. |
| 50 |
.AP Tcl_Trace trace in |
| 51 |
Token for trace to be removed (return value from previous call |
| 52 |
to \fBTcl_CreateTrace\fR). |
| 53 |
.BE |
| 54 |
.SH DESCRIPTION |
| 55 |
.PP |
| 56 |
\fBTcl_CreateObjTrace\fR arranges for command tracing. After it is |
| 57 |
called, \fIobjProc\fR will be invoked before the Tcl interpreter calls |
| 58 |
any command procedure when evaluating commands in \fIinterp\fR. |
| 59 |
The return value from \fBTcl_CreateObjTrace\fR is a token for the trace, |
| 60 |
which may be passed to \fBTcl_DeleteTrace\fR to remove the trace. |
| 61 |
There may be many traces in effect simultaneously for the same |
| 62 |
interpreter. |
| 63 |
.PP |
| 64 |
\fIobjProc\fR should have arguments and result that match the type, |
| 65 |
\fBTcl_CmdObjTraceProc\fR: |
| 66 |
.PP |
| 67 |
.CS |
| 68 |
typedef int \fBTcl_CmdObjTraceProc\fR( |
| 69 |
\fBClientData\fR \fIclientData\fR, |
| 70 |
\fBTcl_Interp\fR* \fIinterp\fR, |
| 71 |
int \fIlevel\fR, |
| 72 |
const char *\fIcommand\fR, |
| 73 |
\fBTcl_Command\fR \fIcommandToken\fR, |
| 74 |
int \fIobjc\fR, |
| 75 |
\fBTcl_Obj\fR *const \fIobjv\fR[]); |
| 76 |
.CE |
| 77 |
.PP |
| 78 |
The \fIclientData\fR and \fIinterp\fR parameters are copies of the |
| 79 |
corresponding arguments given to \fBTcl_CreateTrace\fR. |
| 80 |
\fIClientData\fR typically points to an application-specific data |
| 81 |
structure that describes what to do when \fIobjProc\fR is invoked. The |
| 82 |
\fIlevel\fR parameter gives the nesting level of the command (1 for |
| 83 |
top-level commands passed to \fBTcl_Eval\fR by the application, 2 for |
| 84 |
the next-level commands passed to \fBTcl_Eval\fR as part of parsing or |
| 85 |
interpreting level-1 commands, and so on). The \fIcommand\fR parameter |
| 86 |
points to a string containing the text of the command, before any |
| 87 |
argument substitution. The \fIcommandToken\fR parameter is a Tcl |
| 88 |
command token that identifies the command to be invoked. The token |
| 89 |
may be passed to \fBTcl_GetCommandName\fR, |
| 90 |
\fBTcl_GetCommandInfoFromToken\fR, or \fBTcl_SetCommandInfoFromToken\fR to |
| 91 |
manipulate the definition of the command. The \fIobjc\fR and \fIobjv\fR |
| 92 |
parameters designate the final parameter count and parameter vector |
| 93 |
that will be passed to the command, and have had all substitutions |
| 94 |
performed. |
| 95 |
.PP |
| 96 |
The \fIobjProc\fR callback is expected to return a standard Tcl status |
| 97 |
return code. If this code is \fBTCL_OK\fR (the normal case), then |
| 98 |
the Tcl interpreter will invoke the command. Any other return code |
| 99 |
is treated as if the command returned that status, and the command is |
| 100 |
\fInot\fR invoked. |
| 101 |
.PP |
| 102 |
The \fIobjProc\fR callback must not modify \fIobjv\fR in any way. |
| 103 |
.PP |
| 104 |
Tracing will only occur for commands at nesting level less than |
| 105 |
or equal to the \fIlevel\fR parameter (i.e. the \fIlevel\fR |
| 106 |
parameter to \fIobjProc\fR will always be less than or equal to the |
| 107 |
\fIlevel\fR parameter to \fBTcl_CreateTrace\fR). |
| 108 |
.PP |
| 109 |
Tracing has a significant effect on runtime performance because it |
| 110 |
causes the bytecode compiler to refrain from generating in-line code |
| 111 |
for Tcl commands such as \fBif\fR and \fBwhile\fR in order that they |
| 112 |
may be traced. If traces for the built-in commands are not required, |
| 113 |
the \fIflags\fR parameter may be set to the constant value |
| 114 |
\fBTCL_ALLOW_INLINE_COMPILATION\fR. In this case, traces on built-in |
| 115 |
commands may or may not result in trace callbacks, depending on the |
| 116 |
state of the interpreter, but run-time performance will be improved |
| 117 |
significantly. (This functionality is desirable, for example, when |
| 118 |
using \fBTcl_CreateObjTrace\fR to implement an execution time |
| 119 |
profiler.) |
| 120 |
.PP |
| 121 |
Calls to \fIobjProc\fR will be made by the Tcl parser immediately before |
| 122 |
it calls the command procedure for the command (\fIcmdProc\fR). This |
| 123 |
occurs after argument parsing and substitution, so tracing for |
| 124 |
substituted commands occurs before tracing of the commands |
| 125 |
containing the substitutions. If there is a syntax error in a |
| 126 |
command, or if there is no command procedure associated with a |
| 127 |
command name, then no tracing will occur for that command. If a |
| 128 |
string passed to Tcl_Eval contains multiple commands (bracketed, or |
| 129 |
on different lines) then multiple calls to \fIobjProc\fR will occur, |
| 130 |
one for each command. |
| 131 |
.PP |
| 132 |
\fBTcl_DeleteTrace\fR removes a trace, so that no future calls will be |
| 133 |
made to the procedure associated with the trace. After \fBTcl_DeleteTrace\fR |
| 134 |
returns, the caller should never again use the \fItrace\fR token. |
| 135 |
.PP |
| 136 |
When \fBTcl_DeleteTrace\fR is called, the interpreter invokes the |
| 137 |
\fIdeleteProc\fR that was passed as a parameter to |
| 138 |
\fBTcl_CreateObjTrace\fR. The \fIdeleteProc\fR must match the type, |
| 139 |
\fBTcl_CmdObjTraceDeleteProc\fR: |
| 140 |
.PP |
| 141 |
.CS |
| 142 |
typedef void \fBTcl_CmdObjTraceDeleteProc\fR( |
| 143 |
\fBClientData\fR \fIclientData\fR); |
| 144 |
.CE |
| 145 |
.PP |
| 146 |
The \fIclientData\fR parameter will be the same as the |
| 147 |
\fIclientData\fR parameter that was originally passed to |
| 148 |
\fBTcl_CreateObjTrace\fR. |
| 149 |
.PP |
| 150 |
\fBTcl_CreateTrace\fR is an alternative interface for command tracing, |
| 151 |
\fInot recommended for new applications\fR. It is provided for backward |
| 152 |
compatibility with code that was developed for older versions of the |
| 153 |
Tcl interpreter. It is similar to \fBTcl_CreateObjTrace\fR, except |
| 154 |
that its \fIproc\fR parameter should have arguments and result that |
| 155 |
match the type \fBTcl_CmdTraceProc\fR: |
| 156 |
.PP |
| 157 |
.CS |
| 158 |
typedef void \fBTcl_CmdTraceProc\fR( |
| 159 |
ClientData \fIclientData\fR, |
| 160 |
Tcl_Interp *\fIinterp\fR, |
| 161 |
int \fIlevel\fR, |
| 162 |
char *\fIcommand\fR, |
| 163 |
Tcl_CmdProc *\fIcmdProc\fR, |
| 164 |
ClientData \fIcmdClientData\fR, |
| 165 |
int \fIargc\fR, |
| 166 |
const char *\fIargv\fR[]); |
| 167 |
.CE |
| 168 |
.PP |
| 169 |
The parameters to the \fIproc\fR callback are similar to those of the |
| 170 |
\fIobjProc\fR callback above. The \fIcommandToken\fR is |
| 171 |
replaced with \fIcmdProc\fR, a pointer to the (string-based) command |
| 172 |
procedure that will be invoked; and \fIcmdClientData\fR, the client |
| 173 |
data that will be passed to the procedure. The \fIobjc\fR parameter |
| 174 |
is replaced with an \fIargv\fR parameter, that gives the arguments to |
| 175 |
the command as character strings. |
| 176 |
\fIProc\fR must not modify the \fIcommand\fR or \fIargv\fR strings. |
| 177 |
.PP |
| 178 |
If a trace created with \fBTcl_CreateTrace\fR is in effect, inline |
| 179 |
compilation of Tcl commands such as \fBif\fR and \fBwhile\fR is always |
| 180 |
disabled. There is no notification when a trace created with |
| 181 |
\fBTcl_CreateTrace\fR is deleted. |
| 182 |
There is no way to be notified when the trace created by |
| 183 |
\fBTcl_CreateTrace\fR is deleted. There is no way for the \fIproc\fR |
| 184 |
associated with a call to \fBTcl_CreateTrace\fR to abort execution of |
| 185 |
\fIcommand\fR. |
| 186 |
.SH KEYWORDS |
| 187 |
command, create, delete, interpreter, trace |