23#ifndef __DEBUG_LIB_H__
24#define __DEBUG_LIB_H__
29#define DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED 0x01
30#define DEBUG_PROPERTY_DEBUG_PRINT_ENABLED 0x02
31#define DEBUG_PROPERTY_DEBUG_CODE_ENABLED 0x04
32#define DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED 0x08
33#define DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED 0x10
34#define DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED 0x20
39#define DEBUG_INIT 0x00000001
40#define DEBUG_WARN 0x00000002
41#define DEBUG_LOAD 0x00000004
42#define DEBUG_FS 0x00000008
43#define DEBUG_POOL 0x00000010
44#define DEBUG_PAGE 0x00000020
45#define DEBUG_INFO 0x00000040
46#define DEBUG_DISPATCH 0x00000080
47#define DEBUG_VARIABLE 0x00000100
48#define DEBUG_BM 0x00000400
49#define DEBUG_BLKIO 0x00001000
50#define DEBUG_NET 0x00004000
51#define DEBUG_UNDI 0x00010000
52#define DEBUG_LOADFILE 0x00020000
53#define DEBUG_EVENT 0x00080000
54#define DEBUG_GCD 0x00100000
55#define DEBUG_CACHE 0x00200000
56#define DEBUG_VERBOSE 0x00400000
58#define DEBUG_MANAGEABILITY 0x00800000
60#define DEBUG_ERROR 0x80000000
65#define EFI_D_INIT DEBUG_INIT
66#define EFI_D_WARN DEBUG_WARN
67#define EFI_D_LOAD DEBUG_LOAD
68#define EFI_D_FS DEBUG_FS
69#define EFI_D_POOL DEBUG_POOL
70#define EFI_D_PAGE DEBUG_PAGE
71#define EFI_D_INFO DEBUG_INFO
72#define EFI_D_DISPATCH DEBUG_DISPATCH
73#define EFI_D_VARIABLE DEBUG_VARIABLE
74#define EFI_D_BM DEBUG_BM
75#define EFI_D_BLKIO DEBUG_BLKIO
76#define EFI_D_NET DEBUG_NET
77#define EFI_D_UNDI DEBUG_UNDI
78#define EFI_D_LOADFILE DEBUG_LOADFILE
79#define EFI_D_EVENT DEBUG_EVENT
80#define EFI_D_VERBOSE DEBUG_VERBOSE
81#define EFI_D_ERROR DEBUG_ERROR
92#ifdef DEBUG_LINE_NUMBER
94#define DEBUG_LINE_NUMBER __LINE__
112#ifdef DEBUG_EXPRESSION_STRING_VALUE
113#define DEBUG_EXPRESSION_STRING(Expression) DEBUG_EXPRESSION_STRING_VALUE
115#define DEBUG_EXPRESSION_STRING(Expression) #Expression
328#if defined (EDKII_UNIT_TEST_FRAMEWORK_ENABLED)
349 #if defined (_ASSERT)
352 #if defined (__FILE_NAME__)
353#define _ASSERT(Expression) UnitTestDebugAssert (__FILE_NAME__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))
355#define _ASSERT(Expression) UnitTestDebugAssert (__FILE__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))
358 #if defined (__FILE_NAME__)
359#define _ASSERT(Expression) DebugAssert (__FILE_NAME__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))
361#define _ASSERT(Expression) DebugAssert (__FILE__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))
378#if !defined (MDE_CPU_EBC) && (!defined (_MSC_VER) || _MSC_VER > 1400)
379#define _DEBUG_PRINT(PrintLevel, ...) \
381 if (DebugPrintLevelEnabled (PrintLevel)) { \
382 DebugPrint (PrintLevel, ##__VA_ARGS__); \
385#define _DEBUGLIB_DEBUG(Expression) _DEBUG_PRINT Expression
387#define _DEBUGLIB_DEBUG(Expression) DebugPrint Expression
402#if !defined (MDEPKG_NDEBUG)
403#define ASSERT(Expression) \
405 if (DebugAssertEnabled ()) { \
406 if (!(Expression)) { \
407 _ASSERT (Expression); \
408 ANALYZER_UNREACHABLE (); \
413#define ASSERT(Expression) \
416 (VOID) (Expression); \
433#if !defined (MDEPKG_NDEBUG)
434#define DEBUG(Expression) \
436 if (DebugPrintEnabled ()) { \
437 _DEBUGLIB_DEBUG (Expression); \
441#define DEBUG(Expression) \
444 _DEBUGLIB_DEBUG (Expression); \
461#if !defined (MDEPKG_NDEBUG)
462#define ASSERT_EFI_ERROR(StatusParameter) \
464 if (DebugAssertEnabled ()) { \
465 if (EFI_ERROR (StatusParameter)) { \
466 DEBUG ((DEBUG_ERROR, "\nASSERT_EFI_ERROR (Status = %r)\n", StatusParameter)); \
467 _ASSERT (!EFI_ERROR (StatusParameter)); \
472#define ASSERT_EFI_ERROR(StatusParameter) \
475 (VOID) (StatusParameter); \
492#if !defined (MDEPKG_NDEBUG)
493#define ASSERT_RETURN_ERROR(StatusParameter) \
495 if (DebugAssertEnabled ()) { \
496 if (RETURN_ERROR (StatusParameter)) { \
497 DEBUG ((DEBUG_ERROR, "\nASSERT_RETURN_ERROR (Status = %r)\n", \
499 _ASSERT (!RETURN_ERROR (StatusParameter)); \
504#define ASSERT_RETURN_ERROR(StatusParameter) \
507 (VOID) (StatusParameter); \
534#if !defined (MDEPKG_NDEBUG)
535#define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid) \
537 if (DebugAssertEnabled ()) { \
539 ASSERT (Guid != NULL); \
540 if (Handle == NULL) { \
541 if (!EFI_ERROR (gBS->LocateProtocol ((EFI_GUID *)Guid, NULL, &Instance))) { \
542 _ASSERT (Guid already installed in database); \
545 if (!EFI_ERROR (gBS->HandleProtocol (Handle, (EFI_GUID *)Guid, &Instance))) { \
546 _ASSERT (Guid already installed on Handle); \
552#define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid)
564#define DEBUG_CODE_BEGIN() \
566 if (DebugCodeEnabled ()) { \
578#define DEBUG_CODE_END() \
590#define DEBUG_CODE(Expression) \
591 DEBUG_CODE_BEGIN (); \
605#define DEBUG_CLEAR_MEMORY(Address, Length) \
607 if (DebugClearMemoryEnabled ()) { \
608 DebugClearMemory (Address, Length); \
658#if !defined (MDEPKG_NDEBUG)
659#define CR(Record, TYPE, Field, TestSignature) \
660 (DebugAssertEnabled () && (BASE_CR (Record, TYPE, Field)->Signature != TestSignature)) ? \
661 (TYPE *) (_ASSERT (CR has Bad Signature), Record) : \
662 (BASE_CR (Record, TYPE, Field)->Signature != TestSignature) ? \
664 BASE_CR (Record, TYPE, Field)
666#define CR(Record, TYPE, Field, TestSignature) \
667 (BASE_CR (Record, TYPE, Field)->Signature != TestSignature) ? \
669 BASE_CR (Record, TYPE, Field)
VOID EFIAPI DebugAssert(IN CONST CHAR8 *FileName, IN UINTN LineNumber, IN CONST CHAR8 *Description)
VOID EFIAPI DebugVPrint(IN UINTN ErrorLevel, IN CONST CHAR8 *Format, IN VA_LIST VaListMarker)
BOOLEAN EFIAPI DebugPrintLevelEnabled(IN CONST UINTN ErrorLevel)
VOID EFIAPI DebugBPrint(IN UINTN ErrorLevel, IN CONST CHAR8 *Format, IN BASE_LIST BaseListMarker)
VOID *EFIAPI DebugClearMemory(OUT VOID *Buffer, IN UINTN Length)
VOID EFIAPI DebugPrint(IN UINTN ErrorLevel, IN CONST CHAR8 *Format,...)
BOOLEAN EFIAPI DebugCodeEnabled(VOID)
BOOLEAN EFIAPI DebugClearMemoryEnabled(VOID)
BOOLEAN EFIAPI DebugPrintEnabled(VOID)
BOOLEAN EFIAPI DebugAssertEnabled(VOID)
VOID EFIAPI UnitTestDebugAssert(IN CONST CHAR8 *FileName, IN UINTN LineNumber, IN CONST CHAR8 *Description)