]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Include/Library/DebugLib.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Include / Library / DebugLib.h
index e6a7a357b2cd574a597f567047daed87b83c929c..9110be2f41b394ab44cf283ee4f2382386b8f4bc 100644 (file)
@@ -8,14 +8,8 @@
   of size reduction when compiler optimization is disabled. If MDEPKG_NDEBUG is\r
   defined, then debug and assert related macros wrapped by it are the NULL implementations.\r
 \r
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials are licensed and made available under\r
-the terms and conditions of the BSD License that accompanies this distribution.\r
-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
+Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -54,7 +48,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define DEBUG_CACHE     0x00200000  // Memory range cachability changes\r
 #define DEBUG_VERBOSE   0x00400000  // Detailed debug messages that may\r
                                     // significantly impact boot performance\r
-#define DEBUG_ERROR     0x80000000  // Error\r
+#define DEBUG_ERROR  0x80000000     // Error\r
 \r
 //\r
 // Aliases of debug message mask bits\r
@@ -77,6 +71,41 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define EFI_D_VERBOSE   DEBUG_VERBOSE\r
 #define EFI_D_ERROR     DEBUG_ERROR\r
 \r
+//\r
+// Source file line number.\r
+// Default is use the to compiler provided __LINE__ macro value. The __LINE__\r
+// mapping can be overriden by predefining DEBUG_LINE_NUMBER\r
+//\r
+// Defining DEBUG_LINE_NUMBER to a fixed value is useful when comparing builds\r
+// across source code formatting changes that may add/remove lines in a source\r
+// file.\r
+//\r
+#ifdef DEBUG_LINE_NUMBER\r
+#else\r
+#define DEBUG_LINE_NUMBER  __LINE__\r
+#endif\r
+\r
+/**\r
+  Macro that converts a Boolean expression to a Null-terminated ASCII string.\r
+\r
+  The default is to use the C pre-processor stringizing operator '#' to add\r
+  quotes around the C expression. If DEBUG_EXPRESSION_STRING_VALUE is defined\r
+  then the C expression is converted to the fixed string value.\r
+\r
+  Defining DEBUG_EXPRESSION_STRING_VALUE to a fixed value is useful when\r
+  comparing builds across source code formatting changes that may make\r
+  changes to spaces or parenthesis in a Boolean expression.\r
+\r
+  @param  Expression  Boolean expression.\r
+\r
+**/\r
+\r
+#ifdef DEBUG_EXPRESSION_STRING_VALUE\r
+#define DEBUG_EXPRESSION_STRING(Expression)  DEBUG_EXPRESSION_STRING_VALUE\r
+#else\r
+#define DEBUG_EXPRESSION_STRING(Expression)  #Expression\r
+#endif\r
+\r
 /**\r
   Prints a debug message to the debug output device if the specified error level is enabled.\r
 \r
@@ -100,6 +129,53 @@ DebugPrint (
   ...\r
   );\r
 \r
+/**\r
+  Prints a debug message to the debug output device if the specified\r
+  error level is enabled.\r
+\r
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r
+  GetDebugPrintErrorLevel (), then print the message specified by Format and\r
+  the associated variable argument list to the debug output device.\r
+\r
+  If Format is NULL, then ASSERT().\r
+\r
+  @param  ErrorLevel    The error level of the debug message.\r
+  @param  Format        Format string for the debug message to print.\r
+  @param  VaListMarker  VA_LIST marker for the variable argument list.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+DebugVPrint (\r
+  IN  UINTN        ErrorLevel,\r
+  IN  CONST CHAR8  *Format,\r
+  IN  VA_LIST      VaListMarker\r
+  );\r
+\r
+/**\r
+  Prints a debug message to the debug output device if the specified\r
+  error level is enabled.\r
+  This function use BASE_LIST which would provide a more compatible\r
+  service than VA_LIST.\r
+\r
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r
+  GetDebugPrintErrorLevel (), then print the message specified by Format and\r
+  the associated variable argument list to the debug output device.\r
+\r
+  If Format is NULL, then ASSERT().\r
+\r
+  @param  ErrorLevel      The error level of the debug message.\r
+  @param  Format          Format string for the debug message to print.\r
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+DebugBPrint (\r
+  IN  UINTN        ErrorLevel,\r
+  IN  CONST CHAR8  *Format,\r
+  IN  BASE_LIST    BaseListMarker\r
+  );\r
 \r
 /**\r
   Prints an assert message containing a filename, line number, and description.\r
@@ -130,7 +206,6 @@ DebugAssert (
   IN CONST CHAR8  *Description\r
   );\r
 \r
-\r
 /**\r
   Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r
 \r
@@ -153,7 +228,6 @@ DebugClearMemory (
   IN UINTN  Length\r
   );\r
 \r
-\r
 /**\r
   Returns TRUE if ASSERT() macros are enabled.\r
 \r
@@ -170,7 +244,6 @@ DebugAssertEnabled (
   VOID\r
   );\r
 \r
-\r
 /**\r
   Returns TRUE if DEBUG() macros are enabled.\r
 \r
@@ -187,7 +260,6 @@ DebugPrintEnabled (
   VOID\r
   );\r
 \r
-\r
 /**\r
   Returns TRUE if DEBUG_CODE() macros are enabled.\r
 \r
@@ -204,7 +276,6 @@ DebugCodeEnabled (
   VOID\r
   );\r
 \r
-\r
 /**\r
   Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.\r
 \r
@@ -233,7 +304,7 @@ DebugClearMemoryEnabled (
 BOOLEAN\r
 EFIAPI\r
 DebugPrintLevelEnabled (\r
-  IN  CONST UINTN        ErrorLevel\r
+  IN  CONST UINTN  ErrorLevel\r
   );\r
 \r
 /**\r
@@ -245,8 +316,42 @@ DebugPrintLevelEnabled (
   @param  Expression  Boolean expression that evaluated to FALSE\r
 \r
 **/\r
