From 08bcaf20b1320845ff4b140423dc4023695fe0fd Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Fri, 21 Oct 2016 13:01:44 +0200 Subject: [PATCH] MdePkg/DebugLib.h: add ASSERT_RETURN_ERROR() ASSERT_EFI_ERROR() cannot be used in BASE type modules because - the replacement text calls EFI_ERROR(), - EFI_ERROR() is defined in "MdePkg/Include/Uefi/UefiBaseType.h", - the inclusion of "UefiBaseType.h" is not required for BASE type modules. While ASSERT (!RETURN_ERROR (StatusParameter)) would be a functional statement in BASE type modules, it would be less convenient and less informative: ASSERT_EFI_ERROR() prints the actual StatusParameter. Hence add ASSERT_RETURN_ERROR(), paralleling ASSERT_EFI_ERROR(). Copy the original macro definition and update it as follows: - replace EFI with RETURN, - wrap overlong lines in the comment block and in the code, - EFI_D_ERROR is deprecated, so employ DEBUG_ERROR instead. Cc: Liming Gao Cc: Michael D Kinney Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=166 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek Reviewed-by: Michael Kinney Tested-by: Ard Biesheuvel # RVCT Reviewed-by: Jordan Justen --- MdePkg/Include/Library/DebugLib.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/MdePkg/Include/Library/DebugLib.h b/MdePkg/Include/Library/DebugLib.h index 8190432570..3a910e6a20 100644 --- a/MdePkg/Include/Library/DebugLib.h +++ b/MdePkg/Include/Library/DebugLib.h @@ -348,6 +348,33 @@ DebugPrintLevelEnabled ( #define ASSERT_EFI_ERROR(StatusParameter) #endif +/** + Macro that calls DebugAssert() if a RETURN_STATUS evaluates to an error code. + + If MDEPKG_NDEBUG is not defined and the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED + bit of PcdDebugProperyMask is set, then this macro evaluates the + RETURN_STATUS value specified by StatusParameter. If StatusParameter is an + error code, then DebugAssert() is called passing in the source filename, + source line number, and StatusParameter. + + @param StatusParameter RETURN_STATUS value to evaluate. + +**/ +#if !defined(MDEPKG_NDEBUG) + #define ASSERT_RETURN_ERROR(StatusParameter) \ + do { \ + if (DebugAssertEnabled ()) { \ + if (RETURN_ERROR (StatusParameter)) { \ + DEBUG ((DEBUG_ERROR, "\nASSERT_RETURN_ERROR (Status = %r)\n", \ + StatusParameter)); \ + _ASSERT (!RETURN_ERROR (StatusParameter)); \ + } \ + } \ + } while (FALSE) +#else + #define ASSERT_RETURN_ERROR(StatusParameter) +#endif + /** Macro that calls DebugAssert() if a protocol is already installed in the handle database. -- 2.39.2