From f47220cc470bd746ac1b2309409c0347c63c998f Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 26 Sep 2021 02:09:18 +0200 Subject: [PATCH] FpDebug: Add asserts --- components/fpdebug/fpdbgdarwinclasses.pas | 1 + components/fpdebug/fpdbglinuxclasses.pas | 1 + components/fpdebug/fpdbgwinclasses.pas | 3 +++ 3 files changed, 5 insertions(+) diff --git a/components/fpdebug/fpdbgdarwinclasses.pas b/components/fpdebug/fpdbgdarwinclasses.pas index f52a6613d2..fc7b27da61 100644 --- a/components/fpdebug/fpdbgdarwinclasses.pas +++ b/components/fpdebug/fpdbgdarwinclasses.pas @@ -284,6 +284,7 @@ var aKernResult: kern_return_t; old_StateCnt: mach_msg_Type_number_t; begin + {$IFDEF FPDEBUG_THREAD_CHECK}AssertFpDebugThreadId('TFpInternalBreakpoint.ResetBreak');{$ENDIF} if ID<0 then begin // The ID is set to -1 when the debugger does not have sufficient rights. diff --git a/components/fpdebug/fpdbglinuxclasses.pas b/components/fpdebug/fpdbglinuxclasses.pas index d11309abb3..ca0309b1a1 100644 --- a/components/fpdebug/fpdbglinuxclasses.pas +++ b/components/fpdebug/fpdbglinuxclasses.pas @@ -462,6 +462,7 @@ function TDbgLinuxThread.ReadThreadState: boolean; var io: iovec; begin + {$IFDEF FPDEBUG_THREAD_CHECK}AssertFpDebugThreadId('TFpInternalBreakpoint.ResetBreak');{$ENDIF} assert(FIsPaused, 'TDbgLinuxThread.ReadThreadState: FIsPaused'); result := true; if FHasThreadState then diff --git a/components/fpdebug/fpdbgwinclasses.pas b/components/fpdebug/fpdbgwinclasses.pas index e8301e7cbc..00856728ce 100644 --- a/components/fpdebug/fpdbgwinclasses.pas +++ b/components/fpdebug/fpdbgwinclasses.pas @@ -812,6 +812,7 @@ if AThread<>nil then debugln(['## ath.iss ',AThread.NextIsSingleStep]); result := Windows.ContinueDebugEvent(MDebugEvent.dwProcessId, MDebugEvent.dwThreadId, DBG_CONTINUE); DebugLn(not Result, 'ContinueDebugEvent failed: %d', [Windows.GetLastError]); result := true; + MDebugEvent.dwProcessId := 0; // Flag as running // for assert in ReadThreadState end; function TDbgWinProcess.Detach(AProcess: TDbgProcess; AThread: TDbgThread @@ -1730,6 +1731,8 @@ end; function TDbgWinThread.ReadThreadState: boolean; begin + {$IFDEF FPDEBUG_THREAD_CHECK}AssertFpDebugThreadId('TFpInternalBreakpoint.ResetBreak');{$ENDIF} + assert(MDebugEvent.dwProcessId <> 0, 'TDbgWinThread.ReadThreadState: MDebugEvent.dwProcessId <> 0'); if Process.ProcessID <> MDebugEvent.dwProcessId then begin DebugLn(DBG_WARNINGS, 'ERROR: attempt to read threadstate, for wrong process. Thread: %u Thread-Process: %u Event-Process %u', [Id, Process.ProcessID, MDebugEvent.dwProcessId]); exit(False);