-#define _ASSERT(Expression)  DebugAssert (__FILE__, __LINE__, #Expression)\r
+#if defined (EDKII_UNIT_TEST_FRAMEWORK_ENABLED)\r
+\r
+/**\r
+  Unit test library replacement for DebugAssert() in DebugLib.\r
+\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     The 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
+  @param  Description  The pointer to the description of the assert condition.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+UnitTestDebugAssert (\r
+  IN CONST CHAR8  *FileName,\r
+  IN UINTN        LineNumber,\r
+  IN CONST CHAR8  *Description\r
+  );\r
 \r
+  #if defined (_ASSERT)\r
+    #undef _ASSERT\r
+  #endif\r
+  #if defined (__clang__) && defined (__FILE_NAME__)\r
+#define _ASSERT(Expression)  UnitTestDebugAssert (__FILE_NAME__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))\r
+  #else\r
+#define _ASSERT(Expression)  UnitTestDebugAssert (__FILE__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))\r
+  #endif\r
+#else\r
+  #if defined (__clang__) && defined (__FILE_NAME__)\r
+#define _ASSERT(Expression)  DebugAssert (__FILE_NAME__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))\r
+  #else\r
+#define _ASSERT(Expression)  DebugAssert (__FILE__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))\r
+  #endif\r
+#endif\r
 \r
 /**\r
   Internal worker macro that calls DebugPrint().\r
@@ -261,16 +366,16 @@ DebugPrintLevelEnabled (
 \r
 **/\r
 \r
