From 01a6b1dd5fb5a59f522db146dc3509f5fbae7de6 Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 12 May 2022 19:48:42 +0200 Subject: [PATCH] DebuggerIntf, FpDebug: add boolean --- components/fpdebug/fpwatchresultdata.pas | 11 ++- .../lazdebuggerintf/lazdebuggerintf.pas | 1 + ide/packages/idedebugger/debugger.pp | 9 +++ .../idedebugger/idedebuggerwatchresult.pas | 76 ++++++++++++++++++- 4 files changed, 95 insertions(+), 2 deletions(-) diff --git a/components/fpdebug/fpwatchresultdata.pas b/components/fpdebug/fpwatchresultdata.pas index fc07a092d9..37c2667bdd 100644 --- a/components/fpdebug/fpwatchresultdata.pas +++ b/components/fpdebug/fpwatchresultdata.pas @@ -31,6 +31,7 @@ type function StringToResData(AnFpValue: TFpValue; AnResData: TLzDbgWatchDataIntf): Boolean; function WideStringToResData(AnFpValue: TFpValue; AnResData: TLzDbgWatchDataIntf): Boolean; + function BoolToResData(AnFpValue: TFpValue; AnResData: TLzDbgWatchDataIntf): Boolean; function EnumToResData(AnFpValue: TFpValue; AnResData: TLzDbgWatchDataIntf): Boolean; function SetToResData(AnFpValue: TFpValue; AnResData: TLzDbgWatchDataIntf): Boolean; @@ -206,6 +207,14 @@ begin AddTypeNameToResData(AnFpValue, AnResData); end; +function TFpWatchResultConvertor.BoolToResData(AnFpValue: TFpValue; + AnResData: TLzDbgWatchDataIntf): Boolean; +begin + Result := True; + AnResData.CreateBoolValue(AnFpValue.AsCardinal, SizeToFullBytes(AnFpValue.DataSize)); + AddTypeNameToResData(AnFpValue, AnResData); +end; + function TFpWatchResultConvertor.EnumToResData(AnFpValue: TFpValue; AnResData: TLzDbgWatchDataIntf): Boolean; var @@ -307,7 +316,7 @@ begin skProcedureRef: ; skFunctionRef: ; skSimple: ; - skBoolean: ; + skBoolean: Result := BoolToResData(AnFpValue, AnResData); skCurrency: ; skVariant: ; skEnum, diff --git a/components/lazdebuggers/lazdebuggerintf/lazdebuggerintf.pas b/components/lazdebuggers/lazdebuggerintf/lazdebuggerintf.pas index cf30e2b260..a1481b9c9e 100644 --- a/components/lazdebuggers/lazdebuggerintf/lazdebuggerintf.pas +++ b/components/lazdebuggers/lazdebuggerintf/lazdebuggerintf.pas @@ -122,6 +122,7 @@ type procedure CreateNumValue(ANumValue: QWord; ASigned: Boolean; AByteSize: Integer = 0); procedure CreatePointerValue(AnAddrValue: TDbgPtr); procedure CreateFloatValue(AFloatValue: Extended; APrecission: TLzDbgFloatPrecission); + procedure CreateBoolValue(AnOrdBoolValue: QWord; AByteSize: Integer = 0); procedure CreateEnumValue(ANumValue: QWord; AName: String; AByteSize: Integer = 0; AnIsEnumIdent: Boolean = False); procedure CreateSetValue(const ANames: TStringDynArray); //; const AOrdValues: array of Integer); diff --git a/ide/packages/idedebugger/debugger.pp b/ide/packages/idedebugger/debugger.pp index 7c5a699c3b..50469e589b 100644 --- a/ide/packages/idedebugger/debugger.pp +++ b/ide/packages/idedebugger/debugger.pp @@ -663,6 +663,7 @@ type procedure CreateNumValue(ANumValue: QWord; ASigned: Boolean; AByteSize: Integer = 0); procedure CreatePointerValue(AnAddrValue: TDbgPtr); procedure CreateFloatValue(AFloatValue: Extended; APrecission: TLzDbgFloatPrecission); + procedure CreateBoolValue(AnOrdBoolValue: QWord; AByteSize: Integer = 0); procedure CreateEnumValue(ANumValue: QWord; AName: String; AByteSize: Integer = 0; AnIsEnumIdent: Boolean = False); procedure CreateSetValue(const ANames: TStringDynArray); @@ -3232,6 +3233,14 @@ begin AfterDataCreated; end; +procedure TCurrentResData.CreateBoolValue(AnOrdBoolValue: QWord; + AByteSize: Integer); +begin + assert(FNewResultData=nil, 'TCurrentResData.CreateBoolValue: FNewResultData=nil'); + FNewResultData := TWatchResultDataBoolean.Create(AnOrdBoolValue, AByteSize); + AfterDataCreated; +end; + procedure TCurrentResData.CreateEnumValue(ANumValue: QWord; AName: String; AByteSize: Integer; AnIsEnumIdent: Boolean); begin diff --git a/ide/packages/idedebugger/idedebuggerwatchresult.pas b/ide/packages/idedebugger/idedebuggerwatchresult.pas index cb868e5216..810b7dee12 100644 --- a/ide/packages/idedebugger/idedebuggerwatchresult.pas +++ b/ide/packages/idedebugger/idedebuggerwatchresult.pas @@ -16,7 +16,7 @@ type rdkError, rdkPrePrinted, rdkString, rdkWideString, rdkChar, rdkSignedNumVal, rdkUnsignedNumVal, rdkPointerVal, rdkFloatVal, - rdkEnum, rdkEnumVal, rdkSet + rdkBool, rdkEnum, rdkEnumVal, rdkSet ); TWatchResultData = class; @@ -173,6 +173,15 @@ type procedure SaveDataToXMLConfig(const AConfig: TXMLConfig; const APath: string); end; + { TWatchResultValueBoolean } + + TWatchResultValueBoolean = object(TWatchResultValueOrdNumBase) + protected const + VKind = rdkBool; + protected + function GetAsString: String; inline; + end; + { TWatchResultValueEnumBase } TWatchResultValueEnumBase = object(TWatchResultValueOrdNumBase) @@ -228,6 +237,7 @@ type wdUNum, // TWatchResultDataUnSignedNum wdPtr, // TWatchResultDataPointer wdFloat, // TWatchResultDataFloat + wdBool, // TWatchResultDataBoolean wdEnum, // TWatchResultDataEnum wdEnumVal, // TWatchResultDataEnumVal wdSet, // TWatchResultDataSet @@ -402,6 +412,16 @@ type constructor Create(AFloatValue: Extended; APrecission: TLzDbgFloatPrecission); end; + { TWatchResultDataBoolean } + + TWatchResultDataBoolean = class(specialize TGenericWatchResultDataSizedNum) + private + function GetClassID: TWatchResultDataClassID; override; + public + constructor Create(AnOrdBoolValue: QWord; AByteSize: Integer = 0); + constructor Create(ABoolValue: Boolean); + end; + { TWatchResultDataEnum } TWatchResultDataEnum = class(specialize TGenericWatchResultDataSizedNum) @@ -510,6 +530,23 @@ function PrintWatchValueEx(AResValue: TWatchResultData; ADispFormat: TWatchDispl end; end; + function PrintBool: String; + var + c: QWord; + begin + c := AResValue.GetAsQWord; + if c = 0 then + Result := 'False' + else + Result := 'True'; + + if (ADispFormat in [wdfDecimal, wdfUnsigned, wdfHex, wdfBinary]) then + Result := Result + '(' + PrintNumber(AResValue, False, ADispFormat) + ')' + else + if (c > 1) then + Result := Result + '(' + PrintNumber(AResValue, False, wdfDecimal) + ')'; + end; + function PrintEnum: String; begin if (ADispFormat = wdfDefault) and (AResValue.ValueKind = rdkEnumVal) then @@ -618,6 +655,7 @@ begin rdkChar: Result := PrintChar; rdkString: Result := QuoteText(AResValue.AsString); rdkWideString: Result := QuoteWideText(AResValue.AsWideString); + rdkBool: Result := PrintBool; rdkEnum, rdkEnumVal: Result := PrintEnum; rdkSet: Result := PrintSet; @@ -639,6 +677,7 @@ const TWatchResultDataUnSignedNum, // wdUNum TWatchResultDataPointer, // wdPtr TWatchResultDataFloat, // wdFloat + TWatchResultDataBoolean, // wdBool TWatchResultDataEnum, // wdEnum TWatchResultDataEnumVal, // wdEnumVal TWatchResultDataSet, // wdSet @@ -892,6 +931,16 @@ begin AConfig.SetDeleteValue(APath + 'Prec', FFloatPrecission, ord(dfpSingle), TypeInfo(TLzDbgFloatPrecission)); end; +{ TWatchResultValueBoolean } + +function TWatchResultValueBoolean.GetAsString: String; +begin + if FNumValue <> 0 then + Result := 'True' + else + Result := 'False'; +end; + { TWatchResultValueEnumBase } procedure TWatchResultValueEnumBase.LoadDataFromXMLConfig( @@ -1260,6 +1309,31 @@ begin FType.FFloatPrecission := APrecission; end; +{ TWatchResultDataBoolean } + +function TWatchResultDataBoolean.GetClassID: TWatchResultDataClassID; +begin + Result := wdBool; +end; + +constructor TWatchResultDataBoolean.Create(AnOrdBoolValue: QWord; + AByteSize: Integer); +begin + inherited Create; + FData.FNumValue := AnOrdBoolValue; + FType.FNumByteSize := AByteSize; +end; + +constructor TWatchResultDataBoolean.Create(ABoolValue: Boolean); +begin + inherited Create; + if ABoolValue then + FData.FNumValue := 1 + else + FData.FNumValue := 0; + FType.FNumByteSize := 0; +end; + { TWatchResultDataEnum } function TWatchResultDataEnum.GetClassID: TWatchResultDataClassID;