develooper Front page | perl.perl5.porters | Postings from October 2018

short-circuiting run-time errors in debug mode

Thread Next
Ed Peschko
October 26, 2018 21:19
short-circuiting run-time errors in debug mode
Message ID:

I was sitting here debugging a very long perl script - one that i'm
unsure of the state of - hence being very careful to step over lines
with n and s to make sure I don't hit any errors of type:

Not a HASH reference at line ...


All these are done in eval statements which wrap SIG{__DIE__}, but
doing this is still extremely painful. One slip-up and the stack is
blown out, you lose all context and you have to start over.

So, I was thinking - is it possible to keep the previous state in
memory, and when you hit an error like the above, simply rewind the
context before the runtime error was hit? Something like:

my $err = [];
print $err->{0} # runtime error

where, after the $err->{0} gives you the 'Not a hash reference', it
rewound the effective state of the interpreter back to before the
print statement was issued - hence giving developers a way to mutate
the state of the system in such a way to have the program proceed (in
this case by issuing the command $err = {0 => myval })

That way to debug one could simply hit 'c', continue till you hit the
next error, fix in-line, fix in the code, hit c again, and so forth
and so forth and so forth. As it stands, you lose all the program
state and have to puzzle over the remnants.

I can't tell you how much of a time-saver this would be. I'm already
wrapping all traps to look like the attached to make traps conditional
and to examine state before the program loses it, but frankly am out
of ideas on how to do this with data-structure runtime issues.

any ideas would be appreciated here.


ps: wrapped die to handle cases where you don't want to leave program
state before debugging:

sub _die
    my ($message) = @_;

    my $trap = 1;
    $DB::single = 1;

    if ($trap)

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About