summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael D Kinney <michael.d.kinney@intel.com>2021-10-12 16:42:28 -0700
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2021-11-08 18:01:35 +0000
commit48452993ad2f6b880f12f0e48512d86e8c5a22e9 (patch)
tree5ad83d1b0c815b42735a47dda7e3d922f6b8d34b
parentb5d4a35d90771ec86ce9cf28727f471ee589fb78 (diff)
downloadedk2-48452993ad2f6b880f12f0e48512d86e8c5a22e9.tar.gz
edk2-48452993ad2f6b880f12f0e48512d86e8c5a22e9.tar.bz2
edk2-48452993ad2f6b880f12f0e48512d86e8c5a22e9.zip
MdePkg/Include: Enhance DebugLib to support reproduce builds
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3688 * Add DEBUG_LINE_NUMBER define to DebugLib.h that is by default mapped to __LINE__. A build can define DEBUG_LINE_NUMBER to use a fixed value. * Add DEBUG_EXPRESSION_STRING(Expression) macros to DebugLib.h that is by default mapped to #Expression. A build can define DEBUG_EXPRESSION_STRING_VALUE to set all expression strings to a fixed string value. Cc: Liming Gao <gaoliming@byosoft.com.cn> Cc: Zhiguang Liu <zhiguang.liu@intel.com> Cc: Michael Kubacki <michael.kubacki@microsoft.com> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Tested-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
-rw-r--r--MdePkg/Include/Library/DebugLib.h43
1 files changed, 39 insertions, 4 deletions
diff --git a/MdePkg/Include/Library/DebugLib.h b/MdePkg/Include/Library/DebugLib.h
index 4cacd4b8e2..7fb75f956c 100644
--- a/MdePkg/Include/Library/DebugLib.h
+++ b/MdePkg/Include/Library/DebugLib.h
@@ -71,6 +71,41 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#define EFI_D_VERBOSE DEBUG_VERBOSE
#define EFI_D_ERROR DEBUG_ERROR
+//
+// Source file line number.
+// Default is use the to compiler provided __LINE__ macro value. The __LINE__
+// mapping can be overriden by predefining DEBUG_LINE_NUMBER
+//
+// Defining DEBUG_LINE_NUMBER to a fixed value is useful when comparing builds
+// across source code formatting changes that may add/remove lines in a source
+// file.
+//
+#ifdef DEBUG_LINE_NUMBER
+#else
+#define DEBUG_LINE_NUMBER __LINE__
+#endif
+
+/**
+ Macro that converts a Boolean expression to a Null-terminated ASCII string.
+
+ The default is to use the C pre-processor stringizing operator '#' to add
+ quotes around the C expression. If DEBUG_EXPRESSION_STRING_VALUE is defined
+ then the C expression is converted to the fixed string value.
+
+ Defining DEBUG_EXPRESSION_STRING_VALUE to a fixed value is useful when
+ comparing builds across source code formatting changes that may make
+ changes to spaces or parenthesis in a Boolean expression.
+
+ @param Expression Boolean expression.
+
+**/
+
+#ifdef DEBUG_EXPRESSION_STRING_VALUE
+#define DEBUG_EXPRESSION_STRING(Expression) DEBUG_EXPRESSION_STRING_VALUE
+#else
+#define DEBUG_EXPRESSION_STRING(Expression) #Expression
+#endif
+
/**
Prints a debug message to the debug output device if the specified error level is enabled.
@@ -310,15 +345,15 @@ UnitTestDebugAssert (
);
#if defined(__clang__) && defined(__FILE_NAME__)
-#define _ASSERT(Expression) UnitTestDebugAssert (__FILE_NAME__, __LINE__, #Expression)
+#define _ASSERT(Expression) UnitTestDebugAssert (__FILE_NAME__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))
#else
-#define _ASSERT(Expression) UnitTestDebugAssert (__FILE__, __LINE__, #Expression)
+#define _ASSERT(Expression) UnitTestDebugAssert (__FILE__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))
#endif
#else
#if defined(__clang__) && defined(__FILE_NAME__)
-#define _ASSERT(Expression) DebugAssert (__FILE_NAME__, __LINE__, #Expression)
+#define _ASSERT(Expression) DebugAssert (__FILE_NAME__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))
#else
-#define _ASSERT(Expression) DebugAssert (__FILE__, __LINE__, #Expression)
+#define _ASSERT(Expression) DebugAssert (__FILE__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))
#endif
#endif