如果您创建一个像这样 (concept originated here) 的简单模块,则可以避免更改代码:
package StopBegin;
BEGIN {
$DB::single=1;
}
1;
然后,运行你的代码
perl -I./ -MStopBegin -d test.pl
相关答案(以前的,不太相关的答案在这个下面)
如果 test.pl 看起来像这样:
use constant C => {
map {;
"C$_" => $_;
} 0 .. 255
};
调试交互如下所示:
% perl -I./ -MStopBegin -d test.pl
Loading DB routines from perl5db.pl version 1.53
Editor support available.
Enter h or 'h h' for help, or 'man perldebug' for more help.
StopBegin::CODE(0x55db6287dac0)(StopBegin.pm:8):
8: 1;
DB<1> s
main::CODE(0x55db6287db38)(test.pl:5):
5: };
DB<1> -
1 use constant C => {
2: map {;
3: "C$_" => $_;
4 } 0 .. 255
5==> };
DB<2> b 3
DB<3> c
main::CODE(0x55db6287db38)(test.pl:3):
3: "C$_" => $_;
DB<3>
注意使用断点在map内停止。
以前的,不太相关的答案
如果test.pl 看起来像这样:
my $foo;
BEGIN {
$foo = 1;
};
调试交互如下所示:
% perl -I./ -MStopBegin -d test.pl
Loading DB routines from perl5db.pl version 1.53
Editor support available.
Enter h or 'h h' for help, or 'man perldebug' for more help.
StopBegin::CODE(0x5567e3d79a80)(StopBegin.pm:8):
8: 1;
DB<1> s
main::CODE(0x5567e40f0db0)(test.pl:4):
4: $foo = 1;
DB<1> s
main::(test.pl:1): my $foo;
DB<1> s
Debugged program terminated. Use q to quit or R to restart,
use o inhibit_exit to avoid stopping after program termination,
h q, h R or h o to get additional info.
DB<1>
注意使用s命令前进,否则会跳过test.pl中的BEGIN块