Stopping delphi program in infinite loop

When an indefinite loop occurs in Delphi, the debugger won't even give me a stack trace when I click the stop button. If I suspect that the program has stopped, I can set a breakpoint, and it will stop if it is a valid indefinite loop.

Here is an example program to deliberately trigger 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 similar:

 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 take one step (F7), it takes several steps with several lines, and then blocks until I go to the gap again, after which I get the same result.

+4
source share
2 answers

Answered in the comments by Rob Kennedy. I have to open the stream view from the debug window to get a list of threads and select the desired stream; at this moment I see where my program is looping endlessly.

+5
source

As an alternative answer: given that you are using Delphi XE3, it comes bundled with a profiler: AQTime, which quickly finds things like real ones.

0
source

Source: https://habr.com/ru/post/1441910/


All Articles