-#if !defined(MDE_CPU_EBC) && (!defined (_MSC_VER) || _MSC_VER > 1400)\r
-  #define _DEBUG_PRINT(PrintLevel, ...)              \\r
+#if !defined (MDE_CPU_EBC) && (!defined (_MSC_VER) || _MSC_VER > 1400)\r
+#define _DEBUG_PRINT(PrintLevel, ...)              \\r
     do {                                             \\r
       if (DebugPrintLevelEnabled (PrintLevel)) {     \\r
         DebugPrint (PrintLevel, ##__VA_ARGS__);      \\r
       }                                              \\r
     } while (FALSE)\r
-  #define _DEBUG(Expression)   _DEBUG_PRINT Expression\r
+#define _DEBUG(Expression)  _DEBUG_PRINT Expression\r
 #else\r
-#define _DEBUG(Expression)   DebugPrint Expression\r
+#define _DEBUG(Expression)  DebugPrint Expression\r
 #endif\r
 \r
 /**\r
@@ -285,8 +390,8 @@ DebugPrintLevelEnabled (
   @param  Expression  Boolean expression.\r
 \r
 **/\r
-#if !defined(MDEPKG_NDEBUG)\r
-  #define ASSERT(Expression)        \\r
+#if !defined (MDEPKG_NDEBUG)\r
+#define ASSERT(Expression)        \\r
     do {                            \\r
       if (DebugAssertEnabled ()) {  \\r
         if (!(Expression)) {        \\r
@@ -296,7 +401,7 @@ DebugPrintLevelEnabled (
       }                             \\r
     } while (FALSE)\r
 #else\r
-  #define ASSERT(Expression)\r
+#define ASSERT(Expression)\r
 #endif\r
 \r
 /**\r
@@ -311,15 +416,15 @@ DebugPrintLevelEnabled (
 \r
 \r
 **/\r
-#if !defined(MDEPKG_NDEBUG)\r
-  #define DEBUG(Expression)        \\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
+#define DEBUG(Expression)\r
 #endif\r
 \r
 /**\r
@@ -334,18 +439,18 @@ DebugPrintLevelEnabled (
   @param  StatusParameter  EFI_STATUS value to evaluate.\r
 \r
 **/\r
-#if !defined(MDEPKG_NDEBUG)\r
-  #define ASSERT_EFI_ERROR(StatusParameter)                                              \\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
+          DEBUG ((DEBUG_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
+#define ASSERT_EFI_ERROR(StatusParameter)\r
 #endif\r
 \r
 /**\r
@@ -360,8 +465,8 @@ DebugPrintLevelEnabled (
   @param  StatusParameter  RETURN_STATUS value to evaluate.\r
 \r
 **/\r
-#if !defined(MDEPKG_NDEBUG)\r
-  #define ASSERT_RETURN_ERROR(StatusParameter)                          \\r
+#if !defined (MDEPKG_NDEBUG)\r
+#define ASSERT_RETURN_ERROR(StatusParameter)                          \\r
     do {                                                                \\r
       if (DebugAssertEnabled ()) {                                      \\r
         if (RETURN_ERROR (StatusParameter)) {                           \\r
@@ -372,7 +477,7 @@ DebugPrintLevelEnabled (
       }                                                                 \\r
     } while (FALSE)\r
 #else\r
-  #define ASSERT_RETURN_ERROR(StatusParameter)\r
+#define ASSERT_RETURN_ERROR(StatusParameter)\r
 #endif\r
 \r
 /**\r
@@ -397,8 +502,8 @@ DebugPrintLevelEnabled (
   @param  Guid    The pointer to a protocol GUID.\r
 \r
 **/\r
-#if !defined(MDEPKG_NDEBUG)\r
-  #define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid)                               \\r
+#if !defined (MDEPKG_NDEBUG)\r
+#define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid)                               \\r
     do {                                                                                \\r
       if (DebugAssertEnabled ()) {                                                      \\r
         VOID  *Instance;                                                                \\r
@@ -415,7 +520,7 @@ DebugPrintLevelEnabled (
       }                                                                                 \\r
     } while (FALSE)\r
 #else\r
-  #define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid)\r
+#define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid)\r
 #endif\r
 \r
 /**\r
@@ -429,7 +534,6 @@ DebugPrintLevelEnabled (
 **/\r
 #define DEBUG_CODE_BEGIN()  do { if (DebugCodeEnabled ()) { UINT8  __DebugCodeLocal\r
 \r
-\r
 /**\r
   The macro that marks the end of debug source code.\r
 \r
@@ -439,8 +543,7 @@ DebugPrintLevelEnabled (
   are not included in a module.\r
 \r
 **/\r
-#define DEBUG_CODE_END()    __DebugCodeLocal = 0; __DebugCodeLocal++; } } while (FALSE)\r
-\r
+#define DEBUG_CODE_END()  __DebugCodeLocal = 0; __DebugCodeLocal++; } } while (FALSE)\r
 \r
 /**\r
   The macro that declares a section of debug source code.\r
@@ -455,7 +558,6 @@ DebugPrintLevelEnabled (
   Expression                    \\r
   DEBUG_CODE_END ()\r
 \r
-\r
 /**\r
   The macro that calls DebugClearMemory() to clear a buffer to a default value.\r
 \r
@@ -473,7 +575,6 @@ DebugPrintLevelEnabled (
     }                                        \\r
   } while (FALSE)\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
@@ -516,13 +617,13 @@ DebugPrintLevelEnabled (
   @param  TestSignature  The 32-bit signature value to match.\r
 \r
 **/\r
-#if !defined(MDEPKG_NDEBUG)\r
-  #define CR(Record, TYPE, Field, TestSignature)                                              \\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
+#define CR(Record, TYPE, Field, TestSignature)                                              \\r
     BASE_CR (Record, TYPE, Field)\r
 #endif\r
 \r