如何在调试器中使用 Perl 5.10 功能? [英] How can I use Perl 5.10 features inside the debugger?

查看:58
本文介绍了如何在调试器中使用 Perl 5.10 功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在 Perl 调试器中评估现代 Perl"代码.调试文件中的代码时它可以正常工作,但不能从提示中调试.

最小示例:

# 使用 -E 激活 5-10 个功能(有效)$ perl -E '说x"'X

<前># 使用 -E 调用调试器# 它适用于 infile 代码,但适用于提示行代码...$ perl -dEbug 从 perl5db.pl 版本 1.33 加载数据库例程DB 说x"在 (eval 16)[/local-perl/lib/5.12.1/perl5db.pl:638] 第 2 行,靠近say x""处找到操作符预期的字符串在 (eval 16)[/local-perl/lib/5.12.1/perl5db.pl:638] 第 2 行eval '($@, $!, $^E, $,, $/, $\\, $^W) = @saved;package main;$^D = $^D |$DB::db_stop;说x";

(注意:使用功能':5.10'"也是如此.)

我错过了什么吗?

解决方案

我找到了对该问题的引用 这里,但它大约一岁了.但是,Perl 源代码的相关部分从那以后就没有改变,可以看到 此处.本质上,如果您查看 Perl 源代码中的 toke.c,您会看到以下内容:

if (PL_perldb) {/* 生成一串 Perl 代码来加载调试器.* 如果设置了 PERL5DB,它将返回内容,* 否则编译时需要 perl5db.pl.*/const char * const pdb = PerlEnv_getenv(PERL5DB");...}...如果(PL_minus_E)sv_catpvs(PL_linestr,使用功能':5."STRINGIFY(PERL_VERSION) "';");

基本上,在处理 -E 标志之前 加载调试器,因此在加载调试器时尚未启用这些功能.其要点是您目前不能将 -E-d 命令一起使用.如果您想在调试提示中使用 sayswitch 或任何其他功能,您必须这样做:

 DB<1>使用功能说";说x"X

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

<块引用>

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

我在 PerlMonks 上找到的.

I am unable to evaluate 'modern Perl' code inside the Perl debugger. 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'".)

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. Essentially, if you take a look at toke.c in the Perl source, you see the following:

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. The gist of this is that you can't currently use -E with the -d command. If you want to use say, switch, or any other feature from the debug prompt, you have to do it like this:

  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'; (or just 'state', or just 'say') on the first line. 3. Set the environment variable PERL5DB to "BEGIN { require 'myperl5db.pl' }"

Which I found at PerlMonks.

这篇关于如何在调试器中使用 Perl 5.10 功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