]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Include/Library/DebugLib.h
PI 1.1 SMM Feature Check-in
[mirror_edk2.git] / MdePkg / Include / Library / DebugLib.h
index 5f0c923fb45e93886a162dc0b41ae6d8c623e122..836d807dcfe1bc17d1393356412a9a0e0367b0f7 100644 (file)
@@ -1,14 +1,21 @@
 /** @file\r
-  Public include file for the Debug Library\r
+  Provides services to print debug and assert messages to a debug output device.\r
+  \r
+  The Debug library supports debug print and asserts based on a combination of macros and code.\r
+  The debug library can be turned on and off so that the debug code does not increase the size of an image.\r
+\r
+  Note that a MDEPKG_NDEBUG macro is introduced to switch on/off debug and assert related macros.\r
+  1. If MDEPKG_NDEBUG is defined, then debug and assert related macros are NULL.\r
+  2. If MDEPKG_NDEBUG is not defined, then PcdDebugProperyMask is used to turn on/off these helper macros.\r
 \r
-  Copyright (c) 2006, Intel Corporation                                                         \r
-  All rights reserved. This program and the accompanying materials                          \r
-  are licensed and made available under the terms and conditions of the BSD License         \r
-  which accompanies this distribution.  The full text of the license may be found at        \r
-  http://opensource.org/licenses/bsd-license.php                                            \r
+Copyright (c) 2006 - 2008, Intel Corporation<BR>\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
 \r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 **/\r
 \r
@@ -35,6 +42,7 @@
 #define DEBUG_POOL      0x00000010  // Alloc & Free's\r
 #define DEBUG_PAGE      0x00000020  // Alloc & Free's\r
 #define DEBUG_INFO      0x00000040  // Verbose\r
+#define DEBUG_DISPATCH  0x00000080  // PEI/DXE Dispatchers\r
 #define DEBUG_VARIABLE  0x00000100  // Variable\r
 #define DEBUG_BM        0x00000400  // Boot Manager\r
 #define DEBUG_BLKIO     0x00001000  // BlkIo Driver\r
@@ -54,6 +62,7 @@
 #define EFI_D_POOL      DEBUG_POOL\r
 #define EFI_D_PAGE      DEBUG_PAGE\r
 #define EFI_D_INFO      DEBUG_INFO\r
+#define EFI_D_DISPATCH  DEBUG_DISPATCH\r
 #define EFI_D_VARIABLE  DEBUG_VARIABLE\r
 #define EFI_D_BM        DEBUG_BM\r
 #define EFI_D_BLKIO     DEBUG_BLKIO\r
@@ -64,7 +73,6 @@
 #define EFI_D_ERROR     DEBUG_ERROR\r
 \r
 /**\r
-\r
   Prints a debug message to the debug output device if the specified error level is enabled.\r
 \r
   If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print \r
@@ -75,7 +83,8 @@
 \r
   @param  ErrorLevel  The error level of the debug message.\r
   @param  Format      Format string for the debug message to print.\r
-  @param  ...         The variable argument list.\r
+  @param  ...         Variable argument list whose contents are accessed \r
+                      based on the format string specified by Format.\r
 \r
 **/\r
 VOID\r
