| [25] | 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 by Kevin B. Kenny <kennykb@acm.org>. 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 | '\" RCS: @(#) $Id: CrtTrace.3,v 1.14 2008/03/26 09:59:22 dkf Exp $ |
|---|
| 10 | '\" |
|---|
| 11 | .so man.macros |
|---|
| 12 | .TH Tcl_CreateTrace 3 "" Tcl "Tcl Library Procedures" |
|---|
| 13 | .BS |
|---|
| 14 | .SH NAME |
|---|
| 15 | Tcl_CreateTrace, Tcl_CreateObjTrace, Tcl_DeleteTrace \- arrange for command execution to be traced |
|---|
| 16 | .SH SYNOPSIS |
|---|
| 17 | .nf |
|---|
| 18 | \fB#include <tcl.h>\fR |
|---|
| 19 | .sp |
|---|
| 20 | Tcl_Trace |
|---|
| 21 | \fBTcl_CreateTrace\fR(\fIinterp, level, proc, clientData\fR) |
|---|
| 22 | .sp |
|---|
| 23 | Tcl_Trace |
|---|
| 24 | \fBTcl_CreateObjTrace\fR(\fIinterp, level, flags, objProc, clientData, deleteProc\fR) |
|---|
| 25 | .sp |
|---|
| 26 | \fBTcl_DeleteTrace\fR(\fIinterp, trace\fR) |
|---|
| 27 | .SH ARGUMENTS |
|---|
| 28 | .AS Tcl_CmdObjTraceDeleteProc *deleteProc |
|---|
| 29 | .AP Tcl_Interp *interp in |
|---|
| 30 | Interpreter containing command to be traced or untraced. |
|---|
| 31 | .AP int level in |
|---|
| 32 | Only commands at or below this nesting level will be traced unless |
|---|
| 33 | 0 is specified. 1 means |
|---|
| 34 | top-level commands only, 2 means top-level commands or those that are |
|---|
| 35 | invoked as immediate consequences of executing top-level commands |
|---|
| 36 | (procedure bodies, bracketed commands, etc.) and so on. |
|---|
| 37 | A value of 0 means that commands at any level are traced. |
|---|
| 38 | .AP int flags in |
|---|
| 39 | Flags governing the trace execution. See below for details. |
|---|
| 40 | .AP Tcl_CmdObjTraceProc *objProc in |
|---|
| 41 | Procedure to call for each command that is executed. See below for |
|---|
| 42 | details of the calling sequence. |
|---|
| 43 | .AP Tcl_CmdTraceProc *proc in |
|---|
| 44 | Procedure to call for each command that is executed. See below for |
|---|
| 45 | details on the calling sequence. |
|---|
| 46 | .AP ClientData clientData in |
|---|
| 47 | Arbitrary one-word value to pass to \fIobjProc\fR or \fIproc\fR. |
|---|
| 48 | .AP Tcl_CmdObjTraceDeleteProc *deleteProc in |
|---|
| 49 | Procedure to call when the trace is deleted. See below for details of |
|---|
| 50 | the calling sequence. A NULL pointer is permissible and results in no |
|---|
| 51 | callback when the trace is deleted. |
|---|
| 52 | .AP Tcl_Trace trace in |
|---|
| 53 | Token for trace to be removed (return value from previous call |
|---|
| 54 | to \fBTcl_CreateTrace\fR). |
|---|
| 55 | .BE |
|---|
| 56 | .SH DESCRIPTION |
|---|
| 57 | .PP |
|---|
| 58 | \fBTcl_CreateObjTrace\fR arranges for command tracing. After it is |
|---|
| 59 | called, \fIobjProc\fR will be invoked before the Tcl interpreter calls |
|---|
| 60 | any command procedure when evaluating commands in \fIinterp\fR. |
|---|
| 61 | The return value from \fBTcl_CreateObjTrace\fR is a token for the trace, |
|---|
| 62 | which may be passed to \fBTcl_DeleteTrace\fR to remove the trace. |
|---|
| 63 | There may be many traces in effect simultaneously for the same |
|---|
| 64 | interpreter. |
|---|
| 65 | .PP |
|---|
| 66 | \fIobjProc\fR should have arguments and result that match the type, |
|---|
| 67 | \fBTcl_CmdObjTraceProc\fR: |
|---|
| 68 | .CS |
|---|
| 69 | typedef int \fBTcl_CmdObjTraceProc\fR( |
|---|
| 70 | \fBClientData\fR \fIclientData\fR, |
|---|
| 71 | \fBTcl_Interp\fR* \fIinterp\fR, |
|---|
| 72 | int \fIlevel\fR, |
|---|
| 73 | const char *\fIcommand\fR, |
|---|
| 74 | \fBTcl_Command\fR \fIcommandToken\fR, |
|---|
| 75 | int \fIobjc\fR, |
|---|
| 76 | \fBTcl_Obj\fR *const \fIobjv\fR[] ); |
|---|
| 77 | .CE |
|---|
| 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_GetCommandTokenInfo\fR, or \fBTcl_SetCommandTokenInfo\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. It |
|---|
| 103 | is, however, permissible to change the command by calling |
|---|
| 104 | \fBTcl_SetCommandTokenInfo\fR prior to returning. Any such change |
|---|
| 105 | takes effect immediately, and the command is invoked with the new |
|---|
| 106 | information. |
|---|
| 107 | .PP |
|---|
| 108 | Tracing will only occur for commands at nesting level less than |
|---|
| 109 | or equal to the \fIlevel\fR parameter (i.e. the \fIlevel\fR |
|---|
| 110 | parameter to \fIobjProc\fR will always be less than or equal to the |
|---|
| 111 | \fIlevel\fR parameter to \fBTcl_CreateTrace\fR). |
|---|
| 112 | .PP |
|---|
| 113 | Tracing has a significant effect on runtime performance because it |
|---|
| 114 | causes the bytecode compiler to refrain from generating in-line code |
|---|
| 115 | for Tcl commands such as \fBif\fR and \fBwhile\fR in order that they |
|---|
| 116 | may be traced. If traces for the built-in commands are not required, |
|---|
| 117 | the \fIflags\fR parameter may be set to the constant value |
|---|
| 118 | \fBTCL_ALLOW_INLINE_COMPILATION\fR. In this case, traces on built-in |
|---|
| 119 | commands may or may not result in trace callbacks, depending on the |
|---|
| 120 | state of the interpreter, but run-time performance will be improved |
|---|
| 121 | significantly. (This functionality is desirable, for example, when |
|---|
| 122 | using \fBTcl_CreateObjTrace\fR to implement an execution time |
|---|
| 123 | profiler.) |
|---|
| 124 | .PP |
|---|
| 125 | Calls to \fIobjProc\fR will be made by the Tcl parser immediately before |
|---|
| 126 | it calls the command procedure for the command (\fIcmdProc\fR). This |
|---|
| 127 | occurs after argument parsing and substitution, so tracing for |
|---|
| 128 | substituted commands occurs before tracing of the commands |
|---|
| 129 | containing the substitutions. If there is a syntax error in a |
|---|
| 130 | command, or if there is no command procedure associated with a |
|---|
| 131 | command name, then no tracing will occur for that command. If a |
|---|
| 132 | string passed to Tcl_Eval contains multiple commands (bracketed, or |
|---|
| 133 | on different lines) then multiple calls to \fIobjProc\fR will occur, |
|---|
| 134 | one for each command. |
|---|
| 135 | .PP |
|---|
| 136 | \fBTcl_DeleteTrace\fR removes a trace, so that no future calls will be |
|---|
| 137 | made to the procedure associated with the trace. After \fBTcl_DeleteTrace\fR |
|---|
| 138 | returns, the caller should never again use the \fItrace\fR token. |
|---|
| 139 | .PP |
|---|
| 140 | When \fBTcl_DeleteTrace\fR is called, the interpreter invokes the |
|---|
| 141 | \fIdeleteProc\fR that was passed as a parameter to |
|---|
| 142 | \fBTcl_CreateObjTrace\fR. The \fIdeleteProc\fR must match the type, |
|---|
| 143 | \fBTcl_CmdObjTraceDeleteProc\fR: |
|---|
| 144 | .CS |
|---|
| 145 | typedef void \fBTcl_CmdObjTraceDeleteProc\fR( |
|---|
| 146 | \fBClientData\fR \fIclientData\fR); |
|---|
| 147 | .CE |
|---|
| 148 | The \fIclientData\fR parameter will be the same as the |
|---|
| 149 | \fIclientData\fR parameter that was originally passed to |
|---|
| 150 | \fBTcl_CreateObjTrace\fR. |
|---|
| 151 | .PP |
|---|
| 152 | \fBTcl_CreateTrace\fR is an alternative interface for command tracing, |
|---|
| 153 | \fInot recommended for new applications\fR. It is provided for backward |
|---|
| 154 | compatibility with code that was developed for older versions of the |
|---|
| 155 | Tcl interpreter. It is similar to \fBTcl_CreateObjTrace\fR, except |
|---|
| 156 | that its \fIproc\fR parameter should have arguments and result that |
|---|
| 157 | match the type \fBTcl_CmdTraceProc\fR: |
|---|
| 158 | .CS |
|---|
| 159 | typedef void Tcl_CmdTraceProc( |
|---|
| 160 | ClientData \fIclientData\fR, |
|---|
| 161 | Tcl_Interp *\fIinterp\fR, |
|---|
| 162 | int \fIlevel\fR, |
|---|
| 163 | char *\fIcommand\fR, |
|---|
| 164 | Tcl_CmdProc *\fIcmdProc\fR, |
|---|
| 165 | ClientData \fIcmdClientData\fR, |
|---|
| 166 | int \fIargc\fR, |
|---|
| 167 | const char *\fIargv\fR[]); |
|---|
| 168 | .CE |
|---|
| 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 |
|---|