简体   繁体   English

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

[英]How can I use Perl 5.10 features inside the debugger?

I am unable to evaluate 'modern Perl' code inside the Perl debugger.我无法评估 Perl 调试器中的“现代 Perl”代码。 It works OK when debugging the code in a file, but not from the prompt.在文件中调试代码时它可以正常工作,但不能从提示中调试。

Minimal example:最小的例子:

# 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";

(Note: the same happens with "use feature ':5.10'".) (注意:“使用功能':5.10'”也会发生同样的情况。)

Am I missing something?我错过了什么吗?

I found a reference to the issue here , but it's about a year old.我在这里找到了对这个问题的引用,但它已经有大约一年的历史了。 However, the relevant portion of the Perl source hasn't changed since and can be seen here .但是,Perl 源代码的相关部分从那时起就没有改变,可以在这里看到。 Essentially, if you take a look at toke.c in the Perl source, you see the following:本质上,如果您查看 Perl 源代码中的toke.c ,您会看到以下内容:

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) "';");

Basically, the debugger is loaded before the -E flag is processed, so the features aren't yet enabled when the debugger gets loaded.基本上,调试器处理-E标志之前加载,因此在加载调试器时尚未启用这些功能。 The gist of this is that you can't currently use -E with the -d command.其要点是您目前不能将-E-d命令一起使用。 If you want to use say , switch , or any other feature from the debug prompt, you have to do it like this:如果您想在调试提示中使用sayswitch或任何其他功能,您必须这样做:

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

The closest I've seen to a solution is:我见过的最接近解决方案的是:

  1. copy perl5db.pl from your PERL5LIB to either somewhere in PERL5LIB or the current directory, with a different name, say myperl5db.pl 2. Edit myperl5db.pl to have use feature ':5.10';将 perl5db.pl 从您的 PERL5LIB 复制到 PERL5LIB 或当前目录中的某个位置,使用不同的名称,例如 myperl5db.pl 2. 编辑 myperl5db.pl 以使用功能“:5.10”; (or just 'state', or just 'say') on the first line. (或只是“状态”,或只是“说”)在第一行。 3. Set the environment variable PERL5DB to "BEGIN { require 'myperl5db.pl' }" 3.设置环境变量PERL5DB为“BEGIN { require 'myperl5db.pl' }”

Which I found at PerlMonks .我在PerlMonks找到的。

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

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