加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

如何在Perl调试器中移动指令点?

发布时间:2020-12-15 23:32:22 所属栏目:大数据 来源:网络整理
导读:我希望能够(合理地)在Perl调试器中任意设置我的执行点.例如,在if的主体之前移动if并设置变量. 围绕perldebug(以及perldebguts和perl调试器POD)页面进行翻查表明,这种功能要么不受支持,要么没有记录. 解决方法 一个繁琐的解决方法是在整个代码中添加标签和条
我希望能够(合理地)在Perl调试器中任意设置我的执行点.例如,在if的主体之前移动if并设置变量.

围绕perldebug(以及perldebguts和perl调试器POD)页面进行翻查表明,这种功能要么不受支持,要么没有记录.

解决方法

一个繁琐的解决方法是在整个代码中添加标签和条件goto语句.但是,根据您想要模拟此功能的严重程度,它可能是值得的.

POINT1: $GOTO="";      # $GOTO is our fake variable that we only set from the debugger
($a,$b,$c)=(1,2,3);
POINT2: $GOTO="";
if ($a < $b) {
    goto $GOTO if $GOTO;
    if ($a > $c) {
        goto $GOTO if $GOTO;
        print "foon";
    } else {
        goto $GOTO if $GOTO;
        print "barn";
    }
    goto $GOTO if $GOTO;
 } else {
    goto $GOTO if $GOTO;
    print "nothingn";
    goto $GOTO if $GOTO;
 }

示例调试会话:

$perl -d debuggoto.pl

Loading DB routines from perl5db.pl version 1.28
Editor support available.

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

main::(debuggoto.pl:1): POINT1: $GOTO="";      # $GOTO is our fake variable that we only set from the debugger
  DB<1> n
main::(debuggoto.pl:2): ($a,3);
  DB<1>
main::(debuggoto.pl:3): POINT2: $GOTO="";
  DB<1>
main::(debuggoto.pl:4): if ($a < $b) {
  DB<1>
main::(debuggoto.pl:5):    goto $GOTO if $GOTO;
  DB<1>
main::(debuggoto.pl:6):    if ($a > $c) {
  DB<1>
main::(debuggoto.pl:10):               goto $GOTO if $GOTO;
  DB<1>
main::(debuggoto.pl:11):               print "barn";
  DB<1>
bar
main::(debuggoto.pl:13):           goto $GOTO if $GOTO;
  DB<1> $GOTO="POINT2"

  DB<2> n
main::(debuggoto.pl:3): POINT2: $GOTO="";
  DB<2> $c=0

  DB<3> n
main::(debuggoto.pl:4): if ($a < $b) {
  DB<3>
main::(debuggoto.pl:5):    goto $GOTO if $GOTO;
  DB<3>
main::(debuggoto.pl:6):    if ($a > $c) {
  DB<3>
main::(debuggoto.pl:7):        goto $GOTO if $GOTO;
  DB<3>
main::(debuggoto.pl:8):        print "foon";
  DB<3>
foo
main::(debuggoto.pl:13):           goto $GOTO if $GOTO;
  DB<3>
Debugged program terminated.  Use q to quit or R to restart,use o inhibit_exit to avoid stopping after program termination,h q,h R or h o to get additional info.
  DB<3>
Use `q' to quit or `R' to restart.  `h q' for details.
  DB<3>

我想知道是否有可能构建一个使用这个想法的调试器.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读