From c6ab397e07428a86cd5bdef84b40ac6945f84ec9 Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 24 Jul 2022 14:05:13 +0200 Subject: [PATCH] Debugger: watches window, use result from parent-watch, if sub-watch only has ide-suffix (json expand) --- ide/packages/idedebugger/debugger.pp | 28 +++++++++++++ ide/packages/idedebugger/idedebuggerbase.pas | 42 +++++++++++++------- 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/ide/packages/idedebugger/debugger.pp b/ide/packages/idedebugger/debugger.pp index fe5d41284c..7a28a55909 100644 --- a/ide/packages/idedebugger/debugger.pp +++ b/ide/packages/idedebugger/debugger.pp @@ -558,6 +558,8 @@ type function ExpressionForChildEntry(AnIndex: Int64): String; function ExpressionForChildEntry(AnIndex: String): String; + function MaybeCopyResult(ASourceWatch: TIdeWatch): boolean; + property ChildrenByNameAsField[AName, AClassName: String]: TIdeWatch read GetChildrenByNameAsField; property ChildrenByNameAsArrayEntry[AName: Int64]: TIdeWatch read GetChildrenByNameAsArrayEntry; end; @@ -4021,6 +4023,11 @@ begin FreeAndNil(FFpDbgConverter); if Watch.FpDbgConverter <> nil then FFpDbgConverter := TIdeFpDbgConverterConfig(Watch.FpDbgConverter.CreateCopy); + + if (Watch.ParentWatch <> nil) and (Watch.ParentWatch.FpDbgConverter = Watch.FpDbgConverter) then + if MaybeCopyResult(Watch.ParentWatch) then + exit; + TCurrentWatch(Watch).RequestData(self); end; @@ -4349,6 +4356,27 @@ begin Result := Expression + '[' + AnIndex + ']'; end; +function TIdeWatchValue.MaybeCopyResult(ASourceWatch: TIdeWatch): boolean; +var + ASrcValue: TIdeWatchValue; +begin + Result := (ASourceWatch.GetBackendExpression = GetBackendExpression) and + (ASourceWatch.DisplayFormat = FWatch.DisplayFormat) and + (ASourceWatch.RepeatCount = FWatch.RepeatCount) and + (ASourceWatch.FirstIndexOffs = FWatch.FirstIndexOffs) and + (ASourceWatch.EvaluateFlags = FWatch.EvaluateFlags); + if not Result then + exit; + + ASrcValue := TIdeWatchValue(ASourceWatch.FValueList.ExistingEntries[ThreadId, StackFrame]); + Result := (ASrcValue <> nil) and (ASrcValue.Validity = ddsValid) and (ASrcValue.FResultData <> nil); + if not Result then + exit; + + FResultData := ASrcValue.FResultData.CreateCopy; + SetValidity(ddsValid); +end; + { TIdeWatchesMonitor } function TIdeWatchesMonitor.GetSnapshot(AnID: Pointer): TIdeWatches; diff --git a/ide/packages/idedebugger/idedebuggerbase.pas b/ide/packages/idedebugger/idedebuggerbase.pas index 2e3ac88682..b3e90655e3 100644 --- a/ide/packages/idedebugger/idedebuggerbase.pas +++ b/ide/packages/idedebugger/idedebuggerbase.pas @@ -84,6 +84,8 @@ type FWatch: TWatch; function GetEntry(const AThreadId: Integer; const AStackFrame: Integer): TWatchValue; function GetEntryByIdx(AnIndex: integer): TWatchValue; + function GetExistingEntry(const AThreadId: Integer; + const AStackFrame: Integer): TWatchValue; protected function CreateEntry(const {%H-}AThreadId: Integer; const {%H-}AStackFrame: Integer): TWatchValue; virtual; function CopyEntry(AnEntry: TWatchValue): TWatchValue; @@ -101,6 +103,8 @@ type property EntriesByIdx[AnIndex: integer]: TWatchValue read GetEntryByIdx; property Entries[const AThreadId: Integer; const AStackFrame: Integer]: TWatchValue read GetEntry; default; + property ExistingEntries[const AThreadId: Integer; const AStackFrame: Integer]: TWatchValue + read GetExistingEntry; property Watch: TWatch read FWatch; end; @@ -650,22 +654,10 @@ end; function TWatchValueList.GetEntry(const AThreadId: Integer; const AStackFrame: Integer): TWatchValue; -var - i: Integer; begin - i := FList.Count - 1; - while i >= 0 do begin - Result := TWatchValue(FList[i]); - if (Result.ThreadId = AThreadId) and (Result.StackFrame = AStackFrame) and - (Result.DisplayFormat = FWatch.DisplayFormat) and - (Result.RepeatCount = FWatch.RepeatCount) and - (Result.FirstIndexOffs = FWatch.FirstIndexOffs) and - (Result.EvaluateFlags = FWatch.EvaluateFlags) - then - exit; - dec(i); - end; - Result := CreateEntry(AThreadId, AStackFrame); + Result := GetExistingEntry(AThreadId, AStackFrame); + if Result = nil then + Result := CreateEntry(AThreadId, AStackFrame); end; function TWatchValueList.GetEntriesForRange(const AThreadId: Integer; @@ -717,6 +709,26 @@ begin Result := TWatchValue(FList[AnIndex]); end; +function TWatchValueList.GetExistingEntry(const AThreadId: Integer; + const AStackFrame: Integer): TWatchValue; +var + i: Integer; +begin + i := FList.Count - 1; + while i >= 0 do begin + Result := TWatchValue(FList[i]); + if (Result.ThreadId = AThreadId) and (Result.StackFrame = AStackFrame) and + (Result.DisplayFormat = FWatch.DisplayFormat) and + (Result.RepeatCount = FWatch.RepeatCount) and + (Result.FirstIndexOffs = FWatch.FirstIndexOffs) and + (Result.EvaluateFlags = FWatch.EvaluateFlags) + then + exit; + dec(i); + end; + Result := nil; +end; + function TWatchValueList.CreateEntry(const AThreadId: Integer; const AStackFrame: Integer): TWatchValue; begin