Tracing Perl

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm uncertain on how exactly to do this, maybe just because I'm very
tired, and I'm away from the work systems in question so I can't
easily experiment.  I'm hoping these questions are easy to answer.

I'm working on a large program.  In a sub, I had it output a stack
trace and then die.  I have a warn in the next enclosing eval several
levels up, right after the call where it started down to the point of
the die ... but $@ has been wiped by the time it reaches that warn.
I really want to find out where.

Complicating factors: it's a LARGE program, and it's running under
Apache, I think (I'm sorry, but I know little of Apache and such).

After a little Googling, I think I want to invoke perl with -d:Trace
in PERL5OPT, and I think the appropriate config file allows me to set
arbitrary environment variables.

Devel::Trace is not installed on the system in question.  I think I
should just run cpan in my user account, find where it puts the
resulting Devel/ (and hope that I don't slide into dependency
hell), and make sure -I or whatever is set so Perl can find it.  Do I
have to worry about Devel::Trace being modern but the program is being
run under Perl 5.8.8?  I did stumble over , which shows code
for a simple implementation that is easier to control.

Tim McDaniel,

Re: Tracing Perl

Quoted text here. Click to load it

A simple answer is something like this:

    {   package My::Warn::Errsv;
        use Carp;
        sub DESTROY { Carp::cluck "$\@ cleared" }

and then (temporarily) replace your die with

    die bless [], "My::Warn::Errsv";

This will then give you a stack trace at the point where $@ is cleared.
(Provided, of course, that something else doesn't keep a copy of the old
value around.)

You could also try using the debugger, and setting a watchpoint.

Quoted text here. Click to load it

The correct way to answer that question is (linked from the
Devel-Trace distribution's page as 'CPAN Testers /
Perl/Platform Version Matrix', which tells you that yes, it works just
fine under 5.8.8.

Quoted text here. Click to load it

I would stay away from package DB and * and the other bits of
the debugger's guts if I were you. It's very easy to make a nasty mess.


Site Timeline