From f99f5c0ed9ad5faf586fb7d8b9d5cb6db86ad916 Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 26 Sep 2021 01:56:00 +0200 Subject: [PATCH] LazDebuggerFp: Make sure OnIdle is called, and all results are awaited. (Fixes Debug History) / DebugManager triggers snapshots for any dsPause and dsInternalPause. --- .../lazdebuggerfp/fpdebugdebugger.pas | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/components/lazdebuggers/lazdebuggerfp/fpdebugdebugger.pas b/components/lazdebuggers/lazdebuggerfp/fpdebugdebugger.pas index f8a432a6ae..96d716f435 100644 --- a/components/lazdebuggers/lazdebuggerfp/fpdebugdebugger.pas +++ b/components/lazdebuggers/lazdebuggerfp/fpdebugdebugger.pas @@ -34,7 +34,7 @@ interface uses Classes, SysUtils, fgl, math, process, Forms, Dialogs, syncobjs, - Maps, LazLogger, LazUTF8, lazCollections, + Maps, LazLoggerBase, LazUTF8, lazCollections, DbgIntfBaseTypes, DbgIntfDebuggerBase, FpDebugDebuggerUtils, FpDebugDebuggerWorkThreads, // FpDebug @@ -633,11 +633,18 @@ var c: LongInt; begin FpDebugger.FWorkQueue.Lock; + Application.ProcessMessages; FpDebugger.CheckAndRunIdle; - c := FpDebugger.FWorkQueue.Count; + (* IdleThreadCount could (race condition) be to high. + Then DebugHistory may loose ONE item. (only one working thread. + Practically this is unlikely, since the thread had time to set + the count, since the Lock started. + *) + c := FpDebugger.FWorkQueue.Count + FpDebugger.FWorkQueue.ThreadCount - FpDebugger.FWorkQueue.IdleThreadCount; FpDebugger.FWorkQueue.Unlock; if c = 0 then begin + Application.ProcessMessages; FpDebugger.StartDebugLoop; end else begin @@ -3413,8 +3420,15 @@ begin if State in [dsPause, dsInternalPause] then begin FWorkQueue.Lock; CheckAndRunIdle; - c := FWorkQueue.Count; + (* IdleThreadCount could (race condition) be to high. + Then DebugHistory may loose ONE item. (only one working thread. + Practically this is unlikely, since the thread had time to set + the count, since the Lock started. + *) + c := FWorkQueue.Count + FWorkQueue.ThreadCount - FWorkQueue.IdleThreadCount; FWorkQueue.Unlock; + if c = 0 then + Application.ProcessMessages; end else c := 0; @@ -3464,7 +3478,7 @@ end; procedure TFpDebugDebugger.CheckAndRunIdle; begin - if (State <> dsPause) or + if (not (State in [dsPause, dsInternalPause])) or (not Assigned(OnIdle)) or (FWorkQueue.Count <> 0) then