REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2054
This library allows to make a common part of all DebugLib instances and avoid the need to update every DebugLib on extending a new debug mask PCD bit. Signed-off-by: Vitaly Cheptsov <vit9...@protonmail.com> --- MdePkg/Include/Library/DebugCommonLib.h | 154 ++++++++++++++++++++ MdePkg/Include/Library/DebugLib.h | 137 +---------------- MdePkg/Library/BaseDebugCommonLib/BaseDebugCommonLib.inf | 39 +++++ MdePkg/Library/BaseDebugCommonLib/BaseDebugCommonLib.uni | 16 ++ MdePkg/Library/BaseDebugCommonLib/DebugCommonLib.c | 113 ++++++++++++++ MdePkg/MdePkg.dec | 3 + MdePkg/MdePkg.dsc | 1 + MdePkg/MdePkg.uni | 3 +- 8 files changed, 329 insertions(+), 137 deletions(-) diff --git a/MdePkg/Include/Library/DebugCommonLib.h b/MdePkg/Include/Library/DebugCommonLib.h new file mode 100644 index 0000000000..31249f91fa --- /dev/null +++ b/MdePkg/Include/Library/DebugCommonLib.h @@ -0,0 +1,154 @@ +/** @file + Provides services to access common debugging features. + + The debug common library interface provides common code for all debug libraries. + + Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.<BR> + Copyright (c) 2020, Vitaly Cheptsov. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef __DEBUG_COMMON_LIB_H__ +#define __DEBUG_COMMON_LIB_H__ + +// +// Declare bits for PcdDebugPropertyMask +// +#define DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED 0x01 +#define DEBUG_PROPERTY_DEBUG_PRINT_ENABLED 0x02 +#define DEBUG_PROPERTY_DEBUG_CODE_ENABLED 0x04 +#define DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED 0x08 +#define DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED 0x10 +#define DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED 0x20 + +// +// Declare bits for PcdDebugPrintErrorLevel and the ErrorLevel parameter of DebugPrint() +// +#define DEBUG_INIT 0x00000001 // Initialization +#define DEBUG_WARN 0x00000002 // Warnings +#define DEBUG_LOAD 0x00000004 // Load events +#define DEBUG_FS 0x00000008 // EFI File system +#define DEBUG_POOL 0x00000010 // Alloc & Free (pool) +#define DEBUG_PAGE 0x00000020 // Alloc & Free (page) +#define DEBUG_INFO 0x00000040 // Informational debug messages +#define DEBUG_DISPATCH 0x00000080 // PEI/DXE/SMM Dispatchers +#define DEBUG_VARIABLE 0x00000100 // Variable +#define DEBUG_BM 0x00000400 // Boot Manager +#define DEBUG_BLKIO 0x00001000 // BlkIo Driver +#define DEBUG_NET 0x00004000 // Network Io Driver +#define DEBUG_UNDI 0x00010000 // UNDI Driver +#define DEBUG_LOADFILE 0x00020000 // LoadFile +#define DEBUG_EVENT 0x00080000 // Event messages +#define DEBUG_GCD 0x00100000 // Global Coherency Database changes +#define DEBUG_CACHE 0x00200000 // Memory range cachability changes +#define DEBUG_VERBOSE 0x00400000 // Detailed debug messages that may + // significantly impact boot performance +#define DEBUG_ERROR 0x80000000 // Error + +// +// Aliases of debug message mask bits +// +#define EFI_D_INIT DEBUG_INIT +#define EFI_D_WARN DEBUG_WARN +#define EFI_D_LOAD DEBUG_LOAD +#define EFI_D_FS DEBUG_FS +#define EFI_D_POOL DEBUG_POOL +#define EFI_D_PAGE DEBUG_PAGE +#define EFI_D_INFO DEBUG_INFO +#define EFI_D_DISPATCH DEBUG_DISPATCH +#define EFI_D_VARIABLE DEBUG_VARIABLE +#define EFI_D_BM DEBUG_BM +#define EFI_D_BLKIO DEBUG_BLKIO +#define EFI_D_NET DEBUG_NET +#define EFI_D_UNDI DEBUG_UNDI +#define EFI_D_LOADFILE DEBUG_LOADFILE +#define EFI_D_EVENT DEBUG_EVENT +#define EFI_D_VERBOSE DEBUG_VERBOSE +#define EFI_D_ERROR DEBUG_ERROR + +/** + Returns TRUE if ASSERT() macros are enabled. + + This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of + PcdDebugProperyMask is set. Otherwise, FALSE is returned. + + @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set. + @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear. + +**/ +BOOLEAN +EFIAPI +DebugAssertEnabled ( + VOID + ); + + +/** + Returns TRUE if DEBUG() macros are enabled. + + This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of + PcdDebugProperyMask is set. Otherwise, FALSE is returned. + + @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set. + @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear. + +**/ +BOOLEAN +EFIAPI +DebugPrintEnabled ( + VOID + ); + + +/** + Returns TRUE if DEBUG_CODE() macros are enabled. + + This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of + PcdDebugProperyMask is set. Otherwise, FALSE is returned. + + @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set. + @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear. + +**/ +BOOLEAN +EFIAPI +DebugCodeEnabled ( + VOID + ); + + +/** + Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled. + + This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of + PcdDebugProperyMask is set. Otherwise, FALSE is returned. + + @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set. + @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear. + +**/ +BOOLEAN +EFIAPI +DebugClearMemoryEnabled ( + VOID + ); + + +/** + Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel. + + This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel. + + @retval TRUE Current ErrorLevel is supported. + @retval FALSE Current ErrorLevel is not supported. + +**/ +BOOLEAN +EFIAPI +DebugPrintLevelEnabled ( + IN CONST UINTN ErrorLevel + ); + + +#endif diff --git a/MdePkg/Include/Library/DebugLib.h b/MdePkg/Include/Library/DebugLib.h index baab34bf05..a38e0e2904 100644 --- a/MdePkg/Include/Library/DebugLib.h +++ b/MdePkg/Include/Library/DebugLib.h @@ -16,60 +16,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #ifndef __DEBUG_LIB_H__ #define __DEBUG_LIB_H__ -// -// Declare bits for PcdDebugPropertyMask -// -#define DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED 0x01 -#define DEBUG_PROPERTY_DEBUG_PRINT_ENABLED 0x02 -#define DEBUG_PROPERTY_DEBUG_CODE_ENABLED 0x04 -#define DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED 0x08 -#define DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED 0x10 -#define DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED 0x20 - -// -// Declare bits for PcdDebugPrintErrorLevel and the ErrorLevel parameter of DebugPrint() -// -#define DEBUG_INIT 0x00000001 // Initialization -#define DEBUG_WARN 0x00000002 // Warnings -#define DEBUG_LOAD 0x00000004 // Load events -#define DEBUG_FS 0x00000008 // EFI File system -#define DEBUG_POOL 0x00000010 // Alloc & Free (pool) -#define DEBUG_PAGE 0x00000020 // Alloc & Free (page) -#define DEBUG_INFO 0x00000040 // Informational debug messages -#define DEBUG_DISPATCH 0x00000080 // PEI/DXE/SMM Dispatchers -#define DEBUG_VARIABLE 0x00000100 // Variable -#define DEBUG_BM 0x00000400 // Boot Manager -#define DEBUG_BLKIO 0x00001000 // BlkIo Driver -#define DEBUG_NET 0x00004000 // Network Io Driver -#define DEBUG_UNDI 0x00010000 // UNDI Driver -#define DEBUG_LOADFILE 0x00020000 // LoadFile -#define DEBUG_EVENT 0x00080000 // Event messages -#define DEBUG_GCD 0x00100000 // Global Coherency Database changes -#define DEBUG_CACHE 0x00200000 // Memory range cachability changes -#define DEBUG_VERBOSE 0x00400000 // Detailed debug messages that may - // significantly impact boot performance -#define DEBUG_ERROR 0x80000000 // Error - -// -// Aliases of debug message mask bits -// -#define EFI_D_INIT DEBUG_INIT -#define EFI_D_WARN DEBUG_WARN -#define EFI_D_LOAD DEBUG_LOAD -#define EFI_D_FS DEBUG_FS -#define EFI_D_POOL DEBUG_POOL -#define EFI_D_PAGE DEBUG_PAGE -#define EFI_D_INFO DEBUG_INFO -#define EFI_D_DISPATCH DEBUG_DISPATCH -#define EFI_D_VARIABLE DEBUG_VARIABLE -#define EFI_D_BM DEBUG_BM -#define EFI_D_BLKIO DEBUG_BLKIO -#define EFI_D_NET DEBUG_NET -#define EFI_D_UNDI DEBUG_UNDI -#define EFI_D_LOADFILE DEBUG_LOADFILE -#define EFI_D_EVENT DEBUG_EVENT -#define EFI_D_VERBOSE DEBUG_VERBOSE -#define EFI_D_ERROR DEBUG_ERROR +#include <Library/DebugCommonLib.h> /** Prints a debug message to the debug output device if the specified error level is enabled. @@ -198,88 +145,6 @@ DebugClearMemory ( ); -/** - Returns TRUE if ASSERT() macros are enabled. - - This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of - PcdDebugProperyMask is set. Otherwise, FALSE is returned. - - @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set. - @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear. - -**/ -BOOLEAN -EFIAPI -DebugAssertEnabled ( - VOID - ); - - -/** - Returns TRUE if DEBUG() macros are enabled. - - This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of - PcdDebugProperyMask is set. Otherwise, FALSE is returned. - - @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set. - @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear. - -**/ -BOOLEAN -EFIAPI -DebugPrintEnabled ( - VOID - ); - - -/** - Returns TRUE if DEBUG_CODE() macros are enabled. - - This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of - PcdDebugProperyMask is set. Otherwise, FALSE is returned. - - @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set. - @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear. - -**/ -BOOLEAN -EFIAPI -DebugCodeEnabled ( - VOID - ); - - -/** - Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled. - - This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of - PcdDebugProperyMask is set. Otherwise, FALSE is returned. - - @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set. - @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear. - -**/ -BOOLEAN -EFIAPI -DebugClearMemoryEnabled ( - VOID - ); - -/** - Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel. - - This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel. - - @retval TRUE Current ErrorLevel is supported. - @retval FALSE Current ErrorLevel is not supported. - -**/ -BOOLEAN -EFIAPI -DebugPrintLevelEnabled ( - IN CONST UINTN ErrorLevel - ); - /** Internal worker macro that calls DebugAssert(). diff --git a/MdePkg/Library/BaseDebugCommonLib/BaseDebugCommonLib.inf b/MdePkg/Library/BaseDebugCommonLib/BaseDebugCommonLib.inf new file mode 100644 index 0000000000..c1f4b0d5a8 --- /dev/null +++ b/MdePkg/Library/BaseDebugCommonLib/BaseDebugCommonLib.inf @@ -0,0 +1,39 @@ +## @file +# Instance of Debug Common Library interface. +# It uses PcdLib to provide a common set of Debug Library interface. +# +# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> +# Copyright (c) 2020, Vitaly Cheptsov. All rights reserved.<BR> +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = BaseDebugCommonLib + MODULE_UNI_FILE = BaseDebugCommonLib.uni + FILE_GUID = 7CD790D2-E13F-4446-AF4F-813F0B9DEFF8 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = DebugCommonLib + +# +# VALID_ARCHITECTURES = IA32 X64 EBC +# + +[Sources] + DebugCommonLib.c + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + PcdLib + +[Pcd] + gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue ## SOMETIMES_CONSUMES + gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask ## CONSUMES + gEfiMdePkgTokenSpaceGuid.PcdFixedDebugPrintErrorLevel ## CONSUMES + diff --git a/MdePkg/Library/BaseDebugCommonLib/BaseDebugCommonLib.uni b/MdePkg/Library/BaseDebugCommonLib/BaseDebugCommonLib.uni new file mode 100644 index 0000000000..a5ad34298b --- /dev/null +++ b/MdePkg/Library/BaseDebugCommonLib/BaseDebugCommonLib.uni @@ -0,0 +1,16 @@ +// /** @file +// Instance of Debug Common Library interface. +// +// It uses PcdLib to provide a common set of Debug Library interface. +// +// Copyright (c) 2020, Vitaly Cheptsov. All rights reserved.<BR> +// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Instance of Debug Common Library interface" + +#string STR_MODULE_DESCRIPTION #language en-US "It uses PcdLib to provide a common set of Debug Library interface." + diff --git a/MdePkg/Library/BaseDebugCommonLib/DebugCommonLib.c b/MdePkg/Library/BaseDebugCommonLib/DebugCommonLib.c new file mode 100644 index 0000000000..2291fb5382 --- /dev/null +++ b/MdePkg/Library/BaseDebugCommonLib/DebugCommonLib.c @@ -0,0 +1,113 @@ +/** @file + Instance of Debug Common Library interface. + It uses PcdLib to provide a common set of Debug Library interface. + + Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR> + Copyright (c) 2020, Vitaly Cheptsov. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <Base.h> +#include <Library/DebugCommonLib.h> +#include <Library/PcdLib.h> + + +/** + Returns TRUE if ASSERT() macros are enabled. + + This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of + PcdDebugProperyMask is set. Otherwise FALSE is returned. + + @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set. + @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear. + +**/ +BOOLEAN +EFIAPI +DebugAssertEnabled ( + VOID + ) +{ + return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0); +} + + +/** + Returns TRUE if DEBUG() macros are enabled. + + This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of + PcdDebugProperyMask is set. Otherwise FALSE is returned. + + @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set. + @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear. + +**/ +BOOLEAN +EFIAPI +DebugPrintEnabled ( + VOID + ) +{ + return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0); +} + + +/** + Returns TRUE if DEBUG_CODE() macros are enabled. + + This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of + PcdDebugProperyMask is set. Otherwise FALSE is returned. + + @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set. + @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear. + +**/ +BOOLEAN +EFIAPI +DebugCodeEnabled ( + VOID + ) +{ + return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0); +} + + +/** + Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled. + + This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of + PcdDebugProperyMask is set. Otherwise FALSE is returned. + + @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set. + @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear. + +**/ +BOOLEAN +EFIAPI +DebugClearMemoryEnabled ( + VOID + ) +{ + return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0); +} + + +/** + Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel. + + This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel. + + @retval TRUE Current ErrorLevel is supported. + @retval FALSE Current ErrorLevel is not supported. + +**/ +BOOLEAN +EFIAPI +DebugPrintLevelEnabled ( + IN CONST UINTN ErrorLevel + ) +{ + return (BOOLEAN) ((ErrorLevel & PcdGet32 (PcdFixedDebugPrintErrorLevel)) != 0); +} + diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 0b9c4bc40a..a121b9ecab 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -229,6 +229,9 @@ [LibraryClasses] # library class maps directly on top of the Timer class. S3StallLib|Include/Library/S3StallLib.h + ## @libraryclass Provides services to access common debugging features. + DebugCommonLib|Include/Library/DebugCommonLib.h + ## @libraryclass Defines library APIs used by modules to get/set print error level. DebugPrintErrorLevelLib|Include/Library/DebugPrintErrorLevelLib.h diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index 6cd38e7ec3..1072322450 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -36,6 +36,7 @@ [Components] MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf MdePkg/Library/BaseCpuLib/BaseCpuLib.inf + MdePkg/Library/BaseDebugCommonLib/BaseDebugCommonLib.inf MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf diff --git a/MdePkg/MdePkg.uni b/MdePkg/MdePkg.uni index 5c1fa24065..5addb0eaba 100644 --- a/MdePkg/MdePkg.uni +++ b/MdePkg/MdePkg.uni @@ -189,7 +189,8 @@ "BIT2 - Enable Debug Code.<BR>\n" "BIT3 - Enable Clear Memory.<BR>\n" "BIT4 - Enable BreakPoint as ASSERT.<BR>\n" - "BIT5 - Enable DeadLoop as ASSERT.<BR>" + "BIT5 - Enable DeadLoop as ASSERT.<BR>\n" + "BIT6 - Treat constrait violations as ASSERT.<BR>" #string STR_gEfiMdePkgTokenSpaceGuid_ERR_80000002 #language en-US "Reserved bits must be set to zero." -- 2.24.2 (Apple Git-127) -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#59099): https://edk2.groups.io/g/devel/message/59099 Mute This Topic: https://groups.io/mt/74138530/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-