在无限循环中停止delphi程序 [英] Stopping delphi program in an infinite loop
问题描述
以下是一个示例程序,故意导致无限循环:
procedure TForm1.btnDebugInfiniteLoopClick(Sender:TObject);
var I:整数;
begin
I:= 0;
而I< 100 do begin
I:= 1 + 1;
if I> 64 then I:= I div 2;
结束
结束
停止时,我会看到如下的东西:
ntdll.RtlUserThreadStart:
776301B4 89442404 mov [esp + $ 04],eax
776301B8 895C2408 mov [esp + $ 08],ebx
776301BC E9E99C0200 jmp $ 77659eaa
776301C1 8DA42400000000 lea esp,[esp + $ 0000]
776301C8 8DA42400000000 lea esp,[esp + $ 0000]
776301CF 90 nop
ntdll.KiFastSystemCall:
776301D0 8BD4 mov edx,esp
...
当我单步(F7) ,它单行几行,然后锁定,直到我再次打破,此时我得到相同的结果。
在Rob Kennedy的评论中回答。我必须从调试窗口打开一个线程视图来获取线程列表并选择正确的线程;在这一点上,我可以看到我的程序无限循环。
When an indefinite loop occurs in Delphi, the debugger will not even give me a stack trace when I hit the stop button. If I have a suspicion of where the program is stalling, I can put a breakpoint and it will stop if that is the correct indefinite loop.
Here is a sample program to deliberately cause an indefinite loop:
procedure TForm1.btnDebugInfiniteLoopClick(Sender: TObject);
var I: Integer;
begin
I:=0;
while I<100 do begin
I:=1+1;
if I>64 then I:=I div 2;
end;
end;
When stopped, I get something that looks like:
ntdll.RtlUserThreadStart:
776301B4 89442404 mov [esp+$04],eax
776301B8 895C2408 mov [esp+$08],ebx
776301BC E9E99C0200 jmp $77659eaa
776301C1 8DA42400000000 lea esp,[esp+$0000]
776301C8 8DA42400000000 lea esp,[esp+$0000]
776301CF 90 nop
ntdll.KiFastSystemCall:
776301D0 8BD4 mov edx,esp
...
As I single step (F7), it single steps a few lines, then locks up until I hit break again, at which point I get the same result.
Answered in comments by Rob Kennedy. I must open a thread view from debug window to get a list of threads and choose the correct thread; at that point I can see where my program is indefinitely looping.
这篇关于在无限循环中停止delphi程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!