2012-06-23 56 views
2

使用perl調試器時,有什麼辦法可以跳出當前循環嗎?Perl調試器 - 如何跳出循環

例如:

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

我想調試器來逐步擺脫這種循環,並在3號線停止

回答

6
c 5 

示範:

>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, 
+0

+1詳細答案 –

1

c 3手段繼續執行並停在第3行

0

沒有步驟。 您可以在「第3行」上設置斷點並將「c」設置爲下一個斷點,或者明確指定c <line #>停止在特定行。

2

您可以只設置循環的終止條件:

$i=100000 

詳細點嗎?只需將變量設置爲退出條件,如下所示:

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, 
+0

可以請您詳細說明一下嗎? – AnonGeek