5

当 Delphi 中出现无限循环时,当我点击停止按钮时,调试器甚至不会给我一个堆栈跟踪。如果我怀疑程序在哪里停止,我可以设置一个断点,如果这是正确的无限循环,它将停止。

这是一个故意导致无限循环的示例程序:

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;

停止时,我得到如下内容:

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) 时,它单步走几行,然后锁定,直到我再次按下 break,此时我得到相同的结果。

4

2 回答 2

7

Rob Kennedy 在评论中回答。我必须从调试窗口打开线程视图以获取线程列表并选择正确的线程;那时我可以看到我的程序无限循环的地方。

于 2012-10-25T00:50:55.230 回答
1

As alternative answer: considering you're using Delphi XE3, it comes bundled with the profiler: AQTime which will find things like this real real fast.

于 2012-10-25T07:09:03.607 回答