我有以下perl脚本
#!/usr/bin/env perl
sub bar { foo() }
sub foo { }
sub hello { bar(); }
hello();
哪个会产生以下输出
$ PERLDB_OPTS="NonStop frame=1" perl -d 1.pl > /dev/null
Package 1.pl.
entering DB::Obj::_init
entering main::hello
entering main::bar
entering main::foo
我只需要在调用bar()
函数之前启用调试器。该怎么做?
我尝试过的事情:
1)Enbugger + DB::parse_options
$ cat 1.pl
#!/usr/bin/env perl
sub bar { foo() }
sub foo { }
sub hello {
require Enbugger;
Enbugger->load_debugger();
DB::parse_options("NonStop frame=1");
bar();
Enbugger->stop;
}
hello();
$ perl 1.pl > /dev/null
entering CODE(0x1c551d0)
entering CODE(0x1d23018)
entering strict::import
entering CODE(0x1d23ac8)
Package /usr/lib/x86_64-linux-gnu/perl/5.22/Errno.pm.
entering Errno::TIEHASH
entering CODE(0x1c551b8)
entering CODE(0x1d72b40)
entering strict::import
Package /usr/lib/x86_64-linux-gnu/perl/5.22/Tie/Hash/NamedCapture.pm.
entering XSLoader::load
NonStop = '1'
frame = '1'
entering CODE(0x1bdeca8)
entering warnings::unimport
似乎是可行的原因,如果我更改为frame=2
,将会有更多的输出。但是输出是错误的,应该是:
Package 1.pl.
entering DB::Obj::_init
entering main::bar
entering main::foo
$ cat 1.pl
#!/usr/bin/env perl
sub bar { foo() }
sub foo { }
sub hello {
require "perl5db.pl";
$DB::signal = 1;
bar();
$DB::single = 1;
}
hello();
$ PERLDB_OPTS="NonStop frame=1" perl 1.pl > /dev/null
无输出:(
答案 0 :(得分:1)
现在,我使用了以下技巧-使用-d NonStop frame=0
运行脚本并将$DB::frame=1
设置在要获取堆栈跟踪的位置。
$ cat 1.pl
#!/usr/bin/env perl
sub bar { foo() }
sub foo { }
sub hello {
$DB::frame=1;
bar();
$DB::frame=0;
}
hello();
$ PERL5OPT=-d PERLDB_OPTS=NonStop perl 1.pl
entering main::bar
entering main::foo