Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get exact stack trace (like errorInfo)?

812 views
Skip to first unread message

Gergely Megyeri

unread,
Dec 1, 1997, 3:00:00 AM12/1/97
to

Hi,

is there any way in Tcl to get the exact stack trace information out
of the interpreter? This info is what errorInfo would contain, if an
error had been generated at that place.

I'd like to detect errors, but I'd like to continue with the script to
the end and provide a report file that contains all the errors and
errorInfos. The [info level] command returns pretty little info to find
the exact place of errors in the original script.

I mean a proc, say 'getinfo' that works something like this:

% proc foo val {
global saveInfo
# something
set saveInfo [getinfo "my remarks"]
# something else
}

% foo 15
% set saveInfo
my remarks
(procedure "foo" line 4)
invoked from within
"foo 15"
%

Any solution, ideas, ...?
Thanks in advance,
Gergely

Jacob Levy

unread,
Dec 2, 1997, 3:00:00 AM12/2/97
to

In C you can use Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY).

--JYL

In article <348323...@fzi.de>, meg...@fzi.de says...

Victor Wagner

unread,
Dec 2, 1997, 3:00:00 AM12/2/97
to

Gergely Megyeri (meg...@fzi.de) wrote:
: Hi,

: is there any way in Tcl to get the exact stack trace information out
: of the interpreter? This info is what errorInfo would contain, if an
: error had been generated at that place.

: I'd like to detect errors, but I'd like to continue with the script to
: the end and provide a report file that contains all the errors and
: errorInfos. The [info level] command returns pretty little info to find
: the exact place of errors in the original script.

: I mean a proc, say 'getinfo' that works something like this:

: % proc foo val {
: global saveInfo
: # something
: set saveInfo [getinfo "my remarks"]
: # something else

: }

why not:
proc getinfo {message} {
global errorInfo
catch {error $message}
return [join [concat $message [lrange [split errorInfo "\n"] 2 end]] "\n"]
}

I'm not sure that you have to skip two first lines of errorInfo, but you
got the point.
: % foo 15

Gergely Megyeri

unread,
Dec 2, 1997, 3:00:00 AM12/2/97
to

Victor Wagner wrote:

> : I mean a proc, say 'getinfo' that works something like this:
>
> : % proc foo val {
> : global saveInfo
> : # something
> : set saveInfo [getinfo "my remarks"]
> : # something else
> : }
>
> why not:
> proc getinfo {message} {
> global errorInfo
> catch {error $message}

If only it were so simple... The problem with this is, that at this
point
errorInfo contains only

my remarks
while executing
"error $message"

and not

my remarks
while executing
"error $message"
(procedure "getinfo" line 3)
invoked from within
"getinfo "my remarks""


(procedure "foo" line 4)
invoked from within
"foo 15"

So I get the stack info ONLY to the current execution level and not the
WHOLE traceback info up to the top level. I would need something like

proc getinfo {message} {
set trace "$message\n"
for {set i [expr [info level]-1]} {$i > 0} {incr i -1} {
append trace "[info level $i]\n"
}
return $trace
}

but with the whole infos that errorInfo gives (line numbers, arguments
before substitution, etc.)

John Robert LoVerso

unread,
Dec 2, 1997, 3:00:00 AM12/2/97
to

> but with the whole infos that errorInfo gives (line numbers, arguments
> before substitution, etc.)

The problem is that the information you are looking for doesn't quite exist
yet. Tcl creates the error stack trace as it unwinds the stack following
an error, because the information is stored in the C stack frames of the
calls to Tcl's eval. [this is mostly still true for Tcl8.0, although the
names have changed]. You can only get such a stack trace by returning an
error and letting Tcl unwind.

This is not what you want, by the way your original question was asked.
I think you are looking to get such a stack trace without unwinding the
stack. I do not think you'll be able to do this without writing some C
code to walk up (or down!) the C call stack.

For Tcl8.0, you'll find the error trace generating code split between
Tcl_EvalObj() and RecordTracebackInfo().

John

0 new messages