简体   繁体   English

如何在调试器下运行Perl代码块?

[英]How to run perl code block under debugger?

I'm writing a test for my debugger. 我正在为调试器编写测试。

subtest "main" => sub {
    $ENV{PERL5DB} = 'Devel::AllSubs';
    my $stderr = capture_stderr {
        sub foo { bar(); }
        sub bar { 1; }
        foo();
    };
    $ENV{PERL5DB} = '';
    is $stderr, "main::foo\nmain::bar";
};

How to apply debugger to 如何将调试器应用于

{
sub foo { bar(); }
sub bar { 1; }
foo();
}

block ? 阻止?

I tried to use $ENV{PERL5DB} but no effect. 我尝试使用$ENV{PERL5DB}但没有效果。

You can't use $ENV{PERL5DB} the way you want. 您不能按需要使用$ENV{PERL5DB}

  1. It has to be the full command to load in the debugger code such as use Devel::AllSubs 它必须是完整的命令,才能加载调试器代码,例如use Devel::AllSubs
  2. It is only checked when Perl is started with a bare -d switch 仅在使用裸机-d开关启动Perl时才检查它
  3. It only gets checked when Perl starts as Perl needs to know that it is running the script under the debugger to create the op codes needed to enter the debugger. 仅当Perl启动时才检查它,因为Perl需要知道它正在调试器下运行脚本来创建进入调试器所需的操作码。

So in order to apply your debugger to only part of the code you will need to first load it in using the -d switch like this 因此,为了将调试器仅应用于部分代码,您将需要先使用-d开关将其加载,如下所示

perl -d:AllSubs script.pl

and then use a package variable to decide if you want to process the code or not. 然后使用包变量来确定是否要处理代码。 Looking at your module name I assume you are trying to do something with each subroutine so your test probably wants to be in your DB::sub method 查看模块名称,我假设您正在尝试对每个子例程进行操作,因此您的测试可能希望在您的DB::sub方法中

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

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