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);
if FCallstackEntry.Validity = ddsRequested then begin
if FDbgCallStack = nil then
if not FValid then
FCallstackEntry.Validity := ddsInvalid
else begin
c := FDbgCallStack.SrcClassName;
c := FSrcClassName;
if c <> '' then
c := c + '.';
FCallstackEntry.Init(FDbgCallStack.AnAddress, nil,
c + FDbgCallStack.FunctionName + FParamAsString,
FDbgCallStack.SourceFile, '', FDbgCallStack.Line, ddsValid);
FCallstackEntry.Init(FAnAddress, nil, c + FFunctionName + FParamAsString,
FSourceFile, '', FLine, ddsValid);
end;
end;

View File

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