如何在调试器中使用 Perl 5.10 功能?

2024-01-20

我无法在 Perl 调试器中评估“现代 Perl”代码。在调试文件中的代码时它可以正常工作,但在提示符下却不行。

最小的例子:

# Activating 5-10 features with -E (it works)
$  perl -E 'say "x"'
x


# Calling the debugger with -E
# It works for infile code, but for prompt line code...
$  perl -dEbug    Loading DB routines from perl5db.pl version 1.33
    DB say "x"
    String found where operator expected at (eval 16)[/local-perl/lib/5.12.1/perl5db.pl:638] line 2, near "say "x""
    at (eval 16)[/local-perl/lib/5.12.1/perl5db.pl:638] line 2
        eval '($@, $!, $^E, $,, $/, $\\, $^W) = @saved;package main; $^D = $^D | $DB::db_stop;say "x";
  

(注意:“use feature ':5.10'”也会发生同样的情况。)

我错过了什么吗?


我找到了该问题的参考here http://coding.derkeiler.com/Archive/Perl/comp.lang.perl.misc/2009-07/msg00603.html,但已经有一岁了。然而,Perl 源代码的相关部分从那时起就没有改变,并且可以看到here http://perl5.git.perl.org/APC/perl-5.12.x/toke.c。本质上,如果你看一下toke.c在 Perl 源代码中,您会看到以下内容:

if (PL_perldb) {
    /* Generate a string of Perl code to load the debugger.
     * If PERL5DB is set, it will return the contents of that,
     * otherwise a compile-time require of perl5db.pl.  */

    const char * const pdb = PerlEnv_getenv("PERL5DB");
            ...
}
...
if (PL_minus_E)
    sv_catpvs(PL_linestr,
          "use feature ':5." STRINGIFY(PERL_VERSION) "';");

基本上,调试器已加载before the -E标志已处理,因此加载调试器时尚未启用这些功能。其要点是您当前无法使用-E-d命令。如果你想使用say, switch,或调试提示中的任何其他功能,您必须这样做:

  DB<1> use feature 'say'; say "x"
  x

我见过的最接近的解决方案是:

  1. 将 perl5db.pl 从 PERL5LIB 复制到 PERL5LIB 中的某个位置或当前目录,使用不同的名称,例如 myperl5db.pl 2.编辑myperl5db.pl以使用特性':5.10'; (或者只是“陈述”,或者只是“说”)在第一行。 3. 将环境变量 PERL5DB 设置为“BEGIN { require 'myperl5db.pl' }”

我发现在珀尔蒙克斯 http://www.perlmonks.org/index.pl?node_id=855153.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在调试器中使用 Perl 5.10 功能? 的相关文章

随机推荐