本文介绍了如何在错误点处移动调用堆栈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我知道这个成语:

eval {
    ...
};

$DB::single = 1 if $@;

...但是据我所知,如果调试器在 eval 检查堆栈中的帧已经太迟了,因为它们完全在错误发生的时刻。

...but, as far as I can tell, if the debugger stops after the eval it's already too late to examine the frames in the stack as they were exactly at the instant the error occurred.

是否有一种在错误发生时完全停止调试器的方法,并检查调用堆栈中的帧?

Is there a way to stop the debugger exactly at the moment the error ocurred, and examine the frames in the call stack?

推荐答案

$ SIG {__ DIE __} 被调用在异常抛出的地方,因此您可以添加

$SIG{__DIE__} is called where the exception is thrown, so you could add

local $SIG{__DIE__} = sub { $DB::single = 1; die(@_); };







$ cat a.pl
sub g {
   die "!";
}

sub f {
   g();
}

local $SIG{__DIE__} = sub { $DB::single = 1; die(@_); };
f();

 

$ perl -d a.pl

Loading DB routines from perl5db.pl version 1.49_04
Editor support available.

Enter h or 'h h' for help, or 'man perldebug' for more help.

main::(a.pl:9): local $SIG{__DIE__} = sub { $DB::single = 1; die(@_); };
  DB<1> r
main::CODE(0x1067280)(a.pl:9):  local $SIG{__DIE__} = sub { $DB::single = 1; die(@_); };
  DB<1> T
@ = DB::DB called from file 'a.pl' line 9
$ = main::__ANON__[a.pl:9]('! at a.pl line 2.^J') called from file 'a.pl' line 2
. = main::g() called from file 'a.pl' line 6
. = main::f() called from file 'a.pl' line 10

这篇关于如何在错误点处移动调用堆栈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 02:30