Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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
Node Status?
node history
Node Type: perlquestion [id://738280]
Approved by Corion
and the voices are still...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2017-01-23 02:37 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (190 votes). Check out past polls.