Stopping delphi program in an infinite loop

拜拜、爱过 提交于 2020-01-01 11:29:33

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/13057133/stopping-delphi-program-in-an-infinite-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!