in reply to Subroutine Call Stack - For Entire Program

You'll want to implement a debugger module. Not a replacement for the debugger, but a module that implements the right subs in the DB namespace to capture your trace data.

For example, the way the Perl debugger does this: the DB::sub subroutine gets called automatically by the interpreter for every sub call in the progtram being run; DB::sub captures caller()'s output, and then uses an eval() sub in the debugger's namespace (not the core eval!) to run the subroutine in the caller's context. When DB::eval is over, we pop the stack to remove the caller info for this call.

Meanwhile, DB::DB gets called by the interpreter after every line, so you can set a variable in the DB:: namespace in your main program to signal DB::DB that now's the time to dump the stack.

if you just need a quick-and-dirty one-time, you can put a $DB::single=1 in your code at the point where you want to stop and do your traceback, and then run your code under the debugger.

It will stop at the $DB::single, at which point you can issue the T command to get the call trace.

  • Comment on Re: Subroutine Call Stack - For Entire Program