2 UEFI Debug Lib that sends messages to the Standard Error Device in the EFI System Table.
4 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include <Library/DebugLib.h>
13 #include <Library/PrintLib.h>
14 #include <Library/PcdLib.h>
15 #include <Library/BaseLib.h>
16 #include <Library/BaseMemoryLib.h>
17 #include <Library/DebugPrintErrorLevelLib.h>
20 // Define the maximum debug and assert message length that this library supports
22 #define MAX_DEBUG_MESSAGE_LENGTH 0x100
26 // VA_LIST can not initialize to NULL for all compiler, so we use this to
27 // indicate a null VA_LIST
31 extern BOOLEAN mPostEBS
;
32 extern EFI_SYSTEM_TABLE
*mDebugST
;
35 Prints a debug message to the debug output device if the specified error level is enabled.
37 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
38 GetDebugPrintErrorLevel (), then print the message specified by Format and the
39 associated variable argument list to the debug output device.
41 If Format is NULL, then ASSERT().
43 @param ErrorLevel The error level of the debug message.
44 @param Format The format string for the debug message to print.
45 @param ... The variable argument list whose contents are accessed
46 based on the format string specified by Format.
53 IN CONST CHAR8
*Format
,
59 VA_START (Marker
, Format
);
60 DebugVPrint (ErrorLevel
, Format
, Marker
);
66 Prints a debug message to the debug output device if the specified
67 error level is enabled base on Null-terminated format string and a
68 VA_LIST argument list or a BASE_LIST argument list.
70 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
71 GetDebugPrintErrorLevel (), then print the message specified by Format and
72 the associated variable argument list to the debug output device.
74 If Format is NULL, then ASSERT().
76 @param ErrorLevel The error level of the debug message.
77 @param Format Format string for the debug message to print.
78 @param VaListMarker VA_LIST marker for the variable argument list.
79 @param BaseListMarker BASE_LIST marker for the variable argument list.
85 IN CONST CHAR8
*Format
,
86 IN VA_LIST VaListMarker
,
87 IN BASE_LIST BaseListMarker
90 CHAR16 Buffer
[MAX_DEBUG_MESSAGE_LENGTH
];
94 // If Format is NULL, then ASSERT().
96 ASSERT (Format
!= NULL
);
99 // Check driver debug mask value and global mask
101 if ((ErrorLevel
& GetDebugPrintErrorLevel ()) == 0) {
106 // Convert the DEBUG() message to a Unicode String
108 if (BaseListMarker
== NULL
) {
109 UnicodeVSPrintAsciiFormat (Buffer
, MAX_DEBUG_MESSAGE_LENGTH
, Format
, VaListMarker
);
111 UnicodeBSPrintAsciiFormat (Buffer
, MAX_DEBUG_MESSAGE_LENGTH
, Format
, BaseListMarker
);
115 // Send the print string to the Standard Error device
117 if ((mDebugST
!= NULL
) && (mDebugST
->StdErr
!= NULL
)) {
118 mDebugST
->StdErr
->OutputString (mDebugST
->StdErr
, Buffer
);
125 Prints a debug message to the debug output device if the specified
126 error level is enabled.
128 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
129 GetDebugPrintErrorLevel (), then print the message specified by Format and
130 the associated variable argument list to the debug output device.
132 If Format is NULL, then ASSERT().
134 @param ErrorLevel The error level of the debug message.
135 @param Format Format string for the debug message to print.
136 @param VaListMarker VA_LIST marker for the variable argument list.
143 IN CONST CHAR8
*Format
,
144 IN VA_LIST VaListMarker
147 DebugPrintMarker (ErrorLevel
, Format
, VaListMarker
, NULL
);
152 Prints a debug message to the debug output device if the specified
153 error level is enabled.
154 This function use BASE_LIST which would provide a more compatible
155 service than VA_LIST.
157 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
158 GetDebugPrintErrorLevel (), then print the message specified by Format and
159 the associated variable argument list to the debug output device.
161 If Format is NULL, then ASSERT().
163 @param ErrorLevel The error level of the debug message.
164 @param Format Format string for the debug message to print.
165 @param BaseListMarker BASE_LIST marker for the variable argument list.
172 IN CONST CHAR8
*Format
,
173 IN BASE_LIST BaseListMarker
176 DebugPrintMarker (ErrorLevel
, Format
, mVaListNull
, BaseListMarker
);
181 Prints an assert message containing a filename, line number, and description.
182 This may be followed by a breakpoint or a dead loop.
184 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
185 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
186 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
187 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
188 CpuDeadLoop() is called. If neither of these bits are set, then this function
189 returns immediately after the message is printed to the debug output device.
190 DebugAssert() must actively prevent recursion. If DebugAssert() is called while
191 processing another DebugAssert(), then DebugAssert() must return immediately.
193 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
194 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
196 @param FileName The pointer to the name of the source file that generated
197 the assert condition.
198 @param LineNumber The line number in the source file that generated the
200 @param Description The pointer to the description of the assert condition.
206 IN CONST CHAR8
*FileName
,
208 IN CONST CHAR8
*Description
211 CHAR16 Buffer
[MAX_DEBUG_MESSAGE_LENGTH
];
215 // Generate the ASSERT() message in Unicode format
217 UnicodeSPrintAsciiFormat (
220 "ASSERT [%a] %a(%d): %a\n",
228 // Send the print string to the Standard Error device
230 if ((mDebugST
!= NULL
) && (mDebugST
->StdErr
!= NULL
)) {
231 mDebugST
->StdErr
->OutputString (mDebugST
->StdErr
, Buffer
);
235 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
237 if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED
) != 0) {
239 } else if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED
) != 0) {
247 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
249 This function fills Length bytes of Buffer with the value specified by
250 PcdDebugClearMemoryValue, and returns Buffer.
252 If Buffer is NULL, then ASSERT().
253 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
255 @param Buffer The pointer to the target buffer to be filled with PcdDebugClearMemoryValue.
256 @param Length The number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
258 @return Buffer The pointer to the target buffer filled with PcdDebugClearMemoryValue.
269 // If Buffer is NULL, then ASSERT().
271 ASSERT (Buffer
!= NULL
);
274 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer
276 return SetMem (Buffer
, Length
, PcdGet8(PcdDebugClearMemoryValue
));
281 Returns TRUE if ASSERT() macros are enabled.
283 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
284 PcdDebugProperyMask is set. Otherwise FALSE is returned.
286 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
287 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
296 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
) != 0);
301 Returns TRUE if DEBUG() macros are enabled.
303 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
304 PcdDebugProperyMask is set. Otherwise FALSE is returned.
306 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
307 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
316 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
) != 0);
321 Returns TRUE if DEBUG_CODE() macros are enabled.
323 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
324 PcdDebugProperyMask is set. Otherwise FALSE is returned.
326 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
327 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
336 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED
) != 0);
341 Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.
343 This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of
344 PcdDebugProperyMask is set. Otherwise FALSE is returned.
346 @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
347 @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
352 DebugClearMemoryEnabled (
356 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED
) != 0);
360 Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel.
362 This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel.
364 @retval TRUE Current ErrorLevel is supported.
365 @retval FALSE Current ErrorLevel is not supported.
370 DebugPrintLevelEnabled (
371 IN CONST UINTN ErrorLevel
374 return (BOOLEAN
) ((ErrorLevel
& PcdGet32(PcdFixedDebugPrintErrorLevel
)) != 0);