📄 tracevar.3
字号:
'\"'\" Copyright (c) 1989-1993 The Regents of the University of California.'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\" '\" RCS: @(#) $Id: TraceVar.3,v 1.8 2002/08/05 03:24:39 dgp Exp $'\" .so man.macros.TH Tcl_TraceVar 3 7.4 Tcl "Tcl Library Procedures".BS.SH NAMETcl_TraceVar, Tcl_TraceVar2, Tcl_UntraceVar, Tcl_UntraceVar2, Tcl_VarTraceInfo, Tcl_VarTraceInfo2 \- monitor accesses to a variable.SH SYNOPSIS.nf\fB#include <tcl.h>\fR.spint\fBTcl_TraceVar(\fIinterp, varName, flags, proc, clientData\fB)\fR.spint\fBTcl_TraceVar2(\fIinterp, name1, name2, flags, proc, clientData\fB)\fR.sp\fBTcl_UntraceVar(\fIinterp, varName, flags, proc, clientData\fB)\fR.sp\fBTcl_UntraceVar2(\fIinterp, name1, name2, flags, proc, clientData\fB)\fR.spClientData\fBTcl_VarTraceInfo(\fIinterp, varName, flags, proc, prevClientData\fB)\fR.spClientData\fBTcl_VarTraceInfo2(\fIinterp, name1, name2, flags, proc, prevClientData\fB)\fR.SH ARGUMENTS.AS Tcl_VarTraceProc prevClientData.AP Tcl_Interp *interp inInterpreter containing variable..AP "CONST char" *varName inName of variable. May refer to a scalar variable, toan array variable with no index, or to an array variablewith a parenthesized index..AP int flags inOR-ed combination of the values TCL_TRACE_READS, TCL_TRACE_WRITES, TCL_TRACE_UNSETS, TCL_TRACE_ARRAY, TCL_GLOBAL_ONLY, TCL_NAMESPACE_ONLY,TCL_TRACE_RESULT_DYNAMIC and TCL_TRACE_RESULT_OBJECT. Not all flags are used by allprocedures. See below for more information..AP Tcl_VarTraceProc *proc inProcedure to invoke whenever one of the traced operations occurs..AP ClientData clientData inArbitrary one-word value to pass to \fIproc\fR..AP "CONST char" *name1 inName of scalar or array variable (without array index)..AP "CONST char" *name2 inFor a trace on an element of an array, gives the index of theelement. For traces on scalar variables or on whole arrays,is NULL..AP ClientData prevClientData inIf non-NULL, gives last value returned by \fBTcl_VarTraceInfo\fR or\fBTcl_VarTraceInfo2\fR, so this call will return information aboutnext trace. If NULL, this call will return information about firsttrace..BE.SH DESCRIPTION.PP\fBTcl_TraceVar\fR allows a C procedure to monitor and controlaccess to a Tcl variable, so that the C procedure is invokedwhenever the variable is read or written or unset.If the trace is created successfully then \fBTcl_TraceVar\fR returnsTCL_OK. If an error occurred (e.g. \fIvarName\fR specifies an elementof an array, but the actual variable isn't an array) then TCL_ERRORis returned and an error message is left in the interpreter's result..PPThe \fIflags\fR argument to \fBTcl_TraceVar\fR indicates when thetrace procedure is to be invoked and provides informationfor setting up the trace. It consists of an OR-ed combinationof any of the following values:.TP\fBTCL_GLOBAL_ONLY\fRNormally, the variable will be looked up at the current level ofprocedure call; if this bit is set then the variable will be lookedup at global level, ignoring any active procedures..TP\fBTCL_NAMESPACE_ONLY\fRNormally, the variable will be looked up at the current level ofprocedure call; if this bit is set then the variable will be lookedup in the current namespace, ignoring any active procedures..TP\fBTCL_TRACE_READS\fRInvoke \fIproc\fR whenever an attempt is made to read the variable..TP\fBTCL_TRACE_WRITES\fRInvoke \fIproc\fR whenever an attempt is made to modify the variable..TP\fBTCL_TRACE_UNSETS\fRInvoke \fIproc\fR whenever the variable is unset.A variable may be unset either explicitly by an \fBunset\fR command,or implicitly when a procedure returns (its local variables areautomatically unset) or when the interpreter is deleted (allvariables are automatically unset)..TP\fBTCL_TRACE_ARRAY\fRInvoke \fIproc\fR whenever the array command is invoked.This gives the trace procedure a chance to update the array beforearray names or array get is called. Note that this is calledbefore an array set, but that will trigger write traces..VS 8.4.TP\fBTCL_TRACE_RESULT_DYNAMIC\fRThe result of invoking the \fIproc\fR is a dynamically allocatedstring that will be released by the Tcl library via a call to\fBckfree\fR. Must not be specified at the same time asTCL_TRACE_RESULT_OBJECT..TP\fBTCL_TRACE_RESULT_OBJECT\fRThe result of invoking the \fIproc\fR is a Tcl_Obj* (cast to a char*)with a reference count of at least one. The ownership of thatreference will be transferred to the Tcl core for release (when thecore has finished with it) via a call to \fBTcl_DecrRefCount\fR. Mustnot be specified at the same time as TCL_TRACE_RESULT_DYNAMIC..VE 8.4.PPWhenever one of the specified operations occurs on the variable,\fIproc\fR will be invoked.It should have arguments and result that match the type\fBTcl_VarTraceProc\fR:.CStypedef char *Tcl_VarTraceProc( ClientData \fIclientData\fR, Tcl_Interp *\fIinterp\fR, char *\fIname1\fR, char *\fIname2\fR, int \fIflags\fR);.CEThe \fIclientData\fR and \fIinterp\fR parameters willhave the same values as those passed to \fBTcl_TraceVar\fR when thetrace was created.\fIClientData\fR typically points to an application-specificdata structure that describes what to do when \fIproc\fRis invoked.\fIName1\fR and \fIname2\fR give the name of the traced variablein the normal two-part form (see the description of \fBTcl_TraceVar2\fRbelow for details).\fIFlags\fR is an OR-ed combination of bits providing severalpieces of information.One of the bits TCL_TRACE_READS, TCL_TRACE_WRITES, TCL_TRACE_ARRAY,or TCL_TRACE_UNSETSwill be set in \fIflags\fR to indicate which operation is being performedon the variable.The bit TCL_GLOBAL_ONLY will be set whenever the variable beingaccessed is a global one not accessible from the current level ofprocedure call: the trace procedure will need to pass this flagback to variable-related procedures like \fBTcl_GetVar\fR if itattempts to access the variable.The bit TCL_NAMESPACE_ONLY will be set whenever the variable beingaccessed is a namespace one not accessible from the current level ofprocedure call: the trace procedure will need to pass this flagback to variable-related procedures like \fBTcl_GetVar\fR if itattempts to access the variable.The bit TCL_TRACE_DESTROYED will be set in \fIflags\fR if the trace isabout to be destroyed; this information may be useful to \fIproc\fRso that it can clean up its own internal data structures (seethe section TCL_TRACE_DESTROYED below for more details).Lastly, the bit TCL_INTERP_DESTROYED will be set if the entireinterpreter is being destroyed.When this bit is set, \fIproc\fR must be especially careful inthe things it does (see the section TCL_INTERP_DESTROYED below).The trace procedure's return value should normally be NULL; seeERROR RETURNS below for information on other possibilities..PP\fBTcl_UntraceVar\fR may be used to remove a trace.If the variable specified by \fIinterp\fR, \fIvarName\fR, and \fIflags\fRhas a trace set with \fIflags\fR, \fIproc\fR, and\fIclientData\fR, then the corresponding trace is removed.If no such trace exists, then the call to \fBTcl_UntraceVar\fRhas no effect.The same bits are valid for \fIflags\fR as for calls to \fBTcl_TraceVar\fR..PP\fBTcl_VarTraceInfo\fR may be used to retrieve information abouttraces set on a given variable.The return value from \fBTcl_VarTraceInfo\fR is the \fIclientData\fRassociated with a particular trace.The trace must be on the variable specified by the \fIinterp\fR,\fIvarName\fR, and \fIflags\fR arguments (only the TCL_GLOBAL_ONLY andTCL_NAMESPACE_ONLY bits from \fIflags\fR is used; other bits areignored) and its trace procedure must the same as the \fIproc\fRargument.If the \fIprevClientData\fR argument is NULL then the returnvalue corresponds to the first (most recently created) matchingtrace, or NULL if there are no matching traces.If the \fIprevClientData\fR argument isn't NULL, then it shouldbe the return value from a previous call to \fBTcl_VarTraceInfo\fR.In this case, the new return value will correspond to the nextmatching trace after the one whose \fIclientData\fR matches\fIprevClientData\fR, or NULL if no trace matches \fIprevClientData\fRor if there are no more matching traces after it.This mechanism makes it possible to step through all of thetraces for a given variable that have the same \fIproc\fR.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -