From 9e889b7a40994fa98178e185e638c2e09c6a1a0b Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 10 Feb 2022 21:15:08 +0100 Subject: [PATCH] FpDebug: Ensure internal breakpoint is freed, if cmd is finished. Add asserts (cherry picked from commit 2333696004b24bec77c787f250b5701ebf9bfedc) --- components/fpdebug/fpdbgcontroller.pas | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/components/fpdebug/fpdbgcontroller.pas b/components/fpdebug/fpdbgcontroller.pas index 7554d46a54..f98dcd4b15 100644 --- a/components/fpdebug/fpdbgcontroller.pas +++ b/components/fpdebug/fpdbgcontroller.pas @@ -200,6 +200,7 @@ type procedure RestoreRegisters; public constructor Create(AController: TDbgController; ARoutineAddress: TFpDbgMemLocation; ACallContext:TFpDbgInfoCallContext); + destructor Destroy; override; procedure DoContinue(AProcess: TDbgProcess; AThread: TDbgThread); override; end; @@ -439,6 +440,12 @@ begin StoreRegisters; end; +destructor TDbgControllerCallRoutineCmd.Destroy; +begin + RemoveHiddenBreakpointAtReturnAddress; + inherited Destroy; +end; + procedure TDbgControllerCallRoutineCmd.Init; begin inherited Init; @@ -563,6 +570,8 @@ end; procedure TDbgControllerCallRoutineCmd.SetHiddenBreakpointAtReturnAddress(AnAddress: TDBGPtr); begin + assert(FHiddenBreakpoint = nil, 'TDbgControllerCallRoutineCmd.SetHiddenBreakpointAtReturnAddress: FHiddenBreakpoint = nil'); + FHiddenBreakpoint.Free; FHiddenBreakpoint := FProcess.AddInternalBreak(AnAddress); end; @@ -595,7 +604,7 @@ end; procedure TDbgControllerCallRoutineCmd.RemoveHiddenBreakpointAtReturnAddress(); begin - FHiddenBreakpoint.Free; + FreeAndNil(FHiddenBreakpoint); end; procedure TDbgControllerCallRoutineCmd.StoreRegisters; @@ -743,6 +752,8 @@ end; procedure TDbgControllerHiddenBreakStepBaseCmd.SetHiddenBreak(AnAddr: TDBGPtr); begin + assert(FHiddenBreakpoint = nil, 'TDbgControllerHiddenBreakStepBaseCmd.SetHiddenBreak: FHiddenBreakpoint = nil'); + FHiddenBreakpoint.Free; // The callee may not setup a stackfram (StackBasePtr unchanged). So we use SP to detect recursive hits FHiddenBreakStackPtrAddr := FThread.GetStackPointerRegisterValue; FHiddenBreakInstrPtr := FThread.GetInstructionPointerRegisterValue;