简体   繁体   English

如何在运行时使用 PERLDB_OPTS 运行 Perl 调试器?

[英]How can I run the Perl debugger at runtime with PERLDB_OPTS?

I have following Perl script我有以下 Perl 脚本

#!/usr/bin/env perl
sub bar { foo() }
sub foo { }
sub hello { bar(); }
hello();

Which produces following output产生以下输出

$ 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

I need to enable the debugger only before the bar() function call.我只需要在bar()函数调用之前启用调试器。 How can I do that?我怎样才能做到这一点?

What I've tried:我试过的:

  1. Enbugger + DB::parse_options 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

It seems like is working bebecause if I change to frame=2 there will be more output.似乎正在工作,因为如果我更改为frame=2会有更多输出。 But the output is wrong, and the expected is:但是输出是错误的,预期是:

Package 1.pl.
    entering DB::Obj::_init
       entering main::bar
        entering main::foo
  1. DB global variables :数据库全局变量

     $ 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

No output :(没有输出:(

For now, I used the following hack - run the script with -d NonStop frame=0 and set $DB::frame=1 at a place from which I want to get a stack trace.现在,我使用了以下 hack - 使用-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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM