Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/doc/CrtTrace.3 @ 25

Last change on this file since 25 was 25, checked in by landauf, 16 years ago

added tcl to libs

File size: 8.4 KB
Line 
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
15Tcl_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
20Tcl_Trace
21\fBTcl_CreateTrace\fR(\fIinterp, level, proc, clientData\fR)
22.sp
23Tcl_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
30Interpreter containing command to be traced or untraced.
31.AP int level in
32Only commands at or below this nesting level will be traced unless
330 is specified.  1 means
34top-level commands only, 2 means top-level commands or those that are
35invoked as immediate consequences of executing top-level commands
36(procedure bodies, bracketed commands, etc.) and so on.
37A value of 0 means that commands at any level are traced.
38.AP int flags in
39Flags governing the trace execution.  See below for details.
40.AP Tcl_CmdObjTraceProc *objProc in
41Procedure to call for each command that is executed.  See below for
42details of the calling sequence.
43.AP Tcl_CmdTraceProc *proc in
44Procedure to call for each command that is executed.  See below for
45details on the calling sequence.
46.AP ClientData clientData in
47Arbitrary one-word value to pass to \fIobjProc\fR or \fIproc\fR.
48.AP Tcl_CmdObjTraceDeleteProc *deleteProc in
49Procedure to call when the trace is deleted.  See below for details of
50the calling sequence.  A NULL pointer is permissible and results in no
51callback when the trace is deleted.
52.AP Tcl_Trace trace in
53Token for trace to be removed (return value from previous call
54to \fBTcl_CreateTrace\fR).
55.BE
56.SH DESCRIPTION
57.PP
58\fBTcl_CreateObjTrace\fR arranges for command tracing.  After it is
59called, \fIobjProc\fR will be invoked before the Tcl interpreter calls
60any command procedure when evaluating commands in \fIinterp\fR.
61The return value from \fBTcl_CreateObjTrace\fR is a token for the trace,
62which may be passed to \fBTcl_DeleteTrace\fR to remove the trace.
63There may be many traces in effect simultaneously for the same
64interpreter.
65.PP
66\fIobjProc\fR should have arguments and result that match the type,
67\fBTcl_CmdObjTraceProc\fR:
68.CS
69typedef 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
78The \fIclientData\fR and \fIinterp\fR parameters are copies of the
79corresponding arguments given to \fBTcl_CreateTrace\fR.
80\fIClientData\fR typically points to an application-specific data
81structure that describes what to do when \fIobjProc\fR is invoked.  The
82\fIlevel\fR parameter gives the nesting level of the command (1 for
83top-level commands passed to \fBTcl_Eval\fR by the application, 2 for
84the next-level commands passed to \fBTcl_Eval\fR as part of parsing or
85interpreting level-1 commands, and so on). The \fIcommand\fR parameter
86points to a string containing the text of the command, before any
87argument substitution.  The \fIcommandToken\fR parameter is a Tcl
88command token that identifies the command to be invoked.  The token
89may be passed to \fBTcl_GetCommandName\fR,
90\fBTcl_GetCommandTokenInfo\fR, or \fBTcl_SetCommandTokenInfo\fR to
91manipulate the definition of the command. The \fIobjc\fR and \fIobjv\fR
92parameters designate the final parameter count and parameter vector
93that will be passed to the command, and have had all substitutions
94performed.
95.PP
96The \fIobjProc\fR callback is expected to return a standard Tcl status
97return code.  If this code is \fBTCL_OK\fR (the normal case), then
98the Tcl interpreter will invoke the command.  Any other return code
99is treated as if the command returned that status, and the command is
100\fInot\fR invoked.
101.PP
102The \fIobjProc\fR callback must not modify \fIobjv\fR in any way.  It
103is, however, permissible to change the command by calling
104\fBTcl_SetCommandTokenInfo\fR prior to returning.  Any such change
105takes effect immediately, and the command is invoked with the new
106information.
107.PP
108Tracing will only occur for commands at nesting level less than
109or equal to the \fIlevel\fR parameter (i.e. the \fIlevel\fR
110parameter to \fIobjProc\fR will always be less than or equal to the
111\fIlevel\fR parameter to \fBTcl_CreateTrace\fR).
112.PP
113Tracing has a significant effect on runtime performance because it
114causes the bytecode compiler to refrain from generating in-line code
115for Tcl commands such as \fBif\fR and \fBwhile\fR in order that they
116may be traced.  If traces for the built-in commands are not required,
117the \fIflags\fR parameter may be set to the constant value
118\fBTCL_ALLOW_INLINE_COMPILATION\fR.  In this case, traces on built-in
119commands may or may not result in trace callbacks, depending on the
120state of the interpreter, but run-time performance will be improved
121significantly.  (This functionality is desirable, for example, when
122using \fBTcl_CreateObjTrace\fR to implement an execution time
123profiler.)
124.PP
125Calls to \fIobjProc\fR will be made by the Tcl parser immediately before
126it calls the command procedure for the command (\fIcmdProc\fR).  This
127occurs after argument parsing and substitution, so tracing for
128substituted commands occurs before tracing of the commands
129containing the substitutions.  If there is a syntax error in a
130command, or if there is no command procedure associated with a
131command name, then no tracing will occur for that command.  If a
132string passed to Tcl_Eval contains multiple commands (bracketed, or
133on different lines) then multiple calls to \fIobjProc\fR will occur,
134one for each command.
135.PP
136\fBTcl_DeleteTrace\fR removes a trace, so that no future calls will be
137made to the procedure associated with the trace.  After \fBTcl_DeleteTrace\fR
138returns, the caller should never again use the \fItrace\fR token.
139.PP
140When \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
145typedef void \fBTcl_CmdObjTraceDeleteProc\fR(
146        \fBClientData\fR \fIclientData\fR);
147.CE
148The \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
154compatibility with code that was developed for older versions of the
155Tcl interpreter.  It is similar to \fBTcl_CreateObjTrace\fR, except
156that its \fIproc\fR parameter should have arguments and result that
157match the type \fBTcl_CmdTraceProc\fR:
158.CS
159typedef 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
169The parameters to the \fIproc\fR callback are similar to those of the
170\fIobjProc\fR callback above. The \fIcommandToken\fR is
171replaced with \fIcmdProc\fR, a pointer to the (string-based) command
172procedure that will be invoked; and \fIcmdClientData\fR, the client
173data that will be passed to the procedure.  The \fIobjc\fR parameter
174is replaced with an \fIargv\fR parameter, that gives the arguments to
175the command as character strings.
176\fIProc\fR must not modify the \fIcommand\fR or \fIargv\fR strings.
177.PP
178If a trace created with \fBTcl_CreateTrace\fR is in effect, inline
179compilation of Tcl commands such as \fBif\fR and \fBwhile\fR is always
180disabled.  There is no notification when a trace created with
181\fBTcl_CreateTrace\fR is deleted.
182There 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
184associated with a call to \fBTcl_CreateTrace\fR to abort execution of
185\fIcommand\fR.
186.SH KEYWORDS
187command, create, delete, interpreter, trace
Note: See TracBrowser for help on using the repository browser.