Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re^2: Neat Debugger tricks

by osunderdog (Deacon)
on Nov 17, 2005 at 12:59 UTC ( #509389=note: print w/replies, xml ) Need Help??

in reply to Re: Neat Debugger tricks
in thread Neat Debugger tricks

I understand what you are trying to do...identify a bug, modify the code, and continue debugging with the modified code. That would be very nice.

I think I can point out that you could at least change it for this instance and continue debugging. For example, usin g your code:

# ... 107 sub foo { 108 my $x; 109 $x = 43; 110 => die "invalid x!" unless $x == 42; 111 print "Yay!" 112 # ...

At this point you could set the value of $x before the unless expression is evaluated:

DB<6> $x = 43;

Of course, you would have to remember to make the same modification in code...

As an interesting alternative, you could redefine the function on the fly... This wouldn't work in your example because it dies on a fail case. However after a first run through the function, cut the function from an editor and paste it into the debugger with the change you desire. Subsequent runs restarts through the debugger would have the modified version of the function.

For example:

use strict; foo(); foo(); sub foo { my $x; $x = 43; if($x==42){print "DANGER Will Robinson!\n" +}else{print "Yay!\n";}}

Then I run this in the debugger... After the first execution of foo Cut and paste the modified subroutine in to the debugger and execute it. This redefines the foo function.

main::( foo(); DB<1> n Yay! main::( foo(); <$x = 42; if($x==42){print "DANGER Will Robinson!\n"}else{print "Yay!\ +n";}} DB<2> n DANGER Will Robinson!

I'm not sure if this is practicle, but it is interesting... :)

Hazah! I'm Employed!

Replies are listed 'Best First'.
Re^3: Neat Debugger tricks
by gaal (Parson) on Nov 17, 2005 at 15:40 UTC
    I understand what you are trying to do...identify a bug, modify the code, and continue debugging with the modified code. That would be very nice.

    Yes, yes, yes, and yes :-)

    Microsoft Visual Studio does this, at least for c, and Eclipse does it for Java. These are languages where you'd expect these things to be waaaay harder to get away with than Perl. (Well, except for "set next instruction", which in c is relatively easy.)

      Your wish is granted (in 5.8.5):
      $ perl -de0 Loading DB routines from version 1.28 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(-e:1): 0 DB<1> h rerun rerun Rerun session to current position. rerun n Rerun session to numbered command. rerun -n Rerun session to number'th-to-last command.
      rerun reloads the program and applies all commands you've executed in the debugger to (theoretically) get you back to the same point.
        That's very nice, and has many uses, but isn't what I was wishing for. That's a replay of the complete flow. I want the option to goto an arbitrary line in the code of a running process. Sure, it's not obvious what that means when there are e.g. closures in effect, but I guess that's something to figure out.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://509389]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2020-11-25 16:13 GMT
Find Nodes?
    Voting Booth?

    No recent polls found