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_MANAGEABILITY 0x00800000
53#define DEBUG_ERROR 0x80000000
58#define EFI_D_INIT DEBUG_INIT
59#define EFI_D_WARN DEBUG_WARN
60#define EFI_D_LOAD DEBUG_LOAD
61#define EFI_D_FS DEBUG_FS
62#define EFI_D_POOL DEBUG_POOL
63#define EFI_D_PAGE DEBUG_PAGE
64#define EFI_D_INFO DEBUG_INFO
65#define EFI_D_DISPATCH DEBUG_DISPATCH
66#define EFI_D_VARIABLE DEBUG_VARIABLE
67#define EFI_D_BM DEBUG_BM
68#define EFI_D_BLKIO DEBUG_BLKIO
69#define EFI_D_NET DEBUG_NET
70#define EFI_D_UNDI DEBUG_UNDI
71#define EFI_D_LOADFILE DEBUG_LOADFILE
72#define EFI_D_EVENT DEBUG_EVENT
73#define EFI_D_VERBOSE DEBUG_VERBOSE
74#define EFI_D_ERROR DEBUG_ERROR
85#ifdef DEBUG_LINE_NUMBER
87#define DEBUG_LINE_NUMBER __LINE__
105#ifdef DEBUG_EXPRESSION_STRING_VALUE
106#define DEBUG_EXPRESSION_STRING(Expression) DEBUG_EXPRESSION_STRING_VALUE
108#define DEBUG_EXPRESSION_STRING(Expression) #Expression
321#if defined (EDKII_UNIT_TEST_FRAMEWORK_ENABLED)
342 #if defined (_ASSERT)
345 #if defined (__clang__) && defined (__FILE_NAME__)
346#define _ASSERT(Expression) UnitTestDebugAssert (__FILE_NAME__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))
348#define _ASSERT(Expression) UnitTestDebugAssert (__FILE__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))
351 #if defined (__clang__) && defined (__FILE_NAME__)
352#define _ASSERT(Expression) DebugAssert (__FILE_NAME__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))
354#define _ASSERT(Expression) DebugAssert (__FILE__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))
371#if !defined (MDE_CPU_EBC) && (!defined (_MSC_VER) || _MSC_VER > 1400)
372#define _DEBUG_PRINT(PrintLevel, ...) \
374 if (DebugPrintLevelEnabled (PrintLevel)) { \
375 DebugPrint (PrintLevel, ##__VA_ARGS__); \
378#define _DEBUG(Expression) _DEBUG_PRINT Expression
380#define _DEBUG(Expression) DebugPrint Expression
395#if !defined (MDEPKG_NDEBUG)
396#define ASSERT(Expression) \
398 if (DebugAssertEnabled ()) { \
399 if (!(Expression)) { \
400 _ASSERT (Expression); \
401 ANALYZER_UNREACHABLE (); \
406#define ASSERT(Expression)
421#if !defined (MDEPKG_NDEBUG)
422#define DEBUG(Expression) \
424 if (DebugPrintEnabled ()) { \
425 _DEBUG (Expression); \
429#define DEBUG(Expression)
444#if !defined (MDEPKG_NDEBUG)
445#define ASSERT_EFI_ERROR(StatusParameter) \
447 if (DebugAssertEnabled ()) { \
448 if (EFI_ERROR (StatusParameter)) { \
449 DEBUG ((DEBUG_ERROR, "\nASSERT_EFI_ERROR (Status = %r)\n", StatusParameter)); \
450 _ASSERT (!EFI_ERROR (StatusParameter)); \
455#define ASSERT_EFI_ERROR(StatusParameter)
470#if !defined (MDEPKG_NDEBUG)
471#define ASSERT_RETURN_ERROR(StatusParameter) \
473 if (DebugAssertEnabled ()) { \
474 if (RETURN_ERROR (StatusParameter)) { \
475 DEBUG ((DEBUG_ERROR, "\nASSERT_RETURN_ERROR (Status = %r)\n", \
477 _ASSERT (!RETURN_ERROR (StatusParameter)); \
482#define ASSERT_RETURN_ERROR(StatusParameter)
507#if !defined (MDEPKG_NDEBUG)
508#define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid) \
510 if (DebugAssertEnabled ()) { \
512 ASSERT (Guid != NULL); \
513 if (Handle == NULL) { \
514 if (!EFI_ERROR (gBS->LocateProtocol ((EFI_GUID *)Guid, NULL, &Instance))) { \
515 _ASSERT (Guid already installed in database); \
518 if (!EFI_ERROR (gBS->HandleProtocol (Handle, (EFI_GUID *)Guid, &Instance))) { \
519 _ASSERT (Guid already installed on Handle); \
525#define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid)
537#define DEBUG_CODE_BEGIN() do { if (DebugCodeEnabled ()) { UINT8 __DebugCodeLocal
548#define DEBUG_CODE_END() __DebugCodeLocal = 0; __DebugCodeLocal++; } } while (FALSE)
558#define DEBUG_CODE(Expression) \
559 DEBUG_CODE_BEGIN (); \
573#define DEBUG_CLEAR_MEMORY(Address, Length) \
575 if (DebugClearMemoryEnabled ()) { \
576 DebugClearMemory (Address, Length); \
622#if !defined (MDEPKG_NDEBUG)
623#define CR(Record, TYPE, Field, TestSignature) \
624 (DebugAssertEnabled () && (BASE_CR (Record, TYPE, Field)->Signature != TestSignature)) ? \
625 (TYPE *) (_ASSERT (CR has Bad Signature), Record) : \
626 BASE_CR (Record, TYPE, Field)
628#define CR(Record, TYPE, Field, TestSignature) \
629 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)