16#ifndef __DEBUG_LIB_H__
17#define __DEBUG_LIB_H__
22#define DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED 0x01
23#define DEBUG_PROPERTY_DEBUG_PRINT_ENABLED 0x02
24#define DEBUG_PROPERTY_DEBUG_CODE_ENABLED 0x04
25#define DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED 0x08
26#define DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED 0x10
27#define DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED 0x20
32#define DEBUG_INIT 0x00000001
33#define DEBUG_WARN 0x00000002
34#define DEBUG_LOAD 0x00000004
35#define DEBUG_FS 0x00000008
36#define DEBUG_POOL 0x00000010
37#define DEBUG_PAGE 0x00000020
38#define DEBUG_INFO 0x00000040
39#define DEBUG_DISPATCH 0x00000080
40#define DEBUG_VARIABLE 0x00000100
41#define DEBUG_BM 0x00000400
42#define DEBUG_BLKIO 0x00001000
43#define DEBUG_NET 0x00004000
44#define DEBUG_UNDI 0x00010000
45#define DEBUG_LOADFILE 0x00020000
46#define DEBUG_EVENT 0x00080000
47#define DEBUG_GCD 0x00100000
48#define DEBUG_CACHE 0x00200000
49#define DEBUG_VERBOSE 0x00400000
51#define DEBUG_ERROR 0x80000000
56#define EFI_D_INIT DEBUG_INIT
57#define EFI_D_WARN DEBUG_WARN
58#define EFI_D_LOAD DEBUG_LOAD
59#define EFI_D_FS DEBUG_FS
60#define EFI_D_POOL DEBUG_POOL
61#define EFI_D_PAGE DEBUG_PAGE
62#define EFI_D_INFO DEBUG_INFO
63#define EFI_D_DISPATCH DEBUG_DISPATCH
64#define EFI_D_VARIABLE DEBUG_VARIABLE
65#define EFI_D_BM DEBUG_BM
66#define EFI_D_BLKIO DEBUG_BLKIO
67#define EFI_D_NET DEBUG_NET
68#define EFI_D_UNDI DEBUG_UNDI
69#define EFI_D_LOADFILE DEBUG_LOADFILE
70#define EFI_D_EVENT DEBUG_EVENT
71#define EFI_D_VERBOSE DEBUG_VERBOSE
72#define EFI_D_ERROR DEBUG_ERROR
83#ifdef DEBUG_LINE_NUMBER
85#define DEBUG_LINE_NUMBER __LINE__
103#ifdef DEBUG_EXPRESSION_STRING_VALUE
104#define DEBUG_EXPRESSION_STRING(Expression) DEBUG_EXPRESSION_STRING_VALUE
106#define DEBUG_EXPRESSION_STRING(Expression) #Expression
319#if defined (EDKII_UNIT_TEST_FRAMEWORK_ENABLED)
340 #if defined (__clang__) && defined (__FILE_NAME__)
341#define _ASSERT(Expression) UnitTestDebugAssert (__FILE_NAME__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))
343#define _ASSERT(Expression) UnitTestDebugAssert (__FILE__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))
346 #if defined (__clang__) && defined (__FILE_NAME__)
347#define _ASSERT(Expression) DebugAssert (__FILE_NAME__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))
349#define _ASSERT(Expression) DebugAssert (__FILE__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))
366#if !defined (MDE_CPU_EBC) && (!defined (_MSC_VER) || _MSC_VER > 1400)
367#define _DEBUG_PRINT(PrintLevel, ...) \
369 if (DebugPrintLevelEnabled (PrintLevel)) { \
370 DebugPrint (PrintLevel, ##__VA_ARGS__); \
373#define _DEBUG(Expression) _DEBUG_PRINT Expression
375#define _DEBUG(Expression) DebugPrint Expression
390#if !defined (MDEPKG_NDEBUG)
391#define ASSERT(Expression) \
393 if (DebugAssertEnabled ()) { \
394 if (!(Expression)) { \
395 _ASSERT (Expression); \
396 ANALYZER_UNREACHABLE (); \
401#define ASSERT(Expression)
416#if !defined (MDEPKG_NDEBUG)
417#define DEBUG(Expression) \
419 if (DebugPrintEnabled ()) { \
420 _DEBUG (Expression); \
424#define DEBUG(Expression)
439#if !defined (MDEPKG_NDEBUG)
440#define ASSERT_EFI_ERROR(StatusParameter) \
442 if (DebugAssertEnabled ()) { \
443 if (EFI_ERROR (StatusParameter)) { \
444 DEBUG ((DEBUG_ERROR, "\nASSERT_EFI_ERROR (Status = %r)\n", StatusParameter)); \
445 _ASSERT (!EFI_ERROR (StatusParameter)); \
450#define ASSERT_EFI_ERROR(StatusParameter)
465#if !defined (MDEPKG_NDEBUG)
466#define ASSERT_RETURN_ERROR(StatusParameter) \
468 if (DebugAssertEnabled ()) { \
469 if (RETURN_ERROR (StatusParameter)) { \
470 DEBUG ((DEBUG_ERROR, "\nASSERT_RETURN_ERROR (Status = %r)\n", \
472 _ASSERT (!RETURN_ERROR (StatusParameter)); \
477#define ASSERT_RETURN_ERROR(StatusParameter)
502#if !defined (MDEPKG_NDEBUG)
503#define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid) \
505 if (DebugAssertEnabled ()) { \
507 ASSERT (Guid != NULL); \
508 if (Handle == NULL) { \
509 if (!EFI_ERROR (gBS->LocateProtocol ((EFI_GUID *)Guid, NULL, &Instance))) { \
510 _ASSERT (Guid already installed in database); \
513 if (!EFI_ERROR (gBS->HandleProtocol (Handle, (EFI_GUID *)Guid, &Instance))) { \
514 _ASSERT (Guid already installed on Handle); \
520#define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid)
532#define DEBUG_CODE_BEGIN() do { if (DebugCodeEnabled ()) { UINT8 __DebugCodeLocal
543#define DEBUG_CODE_END() __DebugCodeLocal = 0; __DebugCodeLocal++; } } while (FALSE)
553#define DEBUG_CODE(Expression) \
554 DEBUG_CODE_BEGIN (); \
568#define DEBUG_CLEAR_MEMORY(Address, Length) \
570 if (DebugClearMemoryEnabled ()) { \
571 DebugClearMemory (Address, Length); \
617#if !defined (MDEPKG_NDEBUG)
618#define CR(Record, TYPE, Field, TestSignature) \
619 (DebugAssertEnabled () && (BASE_CR (Record, TYPE, Field)->Signature != TestSignature)) ? \
620 (TYPE *) (_ASSERT (CR has Bad Signature), Record) : \
621 BASE_CR (Record, TYPE, Field)
623#define CR(Record, TYPE, Field, TestSignature) \
624 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)