[edk2-devel] [Patch V2] MdePkg DebugLib: Enable FILE NAME as DEBUG ASSERT for CLANG

Zhiguang Liu posted 1 patch 4 years, 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/edk2 tags/patchew/20200318013930.597-1-zhiguang.liu@intel.com
MdePkg/Include/Library/DebugLib.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
[edk2-devel] [Patch V2] MdePkg DebugLib: Enable FILE NAME as DEBUG ASSERT for CLANG
Posted by Zhiguang Liu 4 years, 1 month ago
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1548
For clang compiler, This change will make the generated image not include the
absolute file path. If so, the generated debug image can be reproduced in the
different root directory. Also, it will reduce the size of debug image size.
To do so, use __FILE_NAME__ macro to replace __FILE__. __FILE_NAME__ is
Clang-specific extension that functions similar to __FILE__ but only renders
the last path component (the filename) instead of an invocation dependent full
path to that file, and __FILE_NAME__ is introduced since clang 9.

CC: Michael D Kinney <michael.d.kinney@intel.com>
CC: Liming Gao <liming.gao@intel.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
---
 MdePkg/Include/Library/DebugLib.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/MdePkg/Include/Library/DebugLib.h b/MdePkg/Include/Library/DebugLib.h
index f1d55cf62b..baab34bf05 100644
--- a/MdePkg/Include/Library/DebugLib.h
+++ b/MdePkg/Include/Library/DebugLib.h
@@ -8,7 +8,7 @@
   of size reduction when compiler optimization is disabled. If MDEPKG_NDEBUG is
   defined, then debug and assert related macros wrapped by it are the NULL implementations.
 
-Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -289,7 +289,11 @@ DebugPrintLevelEnabled (
   @param  Expression  Boolean expression that evaluated to FALSE
 
 **/
+#if defined(__clang__) && defined(__FILE_NAME__)
+#define _ASSERT(Expression)  DebugAssert (__FILE_NAME__, __LINE__, #Expression)
+#else
 #define _ASSERT(Expression)  DebugAssert (__FILE__, __LINE__, #Expression)
+#endif
 
 
 /**
-- 
2.25.1.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#55939): https://edk2.groups.io/g/devel/message/55939
Mute This Topic: https://groups.io/mt/72040378/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [Patch V2] MdePkg DebugLib: Enable FILE NAME as DEBUG ASSERT for CLANG
Posted by Liming Gao 4 years, 1 month ago
Zhiguang:

  This change is good. Reviewed-by: Liming Gao <liming.gao@intel.com>

Thanks
Liming
-----Original Message-----
From: Liu, Zhiguang <zhiguang.liu@intel.com> 
Sent: 2020年3月18日 9:40
To: devel@edk2.groups.io
Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: [Patch V2] MdePkg DebugLib: Enable FILE NAME as DEBUG ASSERT for CLANG

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1548
For clang compiler, This change will make the generated image not include the absolute file path. If so, the generated debug image can be reproduced in the different root directory. Also, it will reduce the size of debug image size.
To do so, use __FILE_NAME__ macro to replace __FILE__. __FILE_NAME__ is Clang-specific extension that functions similar to __FILE__ but only renders the last path component (the filename) instead of an invocation dependent full path to that file, and __FILE_NAME__ is introduced since clang 9.

CC: Michael D Kinney <michael.d.kinney@intel.com>
CC: Liming Gao <liming.gao@intel.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
---
 MdePkg/Include/Library/DebugLib.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/MdePkg/Include/Library/DebugLib.h b/MdePkg/Include/Library/DebugLib.h
index f1d55cf62b..baab34bf05 100644
--- a/MdePkg/Include/Library/DebugLib.h
+++ b/MdePkg/Include/Library/DebugLib.h
@@ -8,7 +8,7 @@
   of size reduction when compiler optimization is disabled. If MDEPKG_NDEBUG is   defined, then debug and assert related macros wrapped by it are the NULL implementations. -Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>+Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent  **/@@ -289,7 +289,11 @@ DebugPrintLevelEnabled (
   @param  Expression  Boolean expression that evaluated to FALSE  **/+#if defined(__clang__) && defined(__FILE_NAME__)+#define _ASSERT(Expression)  DebugAssert (__FILE_NAME__, __LINE__, #Expression)+#else #define _ASSERT(Expression)  DebugAssert (__FILE__, __LINE__, #Expression)+#endif   /**-- 
2.25.1.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#55945): https://edk2.groups.io/g/devel/message/55945
Mute This Topic: https://groups.io/mt/72040378/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-