diff -ru Orig/tcl8.4.9/doc/info.n tcl8.4.9/doc/info.n --- Orig/tcl8.4.9/doc/info.n Mon Nov 8 01:32:00 2004 +++ tcl8.4.9/doc/info.n Thu Mar 17 14:22:47 2005 @@ -124,6 +124,52 @@ variable and may be changed by setting \fBtcl_library\fR. See the \fBtclvars\fR manual entry for more information. .TP +\fBinfo line \fISUBCOMMAND ARGS\fR +The \fBline\fR subcommands access line number information +for procs that were defined via the source command. +Five subcommands are currently defined: line, file and find. +.TP +.RS +.TP +\fBinfo line file \fIprocname \fR?\fIfileName\fR? +For procedures defined via the \fBsource\fR command, +returns the file name that the procedure \fIprocname\fR was sourced +from. If \fIfileName\fR is provided, this is used as the new value. +For procedures not defined via the \fBsource\fR command, +this function does nothing and returns nothing. +.VE +.TP +\fBinfo line find \fIfileName lineNum \fR?\fInamespace\fR? +For procedures defined via the \fBsource\fR command, +find the procedure name defined at line \fIlineNum\fR in file path +\fIfileName\fR. +If found, returns fully namespace qualified procedure name. +This will find only procedures defined via the \fBsource\fR command. +.VE +.TP +\fBinfo line level \fInumber\fR +Like the \fIinfo level\fR command, but returns the line number +and file name from which +the call at level \fInumber\fR originates, when using \fItrace execution\fR. +.VE +.TP +\fBinfo line number \fIprocname \fR?\fIlineNum\fR? +For procedures defined via the \fBsource\fR command, +the line number that a procedure \fIprocname\fR +was defined on. +If \fIlineNum\fR is provided, it is used as the new value. +For procedures not defined via the \fBsource\fR command, +this function does nothing and returns nothing. +.VE +.TP +\fBinfo line relativeerror \fR?\fIBOOL\fR +Set to 1 to disable absolute line number and file path +on a procedure error. This demotes procedure traceback errors +to the same format as all other traceback errors, that is, +using the relative the line number and file name. +.VE +.RE +.TP \fBinfo loaded \fR?\fIinterp\fR? Returns a list describing all of the packages that have been loaded into \fIinterp\fR with the \fBload\fR command. @@ -169,6 +215,12 @@ within; the matching pattern is taken to be the part after the last namespace separator. .TP +\fBinfo return\fR +If in \fBtrace execution\fR mode, returns the saved last result of the +previously executed command. Otherwise returns an empty string. +Commands executed as part of a trace handler do not affect or change +the saved last result. +.TP \fBinfo script\fR ?\fIfilename\fR? If a Tcl script file is currently being evaluated (i.e. there is a call to \fBTcl_EvalFile\fR active or there is an active invocation diff -ru Orig/tcl8.4.9/doc/trace.n tcl8.4.9/doc/trace.n --- Orig/tcl8.4.9/doc/trace.n Mon Nov 8 01:32:02 2004 +++ tcl8.4.9/doc/trace.n Thu Mar 17 14:22:47 2005 @@ -201,6 +201,9 @@ are unset). Variables are also unset when interpreters are deleted, but traces will not be invoked because there is no interpreter in which to execute them. +.TP +\fBdebug\fR +Prevent execution trace from triggering during a variable trace. .PP When the trace triggers, three arguments are appended to \fIcommand\fR so that the actual command is as follows: @@ -334,6 +337,67 @@ have any traces set, then the result of the command will be an empty string. .RE +.TP +\fBtrace execution ?\fItarget ?level??\fR +Arrange for an execution trace to be setup for commands at +nesting \fBlevel\fR or above, +thereby providing a simple Tcl interface to trace +commands say, to implement a debugger. +With no arguments, the current \fItarget\fR is returned. +If \fItarget\fR is the empty string, the execution trace is removed. +If the argument \fItarget\fR is not an output \fBchannel\fR name such as +\fBstdout\fR, it is assumed to be a \fBcommand\fR string. +\fBLevel\fR defaults to 0 if not specified, meaning trace all commands. +The following list of arguments are appended before the call: +.RS +.TP +\fBlinenumber\fR + The line number the instruction begins on. +.TP +\fBfilename\fR + The fully normalized file name. +.TP +\fBnestlevel\fR + The nesting level of the command. +.TP +\fBstacklevel\fR + The stack call level as per [info level]. +.TP +\fBcurnsfunc\fR + The current fully qualified namespace/function +.TP +\fBcmdname\fR + The fully qualified command name of the command to be invoked. +.TP +\fBcommand\fR + The command and arguments as a list. +.TP +\fBflags\fR + The bit flags. Bit 0 set indicates this was a breakpoint. +.RE +.PP +.RS +If \fItarget\fR is a valid Tcl channel opened for output, the trace data is +written out to it with an appended newline. +Otherwise \fItarget\fR is presumed to be a valid Tcl command +onto which is appended the above arguments before evaluation. +For channels, an error on output will cause the trace to be removed and +a Tcl error to be generated. +For commands, any return from the command other than a normal return +results in the command not being executed. +.RE +.TP +\fBtrace breakpoint ??\fIline file ?state? ...?\fR +The \fItrace breakpoint\fR manages a list of breakpoints that cause an +\fIexecution trace\fR to trigger, even when the nestlevel is exceeded. +With no arguments it returns a ternery list of all breakpoints in sets +of the triples: line, file, and state. With two arguments, the +current state for the breakpoint is returned. With three or more arguments, +new breakpoints are created. If created with a state <= zero, +the breakpoint is considered inactive. Setting the state of a +breakpoint to the empty string effectively deletes the breakpoint. +A state to \fIN\fR greater than zero triggers every \fINth\fR time. +.RE .PP For backwards compatibility, three other subcommands are available: .RS diff -ru Orig/tcl8.4.9/generic/tcl.h tcl8.4.9/generic/tcl.h --- Orig/tcl8.4.9/generic/tcl.h Wed Nov 24 16:19:27 2004 +++ tcl8.4.9/generic/tcl.h Thu Mar 17 14:22:47 2005 @@ -917,6 +917,8 @@ char *dummy8; int dummy9; char* dummy10; + int lineNum; + Tcl_Obj *fileName; } Tcl_CallFrame; @@ -1054,6 +1056,7 @@ #define TCL_TRACE_DELETE 0x4000 #define TCL_ALLOW_INLINE_COMPILATION 0x20000 +#define TCL_TRACE_LINE_NUMBERS 0x40000 /* * Flag values passed to Tcl_CreateObjTrace, and used internally @@ -2136,9 +2139,39 @@ * accommodate most commands; dynamic * space is allocated for very large * commands that don't fit here. */ + int lineNum; /* Line number for start of string. */ + int lineCnt; /* Number of lines in parse. */ + Tcl_Obj *fileName; /* File name of parse string. */ } Tcl_Parse; /* + * Breakpoint support for [trace execution]. + */ +typedef struct Tcl_Breakpoint { + Tcl_Obj *fileName; /* Object containing the file name. */ + int lineNum; /* Line number within file of statement. */ + int state; /* 0=disabled, N=trigger every Nth time.*/ + int counter; /* Counter for when state>1. */ + struct Tcl_Breakpoint *next;/* Pointer to next breakpoint in list. */ +} Tcl_Breakpoint; + +/* + * File and line number information maintained during TRACE_LINE_NUMBERS. + * Retrievable with Tcl_GetSourceInfo() in the Stubs 'C' interface. + */ +typedef struct { + Tcl_Obj *curFileName; /* Object containing the file name. */ + int curLineNum; /* Line number within file of statement. */ + int lastTracedLine; /* Line number of last traced statement. */ + int curCharPos; /* Char position in line, or -1 if unknown. */ + int commandLen; /* Length of command string for cmd trace. */ + int stackLevel; /* The current stacklevel as per [info level] */ + Tcl_Obj* lastResultPtr; /* Result from the last executed command. */ + int flags; /* Bit flags: bit 0 = breakpoint. */ + Tcl_Breakpoint *breakpoints; /* List of breakpoints. */ +} Tcl_SourceInfo; + +/* * The following definitions are the error codes returned by the conversion * routines: * diff -ru Orig/tcl8.4.9/generic/tclBasic.c tcl8.4.9/generic/tclBasic.c --- Orig/tcl8.4.9/generic/tclBasic.c Tue Oct 5 16:23:32 2004 +++ tcl8.4.9/generic/tclBasic.c Thu Mar 17 14:22:47 2005 @@ -363,6 +363,16 @@ iPtr->emptyObjPtr = Tcl_NewObj(); /* another empty object */ Tcl_IncrRefCount(iPtr->emptyObjPtr); iPtr->resultSpace[0] = 0; + iPtr->lineNum=0; + iPtr->relError = 0; + iPtr->traceExecCmd = NULL; + iPtr->traceExecId = NULL; + iPtr->sourceInfo.curFileName = NULL; + iPtr->sourceInfo.lastResultPtr = NULL; + iPtr->sourceInfo.curCharPos = -1; + iPtr->sourceInfo.flags = 0; + iPtr->sourceInfo.breakpoints = NULL; + Tcl_InitHashTable(&iPtr->sourcedFiles, TCL_STRING_KEYS); iPtr->globalNsPtr = NULL; /* force creation of global ns below */ iPtr->globalNsPtr = (Namespace *) Tcl_CreateNamespace(interp, "", @@ -1020,6 +1030,16 @@ ckfree((char *) Tcl_GetHashValue(hPtr)); } Tcl_DeleteHashTable(&iPtr->mathFuncTable); + /* + * Tear down the sourced files table. + */ + + for (hPtr = Tcl_FirstHashEntry(&iPtr->sourcedFiles, &search); + hPtr != NULL; + hPtr = Tcl_NextHashEntry(&search)) { + Tcl_DecrRefCount((Tcl_Obj *) Tcl_GetHashValue(hPtr)); + } + Tcl_DeleteHashTable(&iPtr->sourcedFiles); /* * Invoke deletion callbacks; note that a callback can create new @@ -1082,6 +1102,10 @@ } Tcl_DecrRefCount(iPtr->emptyObjPtr); iPtr->emptyObjPtr = NULL; + if (iPtr->sourceInfo.lastResultPtr != NULL) { + Tcl_DecrRefCount(iPtr->sourceInfo.lastResultPtr); + iPtr->sourceInfo.lastResultPtr = NULL; + } resPtr = iPtr->resolverPtr; while (resPtr) { @@ -3086,6 +3110,21 @@ } code = (*cmdPtr->objProc)(cmdPtr->objClientData, interp, objc, objv); iPtr->varFramePtr = savedVarFramePtr; + + /* + * When in [trace execution], make copy of result for [info return], + * except when this is inside a trace callback. + */ + if (!(iPtr->flags & INTERP_TRACE_IN_PROGRESS)) { + if (iPtr->sourceInfo.lastResultPtr != NULL) { + Tcl_DecrRefCount(iPtr->sourceInfo.lastResultPtr); + iPtr->sourceInfo.lastResultPtr = NULL; + } + if (iPtr->flags&TRACE_LINE_NUMBERS) { + iPtr->sourceInfo.lastResultPtr = iPtr->objResultPtr; + Tcl_IncrRefCount(iPtr->sourceInfo.lastResultPtr); + } + } } if (Tcl_AsyncReady()) { code = Tcl_AsyncInvoke(interp, code); @@ -3594,7 +3633,7 @@ #define NUM_STATIC_OBJS 20 Tcl_Obj *staticObjArray[NUM_STATIC_OBJS], **objv; Tcl_Token *tokenPtr; - int i, code, commandLength, bytesLeft, nested; + int i, code, commandLength, bytesLeft, nested, lineNum; CallFrame *savedVarFramePtr; /* Saves old copy of iPtr->varFramePtr * in case TCL_EVAL_GLOBAL was set. */ int allowExceptions = (iPtr->evalFlags & TCL_ALLOW_EXCEPTIONS); @@ -3631,6 +3670,7 @@ nested = 0; } iPtr->evalFlags = 0; + do { if (Tcl_ParseCommand(interp, p, bytesLeft, nested, &parse) != TCL_OK) { @@ -3638,6 +3678,8 @@ goto error; } gotParse = 1; + parse.lineNum = iPtr->lineNum; + lineNum = iPtr->sourceInfo.curLineNum; /* Save lineNum subeval may change it. */ if (nested && parse.term == (script + numBytes)) { /* @@ -3673,15 +3715,17 @@ goto error; } } - + /* * Execute the command and free the objects for its words. */ iPtr->numLevels++; + iPtr->sourceInfo.curFileName = parse.fileName; + iPtr->sourceInfo.curLineNum = parse.lineNum; code = TclEvalObjvInternal(interp, objectsUsed, objv, parse.commandStart, parse.commandSize, 0); - iPtr->numLevels--; + iPtr->numLevels--; if (code != TCL_OK) { if (iPtr->numLevels == 0) { if (code == TCL_RETURN) { @@ -3704,6 +3748,9 @@ objv = staticObjArray; } } + if (iPtr != NULL) { + iPtr->lineNum = parse.lineNum + parse.lineCnt; + } /* * Advance to the next command in the script. @@ -4907,6 +4954,10 @@ } iPtr->tracesForbiddingInline++; } + if (flags & TCL_TRACE_LINE_NUMBERS) { + iPtr->flags |= USE_EVAL_DIRECT|TRACE_LINE_NUMBERS; + } + tracePtr = (Trace *) ckalloc(sizeof(Trace)); tracePtr->level = level; @@ -5103,6 +5154,11 @@ } (*tracePtr2) = (*tracePtr2)->nextPtr; + /* Remove global line number trace. */ + if (tracePtr->flags & TCL_TRACE_LINE_NUMBERS) { + iPtr->flags &= ~(USE_EVAL_DIRECT|TRACE_LINE_NUMBERS); + } + /* * If the trace forbids bytecode compilation, change the interpreter's * state. If bytecode compilation is now permitted, flag the fact and @@ -5132,6 +5188,21 @@ } /* + * Tcl_GetSourceInfo -- + * Stubbed interface to get source info associated with a command trace. + */ +Tcl_SourceInfo * +Tcl_GetSourceInfo(interp) + Tcl_Interp *interp; /* Interpreter for traced command. */ +{ + Interp *iPtr = (Interp*) interp; + if (iPtr == NULL) + return NULL; + return &iPtr->sourceInfo; +} + + +/* *---------------------------------------------------------------------- * * Tcl_AddErrorInfo -- diff -ru Orig/tcl8.4.9/generic/tclCmdAH.c tcl8.4.9/generic/tclCmdAH.c --- Orig/tcl8.4.9/generic/tclCmdAH.c Mon Nov 8 01:32:03 2004 +++ tcl8.4.9/generic/tclCmdAH.c Thu Mar 17 14:22:47 2005 @@ -1609,19 +1609,23 @@ int objc; /* Number of arguments. */ Tcl_Obj *CONST objv[]; /* Argument objects. */ { - int result, value; + int result, value, lineNum, curLine; + Interp *iPtr = (Interp*)interp; if (objc != 5) { Tcl_WrongNumArgs(interp, 1, objv, "start test next command"); return TCL_ERROR; } + lineNum = iPtr->lineNum; + iPtr->lineNum = curLine = iPtr->sourceInfo.curLineNum; + result = Tcl_EvalObjEx(interp, objv[1], 0); if (result != TCL_OK) { if (result == TCL_ERROR) { Tcl_AddErrorInfo(interp, "\n (\"for\" initial command)"); } - return result; + goto doreturn; } while (1) { /* @@ -1631,9 +1635,10 @@ */ Tcl_ResetResult(interp); + iPtr->lineNum = curLine; result = Tcl_ExprBooleanObj(interp, objv[2], &value); if (result != TCL_OK) { - return result; + goto doreturn; } if (!value) { break; @@ -1648,6 +1653,7 @@ } break; } + iPtr->lineNum = curLine; result = Tcl_EvalObjEx(interp, objv[3], 0); if (result == TCL_BREAK) { break; @@ -1655,7 +1661,7 @@ if (result == TCL_ERROR) { Tcl_AddErrorInfo(interp, "\n (\"for\" loop-end command)"); } - return result; + goto doreturn; } } if (result == TCL_BREAK) { @@ -1664,6 +1670,10 @@ if (result == TCL_OK) { Tcl_ResetResult(interp); } + +doreturn: + iPtr->lineNum = lineNum; + iPtr->sourceInfo.curLineNum = curLine; return result; } @@ -1698,6 +1708,7 @@ int v; /* v selects a loop variable */ int numLists; /* Count of value lists */ Tcl_Obj *bodyPtr; + Interp *iPtr = (Interp*)interp; /* * We copy the argument object pointers into a local array to avoid @@ -1722,6 +1733,7 @@ Tcl_Obj ***varvList = varvListArray; /* Array of var name lists */ int *argcList = argcListArray; /* Array of value list sizes */ Tcl_Obj ***argvList = argvListArray; /* Array of value lists */ + int lineNum; if (objc < 4 || (objc%2 != 0)) { Tcl_WrongNumArgs(interp, 1, objv, @@ -1804,6 +1816,7 @@ */ bodyPtr = argObjv[objc-1]; + lineNum = iPtr->lineNum; for (j = 0; j < maxj; j++) { for (i = 0; i < numLists; i++) { /* @@ -1854,6 +1867,7 @@ } } + iPtr->lineNum = lineNum; result = Tcl_EvalObjEx(interp, bodyPtr, 0); if (result != TCL_OK) { if (result == TCL_CONTINUE) { diff -ru Orig/tcl8.4.9/generic/tclCmdIL.c tcl8.4.9/generic/tclCmdIL.c --- Orig/tcl8.4.9/generic/tclCmdIL.c Wed Nov 24 11:30:20 2004 +++ tcl8.4.9/generic/tclCmdIL.c Thu Mar 17 14:22:47 2005 @@ -124,6 +124,9 @@ static int InfoLibraryCmd _ANSI_ARGS_((ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])); +static int InfoLineCmd _ANSI_ARGS_((ClientData dummy, + Tcl_Interp *interp, int objc, + Tcl_Obj *CONST objv[])); static int InfoLoadedCmd _ANSI_ARGS_((ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])); @@ -139,6 +142,9 @@ static int InfoProcsCmd _ANSI_ARGS_((ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])); +static int InfoReturnCmd _ANSI_ARGS_((ClientData dummy, + Tcl_Interp *interp, int objc, + Tcl_Obj *CONST objv[])); static int InfoScriptCmd _ANSI_ARGS_((ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])); @@ -188,8 +194,12 @@ Tcl_Obj *CONST objv[]; /* Argument objects. */ { int thenScriptIndex = 0; /* then script to be evaled after syntax check */ - int i, result, value; + int i, result, value, lineNum, curLine; char *clause; + Interp *iPtr = (Interp *)interp; + + curLine = iPtr->sourceInfo.curLineNum; + lineNum = iPtr->lineNum; i = 1; while (1) { /* @@ -240,7 +250,8 @@ i++; if (i >= objc) { if (thenScriptIndex) { - return Tcl_EvalObjEx(interp, objv[thenScriptIndex], 0); + i = thenScriptIndex; + goto doeval; } return TCL_OK; } @@ -274,9 +285,26 @@ return TCL_ERROR; } if (thenScriptIndex) { - return Tcl_EvalObjEx(interp, objv[thenScriptIndex], 0); + i = thenScriptIndex; + } +doeval: + if (iPtr->flags&TRACE_LINE_NUMBERS) { + int n; + unsigned int nl=0; + for (n=0; nlineNum = curLine + nl; } - return Tcl_EvalObjEx(interp, objv[i], 0); + result = Tcl_EvalObjEx(interp, objv[i], 0); + iPtr->lineNum = lineNum; + iPtr->sourceInfo.curLineNum = curLine; + return result; } /* @@ -399,16 +427,17 @@ static CONST char *subCmds[] = { "args", "body", "cmdcount", "commands", "complete", "default", "exists", "functions", "globals", - "hostname", "level", "library", "loaded", + "hostname", "level", "library", "line", "loaded", "locals", "nameofexecutable", "patchlevel", "procs", - "script", "sharedlibextension", "tclversion", "vars", + "return", "script", "sharedlibextension", "tclversion", "vars", (char *) NULL}; enum ISubCmdIdx { IArgsIdx, IBodyIdx, ICmdCountIdx, ICommandsIdx, ICompleteIdx, IDefaultIdx, IExistsIdx, IFunctionsIdx, IGlobalsIdx, - IHostnameIdx, ILevelIdx, ILibraryIdx, ILoadedIdx, + IHostnameIdx, ILevelIdx, ILibraryIdx, ILineIdx, ILoadedIdx, ILocalsIdx, INameOfExecutableIdx, IPatchLevelIdx, IProcsIdx, - IScriptIdx, ISharedLibExtensionIdx, ITclVersionIdx, IVarsIdx + IReturnIdx, IScriptIdx, ISharedLibExtensionIdx, ITclVersionIdx, + IVarsIdx }; int index, result; @@ -460,6 +489,9 @@ case ILibraryIdx: result = InfoLibraryCmd(clientData, interp, objc, objv); break; + case ILineIdx: + result = InfoLineCmd(clientData, interp, objc, objv); + break; case ILoadedIdx: result = InfoLoadedCmd(clientData, interp, objc, objv); break; @@ -475,6 +507,9 @@ case IProcsIdx: result = InfoProcsCmd(clientData, interp, objc, objv); break; + case IReturnIdx: + result = InfoReturnCmd(clientData, interp, objc, objv); + break; case IScriptIdx: result = InfoScriptCmd(clientData, interp, objc, objv); break; @@ -1292,6 +1327,338 @@ /* *---------------------------------------------------------------------- * + * InfoLineCmd -- + * + * Called to implement the "info line" command that accesses the line + * information for procedures created via the source command. + * + * info line SUBCOMMAND ARGS + * + * Current subcommands include: + * info line number PROC ?LINE? + * info line file ?PROC ?FILE?? + * info line find FILE LINE + * info line relerror ?BOOL? + * + * Results: + * Returns TCL_OK if successful and TCL_ERROR if there is an error. + * + * Side effects: + * Returns a result in the interpreter's result object. If there is + * an error, the result is an error message. + * + *---------------------------------------------------------------------- + */ + +static int +InfoLineCmd(dummy, interp, objc, objv) + ClientData dummy; /* Not used. */ + Tcl_Interp *interp; /* Current interpreter. */ + int objc; /* Number of arguments. */ + Tcl_Obj *CONST objv[]; /* Argument objects. */ +{ + register Interp *iPtr = (Interp *) interp; + char *subCmd, *procName, *fileName; + Proc *procPtr; + Tcl_Obj *resultPtr, *listPtr, *fileNamePtr = NULL, *nsObj; + char iBuf[50]; + int len, lineNum=0, index, level, i; + Namespace *nsPtr=0; + CallFrame *framePtr = NULL, *callerPtr; + + static CONST char *options[] = { + "current", "number", "find", "file", "files", "level", "relerror", + (char*)NULL + }; + enum options { + ILINE_CURRENT, ILINE_NUMBER, ILINE_FIND, ILINE_FILE, ILINE_FILES, + ILINE_LEVEL, ILINE_RELERROR + }; + + if (objc < 3) { + Tcl_WrongNumArgs(interp, 2, objv, "line"); + return TCL_ERROR; + } + + subCmd = Tcl_GetString(objv[2]); + if (Tcl_GetIndexFromObj(interp, objv[2], options, "line", + 0, &index) != TCL_OK) { + return TCL_ERROR; + } + switch ((enum options) index) { + + case ILINE_CURRENT: + if (objc != 3) { + Tcl_WrongNumArgs(interp, objc, objv, subCmd); + return TCL_ERROR; + } + resultPtr = Tcl_NewListObj(0, 0); + Tcl_ListObjAppendElement(interp, resultPtr, + Tcl_NewIntObj(iPtr->sourceInfo.curLineNum)); + Tcl_ListObjAppendElement(interp, resultPtr, + iPtr->sourceInfo.curFileName ? iPtr->sourceInfo.curFileName + : Tcl_NewStringObj("",0)); + Tcl_SetObjResult(interp, resultPtr); + break; + + case ILINE_NUMBER: + + /* + * Get/Set the line number + */ + if (objc < 3 && objc > 5) { + Tcl_WrongNumArgs(interp, objc, objv, subCmd); + return TCL_ERROR; + } + + if (objc == 3) { + resultPtr = Tcl_NewIntObj(iPtr->sourceInfo.curLineNum); + Tcl_SetObjResult(interp, resultPtr); + return TCL_OK; + } + + procName = Tcl_GetString(objv[3]); + procPtr = TclFindProc(iPtr, procName); + if (procPtr == NULL) { + Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), + "\"", procName, "\" isn't a procedure", (char *) NULL); + return TCL_ERROR; + } + if (procPtr->fileName == NULL) { + return TCL_OK; + } + + if (objc >= 5) { + if (Tcl_GetIntFromObj(interp, objv[4], &lineNum) + != TCL_OK) { + Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), + "\"", Tcl_GetString(objv[4]), + "\" isn't a number", (char *) NULL); + return TCL_ERROR; + } + if ((enum options) index == ILINE_NUMBER) { + procPtr->lineNum=lineNum; + } + } + resultPtr = Tcl_NewIntObj(procPtr->lineNum); + Tcl_SetObjResult(interp, resultPtr); + + return TCL_OK; + + + case ILINE_FILES: + + if (objc != 3) { + Tcl_WrongNumArgs(interp, objc, objv, "line files"); + return TCL_ERROR; + } else { + Tcl_HashEntry *entry; + Tcl_HashSearch se; + Tcl_Obj *cp; + entry=Tcl_FirstHashEntry(&iPtr->sourcedFiles, &se); + resultPtr=Tcl_NewListObj(0,0); + while (entry) { + if ((cp=(Tcl_Obj*)Tcl_GetHashValue(entry))) { + Tcl_ListObjAppendElement(interp,resultPtr, cp); + } + entry=Tcl_NextHashEntry(&se); + } + Tcl_SetObjResult(interp, resultPtr); + return TCL_OK; + } + + case ILINE_FILE: + /* + * Set/Get the filename a the given PROC + */ + if (objc < 3 && objc > 5) { + Tcl_WrongNumArgs(interp, objc, objv, "line file"); + return TCL_ERROR; + } + + if (objc == 3) { + resultPtr = iPtr->sourceInfo.curFileName; + Tcl_SetObjResult(interp, resultPtr); + return TCL_OK; + } + + procName = Tcl_GetString(objv[3]); + procPtr = TclFindProc(iPtr, procName); + if (procPtr == NULL) { + Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), + "\"", procName, "\" isn't a procedure", (char *) NULL); + return TCL_ERROR; + } + + if (procPtr->fileName == NULL) { + return TCL_OK; + } + if (objc == 4) { + resultPtr = procPtr->fileName; + Tcl_IncrRefCount(resultPtr); + Tcl_SetObjResult(interp, resultPtr); + return TCL_OK; + } + + fileName=Tcl_GetStringFromObj(objv[5],&len); + Tcl_SetStringObj(procPtr->fileName,fileName,len); + return TCL_OK; + + + case ILINE_FIND: + + /* + * Find a proc given the filename and line number + optional namespace + * that can reduce the cost of the search. + */ + + if (objc != 5) { + Tcl_WrongNumArgs(interp, objc, objv, "line find fileName lineNum"); + return TCL_ERROR; + } + if (Tcl_GetIntFromObj(interp, objv[4], &lineNum) != TCL_OK) { + return TCL_ERROR; + } + if (TclFindProcByLine(iPtr, objv[3], lineNum, nsPtr, &resultPtr)) { + Tcl_SetObjResult(interp, resultPtr); + } + + return TCL_OK; + + + /* + * Set to 0 to report relative line number/filename on proc error. + * tcltest needs this to avoid breaking tests. + */ + + case ILINE_RELERROR: + + if (objc < 4 && objc > 5) { + Tcl_WrongNumArgs(interp, objc, objv, subCmd); + return TCL_ERROR; + } + + if (objc >= 4) { + if (Tcl_GetIntFromObj(interp, objv[3], &iPtr->relError) + != TCL_OK) { + Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), + "\"", Tcl_GetString(objv[4]), + "\" isn't a number", (char *) NULL); + return TCL_ERROR; + } + } + sprintf(iBuf,"%d", iPtr->relError); + resultPtr = Tcl_NewStringObj(iBuf,-1); + Tcl_SetObjResult(interp, resultPtr); + + return TCL_OK; + + case ILINE_LEVEL: + if (objc != 3 && objc != 4) { + Tcl_WrongNumArgs(interp, 3, objv, "?level?"); + return TCL_ERROR; + } + if (objc == 4) { + if (Tcl_GetIntFromObj(interp, objv[3], &level) != TCL_OK) { + return TCL_ERROR; + } + if (level > 0) { + goto levelError; + } + } else { + level = 0; + } + + listPtr = resultPtr = Tcl_NewListObj(0,0); + i = 0; + while (1) { + if (i == 0) { + lineNum = iPtr->sourceInfo.lastTracedLine; + fileNamePtr = iPtr->sourceInfo.curFileName; + callerPtr = iPtr->varFramePtr; + } else { + if (i == -1) { + framePtr = iPtr->varFramePtr; + } else { + framePtr = framePtr->callerVarPtr; + } + if (framePtr == NULL) { + if (objc == 4) + goto levelError; + else + break; + } + + lineNum = framePtr->lineNum; + fileNamePtr = framePtr->fileName; + callerPtr = (framePtr?framePtr->callerVarPtr:NULL); + } + if (objc == 3) { + listPtr = Tcl_NewListObj(0,0); + } + if (objc == 3 || level == i) { + /* Append the following: line, file, level, proc, fullcmd */ + Tcl_ListObjAppendElement(interp, listPtr, + Tcl_NewIntObj(lineNum)); + Tcl_ListObjAppendElement(interp, listPtr, + fileNamePtr ? fileNamePtr : Tcl_NewStringObj("",0)); + Tcl_ListObjAppendElement(interp, listPtr, + Tcl_NewIntObj(callerPtr?callerPtr->level:0)); + + /* Append the current fully namespace qualified function. */ + if (callerPtr == NULL) { + nsObj = Tcl_NewStringObj("::",-1); + } else if (callerPtr->isProcCallFrame) { + Tcl_Command f = Tcl_GetCommandFromObj(interp, + callerPtr->objv[0]); + nsObj = Tcl_NewStringObj("", 0); + Tcl_GetCommandFullName(interp, f, nsObj); + } else if (callerPtr->nsPtr && callerPtr->nsPtr->fullName) { + nsObj = Tcl_NewStringObj(callerPtr->nsPtr->fullName,-1); + Tcl_AppendToObj(nsObj, "::", 2); + } else { + nsObj = Tcl_NewStringObj("", 0); + } + Tcl_ListObjAppendElement(interp, listPtr, nsObj); + + if (callerPtr == NULL) { + nsObj = Tcl_NewStringObj("", 0); + } else { + nsObj = Tcl_NewListObj(callerPtr->objc, callerPtr->objv); + } + Tcl_ListObjAppendElement(interp, listPtr, nsObj); + + if (objc == 4) { + break; + } + } + if (objc == 3) { + Tcl_ListObjAppendElement(interp, resultPtr, listPtr); + } + i--; + } + Tcl_SetObjResult(interp, resultPtr); + return TCL_OK; + + levelError: + if (resultPtr != NULL) { + Tcl_DecrRefCount(resultPtr); + } + Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), + "bad level \"", + Tcl_GetString(objv[3]), + "\"", (char *) NULL); + return TCL_ERROR; + + } + Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), "unknown subcommand: ", + "\"", subCmd, "\"", (char *) NULL); + return TCL_ERROR; +} + +/* + *---------------------------------------------------------------------- + * * InfoLoadedCmd -- * * Called to implement the "info loaded" command that returns the @@ -1742,6 +2109,45 @@ /* *---------------------------------------------------------------------- * + * InfoReturnCmd -- + * + * Called to implement the "info return" command that returns the + * value returned by the previous command when in [trace execution]. + * + * info return + * + * Results: + * Returns TCL_OK. + * + * Side effects: + * Sets the interpreter's result object to the results of the + * previous command. + * + *---------------------------------------------------------------------- + */ + +static int +InfoReturnCmd(dummy, interp, objc, objv) + ClientData dummy; /* Not used. */ + Tcl_Interp *interp; /* Current interpreter. */ + int objc; /* Number of arguments. */ + Tcl_Obj *CONST objv[]; /* Argument objects. */ +{ + Interp *iPtr = (Interp *) interp; + if (objc != 2) { + Tcl_WrongNumArgs(interp, 2, objv, ""); + return TCL_ERROR; + } + + if (iPtr->sourceInfo.lastResultPtr != NULL && iPtr->flags&TRACE_LINE_NUMBERS) { + Tcl_SetObjResult(interp, iPtr->sourceInfo.lastResultPtr); + } + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * * InfoScriptCmd -- * * Called to implement the "info script" command that returns the @@ -1782,6 +2188,8 @@ } iPtr->scriptFile = objv[2]; Tcl_IncrRefCount(iPtr->scriptFile); + iPtr->sourceInfo.curFileName = + TclFSGetSourceFile(interp, iPtr->scriptFile); } if (iPtr->scriptFile != NULL) { Tcl_SetObjResult(interp, iPtr->scriptFile); diff -ru Orig/tcl8.4.9/generic/tclCmdMZ.c tcl8.4.9/generic/tclCmdMZ.c --- Orig/tcl8.4.9/generic/tclCmdMZ.c Tue Nov 16 15:55:54 2004 +++ tcl8.4.9/generic/tclCmdMZ.c Thu Mar 17 14:22:47 2005 @@ -131,6 +131,151 @@ Tcl_Interp *interp, CONST char *oldName, CONST char *newName, int flags)); static Tcl_CmdObjTraceProc TraceExecutionProc; +static int TraceExecProc _ANSI_ARGS_((ClientData clientData, + Tcl_Interp* interp, + int level, + CONST char* command, + Tcl_Command commandInfo, + int objc, + Tcl_Obj *CONST objv[])); + +/* + * TraceExecProc -- + * Trace handler for the "trace execution TARGET" command. + * The handler produces the following list: + * + * - The line number the current instruction begins on. + * - The fully normalized file name. + * - The nesting level of the command. + * - The stack call level as per [info level]. + * - The fully qualified command name of the command being invoked. + * - The command to be invoked including arguments. + * - The current fully namespace:: qualified function + * + * If TARGET is a valid Tcl channel opened for output, the list + nl is + * output to it, otherwise TARGET is presumed to be a valid Tcl command + * to which the list elements are appended as arguments before eval. + */ +static int +TraceExecProc (clientData, interp, level, command, commandInfo, objc, objv) + ClientData clientData; + Tcl_Interp *interp; + int level; + CONST char *command; + Tcl_Command commandInfo; + int objc; + struct Tcl_Obj * CONST * objv; +{ + Interp *iPtr = (Interp *)interp; + Tcl_SourceInfo *srcInfo; + Tcl_Obj *obj, *nobj, *nsObj = NULL; + Tcl_Obj **listv; + int len, lineNum, curLine, mode = 0, result = TCL_OK; + Tcl_Channel channel = NULL; + CONST char *cmdName; + + srcInfo = &iPtr->sourceInfo; + srcInfo->lastTracedLine = srcInfo->curLineNum; + if (iPtr->traceExecCmd == NULL) + return TCL_OK; + cmdName = Tcl_GetString(iPtr->traceExecCmd); + if (*cmdName == '1' && cmdName[1] == 0) { + return TCL_OK; + } + if (Tcl_ListObjGetElements(interp, iPtr->traceExecCmd, &len, &listv) + != TCL_OK) { + return TCL_ERROR; + } + if (len == 1 && ((channel=Tcl_GetChannel(interp, Tcl_GetString(listv[0]), + &mode)) != NULL) && (mode&TCL_WRITABLE)) { + obj = Tcl_NewListObj(0, 0); + } else { + obj = Tcl_NewListObj(len, listv); + } + Tcl_IncrRefCount(obj); + Tcl_ListObjAppendElement(interp, obj, Tcl_NewIntObj(srcInfo->curLineNum)); + Tcl_ListObjAppendElement(interp, obj, + srcInfo->curFileName?srcInfo->curFileName: + Tcl_NewStringObj("",0)); + + Tcl_ListObjAppendElement(interp, obj, Tcl_NewIntObj(level)); + Tcl_ListObjAppendElement(interp, obj, + Tcl_NewIntObj(iPtr->sourceInfo.stackLevel)); + + /* Append the current fully namespace qualified function. */ + if (iPtr->varFramePtr == NULL) { + nsObj = Tcl_NewStringObj("::",-1); + } else if (iPtr->varFramePtr->isProcCallFrame) { + Tcl_Command f = Tcl_GetCommandFromObj(interp, + iPtr->varFramePtr->objv[0]); + nsObj = Tcl_NewStringObj("", 0); + Tcl_GetCommandFullName(interp, f, nsObj); + } else if (iPtr->varFramePtr->nsPtr && iPtr->varFramePtr->nsPtr->fullName) { + nsObj = Tcl_NewStringObj(iPtr->varFramePtr->nsPtr->fullName,-1); + Tcl_AppendToObj(nsObj, "::", 2); + } else { + nsObj = Tcl_NewStringObj("", 0); + } + Tcl_ListObjAppendElement(interp, obj, nsObj); + nobj = Tcl_NewObj(); + Tcl_GetCommandFullName(interp, commandInfo, nobj); + Tcl_ListObjAppendElement(interp, obj, nobj); + Tcl_ListObjAppendElement(interp, obj, Tcl_NewListObj(objc, objv)); + + /* Set the breakpoint flag if necessary. */ + if ((!(iPtr->sourceInfo.flags&1)) && iPtr->sourceInfo.breakpoints != NULL) { + Tcl_Breakpoint *curBP = iPtr->sourceInfo.breakpoints; + + while (curBP != NULL) { + if (curBP->state>0 && + curBP->lineNum == iPtr->sourceInfo.curLineNum && + curBP->fileName == iPtr->sourceInfo.curFileName) { + if ((curBP->counter=(curBP->counter+1)%curBP->state)==0) { + break; + } + } + curBP = curBP->next; + } + if (curBP != NULL) { + iPtr->sourceInfo.flags |= 1; + } + } + Tcl_ListObjAppendElement(interp, obj, Tcl_NewIntObj(srcInfo->flags)); + iPtr->sourceInfo.flags &= ~1; /* Clear the breakpoint flag. */ + + + lineNum = iPtr->lineNum; + curLine = iPtr->sourceInfo.curLineNum; + iPtr->flags |= INTERP_TRACE_IN_PROGRESS; + if (channel != NULL) { + if (Tcl_WriteObj(channel, obj) <0 || Tcl_Write(channel, "\n", 1) <0) { + /* If closed or an IO error occurred, remove the trace. */ + Tcl_GlobalEval(interp, "trace executon {}"); + Tcl_AddErrorInfo(interp, "Execution trace error writing channel: "); + Tcl_BackgroundError( interp ); + } + } else { + Tcl_SavedResult state; + + Tcl_SaveResult(interp, &state); + + result = Tcl_EvalObjEx(interp, obj, TCL_EVAL_DIRECT); + if (result == TCL_OK) { + /* Restore result if trace execution was successful */ + Tcl_RestoreResult(interp, &state); + } else { + Tcl_DiscardResult(&state); + } + + } + Tcl_DecrRefCount(obj); + iPtr->flags &= ~INTERP_TRACE_IN_PROGRESS; + iPtr->lineNum = lineNum; + iPtr->sourceInfo.curLineNum = curLine; + + return result; +} + /* *---------------------------------------------------------------------- @@ -2712,8 +2857,10 @@ { int i, j, index, mode, matched, result, splitObjs; char *string, *pattern; - Tcl_Obj *stringObj; + Tcl_Obj *stringObj, *bodyObj; Tcl_Obj *CONST *savedObjv = objv; + Interp *iPtr = (Interp *)interp; + int lineNum, curLine; static CONST char *options[] = { "-exact", "-glob", "-regexp", "--", NULL @@ -2722,6 +2869,9 @@ OPT_EXACT, OPT_GLOB, OPT_REGEXP, OPT_LAST }; + curLine = iPtr->sourceInfo.curLineNum; + lineNum = iPtr->lineNum; + mode = OPT_EXACT; for (i = 1; i < objc; i++) { string = Tcl_GetString(objv[i]); @@ -2758,6 +2908,7 @@ if (objc == 1) { Tcl_Obj **listv; + bodyObj = objv[0]; if (Tcl_ListObjGetElements(interp, objv[0], &objc, &listv) != TCL_OK) { return TCL_ERROR; } @@ -2870,7 +3021,49 @@ break; } } + if (iPtr->flags&TRACE_LINE_NUMBERS) { + CONST char *cp, *match; + int n; + unsigned int mLen, nl=0; + + /* Count the newlines in the preceding code. */ + if (splitObjs) { + /* Search body for matching strings, counting \n as we go. */ + cp = string; + while (*cp) { + if (*cp++ == '\n') + nl++; + } + cp = Tcl_GetString(bodyObj); + for (n=0; n= (j-1)) + break; + while (*cp && mLen-- > 0) { + if (*cp++ == '\n') + nl++; + } + } + } else { + for (n=0; nlineNum = curLine + nl; + } result = Tcl_EvalObjEx(interp, objv[j], 0); + iPtr->lineNum = lineNum; + iPtr->sourceInfo.curLineNum = curLine; if (result == TCL_ERROR) { char msg[100 + TCL_INTEGER_SPACE]; @@ -2980,7 +3173,7 @@ char *name, *flagOps, *p; /* Main sub commands to 'trace' */ static CONST char *traceOptions[] = { - "add", "info", "remove", + "add", "info", "remove", "execution", "breakpoint", #ifndef TCL_REMOVE_OBSOLETE_TRACES "variable", "vdelete", "vinfo", #endif @@ -2988,7 +3181,7 @@ }; /* 'OLD' options are pre-Tcl-8.4 style */ enum traceOptions { - TRACE_ADD, TRACE_INFO, TRACE_REMOVE, + TRACE_ADD, TRACE_INFO, TRACE_REMOVE, TRACE_EXECUTION, TRACE_BREAKPOINT, #ifndef TCL_REMOVE_OBSOLETE_TRACES TRACE_OLD_VARIABLE, TRACE_OLD_VDELETE, TRACE_OLD_VINFO #endif @@ -3023,6 +3216,124 @@ } return (traceSubCmds[typeIndex])(interp, optionIndex, objc, objv); } + case TRACE_EXECUTION: { + Interp *iPtr = (Interp *)interp; + int strLen, level=0; + + if (objc == 2) { + if (iPtr->traceExecCmd != NULL) { + Tcl_SetObjResult(interp, iPtr->traceExecCmd); + } + return TCL_OK; + } + if (objc != 3 && objc != 4) { + Tcl_WrongNumArgs(interp, 2, objv, "command ?level?"); + return TCL_ERROR; + } + if (objc == 4) { + if (Tcl_GetIntFromObj(interp, objv[3], &level) != TCL_OK) { + return TCL_ERROR; + } + } + if (iPtr->traceExecCmd != NULL) { + Tcl_DecrRefCount(iPtr->traceExecCmd); + iPtr->traceExecCmd = NULL; + } + p = Tcl_GetStringFromObj(objv[2], &strLen); + if (iPtr->traceExecId != NULL) { + Tcl_DeleteTrace(interp, iPtr->traceExecId); + iPtr->traceExecId = NULL; + } + if (strLen>0 && (strcmp(p,"0"))) { + iPtr->traceExecCmd = objv[2]; + Tcl_IncrRefCount(objv[2]); + iPtr->traceExecId = Tcl_CreateObjTrace(interp, level, TCL_TRACE_LINE_NUMBERS, TraceExecProc, 0, 0); + } + return TCL_OK; + break; + } + case TRACE_BREAKPOINT: { + Interp *iPtr = (Interp *)interp; + Tcl_Breakpoint *curBP = iPtr->sourceInfo.breakpoints; + Tcl_Obj *listPtr; + int idx; + + if (objc == 2) { + if (!curBP) { + return TCL_OK; + } + listPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL); + while (curBP) { + Tcl_ListObjAppendElement(NULL, listPtr, + Tcl_NewIntObj(curBP->lineNum)); + Tcl_ListObjAppendElement(NULL, listPtr, curBP->fileName); + Tcl_ListObjAppendElement(NULL, listPtr, + Tcl_NewIntObj(curBP->state)); + curBP = curBP->next; + } + Tcl_SetObjResult(interp, listPtr); + return TCL_OK; + } + if ((objc%3) == 0) { + Tcl_WrongNumArgs(interp, 2, objv, "line file ?state ...?"); + return TCL_ERROR; + } + idx = 2; + while ((idx+1)sourceInfo.breakpoints; + while (curBP != NULL) { + if (curBP->lineNum == lineNum + && (!strcmp(Tcl_GetString(fileName), + Tcl_GetString(curBP->fileName)))) { + break; + } + curBP = curBP->next; + } + if ((idx+2)>objc) { + if (curBP == NULL) { + Tcl_AppendResult(interp, "Breakpoint not found", 0); + return TCL_ERROR; + } + Tcl_SetObjResult(interp, Tcl_NewIntObj(curBP->state)); + return TCL_OK; + } + if (curBP == NULL) { + curBP = (Tcl_Breakpoint*) ckalloc(sizeof(Tcl_Breakpoint)); + curBP->next = iPtr->sourceInfo.breakpoints; + iPtr->sourceInfo.breakpoints = curBP; + curBP->lineNum = lineNum; + curBP->fileName = TclFSGetSourceFile(interp, fileName); + } + curBP->counter = 0; + /* The empty state means delete the breakpoint. */ + if (strlen(Tcl_GetString(objv[idx+2])) == 0) { + Tcl_Breakpoint *prevBP = iPtr->sourceInfo.breakpoints; + + while (prevBP != NULL && prevBP->next != curBP) { + prevBP = prevBP->next; + } + if (prevBP != NULL) { + prevBP->next = curBP->next; + } else { + iPtr->sourceInfo.breakpoints = curBP->next; + } + ckfree((char*) curBP); + } else if (Tcl_GetIntFromObj(interp, objv[idx+2], + &curBP->state) != TCL_OK) { + return TCL_ERROR; + } + idx += 3; + } + break; + } + #ifndef TCL_REMOVE_OBSOLETE_TRACES case TRACE_OLD_VARIABLE: case TRACE_OLD_VDELETE: { @@ -3609,9 +3920,10 @@ size_t length; enum traceOptions { TRACE_ADD, TRACE_INFO, TRACE_REMOVE }; static CONST char *opStrings[] = { "array", "read", "unset", "write", + "debug", (char *) NULL }; enum operations { TRACE_VAR_ARRAY, TRACE_VAR_READ, TRACE_VAR_UNSET, - TRACE_VAR_WRITE }; + TRACE_VAR_WRITE, TRACE_VAR_DEBUG }; switch ((enum traceOptions) optionIndex) { case TRACE_ADD: @@ -3635,7 +3947,7 @@ } if (listLen == 0) { Tcl_SetResult(interp, "bad operation list \"\": must be " - "one or more of array, read, unset, or write", + "one or more of array, read, unset, write, or debug", TCL_STATIC); return TCL_ERROR; } @@ -3657,6 +3969,9 @@ case TRACE_VAR_WRITE: flags |= TCL_TRACE_WRITES; break; + case TRACE_VAR_DEBUG: + flags |= TCL_TRACE_LINE_NUMBERS; + break; } } command = Tcl_GetStringFromObj(objv[5], &commandLength); @@ -3746,6 +4061,10 @@ Tcl_ListObjAppendElement(NULL, elemObjPtr, Tcl_NewStringObj("unset", 5)); } + if (tvarPtr->flags & TCL_TRACE_LINE_NUMBERS) { + Tcl_ListObjAppendElement(NULL, elemObjPtr, + Tcl_NewStringObj("debug", 5)); + } eachTraceObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL); Tcl_ListObjAppendElement(NULL, eachTraceObjPtr, elemObjPtr); @@ -4298,7 +4617,26 @@ active.nextTracePtr = tracePtr->nextPtr; } if (tracePtr->level > 0 && curLevel > tracePtr->level) { - continue; + Tcl_Breakpoint *curBP = iPtr->sourceInfo.breakpoints; + + if ((!(tracePtr->flags&TCL_TRACE_LINE_NUMBERS)) || curBP == NULL) { + continue; + } + /* Determine we are at a breakpoint. */ + while (curBP != NULL) { + if (curBP->state>0 && + curBP->lineNum == iPtr->sourceInfo.curLineNum && + curBP->fileName == iPtr->sourceInfo.curFileName) { + if ((curBP->counter=(curBP->counter+1)%curBP->state)==0) { + break; + } + } + curBP = curBP->next; + } + if (curBP == NULL) { + continue; + } + iPtr->sourceInfo.flags |= 1; } if (!(tracePtr->flags & TCL_TRACE_EXEC_IN_PROGRESS)) { /* @@ -4377,26 +4715,35 @@ Tcl_Obj *CONST objv[]; /* Pointers to Tcl_Obj of each argument. */ { Interp *iPtr = (Interp *) interp; - char *commandCopy; + char *commandCopy = NULL; int traceCode; - /* - * Copy the command characters into a new string. - */ - - commandCopy = (char *) ckalloc((unsigned) (numChars + 1)); - memcpy((VOID *) commandCopy, (VOID *) command, (size_t) numChars); - commandCopy[numChars] = '\0'; + if (tracePtr->flags&TCL_TRACE_LINE_NUMBERS) { + iPtr->sourceInfo.commandLen = numChars; + iPtr->sourceInfo.stackLevel = iPtr->varFramePtr==NULL ? 0 : + iPtr->varFramePtr->level; + } else { + /* + * Copy the command characters into a new string. + */ + + commandCopy = (char *) ckalloc((unsigned) (numChars + 1)); + memcpy((VOID *) commandCopy, (VOID *) command, (size_t) numChars); + commandCopy[numChars] = '\0'; + command = commandCopy; + } /* * Call the trace procedure then free allocated storage. */ traceCode = (tracePtr->proc)( tracePtr->clientData, (Tcl_Interp*) iPtr, - iPtr->numLevels, commandCopy, + iPtr->numLevels, command, (Tcl_Command) cmdPtr, objc, objv ); - ckfree((char *) commandCopy); + if (commandCopy != NULL) { + ckfree((char *) commandCopy); + } return(traceCode); } @@ -4667,8 +5014,9 @@ Tcl_SavedResult state; TraceVarInfo *tvarPtr = (TraceVarInfo *) clientData; char *result; - int code; + int code, setTrace = 0; Tcl_DString cmd; + Interp *iPtr = (Interp *)interp; /* * We might call Tcl_Eval() below, and that might evaluate @@ -4702,6 +5050,8 @@ Tcl_DStringAppend(&cmd, " w", 2); } else if (flags & TCL_TRACE_UNSETS) { Tcl_DStringAppend(&cmd, " u", 2); + } else if (flags & TCL_TRACE_LINE_NUMBERS) { + Tcl_DStringAppend(&cmd, " d", 2); } } else { #endif @@ -4713,6 +5063,8 @@ Tcl_DStringAppend(&cmd, " write", 6); } else if (flags & TCL_TRACE_UNSETS) { Tcl_DStringAppend(&cmd, " unset", 6); + } else if (flags & TCL_TRACE_LINE_NUMBERS) { + Tcl_DStringAppend(&cmd, " debug", 6); } #ifndef TCL_REMOVE_OBSOLETE_TRACES } @@ -4732,8 +5084,17 @@ tvarPtr->flags |= TCL_TRACE_DESTROYED; } - code = Tcl_EvalEx(interp, Tcl_DStringValue(&cmd), - Tcl_DStringLength(&cmd), 0); + if (flags&TCL_TRACE_LINE_NUMBERS && + (!(iPtr->flags&INTERP_TRACE_IN_PROGRESS))) { + iPtr->flags |= INTERP_TRACE_IN_PROGRESS; + setTrace = 1; + } + code = Tcl_EvalEx(interp, Tcl_DStringValue(&cmd), + Tcl_DStringLength(&cmd), 0); + if (setTrace) { + iPtr->flags &= ~INTERP_TRACE_IN_PROGRESS; + } + if (code != TCL_OK) { /* copy error msg to result */ register Tcl_Obj *errMsgObj = Tcl_GetObjResult(interp); Tcl_IncrRefCount(errMsgObj); @@ -4787,14 +5148,18 @@ int objc; /* Number of arguments. */ Tcl_Obj *CONST objv[]; /* Argument objects. */ { - int result, value; + int result, value, lineNum, oldLine; + Interp *iPtr = (Interp*)interp; if (objc != 3) { Tcl_WrongNumArgs(interp, 1, objv, "test command"); return TCL_ERROR; } + oldLine = iPtr->lineNum; + lineNum = iPtr->sourceInfo.curLineNum; while (1) { + iPtr->lineNum = lineNum; result = Tcl_ExprBooleanObj(interp, objv[1], &value); if (result != TCL_OK) { return result; @@ -4814,6 +5179,7 @@ break; } } + iPtr->lineNum = oldLine; if (result == TCL_BREAK) { result = TCL_OK; } diff -ru Orig/tcl8.4.9/generic/tclCompile.c tcl8.4.9/generic/tclCompile.c --- Orig/tcl8.4.9/generic/tclCompile.c Thu Jun 10 09:44:09 2004 +++ tcl8.4.9/generic/tclCompile.c Thu Mar 17 14:22:47 2005 @@ -286,7 +286,7 @@ int numSrcBytes, int numCodeBytes)); static void EnterCmdStartData _ANSI_ARGS_(( CompileEnv *envPtr, int cmdNumber, - int srcOffset, int codeOffset)); + int srcOffset, int codeOffset, Interp *iPtr)); static void FreeByteCodeInternalRep _ANSI_ARGS_(( Tcl_Obj *objPtr)); static int GetCmdLocEncodingSize _ANSI_ARGS_(( @@ -845,10 +845,12 @@ bytesLeft = numBytes; gotParse = 0; do { + envPtr->startLine = iPtr->lineNum; if (Tcl_ParseCommand(interp, p, bytesLeft, nested, &parse) != TCL_OK) { code = TCL_ERROR; goto error; } + parse.lineNum = iPtr->lineNum; /* Save lineNum subeval may change it. */ gotParse = 1; if (nested) { /* @@ -951,7 +953,8 @@ } startCodeOffset = (envPtr->codeNext - envPtr->codeStart); EnterCmdStartData(envPtr, currCmdIndex, - (parse.commandStart - envPtr->source), startCodeOffset); + (parse.commandStart - envPtr->source), startCodeOffset, + iPtr); for (wordIdx = 0, tokenPtr = parse.tokenPtr; wordIdx < parse.numWords; @@ -1079,6 +1082,9 @@ next = parse.commandStart + parse.commandSize; bytesLeft -= (next - p); p = next; + if (iPtr != NULL) { + iPtr->lineNum = parse.lineNum + parse.lineCnt; + } Tcl_FreeParse(&parse); gotParse = 0; if (nested && (*parse.term == ']')) { @@ -2033,7 +2039,7 @@ */ static void -EnterCmdStartData(envPtr, cmdIndex, srcOffset, codeOffset) +EnterCmdStartData(envPtr, cmdIndex, srcOffset, codeOffset, iPtr) CompileEnv *envPtr; /* Points to the compilation environment * structure in which to enter command * location information. */ @@ -2041,6 +2047,7 @@ * is being set. */ int srcOffset; /* Offset of first char of the command. */ int codeOffset; /* Offset of first byte of command code. */ + Interp *iPtr; /* Interpreter for line number info. */ { CmdLocation *cmdLocPtr; @@ -2086,6 +2093,9 @@ cmdLocPtr->srcOffset = srcOffset; cmdLocPtr->numSrcBytes = -1; cmdLocPtr->numCodeBytes = -1; + cmdLocPtr->numCodeBytes = -1; + cmdLocPtr->srcLineNum = iPtr->lineNum; + cmdLocPtr->fileName = iPtr->sourceInfo.curFileName; } /* @@ -2861,6 +2871,8 @@ int codeDelta, codeLen, srcDelta, srcLen, prevOffset; register int i; + codePtr->startLineNum = envPtr->startLine; + codePtr->fileName = envPtr->iPtr->sourceInfo.curFileName; /* * Encode the code offset for each command as a sequence of deltas. */ diff -ru Orig/tcl8.4.9/generic/tclCompile.h tcl8.4.9/generic/tclCompile.h --- Orig/tcl8.4.9/generic/tclCompile.h Wed Oct 9 04:54:05 2002 +++ tcl8.4.9/generic/tclCompile.h Thu Mar 17 14:22:47 2005 @@ -119,6 +119,8 @@ int numCodeBytes; /* Number of bytes for command's code. */ int srcOffset; /* Offset of first char of the command. */ int numSrcBytes; /* Number of command source chars. */ + int srcLineNum; /* The line number in the source. */ + Tcl_Obj *fileName; /* File containing source, if any. */ } CmdLocation; /* @@ -264,6 +266,7 @@ /* Initial storage for cmd location map. */ AuxData staticAuxDataArraySpace[COMPILEENV_INIT_AUX_DATA_SIZE]; /* Initial storage for aux data array. */ + int startLine; } CompileEnv; /* @@ -377,6 +380,8 @@ * are always positive. This sequence is * just after the last byte in the source * delta sequence. */ + int startLineNum; /* The line number of the first instruction. */ + Tcl_Obj *fileName; /* Source file. */ #ifdef TCL_COMPILE_STATS Tcl_Time createTime; /* Absolute time when the ByteCode was * created. */ diff -ru Orig/tcl8.4.9/generic/tclExecute.c tcl8.4.9/generic/tclExecute.c --- Orig/tcl8.4.9/generic/tclExecute.c Mon Nov 8 01:32:04 2004 +++ tcl8.4.9/generic/tclExecute.c Thu Mar 17 14:22:47 2005 @@ -362,7 +362,7 @@ static ExceptionRange * GetExceptRangeForPc _ANSI_ARGS_((unsigned char *pc, int catchOnly, ByteCode* codePtr)); static char * GetSrcInfoForPc _ANSI_ARGS_((unsigned char *pc, - ByteCode* codePtr, int *lengthPtr)); + ByteCode* codePtr, int *lengthPtr, Interp *iPtr)); static void GrowEvaluationStack _ANSI_ARGS_((ExecEnv *eePtr)); static void IllegalExprOperandType _ANSI_ARGS_(( Tcl_Interp *interp, unsigned char *pc, @@ -1380,12 +1380,13 @@ tracePtr = nextTracePtr) { nextTracePtr = tracePtr->nextPtr; if (tracePtr->level == 0 || - iPtr->numLevels <= tracePtr->level) { + iPtr->numLevels <= tracePtr->level || + iPtr->sourceInfo.breakpoints != NULL) { /* * Traces will be called: get command string */ - bytes = GetSrcInfoForPc(pc, codePtr, &length); + bytes = GetSrcInfoForPc(pc, codePtr, &length, iPtr); break; } } @@ -1393,7 +1394,7 @@ Command *cmdPtr; cmdPtr = (Command *) Tcl_GetCommandFromObj(interp, objv[0]); if ((cmdPtr != NULL) && (cmdPtr->flags & CMD_HAS_EXEC_TRACES)) { - bytes = GetSrcInfoForPc(pc, codePtr, &length); + bytes = GetSrcInfoForPc(pc, codePtr, &length, iPtr); } } @@ -4245,7 +4246,7 @@ checkForCatch: if ((result == TCL_ERROR) && !(iPtr->flags & ERR_ALREADY_LOGGED)) { - bytes = GetSrcInfoForPc(pc, codePtr, &length); + bytes = GetSrcInfoForPc(pc, codePtr, &length, iPtr); if (bytes != NULL) { DECACHE_STACK_INFO(); Tcl_LogCommandInfo(interp, codePtr->source, bytes, length); @@ -4451,7 +4452,7 @@ } if ((stackTop < stackLowerBound) || (stackTop > stackUpperBound)) { int numChars; - char *cmd = GetSrcInfoForPc(pc, codePtr, &numChars); + char *cmd = GetSrcInfoForPc(pc, codePtr, &numChars, iPtr); char *ellipsis = ""; fprintf(stderr, "\nBad stack top %d at pc %u in TclExecuteByteCode (min %i, max %i)", @@ -4633,7 +4634,7 @@ */ static char * -GetSrcInfoForPc(pc, codePtr, lengthPtr) +GetSrcInfoForPc(pc, codePtr, lengthPtr, iPtr) unsigned char *pc; /* The program counter value for which to * return the closest command's source info. * This points to a bytecode instruction @@ -4643,6 +4644,7 @@ int *lengthPtr; /* If non-NULL, the location where the * length of the command's source should be * stored. If NULL, no length is stored. */ + Interp *iPtr; { register int pcOffset = (pc - codePtr->codeStart); int numCmds = codePtr->numCommands; @@ -4727,6 +4729,13 @@ if (lengthPtr != NULL) { *lengthPtr = bestSrcLength; } + if (iPtr != NULL) { + iPtr->sourceInfo.curLineNum = iPtr->lineNum; + for (i=0; isource[i] == '\n') + iPtr->sourceInfo.curLineNum++; + } + } return (codePtr->source + bestSrcOffset); } diff -ru Orig/tcl8.4.9/generic/tclIOUtil.c tcl8.4.9/generic/tclIOUtil.c --- Orig/tcl8.4.9/generic/tclIOUtil.c Thu Dec 2 11:16:22 2004 +++ tcl8.4.9/generic/tclIOUtil.c Thu Mar 17 14:22:47 2005 @@ -121,6 +121,7 @@ extern CONST char * tclpFileAttrStrings[]; extern CONST TclFileAttrProcs tclpFileAttrProcs[]; + /* * The following functions are obsolete string based APIs, and should * be removed in a future release (Tcl 9 would be a good time). @@ -1667,6 +1668,30 @@ return mode; } +Tcl_Obj* +TclFSGetSourceFile(interp, pathPtr) + Tcl_Interp *interp; + Tcl_Obj *pathPtr; +{ + int isnew; + Tcl_HashEntry *entry; + Interp *iPtr = (Interp *)interp; + Tcl_Obj *newPtr; + + if (!pathPtr) + return NULL; + entry=Tcl_CreateHashEntry(&iPtr->sourcedFiles, + Tcl_GetString(iPtr->scriptFile), &isnew); + if (isnew) { + newPtr = Tcl_DuplicateObj(iPtr->scriptFile); + Tcl_IncrRefCount(newPtr); + Tcl_SetHashValue(entry, newPtr); + } else { + newPtr = (Tcl_Obj*)Tcl_GetHashValue(entry); + } + return newPtr; +} + /* *---------------------------------------------------------------------- * @@ -1701,6 +1726,7 @@ char *string; Tcl_Channel chan; Tcl_Obj *objPtr; + int lineNum; if (Tcl_FSGetNormalizedPath(interp, pathPtr) == NULL) { return TCL_ERROR; @@ -1744,6 +1770,9 @@ iPtr = (Interp *) interp; oldScriptFile = iPtr->scriptFile; iPtr->scriptFile = pathPtr; + iPtr->sourceInfo.curFileName = TclFSGetSourceFile(interp, pathPtr); + lineNum = iPtr->lineNum; + iPtr->lineNum = 1; Tcl_IncrRefCount(iPtr->scriptFile); string = Tcl_GetStringFromObj(objPtr, &length); result = Tcl_EvalEx(interp, string, length, 0); @@ -1756,6 +1785,7 @@ Tcl_DecrRefCount(iPtr->scriptFile); } iPtr->scriptFile = oldScriptFile; + iPtr->sourceInfo.curFileName = TclFSGetSourceFile(interp, oldScriptFile); if (result == TCL_RETURN) { result = TclUpdateReturnInfo(iPtr); @@ -1770,6 +1800,7 @@ interp->errorLine); Tcl_AddErrorInfo(interp, msg); } + iPtr->lineNum = lineNum; end: Tcl_DecrRefCount(objPtr); diff -ru Orig/tcl8.4.9/generic/tclInt.h tcl8.4.9/generic/tclInt.h --- Orig/tcl8.4.9/generic/tclInt.h Tue Jul 20 18:30:57 2004 +++ tcl8.4.9/generic/tclInt.h Thu Mar 17 14:22:47 2005 @@ -648,6 +648,8 @@ CompiledLocal *lastLocalPtr; /* Pointer to the last allocated local * variable or NULL if none. This has * frame index (numCompiledLocals-1). */ + Tcl_Obj *fileName; /* File command is defined in. */ + int lineNum; /* Line number of proc definition. */ } Proc; /* @@ -756,6 +758,8 @@ * recognized by the compiler. The compiler * emits code that refers to these variables * using an index into this array. */ + int lineNum; /* Line number: meaningful only in "source" */ + Tcl_Obj *fileName; /* Object containing the file name. */ } CallFrame; /* @@ -1239,6 +1243,13 @@ * aren't described in packageTable. * Malloc'ed, may be NULL. */ + int lineNum; /* Line number: meaningfull only in "source" */ + Tcl_SourceInfo sourceInfo; /* Source file/line info. */ + int relError; /* Use relative line # on procedure error. */ + Tcl_HashTable sourcedFiles; /* List of paths for "source"d files */ + Tcl_Obj *traceExecCmd; /* A single command for tracing execution. */ + Tcl_Trace traceExecId; /* Trace associated with traceExecCmd. */ + /* * Miscellaneous information: */ @@ -1318,6 +1329,17 @@ } Interp; /* + * Stores the file name and newline map for a file. + * Eventually will be used as a symbol table. + */ +typedef struct SourceFileInfo { + Tcl_Obj *fileName; /* Object containing the file name. */ + Tcl_Obj *fileBody; /* Contents of the file.*/ + int *newlineMap; /* Newline map.*/ + int mapSize; /* Map size. */ +} SourceFiles; + +/* * EvalFlag bits for Interp structures: * * TCL_BRACKET_TERM 1 means that the current script is terminated by @@ -1367,6 +1389,7 @@ * INTERP_TRACE_IN_PROGRESS: Non-zero means that an interp trace is currently * active; so no further trace callbacks should be * invoked. + * TRACE_LINE_NUMBERS: Tracing line numbers in switch/if/for/while/etc. */ #define DELETED 1 @@ -1379,6 +1402,7 @@ #define SAFE_INTERP 0x80 #define USE_EVAL_DIRECT 0x100 #define INTERP_TRACE_IN_PROGRESS 0x200 +#define TRACE_LINE_NUMBERS 0x400 /* * Maximum number of levels of nesting permitted in Tcl commands (used @@ -1672,7 +1696,7 @@ Tcl_Obj* valuePtr )); EXTERN int TclParseBackslash _ANSI_ARGS_((CONST char *src, - int numBytes, int *readPtr, char *dst)); + int numBytes, int *readPtr, char *dst, Tcl_Parse *parsePtr)); EXTERN int TclParseHex _ANSI_ARGS_((CONST char *src, int numBytes, Tcl_UniChar *resultPtr)); EXTERN int TclParseInteger _ANSI_ARGS_((CONST char *string, @@ -1697,6 +1721,9 @@ Tcl_ThreadDataKey *keyPtr)); EXTERN char * TclpFindExecutable _ANSI_ARGS_(( CONST char *argv0)); +EXTERN Proc * TclFindProcByLine _ANSI_ARGS_((Interp *iPtr, + Tcl_Obj *fileName, int lineNum, Namespace *nsPtr, + Tcl_Obj **procName)); EXTERN int TclpFindVariable _ANSI_ARGS_((CONST char *name, int *lengthPtr)); EXTERN int TclpInitLibraryPath _ANSI_ARGS_((CONST char *argv0)); @@ -2276,5 +2303,6 @@ # undef TCL_STORAGE_CLASS # define TCL_STORAGE_CLASS DLLIMPORT +Tcl_Obj* TclFSGetSourceFile _ANSI_ARGS_((Tcl_Interp *interp, Tcl_Obj *obj)); #endif /* _TCLINT */ diff -ru Orig/tcl8.4.9/generic/tclNamesp.c tcl8.4.9/generic/tclNamesp.c --- Orig/tcl8.4.9/generic/tclNamesp.c Tue Oct 5 16:23:33 2004 +++ tcl8.4.9/generic/tclNamesp.c Thu Mar 17 14:22:47 2005 @@ -322,6 +322,8 @@ iPtr->framePtr = framePtr; iPtr->varFramePtr = framePtr; + framePtr->lineNum = iPtr->sourceInfo.curLineNum; + framePtr->fileName = iPtr->sourceInfo.curFileName; return TCL_OK; } diff -ru Orig/tcl8.4.9/generic/tclObj.c tcl8.4.9/generic/tclObj.c --- Orig/tcl8.4.9/generic/tclObj.c Mon Nov 8 01:32:05 2004 +++ tcl8.4.9/generic/tclObj.c Thu Mar 17 14:22:47 2005 @@ -176,6 +176,12 @@ SetCmdNameFromAny /* setFromAnyProc */ }; +typedef struct ProcLineInfo { + int lineNum; /* Line Number for proc definitions */ + int lineFeeds; /* New lines in proc body */ + struct ProcLineInfo *next; +} ProcLineInfo; + /* * Structure containing a cached pointer to a command that is the result @@ -210,6 +216,7 @@ * ResolvedCmdName structure as its internal * rep. This structure can be freed when * refCount becomes zero. */ + ProcLineInfo * lineInfo; } ResolvedCmdName; @@ -3048,6 +3055,24 @@ cmdPtr = resPtr->cmdPtr; } } + if (resPtr != NULL && resPtr->lineInfo) { + + /* + * Restore saved line number information for proc's. + */ + ProcLineInfo *lineLast, *lineInfo=resPtr->lineInfo; + while (lineInfo->next != (ProcLineInfo *)NULL) { + lineLast = lineInfo; + lineInfo = lineInfo->next; + } + iPtr->lineNum = lineInfo->lineNum; + if (lineInfo == resPtr->lineInfo) { + resPtr->lineInfo=0; + } else { + lineLast->next=0; + } + ckfree((char *)lineInfo); + } iPtr->varFramePtr = savedFramePtr; return (Tcl_Command) cmdPtr; } @@ -3085,9 +3110,11 @@ register ResolvedCmdName *resPtr; Tcl_ObjType *oldTypePtr = objPtr->typePtr; register Namespace *currNsPtr; + ProcLineInfo *lineInfo; if (oldTypePtr == &tclCmdNameType) { - return; + resPtr = (ResolvedCmdName *) objPtr->internalRep.otherValuePtr; + goto setlineinfo; } /* @@ -3108,6 +3135,7 @@ resPtr->refNsCmdEpoch = currNsPtr->cmdRefEpoch; resPtr->cmdEpoch = cmdPtr->cmdEpoch; resPtr->refCount = 1; + resPtr->lineInfo = NULL; if ((oldTypePtr != NULL) && (oldTypePtr->freeIntRepProc != NULL)) { oldTypePtr->freeIntRepProc(objPtr); @@ -3115,6 +3143,18 @@ objPtr->internalRep.twoPtrValue.ptr1 = (VOID *) resPtr; objPtr->internalRep.twoPtrValue.ptr2 = NULL; objPtr->typePtr = &tclCmdNameType; +setlineinfo: + if (cmdPtr->objProc != Tcl_ProcObjCmd) { + return; + } + + /* + * Save line number information for proc's + */ + lineInfo = (ProcLineInfo *)ckalloc(sizeof(ProcLineInfo)); + lineInfo->lineNum = iPtr->lineNum; + lineInfo->next = resPtr->lineInfo; + resPtr->lineInfo = lineInfo; } /* @@ -3162,6 +3202,16 @@ Command *cmdPtr = resPtr->cmdPtr; TclCleanupCommand(cmdPtr); + + if (resPtr->lineInfo != NULL) { + ProcLineInfo *lineLast, *lineInfo=resPtr->lineInfo; + while (lineInfo->next != NULL) { + lineLast = lineInfo; + lineInfo = lineInfo->next; + ckfree((char*) lineLast); + } + ckfree((char*) lineInfo); + } ckfree((char *) resPtr); } } @@ -3275,6 +3325,7 @@ resPtr->refNsCmdEpoch = currNsPtr->cmdRefEpoch; resPtr->cmdEpoch = cmdPtr->cmdEpoch; resPtr->refCount = 1; + resPtr->lineInfo = NULL; } else { resPtr = NULL; /* no command named "name" was found */ } diff -ru Orig/tcl8.4.9/generic/tclParse.c tcl8.4.9/generic/tclParse.c --- Orig/tcl8.4.9/generic/tclParse.c Thu Nov 18 11:31:11 2004 +++ tcl8.4.9/generic/tclParse.c Thu Mar 17 14:22:47 2005 @@ -237,6 +237,7 @@ CONST char *termPtr; /* Set by Tcl_ParseBraces/QuotedString to * point to char after terminating one. */ int scanned; + Interp *iPtr = (Interp *) interp; if ((string == NULL) && (numBytes>0)) { if (interp != NULL) { @@ -247,6 +248,11 @@ if (numBytes < 0) { numBytes = strlen(string); } + parsePtr->lineCnt = 0; + if (iPtr != NULL && nested == 0) { + parsePtr->lineNum = iPtr->lineNum; + parsePtr->fileName = TclFSGetSourceFile(interp, iPtr->scriptFile); + } parsePtr->commentStart = NULL; parsePtr->commentSize = 0; parsePtr->commandStart = NULL; @@ -273,6 +279,10 @@ */ scanned = ParseComment(string, numBytes, parsePtr); + if (iPtr != NULL && parsePtr->lineCnt) { + iPtr->lineNum += parsePtr->lineCnt; + parsePtr->lineCnt = 0; + } src = (string + scanned); numBytes -= scanned; if (numBytes == 0) { if (nested) { @@ -311,6 +321,9 @@ } if ((type & terminators) != 0) { parsePtr->term = src; + if (*src == '\n') { + parsePtr->lineCnt++; + } src++; break; } @@ -382,6 +395,9 @@ } if ((type & terminators) != 0) { parsePtr->term = src; + if (*src == '\n') { + parsePtr->lineCnt++; + } src++; break; } @@ -401,7 +417,6 @@ parsePtr->term = src; goto error; } - parsePtr->commandSize = src - parsePtr->commandStart; return TCL_OK; @@ -460,6 +475,8 @@ } if (p[1] != '\n') { break; + } else { + parsePtr->lineCnt++; } p+=2; if (--numBytes == 0) { @@ -552,7 +569,7 @@ *---------------------------------------------------------------------- */ int -TclParseBackslash(src, numBytes, readPtr, dst) +TclParseBackslash(src, numBytes, readPtr, dst, parsePtr) CONST char * src; /* Points to the backslash character of a * a backslash sequence */ int numBytes; /* Max number of bytes to scan */ @@ -562,6 +579,7 @@ * encoding of the backslash sequence is to be * written. At most TCL_UTF_MAX bytes will be * written there. */ + Tcl_Parse *parsePtr; { register CONST char *p = src+1; Tcl_UniChar result; @@ -635,6 +653,7 @@ } break; case '\n': + if (parsePtr) parsePtr->lineCnt++; count--; do { p++; count++; @@ -723,6 +742,7 @@ do { scanned = TclParseWhiteSpace(p, numBytes, parsePtr, &type); p += scanned; numBytes -= scanned; + if (*p == '\n') parsePtr->lineCnt++; } while (numBytes && (*p == '\n') && (p++,numBytes--)); if ((numBytes == 0) || (*p != '#')) { break; @@ -742,12 +762,13 @@ * and history indicate that it has been the de facto * rule. Don't change it now. */ - TclParseBackslash(p, numBytes, &scanned, NULL); + TclParseBackslash(p, numBytes, &scanned, NULL, parsePtr); p += scanned; numBytes -= scanned; } } else { p++; numBytes--; if (p[-1] == '\n') { + parsePtr->lineCnt++; break; } } @@ -822,10 +843,15 @@ * This is a simple range of characters. Scan to find the end * of the range. */ + if (*src == '\n') { + parsePtr->lineCnt++; + } while ((++src, --numBytes) && !(CHAR_TYPE(*src) & (mask | TYPE_SUBS))) { - /* empty loop */ + if (*src == '\n') { + parsePtr->lineCnt++; + } } tokenPtr->type = TCL_TOKEN_TEXT; tokenPtr->size = src - tokenPtr->start; @@ -859,6 +885,7 @@ parsePtr->incomplete = nested.incomplete; return TCL_ERROR; } + parsePtr->lineCnt += nested.lineCnt; src = nested.commandStart + nested.commandSize; numBytes = parsePtr->end - src; @@ -899,7 +926,7 @@ /* * Backslash substitution. */ - TclParseBackslash(src, numBytes, &tokenPtr->size, NULL); + TclParseBackslash(src, numBytes, &tokenPtr->size, NULL, parsePtr); if (tokenPtr->size == 1) { /* Just a backslash, due to end of string */ @@ -910,6 +937,7 @@ } if (src[1] == '\n') { + parsePtr->lineCnt++; if (numBytes == 2) { parsePtr->incomplete = 1; } @@ -1496,7 +1524,7 @@ } break; case '\\': - TclParseBackslash(src, numBytes, &length, NULL); + TclParseBackslash(src, numBytes, &length, NULL, parsePtr); if ((length > 1) && (src[1] == '\n')) { /* * A backslash-newline sequence must be collapsed, even @@ -1533,6 +1561,9 @@ numBytes -= length - 1; } break; + case '\n': + parsePtr->lineCnt++; + break; } } } @@ -1782,3 +1813,5 @@ return 1; } + + diff -ru Orig/tcl8.4.9/generic/tclProc.c tcl8.4.9/generic/tclProc.c --- Orig/tcl8.4.9/generic/tclProc.c Mon May 3 17:40:30 2004 +++ tcl8.4.9/generic/tclProc.c Thu Mar 17 14:28:09 2005 @@ -132,6 +132,8 @@ Tcl_DStringAppend(&ds, "::", 2); } Tcl_DStringAppend(&ds, procName, -1); + procPtr->lineNum = iPtr->lineNum; + procPtr->fileName = iPtr->sourceInfo.curFileName; Tcl_CreateCommand(interp, Tcl_DStringValue(&ds), TclProcInterpProc, (ClientData) procPtr, TclProcDeleteProc); @@ -747,6 +749,74 @@ return (Proc *) cmdPtr->clientData; } + +/* + *---------------------------------------------------------------------- + * + * TclFindProcByLine -- + * + * Given a file name and a line number, return a pointer to the + * record describing the procedure, if one exists at that line. + * + * Results: + * NULL is returned if no procedure is found at that line number. + * Otherwise, the return value is a pointer to the procedure's record. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ +Proc * +TclFindProcByLine(iPtr, fileName, lineNum, nsPtr, procName) + Interp *iPtr; /* Interpreter in which to look. */ + Tcl_Obj *fileName; /* The file name */ + int lineNum; /* Line number within file. */ + Namespace *nsPtr; /* The namespace to start search from. */ + Tcl_Obj **procName; /* Name of the procedure to call. */ +{ + register Tcl_HashEntry *entryPtr; + Tcl_HashSearch search; + Command *cmdPtr; + Namespace *childNsPtr; + Proc *procPtr; + char *fname=Tcl_GetString(fileName); + + if (nsPtr == (Namespace *)NULL) { + nsPtr=iPtr->globalNsPtr; + } + if (nsPtr == (Namespace *)NULL) { + return (Proc *)NULL; + } + entryPtr = Tcl_FirstHashEntry(&nsPtr->cmdTable, &search); + while (entryPtr != NULL) { + cmdPtr = (Command *) Tcl_GetHashValue(entryPtr); + if ((procPtr=TclIsProc(cmdPtr)) != (Proc *)NULL) { + if (procPtr->fileName && + (!strcmp(fname,Tcl_GetString(procPtr->fileName)))) { + if (lineNum>=procPtr->lineNum /* ??? && + lineNum<=(procPtr->lineNum+procPtr->lineFeeds)*/) { + *procName=Tcl_NewStringObj(nsPtr->fullName,-1); + Tcl_AppendStringsToObj(*procName, + (char*)Tcl_GetHashKey(&nsPtr->cmdTable,entryPtr),0); + return procPtr; + } + } + } + entryPtr = Tcl_NextHashEntry(&search); + } + + for (entryPtr = Tcl_FirstHashEntry(&nsPtr->childTable, &search); + entryPtr != NULL; + entryPtr = Tcl_NextHashEntry(&search)) { + childNsPtr = (Namespace *) Tcl_GetHashValue(entryPtr); + if ((procPtr=TclFindProcByLine(iPtr, fileName, lineNum, childNsPtr, + procName))) + return procPtr; + } + return (Proc *)NULL; +} + /* *---------------------------------------------------------------------- * @@ -909,7 +979,8 @@ register Var *varPtr; register CompiledLocal *localPtr; char *procName; - int nameLen, localCt, numArgs, argCt, i, result; + int nameLen, localCt, numArgs, argCt, i, result, lineNum; + Tcl_Obj *fileName; /* * This procedure generates an array "compiledLocals" that holds the @@ -921,6 +992,10 @@ Var localStorage[NUM_LOCALS]; Var *compiledLocals = localStorage; + lineNum = iPtr->lineNum; + fileName = iPtr->sourceInfo.curFileName; + iPtr->lineNum = procPtr->lineNum; + iPtr->sourceInfo.curFileName = procPtr->fileName; /* * Get the procedure's name. */ @@ -937,7 +1012,7 @@ result = TclProcCompileProc(interp, procPtr, procPtr->bodyPtr, nsPtr, "body of proc", procName); - + if (result != TCL_OK) { return result; } @@ -965,8 +1040,10 @@ (Tcl_Namespace *) nsPtr, /*isProcCallFrame*/ 1); if (result != TCL_OK) { - return result; + goto procExit; } + iPtr->lineNum = iPtr->sourceInfo.curLineNum = procPtr->lineNum; + iPtr->sourceInfo.curFileName = procPtr->fileName; framePtr->objc = objc; framePtr->objv = objv; /* ref counts for args are incremented below */ @@ -996,11 +1073,13 @@ if (!TclIsVarArgument(localPtr)) { panic("TclObjInterpProc: local variable %s is not argument but should be", localPtr->name); - return TCL_ERROR; + result = TCL_ERROR; + goto procExit; } if (TclIsVarTemporary(localPtr)) { panic("TclObjInterpProc: local variable %d is temporary but should be an argument", i); - return TCL_ERROR; + result = TCL_ERROR; + goto procExit; } /* @@ -1117,6 +1196,10 @@ if (compiledLocals != localStorage) { ckfree((char *) compiledLocals); } + + procExit: + iPtr->lineNum = lineNum; + iPtr->sourceInfo.curFileName = fileName; return result; #undef NUM_LOCALS } @@ -1231,6 +1314,8 @@ (Tcl_Namespace*)nsPtr, /* isProcCallFrame */ 0); if (result == TCL_OK) { + procPtr->lineNum = iPtr->lineNum; + procPtr->fileName = iPtr->sourceInfo.curFileName; result = tclByteCodeType.setFromAnyProc(interp, bodyPtr); Tcl_PopCallFrame(interp); } @@ -1239,6 +1324,8 @@ if (result != TCL_OK) { if (result == TCL_ERROR) { + int errorLine; + Proc *procPtr; char buf[100 + TCL_INTEGER_SPACE]; numChars = strlen(procName); @@ -1255,9 +1342,15 @@ numChars--; ellipsis = "..."; } + procPtr=TclFindProc(iPtr, procName); + errorLine = interp->errorLine; + if (procPtr && procPtr->fileName && (!iPtr->relError)) { + procName = Tcl_GetString(procPtr->fileName); + errorLine = procPtr->lineNum; + } sprintf(buf, "\n (compiling %s \"%.*s%s\", line %d)", description, numChars, procName, ellipsis, - interp->errorLine); + errorLine); Tcl_AddObjErrorInfo(interp, buf, -1); } return result; Only in tcl8.4.9/generic: tclProc.c.rej diff -ru Orig/tcl8.4.9/generic/tclTimer.c tcl8.4.9/generic/tclTimer.c --- Orig/tcl8.4.9/generic/tclTimer.c Thu Sep 9 17:14:48 2004 +++ tcl8.4.9/generic/tclTimer.c Thu Mar 17 14:22:47 2005 @@ -53,6 +53,9 @@ * timer handler. */ struct AfterInfo *nextPtr; /* Next in list of all "after" commands for * this interpreter. */ + int lineNum; /* Line number of after event. */ + int curLine; /* Line number of after event. */ + Tcl_Obj *fileName; /* Source filename. */ } AfterInfo; /* @@ -749,6 +752,7 @@ }; enum afterSubCmds {AFTER_CANCEL, AFTER_IDLE, AFTER_INFO}; ThreadSpecificData *tsdPtr = InitTimer(); + Interp *iPtr = (Interp*)interp; if (objc < 2) { Tcl_WrongNumArgs(interp, 1, objv, "option ?arg arg ...?"); @@ -813,6 +817,9 @@ tsdPtr->afterId += 1; afterPtr->token = Tcl_CreateTimerHandler(ms, AfterProc, (ClientData) afterPtr); + afterPtr->lineNum = iPtr->lineNum; + afterPtr->curLine = iPtr->sourceInfo.curLineNum; + afterPtr->fileName = iPtr->sourceInfo.curFileName; afterPtr->nextPtr = assocPtr->firstAfterPtr; assocPtr->firstAfterPtr = afterPtr; sprintf(buf, "after#%d", afterPtr->id); @@ -889,6 +896,9 @@ afterPtr->id = tsdPtr->afterId; tsdPtr->afterId += 1; afterPtr->token = NULL; + afterPtr->lineNum = iPtr->lineNum; + afterPtr->curLine = iPtr->sourceInfo.curLineNum; + afterPtr->fileName = iPtr->sourceInfo.curFileName; afterPtr->nextPtr = assocPtr->firstAfterPtr; assocPtr->firstAfterPtr = afterPtr; Tcl_DoWhenIdle(AfterProc, (ClientData) afterPtr); @@ -1008,10 +1018,12 @@ AfterInfo *afterPtr = (AfterInfo *) clientData; AfterAssocData *assocPtr = afterPtr->assocPtr; AfterInfo *prevPtr; - int result; + int result, lineNum, curLine; Tcl_Interp *interp; char *script; int numBytes; + Tcl_Obj *fileName; + Interp *iPtr; /* * First remove the callback from our list of callbacks; otherwise @@ -1034,9 +1046,21 @@ */ interp = assocPtr->interp; + iPtr = (Interp*)interp; Tcl_Preserve((ClientData) interp); + /* Save/restore file/line number in case of trace. */ + lineNum = iPtr->lineNum; + curLine = iPtr->sourceInfo.curLineNum; + fileName = iPtr->sourceInfo.curFileName; + iPtr->sourceInfo.curFileName = afterPtr->fileName; + iPtr->lineNum = afterPtr->lineNum; + iPtr->sourceInfo.curLineNum = afterPtr->curLine; script = Tcl_GetStringFromObj(afterPtr->commandPtr, &numBytes); result = Tcl_EvalEx(interp, script, numBytes, TCL_EVAL_GLOBAL); + iPtr->sourceInfo.curFileName = fileName; + iPtr->lineNum = lineNum; + iPtr->sourceInfo.curLineNum = curLine; + script = Tcl_GetStringFromObj(afterPtr->commandPtr, &numBytes); if (result != TCL_OK) { Tcl_AddErrorInfo(interp, "\n (\"after\" script)"); Tcl_BackgroundError(interp); diff -ru Orig/tcl8.4.9/generic/tclUtf.c tcl8.4.9/generic/tclUtf.c --- Orig/tcl8.4.9/generic/tclUtf.c Thu Nov 18 11:31:11 2004 +++ tcl8.4.9/generic/tclUtf.c Thu Mar 17 14:22:47 2005 @@ -788,10 +788,10 @@ int numRead; int result; - result = TclParseBackslash(src, LINE_LENGTH, &numRead, dst); + result = TclParseBackslash(src, LINE_LENGTH, &numRead, dst, NULL); if (numRead == LINE_LENGTH) { /* We ate a whole line. Pay the price of a strlen() */ - result = TclParseBackslash(src, (int)strlen(src), &numRead, dst); + result = TclParseBackslash(src, (int)strlen(src), &numRead, dst, NULL); } if (readPtr != NULL) { *readPtr = numRead; diff -ru Orig/tcl8.4.9/library/tcltest/tcltest.tcl tcl8.4.9/library/tcltest/tcltest.tcl --- Orig/tcl8.4.9/library/tcltest/tcltest.tcl Mon Nov 8 01:32:09 2004 +++ tcl8.4.9/library/tcltest/tcltest.tcl Thu Mar 17 14:22:47 2005 @@ -18,6 +18,9 @@ # # RCS: @(#) $Id: tcltest.tcl,v 1.78.2.12 2004/11/02 19:03:07 dgp Exp $ +# Disable absolute line number/filename in proc error. +info line relerror 1 + package require Tcl 8.3 ;# uses [glob -directory] namespace eval tcltest { Only in tcl8.4.9/library/tcltest: tcltest.tcl.orig Only in tcl8.4.9/: pat.log diff -ru Orig/tcl8.4.9/tests/info.test tcl8.4.9/tests/info.test --- Orig/tcl8.4.9/tests/info.test Wed Nov 24 11:30:44 2004 +++ tcl8.4.9/tests/info.test Thu Mar 17 14:22:47 2005 @@ -640,16 +640,16 @@ } {1 {wrong # args: should be "info option ?arg arg ...?"}} test info-21.2 {miscellaneous error conditions} { list [catch {info gorp} msg] $msg -} {1 {bad option "gorp": must be args, body, cmdcount, commands, complete, default, exists, functions, globals, hostname, level, library, loaded, locals, nameofexecutable, patchlevel, procs, script, sharedlibextension, tclversion, or vars}} +} {1 {bad option "gorp": must be args, body, cmdcount, commands, complete, default, exists, functions, globals, hostname, level, library, line, loaded, locals, nameofexecutable, patchlevel, procs, return, script, sharedlibextension, tclversion, or vars}} test info-21.3 {miscellaneous error conditions} { list [catch {info c} msg] $msg -} {1 {ambiguous option "c": must be args, body, cmdcount, commands, complete, default, exists, functions, globals, hostname, level, library, loaded, locals, nameofexecutable, patchlevel, procs, script, sharedlibextension, tclversion, or vars}} +} {1 {ambiguous option "c": must be args, body, cmdcount, commands, complete, default, exists, functions, globals, hostname, level, library, line, loaded, locals, nameofexecutable, patchlevel, procs, return, script, sharedlibextension, tclversion, or vars}} test info-21.4 {miscellaneous error conditions} { list [catch {info l} msg] $msg -} {1 {ambiguous option "l": must be args, body, cmdcount, commands, complete, default, exists, functions, globals, hostname, level, library, loaded, locals, nameofexecutable, patchlevel, procs, script, sharedlibextension, tclversion, or vars}} +} {1 {ambiguous option "l": must be args, body, cmdcount, commands, complete, default, exists, functions, globals, hostname, level, library, line, loaded, locals, nameofexecutable, patchlevel, procs, return, script, sharedlibextension, tclversion, or vars}} test info-21.5 {miscellaneous error conditions} { list [catch {info s} msg] $msg -} {1 {ambiguous option "s": must be args, body, cmdcount, commands, complete, default, exists, functions, globals, hostname, level, library, loaded, locals, nameofexecutable, patchlevel, procs, script, sharedlibextension, tclversion, or vars}} +} {1 {ambiguous option "s": must be args, body, cmdcount, commands, complete, default, exists, functions, globals, hostname, level, library, line, loaded, locals, nameofexecutable, patchlevel, procs, return, script, sharedlibextension, tclversion, or vars}} # cleanup catch {namespace delete test_ns_info1 test_ns_info2} diff -ru Orig/tcl8.4.9/tests/trace.test tcl8.4.9/tests/trace.test --- Orig/tcl8.4.9/tests/trace.test Tue Nov 16 15:55:57 2004 +++ tcl8.4.9/tests/trace.test Thu Mar 17 14:22:47 2005 @@ -784,14 +784,14 @@ test trace-14.5 {trace command, invalid option} { list [catch {trace gorp} msg] $msg -} [list 1 "bad option \"gorp\": must be add, info, remove, variable, vdelete, or vinfo"] +} [list 1 "bad option \"gorp\": must be add, info, remove, execution, variable, vdelete, or vinfo"] # Again, [trace ... command] and [trace ... variable] share syntax and # error message styles for their opList options; these loops test those # error messages. set i 0 -set errs [list "array, read, unset, or write" "delete or rename" "enter, leave, enterstep, or leavestep"] +set errs [list "array, read, unset, write, or debug" "delete or rename" "enter, leave, enterstep, or leavestep"] set abbvs [list {a r u w} {d r} {}] proc x {} {} foreach type {variable command execution} err $errs abbvlist $abbvs { @@ -2148,6 +2148,17 @@ # Unset the varaible when done catch {unset info} +test trace-33.1 { + Line number verification using "trace execution" +} { + set dir [file join [pwd] [file dirname [info script]]] + foreach i {1 2 3} { + set result [exec [info nameofexecutable] ../tools/trcline.tcl ../tests/trcline/trcln$i.tcl] + lappend rc [lindex [lindex [split $result \n] end] end] + } + set rc +} [list 3 0 0] + # cleanup ::tcltest::cleanupTests return Only in tcl8.4.9/unix: Makefile Only in tcl8.4.9/unix: config.cache Only in tcl8.4.9/unix: config.log Only in tcl8.4.9/unix: config.status Only in tcl8.4.9/unix/dltest: Makefile Only in tcl8.4.9/unix: libtcl8.4g.a Only in tcl8.4.9/unix: libtclstub8.4g.a Only in tcl8.4.9/unix: regcomp.o Only in tcl8.4.9/unix: regerror.o Only in tcl8.4.9/unix: regexec.o Only in tcl8.4.9/unix: regfree.o Only in tcl8.4.9/unix: tclAlloc.o Only in tcl8.4.9/unix: tclAppInit.o Only in tcl8.4.9/unix: tclAsync.o Only in tcl8.4.9/unix: tclBasic.o Only in tcl8.4.9/unix: tclBinary.o Only in tcl8.4.9/unix: tclCkalloc.o Only in tcl8.4.9/unix: tclClock.o Only in tcl8.4.9/unix: tclCmdAH.o Only in tcl8.4.9/unix: tclCmdIL.o Only in tcl8.4.9/unix: tclCmdMZ.o Only in tcl8.4.9/unix: tclCompCmds.o Only in tcl8.4.9/unix: tclCompExpr.o Only in tcl8.4.9/unix: tclCompile.o Only in tcl8.4.9/unix: tclConfig.sh Only in tcl8.4.9/unix: tclDate.o Only in tcl8.4.9/unix: tclEncoding.o Only in tcl8.4.9/unix: tclEnv.o Only in tcl8.4.9/unix: tclEvent.o Only in tcl8.4.9/unix: tclExecute.o Only in tcl8.4.9/unix: tclFCmd.o Only in tcl8.4.9/unix: tclFileName.o Only in tcl8.4.9/unix: tclGet.o Only in tcl8.4.9/unix: tclHash.o Only in tcl8.4.9/unix: tclHistory.o Only in tcl8.4.9/unix: tclIO.o Only in tcl8.4.9/unix: tclIOCmd.o Only in tcl8.4.9/unix: tclIOGT.o Only in tcl8.4.9/unix: tclIOSock.o Only in tcl8.4.9/unix: tclIOUtil.o Only in tcl8.4.9/unix: tclIndexObj.o Only in tcl8.4.9/unix: tclInterp.o Only in tcl8.4.9/unix: tclLink.o Only in tcl8.4.9/unix: tclListObj.o Only in tcl8.4.9/unix: tclLiteral.o Only in tcl8.4.9/unix: tclLoad.o Only in tcl8.4.9/unix: tclLoadDl.o Only in tcl8.4.9/unix: tclMain.o Only in tcl8.4.9/unix: tclNamesp.o Only in tcl8.4.9/unix: tclNotify.o Only in tcl8.4.9/unix: tclObj.o Only in tcl8.4.9/unix: tclPanic.o Only in tcl8.4.9/unix: tclParse.o Only in tcl8.4.9/unix: tclParseExpr.o Only in tcl8.4.9/unix: tclPipe.o Only in tcl8.4.9/unix: tclPkg.o Only in tcl8.4.9/unix: tclPosixStr.o Only in tcl8.4.9/unix: tclPreserve.o Only in tcl8.4.9/unix: tclProc.o Only in tcl8.4.9/unix: tclRegexp.o Only in tcl8.4.9/unix: tclResolve.o Only in tcl8.4.9/unix: tclResult.o Only in tcl8.4.9/unix: tclScan.o Only in tcl8.4.9/unix: tclStringObj.o Only in tcl8.4.9/unix: tclStubInit.o Only in tcl8.4.9/unix: tclStubLib.o Only in tcl8.4.9/unix: tclThread.o Only in tcl8.4.9/unix: tclThreadAlloc.o Only in tcl8.4.9/unix: tclThreadJoin.o Only in tcl8.4.9/unix: tclTimer.o Only in tcl8.4.9/unix: tclUnixChan.o Only in tcl8.4.9/unix: tclUnixEvent.o Only in tcl8.4.9/unix: tclUnixFCmd.o Only in tcl8.4.9/unix: tclUnixFile.o Only in tcl8.4.9/unix: tclUnixInit.o Only in tcl8.4.9/unix: tclUnixNotfy.o Only in tcl8.4.9/unix: tclUnixPipe.o Only in tcl8.4.9/unix: tclUnixSock.o Only in tcl8.4.9/unix: tclUnixThrd.o Only in tcl8.4.9/unix: tclUnixTime.o Only in tcl8.4.9/unix: tclUtf.o Only in tcl8.4.9/unix: tclUtil.o Only in tcl8.4.9/unix: tclVar.o Only in tcl8.4.9/unix: tclsh