首先,如果我误解了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.
编辑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 how to,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24097763/