Skip to content

Commit e81738f

Browse files
committed
EmbeddedPkg/GdbStub: Fix VS2022 type conversion warnings
Fix type conversion warnings (C4244) in GdbStub that prevent it from building with Visual Studio 2022 when the /WX flag (treat warnings as errors) is enabled. Instead of adding explicit casts at every assignment, change function parameter types from UINTN to UINT32 to match the UINT32 bitfield definitions in the IA32_DR7 structure, as suggested by maintainer review feedback. Changes made: 1. EmbeddedPkg/GdbStub/GdbStubInternal.h - Update EnableDebugRegister() declaration: Address, Length, Type parameters changed from UINTN to UINT32 - Update FindMatchingDebugRegister() declaration: Address, Length, Type parameters changed from UINTN to UINT32 2. EmbeddedPkg/GdbStub/X64/Processor.c - Update EnableDebugRegister() implementation to use UINT32 parameters, eliminating 12 inline casts - Update DisableDebugRegister() to use UINT32 local variable, eliminating 4 inline casts - Update FindMatchingDebugRegister() implementation to use UINT32 parameters - Update call sites to use (UINT32) casts instead of (UINTN) - Retain necessary (UINT32)Dr7.UintN casts (2 instances) - Update function documentation to reflect UINT32 parameter types Rationale: - Debug registers Dr0-Dr7 are 32-bit registers even on X64 - IA32_DR7 bitfields are defined as UINT32 - UINT32 parameter types reflect actual hardware constraints - Results in cleaner code with fewer casts (net reduction of 14 casts) Tested on: - Windows 11 with VS2022 (X64 and IA32) - Ubuntu with GCC5 (X64) Addresses: #11737 Signed-off-by: Gary Beihl <[email protected]>
1 parent 6c6d4d2 commit e81738f

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

EmbeddedPkg/GdbStub/GdbStubInternal.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -676,17 +676,17 @@ EFI_STATUS
676676
EnableDebugRegister (
677677
IN EFI_SYSTEM_CONTEXT SystemContext,
678678
IN UINTN Register,
679-
IN UINTN Address,
680-
IN UINTN Length,
681-
IN UINTN Type
679+
IN UINT32 Address,
680+
IN UINT32 Length,
681+
IN UINT32 Type
682682
);
683683

684684
EFI_STATUS
685685
FindMatchingDebugRegister (
686686
IN EFI_SYSTEM_CONTEXT SystemContext,
687-
IN UINTN Address,
688-
IN UINTN Length,
689-
IN UINTN Type,
687+
IN UINT32 Address,
688+
IN UINT32 Length,
689+
IN UINT32 Type,
690690
OUT UINTN *Register
691691
);
692692

EmbeddedPkg/GdbStub/X64/Processor.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -560,9 +560,9 @@ FindNextFreeDebugRegister (
560560
561561
@param SystemContext Register content at time of the exception
562562
@param Register Register value (0 - 3)
563-
@param Address Breakpoint address value
563+
@param Address Breakpoint address value (UINT32)
564564
@param Type Breakpoint type (Instruction, Data write,
565-
Data read or write etc.)
565+
Data read or write etc.) (UINT32)
566566
567567
@retval EFI_STATUS Appropriate status value.
568568
@@ -571,15 +571,15 @@ EFI_STATUS
571571
EnableDebugRegister (
572572
IN EFI_SYSTEM_CONTEXT SystemContext,
573573
IN UINTN Register,
574-
IN UINTN Address,
575-
IN UINTN Length,
576-
IN UINTN Type
574+
IN UINT32 Address,
575+
IN UINT32 Length,
576+
IN UINT32 Type
577577
)
578578
{
579579
IA32_DR7 Dr7;
580580

581581
// Convert length data
582-
Length = ConvertLengthData (Length);
582+
Length = (UINT32)ConvertLengthData (Length);
583583

584584
// For Instruction execution, length should be 0
585585
// (Ref. Intel reference manual 18.2.4)
@@ -623,7 +623,7 @@ EnableDebugRegister (
623623
}
624624

625625
// Update Dr7 with appropriate Gn, RWn and LENn bits
626-
SystemContext.SystemContextIa32->Dr7 = Dr7.UintN;
626+
SystemContext.SystemContextIa32->Dr7 = (UINT32)Dr7.UintN;
627627

628628
return EFI_SUCCESS;
629629
}
@@ -635,10 +635,10 @@ EnableDebugRegister (
635635
In case of mismatch, function returns EFI_NOT_FOUND message.
636636
637637
@param SystemContext Register content at time of the exception
638-
@param Address Breakpoint address value
639-
@param Length Breakpoint length value
638+
@param Address Breakpoint address value (UINT32)
639+
@param Length Breakpoint length value (UINT32)
640640
@param Type Breakpoint type (Instruction, Data write, Data read
641-
or write etc.)
641+
or write etc.) (UINT32)
642642
@param Register Register value to be returned
643643
644644
@retval EFI_STATUS Appropriate status value.
@@ -647,9 +647,9 @@ EnableDebugRegister (
647647
EFI_STATUS
648648
FindMatchingDebugRegister (
649649
IN EFI_SYSTEM_CONTEXT SystemContext,
650-
IN UINTN Address,
651-
IN UINTN Length,
652-
IN UINTN Type,
650+
IN UINT32 Address,
651+
IN UINT32 Length,
652+
IN UINT32 Type,
653653
OUT UINTN *Register
654654
)
655655
{
@@ -664,7 +664,7 @@ FindMatchingDebugRegister (
664664
}
665665

666666
// Convert length data
667-
Length = ConvertLengthData (Length);
667+
Length = (UINT32)ConvertLengthData (Length);
668668

669669
Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
670670

@@ -716,7 +716,7 @@ DisableDebugRegister (
716716
)
717717
{
718718
IA32_DR7 Dr7;
719-
UINTN Address = 0;
719+
UINT32 Address = 0;
720720

721721
// Read DR7 register so appropriate Gn, RWn and LENn bits can be turned off.
722722
Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
@@ -746,7 +746,7 @@ DisableDebugRegister (
746746
}
747747

748748
// Update DR7 register so appropriate Gn, RWn and LENn bits can be turned off.
749-
SystemContext.SystemContextIa32->Dr7 = Dr7.UintN;
749+
SystemContext.SystemContextIa32->Dr7 = (UINT32)Dr7.UintN;
750750

751751
return EFI_SUCCESS;
752752
}
@@ -820,7 +820,7 @@ InsertBreakPoint (
820820
}
821821

822822
// Write Address, length data at particular DR register
823-
Status = EnableDebugRegister (SystemContext, Register, Address, Length, (UINTN)BreakType);
823+
Status = EnableDebugRegister (SystemContext, Register, (UINT32)Address, (UINT32)Length, (UINT32)BreakType);
824824
if (EFI_ERROR (Status)) {
825825
if (Status == EFI_UNSUPPORTED) {
826826
Print ((CHAR16 *)L"Not supported\n");
@@ -896,7 +896,7 @@ RemoveBreakPoint (
896896
}
897897

898898
// Find matching debug register
899-
Status = FindMatchingDebugRegister (SystemContext, Address, Length, (UINTN)BreakType, &Register);
899+
Status = FindMatchingDebugRegister (SystemContext, (UINT32)Address, (UINT32)Length, (UINT32)BreakType, &Register);
900900
if (EFI_ERROR (Status)) {
901901
if (Status == EFI_UNSUPPORTED) {
902902
Print ((CHAR16 *)L"Not supported.\n");

0 commit comments

Comments
 (0)