This is not necessarily the current version of this TIP.
|Title:||Substituted 'errorStack' / 'traceback'|
|Version:||$Revision: 1.8 $|
|Author:||Alexandre Ferrieux <alexandre dot ferrieux at gmail dot com>|
|Created:||Thursday, 26 February 2009|
This TIP proposes to add an errorstack options dict entry and associated info subcommand, giving a "substituted" traceback similar to Python's or gdb's ones.
The ::errorInfo variable is a valuable tool for debugging; however, it yields mostly static information regarding each level of procedure call, as it only gives the static text (extracted from the source) at the call site. This leads to frustrating situations, like when an error occurs at a deep level of a recursive function, ::errorInfo repeatedly reporting "f $x [foo [bar]]" or similar un-substituted commands. In other languages, the traceback is more useful in that it contains the actual values passed as arguments.
This TIP proposes to create a -errorstack options dictionary entry, and an associated info errorstack command returning a list of lists, made of the [info level 0] lists of command-and-args at each proc level at the time of error unwinding.
In a natural implementation, its construction is analogous to ::errorInfo's, which is built incrementally, one level at a time while popping back from the error site. The only differences are that (1) dynamic arglists (from [info level 0]) are stored, (2) the result is a true list built by (the equivalent of) lappend, and (3) the granularity is coarser than ::errorInfo's since there is just one element per proc level (and not for intervening while or foreach constructs) and no adornment like "... while executing ..." .
Measurements show that the performance hit of maintaining errorstack is small, being under 5% for realistic errorstack sizes, and hits only the error cases. To achieve this speed, the list-growing is done carefully, reusing earlier Tcl_ListObjReplace optimizations for the in-place case, so that in routine use the allocated Tcl_Obj, intrep, and element array storage backing the list never cha