> On Jul 8, 2015, at 12:02 PM, Laszlo Ersek <ler...@redhat.com> wrote:
>
>>
>> It should be noted that once in a while I run into this sort of thing in
>> VxWorks as well, only it's often the other way around. We typically have
>> DEBUG()-style messages turned off by default, and sometimes there are debug
>> messages that refer to variables which no longer exist in the code. (The
>> variables were removed but the debug messages were never updated to match.)
>
> SeaBIOS employs the following trick to avoid this: all CONFIG_XXXX flags
> are checked in regular if() statements, not in #if macros. That is, any
> elmination happens during compilation / optimization / linking, not in
> preprocessing. This allows the compiler to catch such errors even when a
> CONFIG_XXXX option is predominantly false (or predominantly true).
This is how the edk2 works. Your platform has to “opt-in” to the #if. The
default is to use PCDs, and that is what happens on VC++. The MDEPKG_NDEBUG
#define was added for compilers, like gcc, that could not dead strip the code.
https://svn.code.sf.net/p/edk2/code/trunk/edk2/MdePkg/Include/Library/DebugLib.h
<https://svn.code.sf.net/p/edk2/code/trunk/edk2/MdePkg/Include/Library/DebugLib.h>
#if !defined(MDEPKG_NDEBUG)
#define ASSERT(Expression) \
do { \
if (DebugAssertEnabled ()) { \
if (!(Expression)) { \
_ASSERT (Expression); \
} \
} \
} while (FALSE)
#else
#define ASSERT(Expression)
#endif
If you are not using the optional MDEPKG_NDEBUG flag then DEBUG and ASSERT
macros just become policy for a release build based on PCD.
Also in most of the DebugLib instances what do on the ASSERT is a policy choice
(breakpoint, dead loop, no-op).
https://svn.code.sf.net/p/edk2/code/trunk/edk2/MdePkg/Library/BaseDebugLibSerialPort/DebugLib.c
<https://svn.code.sf.net/p/edk2/code/trunk/edk2/MdePkg/Library/BaseDebugLibSerialPort/DebugLib.c>
VOID
EFIAPI
DebugAssert (
IN CONST CHAR8 *FileName,
IN UINTN LineNumber,
IN CONST CHAR8 *Description
)
{
CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];
//
// Generate the ASSERT() message in Ascii format
//
AsciiSPrint (Buffer, sizeof (Buffer), "ASSERT %a(%d): %a\n", FileName,
LineNumber, Description);
//
// Send the print string to the Console Output device
//
SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));
//
// Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
//
if ((PcdGet8(PcdDebugPropertyMask) &
DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {
CpuBreakpoint ();
} else if ((PcdGet8(PcdDebugPropertyMask) &
DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {
CpuDeadLoop ();
}
}
Thanks,
Andrew Fish
------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel