From 6f2adbbcb2886b55ec527c852265c2a4aa232c06 Mon Sep 17 00:00:00 2001 From: Martin Date: Sat, 8 Jan 2022 00:30:09 +0100 Subject: [PATCH] Debugger: Move TWatchValue to IdeDebugger --- .../debuggerintf/dbgintfdebuggerbase.pp | 136 ------------- .../lazdebugtestbase/ttestdebuggerclasses.pas | 22 +-- debugger/debugger.pp | 12 +- ide/packages/idedebugger/idedebuggerbase.pas | 185 +++++++++++++++--- 4 files changed, 175 insertions(+), 180 deletions(-) diff --git a/components/debuggerintf/dbgintfdebuggerbase.pp b/components/debuggerintf/dbgintfdebuggerbase.pp index 6436e2947c..566487be93 100644 --- a/components/debuggerintf/dbgintfdebuggerbase.pp +++ b/components/debuggerintf/dbgintfdebuggerbase.pp @@ -620,50 +620,6 @@ type TWatchesMonitor = class; - { TWatchValue } - - TWatchValue = class(TFreeNotifyingObject, TWatchValueIntf) - private - FTypeInfo: TDBGType; - FValue: String; - FValidity: TDebuggerDataState; - - function GetDisplayFormat: TWatchDisplayFormat; - function GetEvaluateFlags: TWatcheEvaluateFlags; - function GetRepeatCount: Integer; - function GetStackFrame: Integer; - function GetThreadId: Integer; - function GetValidity: TDebuggerDataState; - procedure SetValidity(AValue: TDebuggerDataState); virtual; - procedure SetValue(AValue: String); - procedure SetTypeInfo(AValue: TDBGType); - procedure SetTypeInfo(AValue: TDBGTypeBase); - protected - FDisplayFormat: TWatchDisplayFormat; - FEvaluateFlags: TWatcheEvaluateFlags; - FRepeatCount: Integer; - FStackFrame: Integer; - FThreadId: Integer; - procedure DoDataValidityChanged({%H-}AnOldValidity: TDebuggerDataState); virtual; - - function GetExpression: String; virtual; abstract; - function GetTypeInfo: TDBGType; virtual; - function GetValue: String; virtual; - public - destructor Destroy; override; - procedure Assign(AnOther: TWatchValue); virtual; - property DisplayFormat: TWatchDisplayFormat read GetDisplayFormat; - property EvaluateFlags: TWatcheEvaluateFlags read GetEvaluateFlags; - property RepeatCount: Integer read GetRepeatCount; - property ThreadId: Integer read GetThreadId; - property StackFrame: Integer read GetStackFrame; - property Expression: String read GetExpression; - public - property Validity: TDebuggerDataState read GetValidity write SetValidity; - property Value: String read GetValue write SetValue; - property TypeInfo: TDBGType read GetTypeInfo write SetTypeInfo; - end; - { TWatchesSupplier } TWatchesSupplier = class(TDebuggerDataSupplier) @@ -2690,98 +2646,6 @@ begin Result := FUpdateCount > 0; end; -{ TWatchValue } - -procedure TWatchValue.SetValidity(AValue: TDebuggerDataState); -var - OldValidity: TDebuggerDataState; -begin - if FValidity = AValue then exit; - //DebugLn(DBG_DATA_MONITORS, ['DebugDataMonitor: TWatchValue.SetValidity: FThreadId=', FThreadId, ' FStackFrame=',FStackFrame, ' Expr=', Expression, ' AValidity=',dbgs(AValue)]); - DebugLn(DBG_DATA_MONITORS, ['DebugDataMonitor: TWatchValue.SetValidity: Expr=', Expression, ' AValidity=',dbgs(AValue)]); - OldValidity := FValidity; - FValidity := AValue; - DoDataValidityChanged(OldValidity); -end; - -function TWatchValue.GetValidity: TDebuggerDataState; -begin - Result := FValidity; -end; - -function TWatchValue.GetStackFrame: Integer; -begin - Result := FStackFrame; -end; - -function TWatchValue.GetEvaluateFlags: TWatcheEvaluateFlags; -begin - Result := FEvaluateFlags; -end; - -function TWatchValue.GetDisplayFormat: TWatchDisplayFormat; -begin - Result := FDisplayFormat; -end; - -function TWatchValue.GetRepeatCount: Integer; -begin - Result := FRepeatCount; -end; - -function TWatchValue.GetThreadId: Integer; -begin - Result := FThreadId; -end; - -procedure TWatchValue.SetValue(AValue: String); -begin - if FValue = AValue then exit; - //asser not immutable - FValue := AValue; -end; - -procedure TWatchValue.SetTypeInfo(AValue: TDBGType); -begin - //assert(Self is TCurrentWatchValue, 'TWatchValue.SetTypeInfo'); - FreeAndNil(FTypeInfo); - FTypeInfo := AValue; -end; - -procedure TWatchValue.SetTypeInfo(AValue: TDBGTypeBase); -begin - SetTypeInfo(TDBGType(AValue)); -end; - -procedure TWatchValue.DoDataValidityChanged(AnOldValidity: TDebuggerDataState); -begin - -end; - -function TWatchValue.GetTypeInfo: TDBGType; -begin - Result := FTypeInfo; -end; - -function TWatchValue.GetValue: String; -begin - Result := FValue; -end; - -destructor TWatchValue.Destroy; -begin - inherited Destroy; - FreeAndNil(FTypeInfo); -end; - -procedure TWatchValue.Assign(AnOther: TWatchValue); -begin - FreeAndNil(FTypeInfo); - //FTypeInfo := TWatchValue(AnOther).FTypeInfo.cre; - FValue := AnOther.FValue; - FValidity := AnOther.FValidity; -end; - { TRegisterSupplier } function TRegisterSupplier.GetCurrentRegistersList: TRegistersList; diff --git a/components/lazdebuggers/lazdebugtestbase/ttestdebuggerclasses.pas b/components/lazdebuggers/lazdebugtestbase/ttestdebuggerclasses.pas index ae4acf1f42..1a43a6a661 100644 --- a/components/lazdebuggers/lazdebugtestbase/ttestdebuggerclasses.pas +++ b/components/lazdebuggers/lazdebugtestbase/ttestdebuggerclasses.pas @@ -76,7 +76,7 @@ type { TTestWatchValue } - TTestWatchValue = class(TGuiWatchValue) + TTestWatchValue = class(TWatchValue) protected procedure RequestData; function GetTypeInfo: TDBGType; override; @@ -93,8 +93,8 @@ type TTestWatchValueList = class(TWatchValueList) protected - function CopyEntry(AnEntry: TGuiWatchValue): TGuiWatchValue; override; - function CreateEntry(const {%H-}AThreadId: Integer; const {%H-}AStackFrame: Integer): TGuiWatchValue; override; + function CopyEntry(AnEntry: TWatchValue): TWatchValue; override; + function CreateEntry(const {%H-}AThreadId: Integer; const {%H-}AStackFrame: Integer): TWatchValue; override; end; { TTestWatch } @@ -112,7 +112,7 @@ type protected FMonitor: TTestWatchesMonitor; function WatchClass: TWatchClass; override; - procedure RequestData(AWatchValue: TGuiWatchValue); + procedure RequestData(AWatchValue: TWatchValue); end; { TTestWatchesMonitor } @@ -122,7 +122,7 @@ type FWatches: TWatches; protected procedure DoStateChangeEx(const AOldState, ANewState: TDBGState); override; - procedure RequestData(AWatchValue: TGuiWatchValue); + procedure RequestData(AWatchValue: TWatchValue); function CreateWatches: TWatches; public constructor Create; @@ -317,7 +317,7 @@ begin Result := TTestWatch; end; -procedure TTestWatches.RequestData(AWatchValue: TGuiWatchValue); +procedure TTestWatches.RequestData(AWatchValue: TWatchValue); begin TTestWatchesMonitor(FMonitor).RequestData(AWatchValue); end; @@ -330,7 +330,7 @@ begin Watches.ClearValues; end; -procedure TTestWatchesMonitor.RequestData(AWatchValue: TGuiWatchValue); +procedure TTestWatchesMonitor.RequestData(AWatchValue: TWatchValue); begin if Supplier <> nil then Supplier.RequestData(AWatchValue) @@ -369,7 +369,7 @@ begin Result := nil; if not Watch.Enabled then exit; - i := DbgStateChangeCounter; // workaround for state changes during TGuiWatchValue.GetValue + i := DbgStateChangeCounter; // workaround for state changes during TWatchValue.GetValue if Validity = ddsUnknown then begin Validity := ddsRequested; RequestData; @@ -392,7 +392,7 @@ begin Result := ''; exit; end; - i := DbgStateChangeCounter; // workaround for state changes during TGuiWatchValue.GetValue + i := DbgStateChangeCounter; // workaround for state changes during TWatchValue.GetValue if Validity = ddsUnknown then begin Result := ''; Validity := ddsRequested; @@ -431,14 +431,14 @@ end; { TTestWatchValueList } -function TTestWatchValueList.CopyEntry(AnEntry: TGuiWatchValue): TGuiWatchValue; +function TTestWatchValueList.CopyEntry(AnEntry: TWatchValue): TWatchValue; begin Result := TTestWatchValue.Create(Watch); Result.Assign(AnEntry); end; function TTestWatchValueList.CreateEntry(const AThreadId: Integer; - const AStackFrame: Integer): TGuiWatchValue; + const AStackFrame: Integer): TWatchValue; begin Result := TTestWatchValue.Create(Watch, AThreadId, AStackFrame); Add(Result); diff --git a/debugger/debugger.pp b/debugger/debugger.pp index 4331604405..6a47a795e4 100644 --- a/debugger/debugger.pp +++ b/debugger/debugger.pp @@ -587,7 +587,7 @@ type { TIdeWatchValue } - TIdeWatchValue = class(TGuiWatchValue) + TIdeWatchValue = class(TWatchValue) private function GetWatch: TIdeWatch; protected @@ -618,7 +618,7 @@ type function GetEntryByIdx(AnIndex: integer): TIdeWatchValue; function GetWatch: TIdeWatch; protected - function CopyEntry(AnEntry: TGuiWatchValue): TGuiWatchValue; override; + function CopyEntry(AnEntry: TWatchValue): TWatchValue; override; procedure LoadDataFromXMLConfig(const AConfig: TXMLConfig; APath: string); procedure SaveDataToXMLConfig(const AConfig: TXMLConfig; @@ -3310,7 +3310,7 @@ begin Result := TIdeWatch(inherited Watch); end; -function TIdeWatchValueList.CopyEntry(AnEntry: TGuiWatchValue): TGuiWatchValue; +function TIdeWatchValueList.CopyEntry(AnEntry: TWatchValue): TWatchValue; begin Result := TIdeWatchValue.Create(Watch); Result.Assign(AnEntry); @@ -3350,7 +3350,7 @@ begin inherited Create(AOwnerWatch); end; -{ TGuiWatchValue } +{ TWatchValue } function TIdeWatchValue.GetValue: String; var @@ -3359,7 +3359,7 @@ begin Result := ''; if not Watch.Enabled then exit(''); - i := DbgStateChangeCounter; // workaround for state changes during TGuiWatchValue.GetValue + i := DbgStateChangeCounter; // workaround for state changes during TWatchValue.GetValue if Validity = ddsUnknown then begin Result := ''; Validity := ddsRequested; @@ -3388,7 +3388,7 @@ begin Result := nil; if not Watch.Enabled then exit; - i := DbgStateChangeCounter; // workaround for state changes during TGuiWatchValue.GetValue + i := DbgStateChangeCounter; // workaround for state changes during TWatchValue.GetValue if Validity = ddsUnknown then begin Validity := ddsRequested; RequestData; diff --git a/ide/packages/idedebugger/idedebuggerbase.pas b/ide/packages/idedebugger/idedebuggerbase.pas index 30b58ad1b1..c294829bcd 100644 --- a/ide/packages/idedebugger/idedebuggerbase.pas +++ b/ide/packages/idedebugger/idedebuggerbase.pas @@ -5,23 +5,58 @@ unit IdeDebuggerBase; interface uses - Classes, SysUtils, - DbgIntfDebuggerBase, DbgIntfMiscClasses, LazDebuggerIntf; + Classes, SysUtils, DbgIntfDebuggerBase, DbgIntfMiscClasses, LazClasses, + LazLoggerBase, LazDebuggerIntf; type TWatch = class; - { TGuiWatchValue } + { TWatchValue } - TGuiWatchValue = class(TWatchValue) + TWatchValue = class(TFreeNotifyingObject, TWatchValueIntf) private FWatch: TWatch; + FTypeInfo: TDBGType; + FValue: String; + FValidity: TDebuggerDataState; + + function GetDisplayFormat: TWatchDisplayFormat; + function GetEvaluateFlags: TWatcheEvaluateFlags; + function GetRepeatCount: Integer; + function GetStackFrame: Integer; + function GetThreadId: Integer; + function GetValidity: TDebuggerDataState; + procedure SetValidity(AValue: TDebuggerDataState); virtual; + procedure SetValue(AValue: String); + procedure SetTypeInfo(AValue: TDBGType); + procedure SetTypeInfo(AValue: TDBGTypeBase); protected - function GetExpression: String; override; + FDisplayFormat: TWatchDisplayFormat; + FEvaluateFlags: TWatcheEvaluateFlags; + FRepeatCount: Integer; + FStackFrame: Integer; + FThreadId: Integer; + procedure DoDataValidityChanged({%H-}AnOldValidity: TDebuggerDataState); virtual; + + function GetExpression: String; virtual; + function GetTypeInfo: TDBGType; virtual; + function GetValue: String; virtual; public constructor Create(AOwnerWatch: TWatch); + destructor Destroy; override; + procedure Assign(AnOther: TWatchValue); virtual; + property DisplayFormat: TWatchDisplayFormat read GetDisplayFormat; + property EvaluateFlags: TWatcheEvaluateFlags read GetEvaluateFlags; + property RepeatCount: Integer read GetRepeatCount; + property ThreadId: Integer read GetThreadId; + property StackFrame: Integer read GetStackFrame; + property Expression: String read GetExpression; + public property Watch: TWatch read FWatch; + property Validity: TDebuggerDataState read GetValidity write SetValidity; + property Value: String read GetValue write SetValue; + property TypeInfo: TDBGType read GetTypeInfo write SetTypeInfo; end; { TWatchValueList } @@ -30,20 +65,20 @@ type private FList: TList; FWatch: TWatch; - function GetEntry(const AThreadId: Integer; const AStackFrame: Integer): TGuiWatchValue; - function GetEntryByIdx(AnIndex: integer): TGuiWatchValue; + function GetEntry(const AThreadId: Integer; const AStackFrame: Integer): TWatchValue; + function GetEntryByIdx(AnIndex: integer): TWatchValue; protected - function CreateEntry(const {%H-}AThreadId: Integer; const {%H-}AStackFrame: Integer): TGuiWatchValue; virtual; - function CopyEntry(AnEntry: TGuiWatchValue): TGuiWatchValue; virtual; + function CreateEntry(const {%H-}AThreadId: Integer; const {%H-}AStackFrame: Integer): TWatchValue; virtual; + function CopyEntry(AnEntry: TWatchValue): TWatchValue; virtual; public procedure Assign(AnOther: TWatchValueList); constructor Create(AOwnerWatch: TWatch); destructor Destroy; override; - procedure Add(AnEntry: TGuiWatchValue); + procedure Add(AnEntry: TWatchValue); procedure Clear; function Count: Integer; - property EntriesByIdx[AnIndex: integer]: TGuiWatchValue read GetEntryByIdx; - property Entries[const AThreadId: Integer; const AStackFrame: Integer]: TGuiWatchValue + property EntriesByIdx[AnIndex: integer]: TWatchValue read GetEntryByIdx; + property Entries[const AThreadId: Integer; const AStackFrame: Integer]: TWatchValue read GetEntry; default; property Watch: TWatch read FWatch; end; @@ -58,7 +93,7 @@ type procedure SetEvaluateFlags(AValue: TWatcheEvaluateFlags); procedure SetExpression(AValue: String); procedure SetRepeatCount(AValue: Integer); - function GetValue(const AThreadId: Integer; const AStackFrame: Integer): TGuiWatchValue; + function GetValue(const AThreadId: Integer; const AStackFrame: Integer): TWatchValue; protected FEnabled: Boolean; FEvaluateFlags: TWatcheEvaluateFlags; @@ -83,7 +118,7 @@ type property DisplayFormat: TWatchDisplayFormat read FDisplayFormat write SetDisplayFormat; property EvaluateFlags: TWatcheEvaluateFlags read FEvaluateFlags write SetEvaluateFlags; property RepeatCount: Integer read FRepeatCount write SetRepeatCount; - property Values[const AThreadId: Integer; const AStackFrame: Integer]: TGuiWatchValue + property Values[const AThreadId: Integer; const AStackFrame: Integer]: TWatchValue read GetValue; end; TWatchClass = class of TWatch; @@ -105,19 +140,112 @@ type implementation -{ TGuiWatchValue } +var + DBG_DATA_MONITORS: PLazLoggerLogGroup; -function TGuiWatchValue.GetExpression: String; +{ TWatchValue } + +procedure TWatchValue.SetValidity(AValue: TDebuggerDataState); +var + OldValidity: TDebuggerDataState; +begin + if FValidity = AValue then exit; + //DebugLn(DBG_DATA_MONITORS, ['DebugDataMonitor: TWatchValue.SetValidity: FThreadId=', FThreadId, ' FStackFrame=',FStackFrame, ' Expr=', Expression, ' AValidity=',dbgs(AValue)]); + DebugLn(DBG_DATA_MONITORS, ['DebugDataMonitor: TWatchValue.SetValidity: Expr=', Expression, ' AValidity=',dbgs(AValue)]); + OldValidity := FValidity; + FValidity := AValue; + DoDataValidityChanged(OldValidity); +end; + +function TWatchValue.GetValidity: TDebuggerDataState; +begin + Result := FValidity; +end; + +function TWatchValue.GetStackFrame: Integer; +begin + Result := FStackFrame; +end; + +function TWatchValue.GetEvaluateFlags: TWatcheEvaluateFlags; +begin + Result := FEvaluateFlags; +end; + +function TWatchValue.GetDisplayFormat: TWatchDisplayFormat; +begin + Result := FDisplayFormat; +end; + +function TWatchValue.GetRepeatCount: Integer; +begin + Result := FRepeatCount; +end; + +function TWatchValue.GetThreadId: Integer; +begin + Result := FThreadId; +end; + +procedure TWatchValue.SetValue(AValue: String); +begin + if FValue = AValue then exit; + //asser not immutable + FValue := AValue; +end; + +procedure TWatchValue.SetTypeInfo(AValue: TDBGType); +begin + //assert(Self is TCurrentWatchValue, 'TWatchValue.SetTypeInfo'); + FreeAndNil(FTypeInfo); + FTypeInfo := AValue; +end; + +procedure TWatchValue.SetTypeInfo(AValue: TDBGTypeBase); +begin + SetTypeInfo(TDBGType(AValue)); +end; + +procedure TWatchValue.DoDataValidityChanged(AnOldValidity: TDebuggerDataState); +begin + +end; + +function TWatchValue.GetExpression: String; begin Result := FWatch.Expression; end; -constructor TGuiWatchValue.Create(AOwnerWatch: TWatch); +function TWatchValue.GetTypeInfo: TDBGType; +begin + Result := FTypeInfo; +end; + +function TWatchValue.GetValue: String; +begin + Result := FValue; +end; + +constructor TWatchValue.Create(AOwnerWatch: TWatch); begin FWatch := AOwnerWatch; inherited Create; end; +destructor TWatchValue.Destroy; +begin + inherited Destroy; + FreeAndNil(FTypeInfo); +end; + +procedure TWatchValue.Assign(AnOther: TWatchValue); +begin + FreeAndNil(FTypeInfo); + //FTypeInfo := TWatchValue(AnOther).FTypeInfo.cre; + FValue := AnOther.FValue; + FValidity := AnOther.FValidity; +end; + { TWatch } procedure TWatch.SetDisplayFormat(AValue: TWatchDisplayFormat); @@ -163,7 +291,7 @@ begin end; function TWatch.GetValue(const AThreadId: Integer; - const AStackFrame: Integer): TGuiWatchValue; + const AStackFrame: Integer): TWatchValue; begin Result := FValueList[AThreadId, AStackFrame]; end; @@ -271,13 +399,13 @@ end; { TWatchValueList } function TWatchValueList.GetEntry(const AThreadId: Integer; - const AStackFrame: Integer): TGuiWatchValue; + const AStackFrame: Integer): TWatchValue; var i: Integer; begin i := FList.Count - 1; while i >= 0 do begin - Result := TGuiWatchValue(FList[i]); + Result := TWatchValue(FList[i]); if (Result.ThreadId = AThreadId) and (Result.StackFrame = AStackFrame) and (Result.DisplayFormat = FWatch.DisplayFormat) and (Result.RepeatCount = FWatch.RepeatCount) and @@ -289,20 +417,20 @@ begin Result := CreateEntry(AThreadId, AStackFrame); end; -function TWatchValueList.GetEntryByIdx(AnIndex: integer): TGuiWatchValue; +function TWatchValueList.GetEntryByIdx(AnIndex: integer): TWatchValue; begin - Result := TGuiWatchValue(FList[AnIndex]); + Result := TWatchValue(FList[AnIndex]); end; function TWatchValueList.CreateEntry(const AThreadId: Integer; - const AStackFrame: Integer): TGuiWatchValue; + const AStackFrame: Integer): TWatchValue; begin Result := nil; end; -function TWatchValueList.CopyEntry(AnEntry: TGuiWatchValue): TGuiWatchValue; +function TWatchValueList.CopyEntry(AnEntry: TWatchValue): TWatchValue; begin - Result := TGuiWatchValue.Create(FWatch); + Result := TWatchValue.Create(FWatch); Result.Assign(AnEntry); end; @@ -312,7 +440,7 @@ var begin Clear; for i := 0 to AnOther.FList.Count - 1 do begin - FList.Add(CopyEntry(TGuiWatchValue(AnOther.FList[i]))); + FList.Add(CopyEntry(TWatchValue(AnOther.FList[i]))); end; end; @@ -331,7 +459,7 @@ begin FreeAndNil(FList); end; -procedure TWatchValueList.Add(AnEntry: TGuiWatchValue); +procedure TWatchValueList.Add(AnEntry: TWatchValue); begin Flist.Add(AnEntry); end; @@ -349,5 +477,8 @@ begin Result := FList.Count; end; +initialization + DBG_DATA_MONITORS := DebugLogger.FindOrRegisterLogGroup('DBG_DATA_MONITORS' {$IFDEF DBG_DATA_MONITORS} , True {$ENDIF} ); + end.