@@ -88,7 +97,6 @@ DebugPrint (
 \r
 \r
 /**\r
-\r
   Prints an assert message containing a filename, line number, and description.  \r
   This may be followed by a breakpoint or a dead loop.\r
 \r
@@ -98,12 +106,11 @@ DebugPrint (
   DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then \r
   CpuDeadLoop() is called.  If neither of these bits are set, then this function \r
   returns immediately after the message is printed to the debug output device.\r
-  DebugAssert() must actively prevent recusrsion.  If DebugAssert() is called while\r
+  DebugAssert() must actively prevent recursion.  If DebugAssert() is called while\r
   processing another DebugAssert(), then DebugAssert() must return immediately.\r
 \r
-  If FileName is NULL, then a <FileName> string of ?NULL) Filename?is printed.\r
-\r
-  If Description is NULL, then a <Description> string of ?NULL) Description?is printed.\r
+  If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r
+  If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r
 \r
   @param  FileName     Pointer to the name of the source file that generated the assert condition.\r
   @param  LineNumber   The line number in the source file that generated the assert condition\r
@@ -120,15 +127,13 @@ DebugAssert (
 \r
 \r
 /**\r
-\r
   Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r
 \r
   This function fills Length bytes of Buffer with the value specified by \r
   PcdDebugClearMemoryValue, and returns Buffer.\r
 \r
   If Buffer is NULL, then ASSERT().\r
-\r
-  If Length is greater than (MAX_ADDRESS ?Buffer + 1), then ASSERT(). \r
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
 \r
   @param   Buffer  Pointer to the target buffer to be filled with PcdDebugClearMemoryValue.\r
   @param   Length  Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue. \r
@@ -145,7 +150,6 @@ DebugClearMemory (
 \r
 \r
 /**\r
-  \r
   Returns TRUE if ASSERT() macros are enabled.\r
 \r
   This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of \r
@@ -162,9 +166,8 @@ DebugAssertEnabled (
   );\r
 \r
 \r
-/**\r
-  \r
-  Returns TRUE if DEBUG()macros are enabled.\r
+/**  \r
+  Returns TRUE if DEBUG() macros are enabled.\r
 \r
   This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of \r
   PcdDebugProperyMask is set.  Otherwise FALSE is returned.\r
@@ -180,9 +183,8 @@ DebugPrintEnabled (
   );\r
 \r
 \r
-/**\r
-  \r
-  Returns TRUE if DEBUG_CODE()macros are enabled.\r
+/**  \r
+  Returns TRUE if DEBUG_CODE() macros are enabled.\r
 \r
   This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of \r
   PcdDebugProperyMask is set.  Otherwise FALSE is returned.\r
@@ -198,9 +200,8 @@ DebugCodeEnabled (
   );\r
 \r
 \r
-/**\r
-  \r
-  Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.\r
+/**  \r
+  Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.\r
 \r
   This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of \r
   PcdDebugProperyMask is set.  Otherwise FALSE is returned.\r
@@ -216,21 +217,19 @@ DebugClearMemoryEnabled (
   );\r
 \r
 \r
-/**\r
-  \r
+/**  \r
   Internal worker macro that calls DebugAssert().\r
 \r
-  This macro calls DebugAssert() passing in the filename, line number, and \r
-  expression that evailated to FALSE.\r
+  This macro calls DebugAssert(), passing in the filename, line number, and an\r
+  expression that evaluated to FALSE.\r
 \r
-  @param  Expression  Boolean expression that evailated to FALSE\r
+  @param  Expression  Boolean expression that evaluated to FALSE\r
 \r
 **/\r
 #define _ASSERT(Expression)  DebugAssert (__FILE__, __LINE__, #Expression)\r
 \r
 \r
-/**\r
-  \r
+/**  \r
   Internal worker macro that calls DebugPrint().\r
 \r
   This macro calls DebugPrint() passing in the debug error level, a format \r
@@ -243,78 +242,86 @@ DebugClearMemoryEnabled (
 #define _DEBUG(Expression)   DebugPrint Expression\r
 \r
 \r
-/**\r
-  \r
-  Macro that calls DebugAssert() if a expression evaluates to FALSE.\r
+/**  \r
+  Macro that calls DebugAssert() if an expression evaluates to FALSE.\r
 \r
-  If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set, \r
-  then this macro evaluates the Boolean expression specified by Expression.  If \r
-  Expression evaluates to FALSE, then DebugAssert() is called passing in the \r
-  source filename, source line number, and Expression.\r
+  If MDEPKG_NDEBUG is not defined and the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED \r
+  bit of PcdDebugProperyMask is set, then this macro evaluates the Boolean \r
+  expression specified by Expression.  If Expression evaluates to FALSE, then \r
+  DebugAssert() is called passing in the source filename, source line number, \r
+  and Expression.\r
 \r
   @param  Expression  Boolean expression\r
 \r
 **/\r
-#define ASSERT(Expression)        \\r
-  do {                            \\r
-    if (DebugAssertEnabled ()) {  \\r
-      if (!(Expression)) {        \\r
-        _ASSERT (Expression);     \\r
-      }                           \\r
-    }                             \\r
-  } while (FALSE)\r
-\r
+#if !defined(MDEPKG_NDEBUG)       \r
+  #define ASSERT(Expression)        \\r
+    do {                            \\r
+      if (DebugAssertEnabled ()) {  \\r
+        if (!(Expression)) {        \\r
+          _ASSERT (Expression);     \\r
+        }                           \\r
+      }                             \\r
+    } while (FALSE)\r
+#else\r
+  #define ASSERT(Expression)\r
+#endif\r
 \r
-/**\r
-  \r
+/**  \r
   Macro that calls DebugPrint().\r
 \r
-  If the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set, \r
-  then this macro passes Expression to DebugPrint().\r
+  If MDEPKG_NDEBUG is not defined and the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED \r
+  bit of PcdDebugProperyMask is set, then this macro passes Expression to \r
+  DebugPrint().\r
 \r
   @param  Expression  Expression containing an error level, a format string, \r
                       and a variable argument list based on the format string.\r
   \r
 \r
 **/\r
-#define DEBUG(Expression)        \\r
-  do {                           \\r
-    if (DebugPrintEnabled ()) {  \\r
-      _DEBUG (Expression);       \\r
-    }                            \\r
-  } while (FALSE)\r
-\r
+#if !defined(MDEPKG_NDEBUG)      \r
+  #define DEBUG(Expression)        \\r
+    do {                           \\r
+      if (DebugPrintEnabled ()) {  \\r
+        _DEBUG (Expression);       \\r
+      }                            \\r
+    } while (FALSE)\r
+#else\r
+  #define DEBUG(Expression)\r
+#endif\r
 \r
-/**\r
-  \r
+/**  \r
   Macro that calls DebugAssert() if an EFI_STATUS evaluates to an error code.\r
 \r
-  If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set, \r
-  then this macro evaluates the EFI_STATUS value specified by StatusParameter.  \r
-  If StatusParameter is an error code, then DebugAssert() is called passing in \r
-  the source filename, source line number, and StatusParameter.\r
+  If MDEPKG_NDEBUG is not defined and the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED \r
+  bit of PcdDebugProperyMask is set, then this macro evaluates the EFI_STATUS \r
+  value specified by StatusParameter.  If StatusParameter is an error code, \r
+  then DebugAssert() is called passing in the source filename, source line \r
+  number, and StatusParameter.\r
 \r
   @param  StatusParameter  EFI_STATUS value to evaluate.\r
 \r
 **/\r
-#define ASSERT_EFI_ERROR(StatusParameter)                                              \\r
-  do {                                                                                 \\r
-    if (DebugAssertEnabled ()) {                                                       \\r
-      if (EFI_ERROR (StatusParameter)) {                                               \\r
-        DEBUG ((EFI_D_ERROR, "\nASSERT_EFI_ERROR (Status = %r)\n", StatusParameter));  \\r
-        _ASSERT (!EFI_ERROR (StatusParameter));                                        \\r
-      }                                                                                \\r
-    }                                                                                  \\r
-  } while (FALSE)\r
-\r
+#if !defined(MDEPKG_NDEBUG)\r
+  #define ASSERT_EFI_ERROR(StatusParameter)                                              \\r
+    do {                                                                                 \\r
+      if (DebugAssertEnabled ()) {                                                       \\r
+        if (EFI_ERROR (StatusParameter)) {                                               \\r
+          DEBUG ((EFI_D_ERROR, "\nASSERT_EFI_ERROR (Status = %r)\n", StatusParameter));  \\r
+          _ASSERT (!EFI_ERROR (StatusParameter));                                        \\r
+        }                                                                                \\r
+      }                                                                                  \\r
+    } while (FALSE)\r
+#else\r
+  #define ASSERT_EFI_ERROR(StatusParameter)\r
+#endif\r
 \r
-/**\r
-  \r
+/**  \r
   Macro that calls DebugAssert() if a protocol is already installed in the \r
   handle database.\r
 \r
-  If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear, \r
-  then return.\r
+  If MDEPKG_NDEBUG is defined or the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit \r
+  of PcdDebugProperyMask is clear, then return.\r
 \r
   If Handle is NULL, then a check is made to see if the protocol specified by Guid \r
   is present on any handle in the handle database.  If Handle is not NULL, then \r
@@ -331,23 +338,26 @@ DebugClearMemoryEnabled (
   @param  Guid    Pointer to a protocol GUID.\r
 \r
 **/\r
-#define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid)                               \\r
-  do {                                                                                \\r
-    if (DebugAssertEnabled ()) {                                                      \\r
-      VOID  *Instance;                                                                \\r
-      ASSERT (Guid != NULL);                                                          \\r
-      if (Handle == NULL) {                                                           \\r
-        if (!EFI_ERROR (gBS->LocateProtocol ((EFI_GUID *)Guid, NULL, &Instance))) {   \\r
-          _ASSERT (Guid already installed in database);                               \\r
-        }                                                                             \\r
-      } else {                                                                        \\r
-        if (!EFI_ERROR (gBS->HandleProtocol (Handle, (EFI_GUID *)Guid, &Instance))) { \\r
-          _ASSERT (Guid already installed on Handle);                                 \\r
-        }                                                                             \\r
-      }                                                                               \\r
-    }                                                                                 \\r
-  } while (FALSE)\r
-\r
+#if !defined(MDEPKG_NDEBUG)\r
+  #define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid)                               \\r
+    do {                                                                                \\r
+      if (DebugAssertEnabled ()) {                                                      \\r
+        VOID  *Instance;                                                                \\r
+        ASSERT (Guid != NULL);                                                          \\r
+        if (Handle == NULL) {                                                           \\r
+          if (!EFI_ERROR (gBS->LocateProtocol ((EFI_GUID *)Guid, NULL, &Instance))) {   \\r
+            _ASSERT (Guid already installed in database);                               \\r
+          }                                                                             \\r
+        } else {                                                                        \\r
+          if (!EFI_ERROR (gBS->HandleProtocol (Handle, (EFI_GUID *)Guid, &Instance))) { \\r
+            _ASSERT (Guid already installed on Handle);                                 \\r
+          }                                                                             \\r
+        }                                                                               \\r
+      }                                                                                 \\r
+    } while (FALSE)\r
+#else\r
+  #define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid)\r
+#endif\r
 \r
 /**\r
   Macro that marks the beginning of debug source code.\r
@@ -361,8 +371,7 @@ DebugClearMemoryEnabled (
 #define DEBUG_CODE_BEGIN()  do { if (DebugCodeEnabled ()) { UINT8  __DebugCodeLocal\r
 \r
 \r
-/**\r
-  \r
+/**  \r
   Macro that marks the end of debug source code.\r
 \r
   If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set, \r
@@ -374,8 +383,7 @@ DebugClearMemoryEnabled (
 #define DEBUG_CODE_END()    __DebugCodeLocal = 0; __DebugCodeLocal++; } } while (FALSE)\r
 \r
 \r
-/**\r
-  \r
+/**  \r
   Macro that declares a section of debug source code.\r
 \r
   If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set, \r
@@ -389,8 +397,7 @@ DebugClearMemoryEnabled (
   DEBUG_CODE_END ()\r
 \r
 \r
-/**\r
-  \r
+/**  \r
   Macro that calls DebugClearMemory() to clear a buffer to a default value.\r
 \r
   If the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set, \r
@@ -409,7 +416,6 @@ DebugClearMemoryEnabled (
 \r
 \r
 /**\r
-\r
   Macro that calls DebugAssert() if the containing record does not have a \r
   matching signature.  If the signatures matches, then a pointer to the data \r
   structure that contains a specified field of that data structure is returned.  \r
@@ -417,21 +423,21 @@ DebugClearMemoryEnabled (
   structure inside a larger private data structure and using a pointer to the \r
   public data structure to retrieve a pointer to the private data structure.\r
 \r
-  If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear, \r
-  then this macro computes the offset, in bytes, of field specified by Field \r
-  from the beginning of the  data structure specified by TYPE.  This offset is \r
-  subtracted from Record, and is used to return a pointer to a data structure \r
-  of the type specified by TYPE.\r
-\r
-  If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set,  \r
-  then this macro computes the offset, in bytes, of field specified by Field from \r
-  the beginning of the data structure specified by TYPE.  This offset is \r
-  subtracted from Record, and is used to compute a pointer to a data structure of \r
-  the type specified by TYPE.  The Signature field of the data structure specified \r
-  by TYPE is compared to TestSignature.  If the signatures match, then a pointer \r
-  to the pointer to a data structure of the type specified by TYPE is returned.  \r
-  If the signatures do not match, then DebugAssert() is called with a description \r
-  of "CR has a bad signature" and Record is returned.  \r
+  If MDEPKG_NDEBUG is defined or the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit \r
+  of PcdDebugProperyMask is clear, then this macro computes the offset, in bytes,\r
+  of field specified by Field from the beginning of the  data structure specified \r
+  by TYPE.  This offset is subtracted from Record, and is used to return a pointer \r
+  to a data structure of the type specified by TYPE.\r
+\r
+  If MDEPKG_NDEBUG is not defined and the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit\r
+  of PcdDebugProperyMask is set, then this macro computes the offset, in bytes, \r
+  of field specified by Field from the beginning of the data structure specified \r
+  by TYPE.  This offset is subtracted from Record, and is used to compute a pointer\r
+  to a data structure of the type specified by TYPE.  The Signature field of the \r
+  data structure specified by TYPE is compared to TestSignature.  If the signatures \r
+  match, then a pointer to the pointer to a data structure of the type specified by \r
+  TYPE is returned.  If the signatures do not match, then DebugAssert() is called \r
+  with a description of "CR has a bad signature" and Record is returned.  \r
 \r
   If the data type specified by TYPE does not contain the field specified by Field, \r
   then the module will not compile.\r
@@ -451,9 +457,14 @@ DebugClearMemoryEnabled (
   @param  TestSignature  The 32-bit signature value to match.\r
 \r
 **/\r
-#define CR(Record, TYPE, Field, TestSignature)                                          \\r
-  (DebugAssertEnabled () && (_CR (Record, TYPE, Field)->Signature != TestSignature)) ?  \\r
-  (TYPE *) (_ASSERT (CR has Bad Signature), Record) :                                   \\r
-  _CR (Record, TYPE, Field)\r
+#if !defined(MDEPKG_NDEBUG)\r
+  #define CR(Record, TYPE, Field, TestSignature)                                              \\r
+    (DebugAssertEnabled () && (BASE_CR (Record, TYPE, Field)->Signature != TestSignature)) ?  \\r
+    (TYPE *) (_ASSERT (CR has Bad Signature), Record) :                                       \\r
+    BASE_CR (Record, TYPE, Field)\r
+#else\r
+  #define CR(Record, TYPE, Field, TestSignature)                                              \\r
+    BASE_CR (Record, TYPE, Field)\r
+#endif\r
     \r
 #endif\r