Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Perl Debugger: setting a breakpoint in another file with 'b'

by Dumu (Monk)
on May 14, 2015 at 13:12 UTC ( [id://1126649]=perlquestion: print w/replies, xml ) Need Help??

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

Brethren and Sistren

I am a big fan of the Perl Debugger, perl5dp.pl (aka perl -d) and would like to make the most of its many capabilities. I would really like to be able to utilise the debugger's ability to set a breakpoint at a line in a file other than the one you start off in. E.g.:

b lib/UsefulModule.pm:124
As this would mean I could jump to wherever I want in any module I'm using.

The trouble is, whatever line I set, I always get the same message:

Line 124 of 'lib/UsefulModule.pm' not breakable.

Yes, these are lines that should be breakable and indeed are when I step through the code to reach them in another way, with colons on the left and everything. I have never managed to break any line in any module with this functionality as I remember.

Breakpointing in the same module using the 'breakpoint at the start of a sub' functionality works just fine.

b UsefulModule::do_stuff
I even get auto-complete on the subroutines in the module when I type:
b UsefulModule::
and/or the first letter / couple of letters of the sub. This is great, but means an extra step if I want to stop in the middle of a sub.

For one thing, I wanted to check that this isn't a bug in the debugger. (A classic but inevitable paradox). Has anyone else used this functionality recently, or indeed ever?

I just had a look at the debugger source but I can't see anything obvious that I could be running aground on. (The relevant area seems to be around &break_on_filename_line: breakpoint-related subs are above and below this line.) But then, the debugger code is some of the most legendarily dense Perl there is.

Thanks in advance for your responses.

Replies are listed 'Best First'.
Re: Perl Debugger: setting a breakpoint in another file with 'b'
by Dumu (Monk) on May 14, 2015 at 13:26 UTC
      > &break_on_filename_line

      it's an internal routine which is only called by other routines, not from the command loop parser (which is a pretty messed up sequence of reqexes spawning hundreds of lines)

      however you can call it directly by yourself

      DB<3> &DB::break_on_filename_line('/tmp/sub.pl',4) DB<4> L /tmp/sub.pl: 4: print __FILE__,":",__LINE__; break if (1)

      which poses a problem if the file isn't already loaded.

      > I'd still like to be able to use the b filename:line [condition] syntax

      you can use the aliasing mechanism to define your own command for "break_on_filename_line" and put it into your .perldb rc-file.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

Re: Perl Debugger: setting a breakpoint in another file with 'b'
by hexcoder (Curate) on May 15, 2015 at 23:20 UTC
    If you want to stop at a function mod::subname in a not-yet-loaded module, you can use the
    b postpone mod::subname [condition] debugger command. It will delay the setting of the breakpoint until the module has been loaded. The filename:linenumber syntax is not available, as far as I know.

    So  b postpone UsefulModule::do_stuff should work.

    This is described in the book "Pro Perl Debugging" from Richard Foley and Andy Lester.

      no book needed :)

      lanx@lanx-1005HA:~$ perl -de0 Loading DB routines from perl5db.pl version 1.33 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(-e:1): 0 DB<1> h b b Sets breakpoint on current line) b [line] [condition] Set breakpoint; line defaults to the current execution line; condition breaks if it evaluates to true, defaults to '1'. b subname [condition] Set breakpoint at first line of subroutine. b $var Set breakpoint at first line of subroutine referenced by + $var. b load filename Set breakpoint on 'require'ing the given file. b postpone subname [condition] Set breakpoint at first line of subroutine after it is compiled. b compile subname Stop after the subroutine is compiled. DB<2>

      see also perldebug

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

        Incidentally, I realised last night that you can even start a Perl debugger REPL using a divide by zero:

        perl -de1/0

        And it still works (i.e. starts the debugger and puts you into a "Perl shell"), although you do get an 'Illegal division by zero' error if you then execute any of the 'stepping' commands.

        So I wonder if there is anything you can put after perl -de that won't let the debugger start?

        Danke sehr, Rolf... I had not tried 'b postpone', only 'b compile' and 'b load', which hadn't apparently worked. I shall try 'b postpone'!

        It was staring me in the face the whole time.

      Thanks hexcoder, I shall try to get a copy of that book. I have alredy enjoyed Perl Debugged by Peter Scott and Ed Wright, which is useful despite being a bit of an old book.
Re: Perl Debugger: setting a breakpoint in another file with 'b'
by thomas895 (Deacon) on May 15, 2015 at 01:40 UTC

    Has that file been loaded yet? As in, have you already executed the corresponding require statement when trying to set the breakpoint?

    -Thomas
    "Excuse me for butting in, but I'm interrupt-driven..."

      Well, I've used the module at the top of my script, so I suppose that equates to being required in a BEGIN block, so I would imagine so, yes.

        Well I couldn't see that in your code, now could I?

        I've only experienced your problem when it's about require statements, never with use. Sorry I can't help you there.

        -Thomas
        "Excuse me for butting in, but I'm interrupt-driven..."

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-24 05:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found