2 Base Debug Library that uses PrintLib to print messages to a memory buffer.
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 // Define the maximum debug and assert message length that this library supports
18 #define MAX_DEBUG_MESSAGE_LENGTH 0x100
22 Prints a debug message to the debug output device if the specified error level is enabled.
24 If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print
25 the message specified by Format and the associated variable argument list to
26 the debug output device.
28 If Format is NULL, then ASSERT().
30 @param ErrorLevel The error level of the debug message.
31 @param Format Format string for the debug message to print.
38 IN CONST CHAR8
*Format
,
42 CHAR8 Buffer
[MAX_DEBUG_MESSAGE_LENGTH
];
46 // If Format is NULL, then ASSERT().
48 ASSERT (Format
!= NULL
);
51 // Print the assert message to a buffer
53 VA_START (Marker
, Format
);
54 AsciiVSPrint (Buffer
, sizeof (Buffer
), Format
, Marker
);
61 Prints an assert message containing a filename, line number, and description.
62 This may be followed by a breakpoint or a dead loop.
64 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
65 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
66 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
67 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
68 CpuDeadLoop() is called. If neither of these bits are set, then this function
69 returns immediately after the message is printed to the debug output device.
70 DebugAssert() must actively prevent recusrsion. If DebugAssert() is called while
71 processing another DebugAssert(), then DebugAssert() must return immediately.
73 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
75 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
77 @param FileName Pointer to the name of the source file that generated the assert condition.
78 @param LineNumber The line number in the source file that generated the assert condition
79 @param Description Pointer to the description of the assert condition.
85 IN CONST CHAR8
*FileName
,
87 IN CONST CHAR8
*Description
90 CHAR8 Buffer
[MAX_DEBUG_MESSAGE_LENGTH
];
93 // Print the assert message to a buffer
95 AsciiSPrint (Buffer
, sizeof (Buffer
), "ASSERT %s(%d): %s\n", FileName
, LineNumber
, Description
);
98 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
100 if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED
) != 0) {
102 } else if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED
) != 0) {
110 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
112 This function fills Length bytes of Buffer with the value specified by
113 PcdDebugClearMemoryValue, and returns Buffer.
115 If Buffer is NULL, then ASSERT().
117 If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT().
119 @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.
120 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
133 // If Buffer is NULL, then ASSERT().
135 ASSERT (Buffer
!= NULL
);
138 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer
140 return SetMem (Buffer
, Length
, PcdGet8(PcdDebugClearMemoryValue
));
146 Returns TRUE if ASSERT() macros are enabled.
148 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
149 PcdDebugProperyMask is set. Otherwise FALSE is returned.
151 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
152 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
161 return ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
) != 0);
167 Returns TRUE if DEBUG()macros are enabled.
169 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
170 PcdDebugProperyMask is set. Otherwise FALSE is returned.
172 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
173 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
182 return ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
) != 0);
188 Returns TRUE if DEBUG_CODE()macros are enabled.
190 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
191 PcdDebugProperyMask is set. Otherwise FALSE is returned.
193 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
194 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
203 return ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED
) != 0);
209 Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.
211 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of
212 PcdDebugProperyMask is set. Otherwise FALSE is returned.
214 @retval TRUE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
215 @retval FALSE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
220 DebugClearMemoryEnabled (
224 return ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED
) != 0);