Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Specifying a Filename in a Breakpoint in the Perl Debugger

by clwolfe (Scribe)
on Jan 22, 2009 at 19:33 UTC ( #738280=perlquestion: print w/replies, xml ) Need Help??

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

Hello all,

I've been using the Perl debugger (perl -d) more and more lately, especially running it on test files to exercise modules. I often want to set a breakpoint in a file other than the current one, but I can't seem to figure that out. Any suggestions?

To clarify, suppose I have a test script, that calls methods in a OOP module Fragile, which in turn calls methods in Broken::Completely. When I run perl -d, I can step line by line, and set breakpoints by specifying a line within the current file (using  b 123 for line 123), but I have to wait until I step into Fragile, and then step into Broken/Completely before setting a breakpoint in that file. I thus end up usually running the file at least twice - one pass just to set breakpoints, then restart using 'R', then run to next breakpoint using 'c'. Is there a better way?


Replies are listed 'Best First'.
Re: Specifying a Filename in a Breakpoint in the Perl Debugger
by zwon (Abbot) on Jan 22, 2009 at 19:43 UTC

    You can set breakpoint in other module using the same b command:

    b Broken::Completely::method
      Ahh, I see. I had used that before, but I had read the docs as b subname, not thinking that I could use the full package name of a sub.

      My only complaint is that will set a breakpoint on entry to the sub. If the sub is many lines long, I want to give a line number, like b some/file/name 1165...

      (Or, I could be a good little agile programmer and write shorter subs....)

      Thanks for the response!

Re: Specifying a Filename in a Breakpoint in the Perl Debugger
by clwolfe (Scribe) on Jan 27, 2009 at 03:55 UTC
    And now to answer my own question...

    Turns out the 'f' command will help. The 'h' docs says that it let you view the code in another file, but in fact it switches your whole context to the other files (not the execution point, of course). You can then easily say 'b 1024' or whatever to set a breakpoint at a particular line, then switch back using 'f' again.

    So, in my example above, I might run the debugger on, then immediately type f lib/Broken/Completely, then b 1234 to set a breakpoint at line 1234, then switch back to with f

      Thanks clwolfe, that was a very useful piece of information

      Thanks clwolfe. It works perfectly.

Re: Specifying a Filename in a Breakpoint in the Perl Debugger
by targetsmart (Curate) on Jan 23, 2009 at 06:25 UTC
    You can try devel::sdb it has flexible breakpoints and zoom points which might help you.

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2023-12-11 08:55 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (41 votes). Check out past polls.