开发者

Is there any work around to make perl debugger set break points on modules not yet loaded?

开发者 https://www.devze.com 2023-03-23 03:09 出处:网络
So that in future the break points take affect as soon as the target file is loaded. Otherwise the debugge开发者_C百科r hardly helps ...

So that in future the break points take affect as soon as the target file is loaded. Otherwise the debugge开发者_C百科r hardly helps ...

main::(test.pl:7):      Class->new->go;
  DB<1> f Movie.pm
No file matching `Movie.pm' is loaded.
  DB<2> b Movie.pm:10
Subroutine main::Movie not found.

I know Movie.pm will be loaded and want to set a bp on its 10th line...


I get round problems like this by manually typing the 'use' line into the debugger.

  DB<1> b LWP::Simple::get
Subroutine LWP::Simple::get not found.

  DB<2> use LWP::Simple


  DB<3> b LWP::Simple::get

  DB<4>

Does that help?


Workaround: require the module when the debugger starts. You can put stuff in your .perldb rc file so you don't have to type/paste it every debugger session.


According to the DOC

After each required file is compiled, but before it is executed, DB::postponed(*{"_<\$filename"}) is called if the subroutine DB::postponed exists. Here, the $filename is the expanded name of the required file, as found in the values of %INC.

So you may hook this event and set breakpoints as soon as your module is loaded.

Also you may try the Devel::DebugHooks module. Feel free to ask me on irc.perl.org #debughooks if you have any questions


"b postpone" seems to do the trick for me. This works similar to WinDbg's Set Unresolved Breakpoint "bu" command.

I can run this command when a Perl script breaks into the built-in debugger mode. Then, Perl honors the breakpoint and automatically stops at the right time.

perl -d 
b postpone PackageName::FunctionName
c

Reference: https://perldoc.perl.org/perldebug

#b postpone subname [condition]

Set a breakpoint at first line of subroutine after it is compiled.

0

精彩评论

暂无评论...
验证码 换一张
取 消