mirror of https://github.com/acidanthera/audk.git
Introduce a MDEPKG_NDEBUG macro to provide a method which can be used to reduce code size when compiler optimization is disabled.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9560 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
4b37cc04b7
commit
c9ec70470d
|
@ -3,7 +3,11 @@
|
||||||
|
|
||||||
The Debug library supports debug print and asserts based on a combination of macros and code.
|
The Debug library supports debug print and asserts based on a combination of macros and code.
|
||||||
The debug library can be turned on and off so that the debug code does not increase the size of an image.
|
The debug library can be turned on and off so that the debug code does not increase the size of an image.
|
||||||
|
|
||||||
|
Note that a MDEPKG_NDEBUG macro is introduced to switch on/off debug and assert related macros.
|
||||||
|
1. If MDEPKG_NDEBUG is defined, then debug and assert related macros are NULL.
|
||||||
|
2. If MDEPKG_NDEBUG is not defined, then PcdDebugProperyMask is used to turn on/off these helper macros.
|
||||||
|
|
||||||
Copyright (c) 2006 - 2008, Intel Corporation<BR>
|
Copyright (c) 2006 - 2008, Intel Corporation<BR>
|
||||||
All rights reserved. This program and the accompanying materials
|
All rights reserved. This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
@ -241,71 +245,83 @@ DebugClearMemoryEnabled (
|
||||||
/**
|
/**
|
||||||
Macro that calls DebugAssert() if an expression evaluates to FALSE.
|
Macro that calls DebugAssert() if an expression evaluates to FALSE.
|
||||||
|
|
||||||
If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set,
|
If MDEPKG_NDEBUG is not defined and the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
|
||||||
then this macro evaluates the Boolean expression specified by Expression. If
|
bit of PcdDebugProperyMask is set, then this macro evaluates the Boolean
|
||||||
Expression evaluates to FALSE, then DebugAssert() is called passing in the
|
expression specified by Expression. If Expression evaluates to FALSE, then
|
||||||
source filename, source line number, and Expression.
|
DebugAssert() is called passing in the source filename, source line number,
|
||||||
|
and Expression.
|
||||||
|
|
||||||
@param Expression Boolean expression
|
@param Expression Boolean expression
|
||||||
|
|
||||||
**/
|
**/
|
||||||
#define ASSERT(Expression) \
|
#if !defined(MDEPKG_NDEBUG)
|
||||||
do { \
|
#define ASSERT(Expression) \
|
||||||
if (DebugAssertEnabled ()) { \
|
do { \
|
||||||
if (!(Expression)) { \
|
if (DebugAssertEnabled ()) { \
|
||||||
_ASSERT (Expression); \
|
if (!(Expression)) { \
|
||||||
} \
|
_ASSERT (Expression); \
|
||||||
} \
|
} \
|
||||||
} while (FALSE)
|
} \
|
||||||
|
} while (FALSE)
|
||||||
|
#else
|
||||||
|
#define ASSERT(Expression)
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Macro that calls DebugPrint().
|
Macro that calls DebugPrint().
|
||||||
|
|
||||||
If the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set,
|
If MDEPKG_NDEBUG is not defined and the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
|
||||||
then this macro passes Expression to DebugPrint().
|
bit of PcdDebugProperyMask is set, then this macro passes Expression to
|
||||||
|
DebugPrint().
|
||||||
|
|
||||||
@param Expression Expression containing an error level, a format string,
|
@param Expression Expression containing an error level, a format string,
|
||||||
and a variable argument list based on the format string.
|
and a variable argument list based on the format string.
|
||||||
|
|
||||||
|
|
||||||
**/
|
**/
|
||||||
#define DEBUG(Expression) \
|
#if !defined(MDEPKG_NDEBUG)
|
||||||
do { \
|
#define DEBUG(Expression) \
|
||||||
if (DebugPrintEnabled ()) { \
|
do { \
|
||||||
_DEBUG (Expression); \
|
if (DebugPrintEnabled ()) { \
|
||||||
} \
|
_DEBUG (Expression); \
|
||||||
} while (FALSE)
|
} \
|
||||||
|
} while (FALSE)
|
||||||
|
#else
|
||||||
|
#define DEBUG(Expression)
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Macro that calls DebugAssert() if an EFI_STATUS evaluates to an error code.
|
Macro that calls DebugAssert() if an EFI_STATUS evaluates to an error code.
|
||||||
|
|
||||||
If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set,
|
If MDEPKG_NDEBUG is not defined and the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
|
||||||
then this macro evaluates the EFI_STATUS value specified by StatusParameter.
|
bit of PcdDebugProperyMask is set, then this macro evaluates the EFI_STATUS
|
||||||
If StatusParameter is an error code, then DebugAssert() is called passing in
|
value specified by StatusParameter. If StatusParameter is an error code,
|
||||||
the source filename, source line number, and StatusParameter.
|
then DebugAssert() is called passing in the source filename, source line
|
||||||
|
number, and StatusParameter.
|
||||||
|
|
||||||
@param StatusParameter EFI_STATUS value to evaluate.
|
@param StatusParameter EFI_STATUS value to evaluate.
|
||||||
|
|
||||||
**/
|
**/
|
||||||
#define ASSERT_EFI_ERROR(StatusParameter) \
|
#if !defined(MDEPKG_NDEBUG)
|
||||||
do { \
|
#define ASSERT_EFI_ERROR(StatusParameter) \
|
||||||
if (DebugAssertEnabled ()) { \
|
do { \
|
||||||
if (EFI_ERROR (StatusParameter)) { \
|
if (DebugAssertEnabled ()) { \
|
||||||
DEBUG ((EFI_D_ERROR, "\nASSERT_EFI_ERROR (Status = %r)\n", StatusParameter)); \
|
if (EFI_ERROR (StatusParameter)) { \
|
||||||
_ASSERT (!EFI_ERROR (StatusParameter)); \
|
DEBUG ((EFI_D_ERROR, "\nASSERT_EFI_ERROR (Status = %r)\n", StatusParameter)); \
|
||||||
} \
|
_ASSERT (!EFI_ERROR (StatusParameter)); \
|
||||||
} \
|
} \
|
||||||
} while (FALSE)
|
} \
|
||||||
|
} while (FALSE)
|
||||||
|
#else
|
||||||
|
#define ASSERT_EFI_ERROR(StatusParameter)
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Macro that calls DebugAssert() if a protocol is already installed in the
|
Macro that calls DebugAssert() if a protocol is already installed in the
|
||||||
handle database.
|
handle database.
|
||||||
|
|
||||||
If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear,
|
If MDEPKG_NDEBUG is defined or the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit
|
||||||
then return.
|
of PcdDebugProperyMask is clear, then return.
|
||||||
|
|
||||||
If Handle is NULL, then a check is made to see if the protocol specified by Guid
|
If Handle is NULL, then a check is made to see if the protocol specified by Guid
|
||||||
is present on any handle in the handle database. If Handle is not NULL, then
|
is present on any handle in the handle database. If Handle is not NULL, then
|
||||||
|
@ -322,23 +338,26 @@ DebugClearMemoryEnabled (
|
||||||
@param Guid Pointer to a protocol GUID.
|
@param Guid Pointer to a protocol GUID.
|
||||||
|
|
||||||
**/
|
**/
|
||||||
#define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid) \
|
#if !defined(MDEPKG_NDEBUG)
|
||||||
do { \
|
#define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid) \
|
||||||
if (DebugAssertEnabled ()) { \
|
do { \
|
||||||
VOID *Instance; \
|
if (DebugAssertEnabled ()) { \
|
||||||
ASSERT (Guid != NULL); \
|
VOID *Instance; \
|
||||||
if (Handle == NULL) { \
|
ASSERT (Guid != NULL); \
|
||||||
if (!EFI_ERROR (gBS->LocateProtocol ((EFI_GUID *)Guid, NULL, &Instance))) { \
|
if (Handle == NULL) { \
|
||||||
_ASSERT (Guid already installed in database); \
|
if (!EFI_ERROR (gBS->LocateProtocol ((EFI_GUID *)Guid, NULL, &Instance))) { \
|
||||||
} \
|
_ASSERT (Guid already installed in database); \
|
||||||
} else { \
|
} \
|
||||||
if (!EFI_ERROR (gBS->HandleProtocol (Handle, (EFI_GUID *)Guid, &Instance))) { \
|
} else { \
|
||||||
_ASSERT (Guid already installed on Handle); \
|
if (!EFI_ERROR (gBS->HandleProtocol (Handle, (EFI_GUID *)Guid, &Instance))) { \
|
||||||
} \
|
_ASSERT (Guid already installed on Handle); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} while (FALSE)
|
} \
|
||||||
|
} while (FALSE)
|
||||||
|
#else
|
||||||
|
#define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid)
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Macro that marks the beginning of debug source code.
|
Macro that marks the beginning of debug source code.
|
||||||
|
@ -404,21 +423,21 @@ DebugClearMemoryEnabled (
|
||||||
structure inside a larger private data structure and using a pointer to the
|
structure inside a larger private data structure and using a pointer to the
|
||||||
public data structure to retrieve a pointer to the private data structure.
|
public data structure to retrieve a pointer to the private data structure.
|
||||||
|
|
||||||
If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear,
|
If MDEPKG_NDEBUG is defined or the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit
|
||||||
then this macro computes the offset, in bytes, of field specified by Field
|
of PcdDebugProperyMask is clear, then this macro computes the offset, in bytes,
|
||||||
from the beginning of the data structure specified by TYPE. This offset is
|
of field specified by Field from the beginning of the data structure specified
|
||||||
subtracted from Record, and is used to return a pointer to a data structure
|
by TYPE. This offset is subtracted from Record, and is used to return a pointer
|
||||||
of the type specified by TYPE.
|
to a data structure of the type specified by TYPE.
|
||||||
|
|
||||||
If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set,
|
If MDEPKG_NDEBUG is not defined and the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit
|
||||||
then this macro computes the offset, in bytes, of field specified by Field from
|
of PcdDebugProperyMask is set, then this macro computes the offset, in bytes,
|
||||||
the beginning of the data structure specified by TYPE. This offset is
|
of field specified by Field from the beginning of the data structure specified
|
||||||
subtracted from Record, and is used to compute a pointer to a data structure of
|
by TYPE. This offset is subtracted from Record, and is used to compute a pointer
|
||||||
the type specified by TYPE. The Signature field of the data structure specified
|
to a data structure of the type specified by TYPE. The Signature field of the
|
||||||
by TYPE is compared to TestSignature. If the signatures match, then a pointer
|
data structure specified by TYPE is compared to TestSignature. If the signatures
|
||||||
to the pointer to a data structure of the type specified by TYPE is returned.
|
match, then a pointer to the pointer to a data structure of the type specified by
|
||||||
If the signatures do not match, then DebugAssert() is called with a description
|
TYPE is returned. If the signatures do not match, then DebugAssert() is called
|
||||||
of "CR has a bad signature" and Record is returned.
|
with a description of "CR has a bad signature" and Record is returned.
|
||||||
|
|
||||||
If the data type specified by TYPE does not contain the field specified by Field,
|
If the data type specified by TYPE does not contain the field specified by Field,
|
||||||
then the module will not compile.
|
then the module will not compile.
|
||||||
|
@ -438,9 +457,14 @@ DebugClearMemoryEnabled (
|
||||||
@param TestSignature The 32-bit signature value to match.
|
@param TestSignature The 32-bit signature value to match.
|
||||||
|
|
||||||
**/
|
**/
|
||||||
#define CR(Record, TYPE, Field, TestSignature) \
|
#if !defined(MDEPKG_NDEBUG)
|
||||||
(DebugAssertEnabled () && (BASE_CR (Record, TYPE, Field)->Signature != TestSignature)) ? \
|
#define CR(Record, TYPE, Field, TestSignature) \
|
||||||
(TYPE *) (_ASSERT (CR has Bad Signature), Record) : \
|
(DebugAssertEnabled () && (BASE_CR (Record, TYPE, Field)->Signature != TestSignature)) ? \
|
||||||
BASE_CR (Record, TYPE, Field)
|
(TYPE *) (_ASSERT (CR has Bad Signature), Record) : \
|
||||||
|
BASE_CR (Record, TYPE, Field)
|
||||||
|
#else
|
||||||
|
#define CR(Record, TYPE, Field, TestSignature) \
|
||||||
|
BASE_CR (Record, TYPE, Field)
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue