在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 3300|回复: 0

[转贴] PERL -d参数用来debug的方法

[复制链接]
发表于 2012-12-24 10:56:28 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
还在通过在代码加各种“if” "print"来调试脚本吗?这样已经落伍了,要像个牛人一样debug。

以下列出几条必备命令,帮助你轻松调试:


perl -d myprogram
Essentially the -d switch allows you to communicate with the perlexecutable, and allows the perl executable to communicate with you.
Stepping up to the plate
  • l - lists the next few lines
  • p [variable name] - lets you print the value of a variable to the              command line
  • q - I quit.
  • r - returns from current subroutine
      If you have written your program as a few subroutines, this is handy for running through each and checking the return.
             
  • n - executes the next statement at this level
      Meansyou don't have to go through those boring subroutine calls. If youdon't know what I just wrote, get into a program and try it a couple oftimes. You'll get the hang of it.
                
  • s - The step command
      Okay,this is the key for simple debugging. Crank up your program in thedebugger and step through it. If its a small program, this and the rcommand can take care of most of your needs. By the way, once you enterthe s command, just hit enter to repeat the command.
                   
            Breaking away
            Breakpointsallow you to specify the next stopping point in a program. For example,lets say I know my problems at line 65, I might insert a breakpoint atline 60 and step through the final five lines of code before theproblem. You just saved hitting the enter key 60 times.
            b - Set a breakpoint
            Once you have started the perl debugger you may set a breakpoint at any executable line number.
            b 20 - Sets a breakpoint at line 20.
            b subroutinename - handy little deviation.  If you know the subroutine name, this breaks on the first line inside the routine.
            b 20 condition- depending on your background, this is called a conditional breakpointor watchpoint. Perl breaks when the condition you specify is met.
            

    Examples
  • b 20 x>30 Breaks at line 20 when x is greater than 30
  • b 20 x=~/foo/i Breaks at line 20 when x contains "foo"
            To start the program use c (continue), which runs the program to the first breakpoint or watchpoint.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

×

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-9 08:20 , Processed in 0.017758 second(s), 8 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表