LazDebuggerFp: fixed crash in callstack / dangling pointer

(cherry picked from commit dd89fc14e1)
This commit is contained in:
Martin 2022-06-23 17:22:23 +02:00
parent f709a752d9
commit 79dedefb44
2 changed files with 19 additions and 9 deletions

View File

@ -835,15 +835,14 @@ begin
FCallstackEntry.RemoveFreeNotification(@DoCallstackEntryFreed_DecRef); FCallstackEntry.RemoveFreeNotification(@DoCallstackEntryFreed_DecRef);
if FCallstackEntry.Validity = ddsRequested then begin if FCallstackEntry.Validity = ddsRequested then begin
if FDbgCallStack = nil then if not FValid then
FCallstackEntry.Validity := ddsInvalid FCallstackEntry.Validity := ddsInvalid
else begin else begin
c := FDbgCallStack.SrcClassName; c := FSrcClassName;
if c <> '' then if c <> '' then
c := c + '.'; c := c + '.';
FCallstackEntry.Init(FDbgCallStack.AnAddress, nil, FCallstackEntry.Init(FAnAddress, nil, c + FFunctionName + FParamAsString,
c + FDbgCallStack.FunctionName + FParamAsString, FSourceFile, '', FLine, ddsValid);
FDbgCallStack.SourceFile, '', FDbgCallStack.Line, ddsValid);
end; end;
end; end;

View File

@ -175,7 +175,10 @@ type
TFpThreadWorkerCallEntry = class(TFpThreadWorkerPrepareCallStackEntryList) TFpThreadWorkerCallEntry = class(TFpThreadWorkerPrepareCallStackEntryList)
protected protected
FCallstackIndex: Integer; FCallstackIndex: Integer;
FDbgCallStack: TDbgCallstackEntry; FValid: Boolean;
FSrcClassName, FFunctionName, FSourceFile: String;
FAnAddress: TDBGPtr;
FLine: Integer;
FParamAsString: String; FParamAsString: String;
procedure UpdateCallstackEntry_DecRef(Data: PtrInt = 0); virtual; abstract; procedure UpdateCallstackEntry_DecRef(Data: PtrInt = 0); virtual; abstract;
procedure DoExecute; override; procedure DoExecute; override;
@ -605,11 +608,13 @@ procedure TFpThreadWorkerCallEntry.DoExecute;
var var
PrettyPrinter: TFpPascalPrettyPrinter; PrettyPrinter: TFpPascalPrettyPrinter;
Prop: TFpDebugDebuggerProperties; Prop: TFpDebugDebuggerProperties;
DbgCallStack: TDbgCallstackEntry;
begin begin
inherited DoExecute; inherited DoExecute;
FDbgCallStack := FThread.CallStackEntryList[FCallstackIndex]; DbgCallStack := FThread.CallStackEntryList[FCallstackIndex];
if (FDbgCallStack <> nil) and (not StopRequested) then begin FValid := (DbgCallStack <> nil) and (not StopRequested);
if FValid then begin
Prop := TFpDebugDebuggerProperties(FDebugger.GetProperties); Prop := TFpDebugDebuggerProperties(FDebugger.GetProperties);
PrettyPrinter := TFpPascalPrettyPrinter.Create(DBGPTRSIZE[FDebugger.FDbgController.CurrentProcess.Mode]); PrettyPrinter := TFpPascalPrettyPrinter.Create(DBGPTRSIZE[FDebugger.FDbgController.CurrentProcess.Mode]);
PrettyPrinter.Context := FDebugger.FDbgController.DefaultContext; PrettyPrinter.Context := FDebugger.FDbgController.DefaultContext;
@ -618,7 +623,13 @@ begin
FDebugger.FMemManager.MemLimits.MaxStringLen := Prop.MemLimits.MaxStackStringLen; FDebugger.FMemManager.MemLimits.MaxStringLen := Prop.MemLimits.MaxStackStringLen;
FDebugger.FMemManager.MemLimits.MaxNullStringSearchLen := Prop.MemLimits.MaxStackNullStringSearchLen; FDebugger.FMemManager.MemLimits.MaxNullStringSearchLen := Prop.MemLimits.MaxStackNullStringSearchLen;
FParamAsString := FDbgCallStack.GetParamsAsString(PrettyPrinter); FSrcClassName := DbgCallStack.SrcClassName;
FAnAddress := DbgCallStack.AnAddress;
FFunctionName := DbgCallStack.FunctionName;
FSourceFile := DbgCallStack.SourceFile;
FLine := DbgCallStack.Line;
FParamAsString := DbgCallStack.GetParamsAsString(PrettyPrinter);
PrettyPrinter.Free; PrettyPrinter.Free;
FDebugger.FMemManager.MemLimits.MaxArrayLen := Prop.MemLimits.MaxArrayLen; FDebugger.FMemManager.MemLimits.MaxArrayLen := Prop.MemLimits.MaxArrayLen;