简体   繁体   中英

Perl Debugger - How to step out of a loop

While using perl debugger, is there any way to step out of the current loop?

For example:

line 1
for($i=1;$i<100000:$i++)
{
    line2
}
line3

I want the debugger to step out of this for loop and stop at line3

c 5

Demonstration:

>perl -d

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

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

print "line1\n";
for (1..100000) {
   print "line2\n";
}
print "line3\n";
^Z
main::(-:1):    print "line1\n";

  DB<1> s
line1
main::(-:2):    for (1..100000) {

  DB<1> s
main::(-:3):       print "line2\n";

  DB<1> s
line2
main::(-:3):       print "line2\n";

  DB<1> c 5
line2
line2
line2
...
line2
line2
line2
main::(-:5):    print "line3\n";

  DB<2> s
line3
Debugged program terminated.  Use q to quit or R to restart,

You can just set the loop termination condition:

$i=100000

Elaborate? Just set the variable to the exit condition like so:

  DB<5> $i=1

  DB<6> print $i
1
  DB<7> $i=100000

  DB<8> print $i
100000
  DB<9> c
Debugged program terminated.  Use q to quit or R to restart,

c 3表示继续执行并在第3行停止

There is no step out. You can either setup a break point on "line 3" and continue "c" to next breakpoint, or explicitly state c <line #> to stop at a particular line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM