首先,如果我误解了 Devel::ebug 的整个概念,我想道歉以及应该如何使用。所以我想用 Devel::ebug perl 模块做一些实验。在这里我找到了一些例子:What is the perl equivalent of a bash -xv所以我采用了以下代码并对其进行了一些修改。根据官方文档Devel::ebug CPAN program 方法选择加载哪个程序,所以这是我唯一改变的地方。
#!/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 在同一目录中我还有文件:debugme.pl from What is the perl equivalent of a bash -xv页。但不是 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.
编辑2: 我也在 perlmonks 上交叉发布了这个
最佳答案
好的,Devel::ebug 是这样工作的:有一个控制进程监听套接字(这是您在上面粘贴的脚本)并执行调试器的“用户界面”位。然后是您要调试的脚本,控制进程启动该脚本并告诉它加载 Devel::ebug 调试器,当该脚本执行时,它通过套接字与控制脚本对话,以确定在调试时做什么。
我认为问题是因为控制 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
关于linux - perl 的 Devel::ebug 如何,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24097763/