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

Anyone have gdb/python script, or even a C function to generate the current stack trace from a Tcl_Interp*?

78 views
Skip to first unread message

Trey Jackson

unread,
Dec 19, 2018, 7:14:15 PM12/19/18
to
Periodically I'll run into a problem in C code, and I don't know the execution path in Tcl that led to that point.

Does anyone have a canned routine to use in gdb, or perhaps a C implementation of the same, which basically introspects the underlying Interp* ala [info frame] or [info level] to get a list/print out of the various stack levels.

FWIW, on Tcl 8.6.9

stefan

unread,
Dec 20, 2018, 5:59:42 PM12/20/18
to
> Does anyone have a canned routine to use in gdb, or perhaps a C implementation of the same, which basically introspects the underlying Interp* ala [info frame] or [info level] to get a list/print out of the various stack levels.

Common advise is to define and to provide for a helper Tcl proc ("printCallStack") using "[info level]", and from within gdb, call on it to get what you want:

print Tcl_Eval(interp, "printCallStack")

Stefan

Uwe Klein

unread,
Dec 29, 2018, 6:14:48 AM12/29/18
to
Dumb question:
It is not the GDB 'bt' (backtrace) command you are looking for?

Uwe

heinrichmartin

unread,
Dec 30, 2018, 11:06:06 AM12/30/18
to
bt gives the C (not Tcl) stack

Donal K. Fellows

unread,
Jan 1, 2019, 2:11:46 PM1/1/19
to
Also, in 8.6 (and later) the C stack and the Tcl stack are not closely
related at all. That's the real core of what the NRE execution engine
does, meaning that Tcl stacks can be managed in much more interesting
ways, but it does make debugging from inside C rather more difficult
(not that it was ever easy, as procedure implementations didn't say
which procedure they were inside 'bt', but the clues were fairly easy to
follow, especially before 8.0).

Donal.
--
Donal Fellows — Tcl user, Tcl maintainer, TIP editor.
0 new messages