首先,如果我误解了Devel::ebug的整个概念以及应该如何使用它,我想道歉。所以我想用Devel :: ebug perl模块做一些实验。在这里我找到了一些例子:What is the perl equivalent of a bash -xv所以我采用了以下代码并对其进行了一些修改。根据官方文档Devel::ebug CPAN,程序方法选择要加载的程序,所以这只是我改变的事情。
#!/usr/bin/perl
use strict;
use warnings;
use Devel::ebug;
use Data::Dumper;
my $ebug = Devel::ebug->new;
# $ebug->program(shift); # OLD VALUE:
$ebug->program($ARGV[0]); # NEW VALUE:
$ebug->load;
until ($ebug->finished) {
print "+++ file:", $ebug->filename, " line: ", $ebug->line, "\n";
my $pad = $ebug->pad;
for my $var (sort keys %$pad) {
if (ref $pad->{$var}) {
for my $line (split /\n/, Data::Dumper->Dump([$pad->{$var}], [$var])) {
print "++ $line\n";
}
} else {
print "++ $var = $pad->{$var}\n";
}
}
for my $line ($ebug->codelines($ebug->line-3 .. $ebug->line-1)) {
next unless defined $line;
print "+ $line\n";
}
print "+> ", $ebug->codeline, "\n";
for my $line ($ebug->codelines($ebug->line+1 .. $ebug->line+3)) {
next unless defined $line;
print "+ $line\n";
}
$ebug->step;
}
然后我将这个文件保存为:stacktrace.pl在同一目录中我也有文件:来自What is the perl equivalent of a bash -xv页面的debugme.pl。但是,不是在What is the perl equivalent of a bash -xv页面上提到的输出,而是我得到了这个:
> ./stacktrace.pl debugme.pl
./stacktrace.pl: exec failed: No such file or directory
at /home/wakatana/perl5/lib/perl5/Devel/ebug.pm line 41
Could not connect: Connection refused at /home/wakatana/perl5/lib/perl5/Devel/ebug.pm line 71.
进一步调试指出了我:
Proc::Background::Unix::_new(/home/wakatana/perl5/lib/perl5/Proc/Background/Unix.pm:47):
47: if ($pid = fork()) {
DB<7> s
Proc::Background::Unix::_new(/home/wakatana/perl5/lib/perl5/Proc/Background/Unix.pm:49):
49: $self->{_os_obj} = $pid;
######### Forked, but do not know how to create a new TTY. #########
Since two debuggers fight for the same TTY, input is severely entangled.
I know how to switch the output to a different window in xterms, OS/2
consoles, and Mac OS X Terminal.app only. For a manual switch, put the name
of the created TTY in $DB::fork_TTY, or define a function
DB::get_fork_TTY() returning this.
On UNIX-like systems one can get the name of a TTY for the given window
by typing tty, and disconnect the shell from TTY by sleep 1000000.
Proc::Background::Unix::_new(/home/wakatana/perl5/lib/perl5/Proc/Background/Unix.pm:54):
54: exec @_ or croak "$0: exec failed: $!\n";
首先我假设这是因为我在GNU屏幕下运行它并且不知何故它无法创建新的TTY。但这不是问题。我在这里缺少什么?
PS:看起来在使用Proc :: Background :: Unix模块时出现问题所以上面输出我使用以下调试器命令获得:
b Proc::Background::Unix::_new
c
编辑: 关于@Chankey Pathak评论。我在终结器下发出了这个命令。在xterm下,情况是一样的:
> echo $$
18548
> ps -elf | grep 18548
0 S wakatana 18548 18546 0 80 0 - 6296 - 16:09 pts/5 00:00:00 bash
0 R wakatana 18990 18548 0 80 0 - 4209 - 16:10 pts/5 00:00:00 ps -elf
0 R wakatana 18991 18548 0 80 0 - 1958 - 16:10 pts/5 00:00:00 grep 18548
> ps -elf | grep 18546
0 S wakatana 18546 18254 0 80 0 - 17220 - 16:09 pts/3 00:00:00 xterm
0 S wakatana 18548 18546 0 80 0 - 6296 - 16:09 pts/5 00:00:00 bash
0 R wakatana 19004 18548 0 80 0 - 1959 - 16:10 pts/5 00:00:00 grep 18546
> perl stacktrace.pl debugme.pl
stacktrace.pl: exec failed: No such file or directory
at /home/wakatana/perl5/lib/perl5/Devel/ebug.pm line 41
Could not connect: Connection refused at /home/wakatana/perl5/lib/perl5/Devel/ebug.pm line 71.
EDIT2: 我也在perlmonks
上交叉发布了这个帖子答案 0 :(得分:0)
好的,Devel :: ebug的工作方式如下:有一个控制进程可以监听套接字(这是你上面粘贴的脚本)并执行调试器的“用户界面”位。然后是您正在尝试调试的脚本,控制进程启动并告诉它加载Devel :: ebug调试器,并且当该脚本执行时,它通过套接字与控制脚本进行通信,以确定它的debbuging是什么。
我认为问题是因为控制Deve :: ebug在执行程序调试时遇到问题。看看Devel :: ebug的第41行,我们看到:
my $backend = $self->backend || "$Bin/ebug_backend_perl";
my $command = "$backend $program";;
my $proc = Proc::Background->new(
{'die_upon_destroy' => 1},
$command
);
看起来->backend
应包含使用正确的命令行标志执行脚本的路径,以便启动进程调试器,配置为通过套接字与控制程序进行对话包含在上面。
随着模块一起安装的ebug_backend_perl似乎可以为您处理这项工作。在调用$ebug->backend($path)
/home/wakatana/perl5/bin/ebug_backend_perl
成为那个位置(如果我猜的正确可能是您系统上的$ebug->load
)