Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

debugger query: move execution point?

by vnpandey (Scribe)
on Jul 16, 2003 at 18:19 UTC ( [id://274970]=perlquestion: print w/replies, xml ) Need Help??

vnpandey has asked for the wisdom of the Perl Monks concerning the following question:

I am using perl debugger. My code is some 500 lines long. Let us assume I set two break points at line numbers 100 and 200. Now I execute the code till first break point 100, which is fine. I then execute the next 100 lines till break point 200.. OOps I discover there is some goof up at say line 105 .. but I am already at line 200.. Is there some way to go back to line 100 back and then execute the code from there or set different break points, inspite of going back again from the begining of the code.

In short can one go back to start of block of statements after they have been executed using perl debugger.

Thanks in advance ..
Pandey

Edit by tye, title, preserve breaks

Replies are listed 'Best First'.
Re: debugger query: move execution point?
by jsegal (Friar) on Jul 16, 2003 at 19:18 UTC
    Unfortunately, you cannot do that (though I agree it would be nice sometimes :-) ). You can approximate it though, by using the "R" command in the debugger, which restarts the program using the same command line arguments and keeping all breakpoints you have set. So in your case, once you realize the problem was line 105, you could do:
    <db> b 104 ## set a breakpoint before your problem <db> R ## restart keeping breakpoints <db> c ## continue to first breakpoint at 100 <db> c ## continue to breakpoint at 104

    and then you could use whatever other debugger tricks you want to figure out what is going on.

    Of couse, you could also delete your breakpoint at 100 first and avoid needing the second "c" command.

    Hope this helps...

    --JAS

Re: debugger query: move execution point?
by bunnyman (Hermit) on Jul 16, 2003 at 19:50 UTC

    To do what you are asking requires the perl interpreter to provide an "undo" feature.

    This feature is not provided because it would slow down the program way too much. For every line of code that is run, perl would have to record what happened and how to undo that. That is just too much information to keep for the small amount of benefit that it would have for debugging.

    That said, it is not impossible to do this, in fact "toy" languages exist which do it. Kayak is one of them. Here is a PhD. Thesis Proposal on the subject of reversable computers.

Re: debugger query: move execution point?
by fglock (Vicar) on Jul 16, 2003 at 19:15 UTC

    You can't, but this will work as if you could:

    R c 105
Re: debugger query: move execution point?
by perrin (Chancellor) on Jul 16, 2003 at 18:59 UTC
    Can you un-execute code that has already been executed? No. You have start the program over with a new break point.
Re: debugger query: move execution point?
by vnpandey (Scribe) on Jul 16, 2003 at 20:21 UTC
    Thanks for your replies. Well My querry was posted based on experieance I had when trying to use debugger on my code.

    The pain was that I have a lot of inputs to be given interactively (not via the command line) and once I have to restart the debugger, I have to enter all the inputs again even to the point till where things were fine. I may not be able to direct them via file simply because then trouble will arise when you want to give further inputs (after the place where things were fine) interactively which depend upon the results at different stages of the program.

    The actual code (6000 lines) I am writing is to automate the processing of astronomical data from the Mauritius Radio Telescope to image the southern universe at radio wavelength (150MHz). The code basically calls a lot of programs and runs them with appropriate flags (this used to take earlier few months and now will be few hours).

    So this feature may be of immense use in such cases. As pointed out that it will make the whole stuff very slow.

    In principle if such a feature were existing, Is it possible to make it optional while invoking the debugger so as it does not make the code slow on programs when this feature is not needed ????.

    Thanks once again for all your prompt answers. From your prompt answers it gives me a feeling as if I am talking to all you helpful monks. Hope I do take out sometime later when I am capable enough to write atleast something small for perl as my expression of thanks.
    Pandey
      All these interactive inputs are going into variables, right? Dump the info you get via the inputs into files (you can do this directly to the variables using Data::Dumper or that other module I can't remember right now) and then, with a little hacking, you can run it without the inputs - just simulate the inputs with the information you got from them.
        Yes! This is nice worth trying idea..

        Well I wanted to do something like that, in a more rusty way although. For my application, perhabs this may be a little tedious, as my whole code is itself about flags and input output options which are too many and to be debugged itself.. so simulating the further inputs using the earlier inputs may be like writing a minicode itself..!

        Let me see if I can do that with ease !
        Thanks for your help!

        Pandey
Re: debugger query: move execution point?
by Anonymous Monk on Jul 16, 2003 at 20:34 UTC
    Hi,

    maybe this doesn't work for you. I have a program which collects data from another computer and then works with that, interactively.

    Collecting the data takes 3-4 minutes, which makes debugging quite slow. To speed it up, I can now load Perl code from a file interactively into my Perl script and then run that (via eval()). If I make a mistake, I edit the code in the file and re-load it into my Perl script again. Later, when I know it works, I make that code permanent.

    I don't use a debugger, only print() and staring at the code.

    Maybe you can use this trick.

    Good luck,
    Alex.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://274970]
Approved by tye
Front-paged by diotalevi
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (10)
As of 2024-04-18 10:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found