Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Can I make the debugger press 'v' for me after every step?

by will_ (Scribe)
on Jul 25, 2011 at 13:22 UTC ( [id://916519]=perlquestion: print w/replies, xml ) Need Help??

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

I want to quickly step through my script, but be able to see where it's going.

i.e. instead of pressing n, v, n, v, n, v, n, v. I just want to press n, n, n, n, n, and have it display 10 (or 20, or 30) lines of context automatically.

Is that possible? I know there's the post-prompt commands, but they are for perl commands, not debugger commands.

  • Comment on Can I make the debugger press 'v' for me after every step?

Replies are listed 'Best First'.
Re: Can I make the debugger press 'v' for me after every step?
by chrestomanci (Priest) on Jul 25, 2011 at 13:58 UTC

    If you want to see context, then I think your best bet would be to use a visual debugger. Devel::ptkdb is available from the usual places, works on both Windows and Unix, and is fairly easy to setup and install. Just run: perl -d:ptkdb <your program.pl>. If you don't like the rather primitive user interface, or you need to remotely debug on a device that dose not support graphics, then you could also consider the EPIC plugin for eclipse, which incorporates a visual debugger that supports remote debugging over a network, but it is slightly more difficult to install and setup.

    Having said that, I would have thought that stepping over every statement that perl runs will get very tedious quite quickly, especially if your program is running any sort of loop. When I am debugging, I usually type l <lines> to view 30-50 lines of code in one function or block, and then with them on screen just use n to step over the code. One line of context it enough if the code is already on screen. If I find myself in a repetitive loop, I just type c <line> to continue after the loop.

      Yes, I've used ptkdb before and it is brilliant.

      But you guessed right, the code is on a remote server, being read via a terminal.

      I did mount it locally and try to run in Eclipse, but there were so many other module dependencies missing that I gave up after installing several dozen.

        It looks like BrowserUk has offered a soltuon to your original question.

        As for running your script with a visual debugger on your remote server, is there enough bandwith and resources to enable you to run a remote X application? I have done that sort of thing a lot when debugging perl on local servers, where the server room is across the hall from my desk, the server is a huge 16 core Solaris box, and there is plenty of bandwith between me and it.

Re: Can I make the debugger press 'v' for me after every step?
by BrowserUk (Patriarch) on Jul 25, 2011 at 16:57 UTC

    Doesn't {{v do exactly what you've asked for?

      Yes BrowserUk, yes it does. Thank you!

        Thanks for the tip BrowserUk I will remember that for future reference.

        Are you able to explain the syntax of the command and how it works? I can see there is a section documenting it in perldebug, but it is not clear what the difference is between a { [command] and a {{ [command] (Two curly braces)

        Edit: That post had the wrong parent. will_ please ignore.

Re: Can I make the debugger press 'v' for me after every step?
by zentara (Archbishop) on Jul 25, 2011 at 16:26 UTC
    I second the recommendation for using Devel::ptkdb. What I think you are looking for, is called setting the breakpoints. As a tip, remember to save your breakpoint setup as a ptkdb file, so you don't have to reset them everytime you run the script. Numerous tutorials for ptkdb on google show how it's done. I have hardly ever used the commandline debugger, but it may have a similar breakpoint mechanism, which you can save to automatically be loaded with the file to be debugged.

    Devel::ptkdb makes it as simple as clicking on a line of code, to set a breakpoint.


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: Can I make the debugger press 'v' for me after every step?
by bluescreen (Friar) on Jul 25, 2011 at 14:34 UTC

    Another option would be creating your own debugger extending DB.pm and add that behavior to it. The debugger's code is not hard to extend/modify. Then you can run your script using perl -d:MyDB

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-24 19:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found