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/UefiBootServicesTableLib.h>
14 #include <Library/PrintLib.h>
15 #include <Library/PcdLib.h>
16 #include <Library/BaseLib.h>
17 #include <Library/BaseMemoryLib.h>
18 #include <Library/DebugPrintErrorLevelLib.h>
21 // Define the maximum debug and assert message length that this library supports
23 #define MAX_DEBUG_MESSAGE_LENGTH 0x100
27 // VA_LIST can not initialize to NULL for all compiler, so we use this to
28 // indicate a null VA_LIST
34 Prints a debug message to the debug output device if the specified error level is enabled.
36 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
37 GetDebugPrintErrorLevel (), then print the message specified by Format and the
38 associated variable argument list to the debug output device.
40 If Format is NULL, then ASSERT().
42 @param ErrorLevel The error level of the debug message.
43 @param Format The format string for the debug message to print.
44 @param ... The variable argument list whose contents are accessed
45 based on the format string specified by Format.
52 IN CONST CHAR8
*Format
,
58 VA_START (Marker
, Format
);
59 DebugVPrint (ErrorLevel
, Format
, Marker
);
65 Prints a debug message to the debug output device if the specified
66 error level is enabled base on Null-terminated format string and a
67 VA_LIST argument list or a BASE_LIST argument list.
69 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
70 GetDebugPrintErrorLevel (), then print the message specified by Format and
71 the associated variable argument list to the debug output device.
73 If Format is NULL, then ASSERT().
75 @param ErrorLevel The error level of the debug message.
76 @param Format Format string for the debug message to print.
77 @param VaListMarker VA_LIST marker for the variable argument list.
78 @param BaseListMarker BASE_LIST marker for the variable argument list.
84 IN CONST CHAR8
*Format
,
85 IN VA_LIST VaListMarker
,
86 IN BASE_LIST BaseListMarker
89 CHAR16 Buffer
[MAX_DEBUG_MESSAGE_LENGTH
];
92 // If Format is NULL, then ASSERT().
94 ASSERT (Format
!= NULL
);
97 // Check driver debug mask value and global mask
99 if ((ErrorLevel
& GetDebugPrintErrorLevel ()) == 0) {
104 // Convert the DEBUG() message to a Unicode String
106 if (BaseListMarker
== NULL
) {
107 UnicodeVSPrintAsciiFormat (Buffer
, MAX_DEBUG_MESSAGE_LENGTH
, Format
, VaListMarker
);
109 UnicodeBSPrintAsciiFormat (Buffer
, MAX_DEBUG_MESSAGE_LENGTH
, Format
, BaseListMarker
);
113 // Send the print string to the Standard Error device
115 if ((gST
!= NULL
) && (gST
->StdErr
!= NULL
)) {
116 gST
->StdErr
->OutputString (gST
->StdErr
, Buffer
);
122 Prints a debug message to the debug output device if the specified
123 error level is enabled.
125 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
126 GetDebugPrintErrorLevel (), then print the message specified by Format and
127 the associated variable argument list to the debug output device.
129 If Format is NULL, then ASSERT().
131 @param ErrorLevel The error level of the debug message.
132 @param Format Format string for the debug message to print.
133 @param VaListMarker VA_LIST marker for the variable argument list.
140 IN CONST CHAR8
*Format
,
141 IN VA_LIST VaListMarker
144 DebugPrintMarker (ErrorLevel
, Format
, VaListMarker
, NULL
);
149 Prints a debug message to the debug output device if the specified
150 error level is enabled.
151 This function use BASE_LIST which would provide a more compatible
152 service than VA_LIST.
154 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
155 GetDebugPrintErrorLevel (), then print the message specified by Format and
156 the associated variable argument list to the debug output device.
158 If Format is NULL, then ASSERT().
160 @param ErrorLevel The error level of the debug message.
161 @param Format Format string for the debug message to print.
162 @param BaseListMarker BASE_LIST marker for the variable argument list.
169 IN CONST CHAR8
*Format
,
170 IN BASE_LIST BaseListMarker
173 DebugPrintMarker (ErrorLevel
, Format
, mVaListNull
, BaseListMarker
);
178 Prints an assert message containing a filename, line number, and description.
179 This may be followed by a breakpoint or a dead loop.
181 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
182 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
183 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
184 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
185 CpuDeadLoop() is called. If neither of these bits are set, then this function
186 returns immediately after the message is printed to the debug output device.
187 DebugAssert() must actively prevent recursion. If DebugAssert() is called while
188 processing another DebugAssert(), then DebugAssert() must return immediately.
190 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
191 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
193 @param FileName The pointer to the name of the source file that generated
194 the assert condition.
195 @param LineNumber The line number in the source file that generated the
197 @param Description The pointer to the description of the assert condition.
203 IN CONST CHAR8
*FileName
,
205 IN CONST CHAR8
*Description
208 CHAR16 Buffer
[MAX_DEBUG_MESSAGE_LENGTH
];
211 // Generate the ASSERT() message in Unicode format
213 UnicodeSPrintAsciiFormat (
216 "ASSERT [%a] %a(%d): %a\n",
224 // Send the print string to the Standard Error device
226 if ((gST
!= NULL
) && (gST
->StdErr
!= NULL
)) {
227 gST
->StdErr
->OutputString (gST
->StdErr
, Buffer
);
231 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
233 if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED
) != 0) {
235 } else if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED
) != 0) {
242 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
244 This function fills Length bytes of Buffer with the value specified by
245 PcdDebugClearMemoryValue, and returns Buffer.
247 If Buffer is NULL, then ASSERT().
248 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
250 @param Buffer The pointer to the target buffer to be filled with PcdDebugClearMemoryValue.
251 @param Length The number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
253 @return Buffer The pointer to the target buffer filled with PcdDebugClearMemoryValue.
264 // If Buffer is NULL, then ASSERT().
266 ASSERT (Buffer
!= NULL
);
269 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer
271 return SetMem (Buffer
, Length
, PcdGet8(PcdDebugClearMemoryValue
));
276 Returns TRUE if ASSERT() macros are enabled.
278 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
279 PcdDebugProperyMask is set. Otherwise FALSE is returned.
281 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
282 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
291 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
) != 0);
296 Returns TRUE if DEBUG() macros are enabled.
298 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
299 PcdDebugProperyMask is set. Otherwise FALSE is returned.
301 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
302 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
311 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
) != 0);
316 Returns TRUE if DEBUG_CODE() macros are enabled.
318 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
319 PcdDebugProperyMask is set. Otherwise FALSE is returned.
321 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
322 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
331 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED
) != 0);
336 Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.
338 This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of
339 PcdDebugProperyMask is set. Otherwise FALSE is returned.
341 @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
342 @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
347 DebugClearMemoryEnabled (
351 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED
) != 0);
355 Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel.
357 This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel.
359 @retval TRUE Current ErrorLevel is supported.
360 @retval FALSE Current ErrorLevel is not supported.
365 DebugPrintLevelEnabled (
366 IN CONST UINTN ErrorLevel
369 return (BOOLEAN
) ((ErrorLevel
& PcdGet32(PcdFixedDebugPrintErrorLevel
)) != 0);