【问题标题】:Running Perl debugger twice运行 Perl 调试器两次
【发布时间】:2015-05-18 22:23:04
【问题描述】:

我有两次调用 Perl 调试器的情况。例如progA.pl:

use warnings;
use strict;

system("perl -d progB.pl");

progB.pl:

use warnings;
use strict;
$DB::single=1;
print "Hello\n";

然后我运行progA.pl 喜欢:

$ perl -d progA.pl

这不是很好。在我的系统(Ubuntu 14.04 和 Perl 版本 5.18)上,调试器出现了一些错误。例如:

### forked,但不知道如何创建新的 TTY。 #########由于两个调试器争夺同一个TTY,输入严重

纠缠。

我知道如何在 xterms 中将输出切换到不同的窗口, 仅限 OS/2 控制台和 Mac OS X Terminal.app。对于手动开关, 将创建的 TTY 的名称放在 $DB::fork_TTY 中,或者定义一个 函数 DB::get_fork_TTY() 返回 this。

在类 UNIX 系统上,可以获取给定的 TTY 的名称 通过键入 tty 来打开窗口,然后通过 sleep 断开外壳与 TTY 的连接 1000000。

它还尝试打开一个新的终端窗口,标题为Dauther Perl debugger,但新终端只显示错误sh: 1: 3: Bad file descriptor

如何避免这些问题?我只想让调试器正常工作。

【问题讨论】:

  • 为什么要使用 system() 在调试模式下启动 Perl?
  • 我不在 linux 机器上,所以无法测试,但这样的东西应该可以工作:system('xterm -e perl -d progB.pl');

标签: perl


【解决方案1】:

使用“做”而不是“系统”

perl -d progA.pl
# will stop after your $DB::single = 1 
# line in progB.pl

perldoc -f do

    do EXPR Uses the value of EXPR as a filename and executes the contents
            of the file as a Perl script.

                   do 'stat.pl';

               is just like

                   eval `cat stat.pl`;

【讨论】:

    【解决方案2】:

    我不确定这是否是您正在寻找的,因为我不了解您想要做的事情的大局。

    但是,如果您一开始就使用 Devel::Trepan 之类的其他调试器,那么事情可能会奏效:

    $ trepan.pl progA.pl 
    -- main::(progA.pl:4 @0x21282c8)
    system("perl -d progB.pl");
    (trepanpl): s
    -- main::(progB.pl:3 @0x7042a8)
    $DB::single=1;
    (trepanpl): s
    -- main::(progB.pl:4 @0x878be8)
    print "Hello\n";
    (trepanpl): s
    Hello
    Debugged program terminated.  Use 'q' to quit or 'R' to restart.
    (trepanpl): quit
    trepan.pl: That's all, folks...
    Debugged program terminated.  Use 'q' to quit or 'R' to restart 
    (trepanpl) quit
    trepan.pl: That's all, folks...
    

    “程序终止”消息后的(trepanpl) 提示有点奇怪。但这意味着 progB.pl 已经完成。在退出之后,就像我在上面所做的那样,如果您在 system() 命令之后还有另一个 Perl 语句,那么调试器会显示它而不是给出第二个“完成”消息。

    Devel::Trepan 的另一个特性是您可以使用其debug command 在该调试器内部进行嵌套调试。这是一个例子:

    trepan.pl progA.pl 
    -- main::(progA.pl:4 @0x10612c8)
    system("perl -d progB.pl");
    set auto eval is on.
    (trepanpl): debug system("perl -d progB.pl")
    -- main::((eval 1437)[/usr/local/share/perl/5.18.2/Devel/Trepan/DB/../../../Devel/Trepan/DB/Eval.pm:129] remapped /tmp/HSXy.pl:6 @0x51f13e0)
    system("perl -d progB.pl")
    ((trepanpl)): s
    -- main::(progB.pl:3 @0x9382a8)
    $DB::single=1;
    (trepanpl): s
    -- main::(progB.pl:4 @0xaacbe8)
    print "Hello\n";
    (trepanpl): s
    Hello
    Debugged program terminated.  Use 'q' to quit or 'R' to restart.
    (trepanpl): quit
    trepan.pl: That's all, folks...
    $DB::D[0] = 0
    Leaving nested debug level 1
    -- main::(progA.pl:4 @0x10612c8)
    system("perl -d progB.pl");
    (trepanpl): 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多