From 28ac5176a9b40e8957f50fc413953fb75bc1127a Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 12 May 2022 20:15:26 +0200 Subject: [PATCH] IdeDebugger: Fix Display-Format related conversion of numeric watches. --- .../idedebugger/idedebuggerwatchresult.pas | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/ide/packages/idedebugger/idedebuggerwatchresult.pas b/ide/packages/idedebugger/idedebuggerwatchresult.pas index 9a25f51cbc..5530439d12 100644 --- a/ide/packages/idedebugger/idedebuggerwatchresult.pas +++ b/ide/packages/idedebugger/idedebuggerwatchresult.pas @@ -337,9 +337,17 @@ type constructor Create(AStringVal: WideString); end; + { TGenericWatchResultDataSizedNum } + + generic TGenericWatchResultDataSizedNum<_DATA> = class(specialize TGenericWatchResultDataWithType<_DATA, TWatchResultTypeOrdNum>) + protected + function GetAsQWord: QWord; override; + function GetAsInt64: Int64; override; + end; + { TWatchResultDataSignedNum } - TWatchResultDataSignedNum = class(specialize TGenericWatchResultDataWithType) + TWatchResultDataSignedNum = class(specialize TGenericWatchResultDataSizedNum) private function GetClassID: TWatchResultDataClassID; override; public @@ -348,7 +356,7 @@ type { TWatchResultDataUnSignedNum } - TWatchResultDataUnSignedNum = class(specialize TGenericWatchResultDataWithType) + TWatchResultDataUnSignedNum = class(specialize TGenericWatchResultDataSizedNum) private function GetClassID: TWatchResultDataClassID; override; public @@ -377,7 +385,7 @@ type { TWatchResultDataEnum } - TWatchResultDataEnum = class(specialize TGenericWatchResultDataWithType) + TWatchResultDataEnum = class(specialize TGenericWatchResultDataSizedNum) private function GetClassID: TWatchResultDataClassID; override; public @@ -386,7 +394,7 @@ type { TWatchResultDataEnumVal } - TWatchResultDataEnumVal = class(specialize TGenericWatchResultDataWithType) + TWatchResultDataEnumVal = class(specialize TGenericWatchResultDataSizedNum) private function GetClassID: TWatchResultDataClassID; override; public @@ -457,7 +465,7 @@ function PrintWatchValueEx(AResValue: TWatchResultData; ADispFormat: TWatchDispl end; wdfBinary: begin n := HexDigicCount(ANumValue.AsQWord, ANumValue.ByteSize, AnIsPointer); - Result := '%'+IntToBin(ANumValue.AsInt64, n*4); + Result := '%'+IntToBin(Int64(ANumValue.AsQWord), n*4); // Don't get any extra leading 1 end; wdfPointer: begin n := HexDigicCount(ANumValue.AsQWord, ANumValue.ByteSize, True); @@ -1112,6 +1120,26 @@ begin FData.FWideText := AStringVal; end; +{ TGenericWatchResultDataSizedNum } + +function TGenericWatchResultDataSizedNum.GetAsQWord: QWord; +begin + Result := FData.GetAsQWord; + if (FType.GetByteSize > 0) and (FType.GetByteSize < 8) then + Result := Result and not(QWord(-1) << (FType.GetByteSize<<3)); +end; + +function TGenericWatchResultDataSizedNum.GetAsInt64: Int64; +begin + Result := FData.GetAsInt64; + if (FType.GetByteSize > 0) and (FType.GetByteSize < 8) then begin + if Result and (1 << ((FType.GetByteSize<<3) - 1)) <> 0 then + Result := Result or (Int64(-1) << (FType.GetByteSize<<3)) + else + Result := Result and not(Int64(-1) << (FType.GetByteSize<<3)); + end; +end; + { TWatchResultDataSignedNum } function TWatchResultDataSignedNum.GetClassID: TWatchResultDataClassID;