2 UEFI Debug Library that sends messages to the Console Output 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
11 #include <Library/DebugLib.h>
12 #include <Library/UefiBootServicesTableLib.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
25 // VA_LIST can not initialize to NULL for all compiler, so we use this to
26 // indicate a null VA_LIST
31 Prints a debug message to the debug output device if the specified error level is enabled.
33 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
34 GetDebugPrintErrorLevel (), then print the message specified by Format and the
35 associated variable argument list to the debug output device.
37 If Format is NULL, then ASSERT().
39 @param ErrorLevel The error level of the debug message.
40 @param Format Format string for the debug message to print.
41 @param ... A variable argument list whose contents are accessed
42 based on the format string specified by Format.
49 IN CONST CHAR8
*Format
,
55 VA_START (Marker
, Format
);
56 DebugVPrint (ErrorLevel
, Format
, Marker
);
62 Prints a debug message to the debug output device if the specified
63 error level is enabled base on Null-terminated format string and a
64 VA_LIST argument list or a BASE_LIST argument list.
66 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
67 GetDebugPrintErrorLevel (), then print the message specified by Format and
68 the associated variable argument list to the debug output device.
70 If Format is NULL, then ASSERT().
72 @param ErrorLevel The error level of the debug message.
73 @param Format Format string for the debug message to print.
74 @param VaListMarker VA_LIST marker for the variable argument list.
75 @param BaseListMarker BASE_LIST marker for the variable argument list.
81 IN CONST CHAR8
*Format
,
82 IN VA_LIST VaListMarker
,
83 IN BASE_LIST BaseListMarker
86 CHAR16 Buffer
[MAX_DEBUG_MESSAGE_LENGTH
];
89 // If Format is NULL, then ASSERT().
91 ASSERT (Format
!= NULL
);
94 // Check driver debug mask value and global mask
96 if ((ErrorLevel
& GetDebugPrintErrorLevel ()) == 0) {
101 // Convert the DEBUG() message to a Unicode String
103 if (BaseListMarker
== NULL
) {
104 UnicodeVSPrintAsciiFormat (Buffer
, MAX_DEBUG_MESSAGE_LENGTH
, Format
, VaListMarker
);
106 UnicodeBSPrintAsciiFormat (Buffer
, MAX_DEBUG_MESSAGE_LENGTH
, Format
, BaseListMarker
);
111 // Send the print string to the Console Output device
113 if ((gST
!= NULL
) && (gST
->ConOut
!= NULL
)) {
114 gST
->ConOut
->OutputString (gST
->ConOut
, Buffer
);
120 Prints a debug message to the debug output device if the specified
121 error level is enabled.
123 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
124 GetDebugPrintErrorLevel (), then print the message specified by Format and
125 the associated variable argument list to the debug output device.
127 If Format is NULL, then ASSERT().
129 @param ErrorLevel The error level of the debug message.
130 @param Format Format string for the debug message to print.
131 @param VaListMarker VA_LIST marker for the variable argument list.
138 IN CONST CHAR8
*Format
,
139 IN VA_LIST VaListMarker
142 DebugPrintMarker (ErrorLevel
, Format
, VaListMarker
, NULL
);
147 Prints a debug message to the debug output device if the specified
148 error level is enabled.
149 This function use BASE_LIST which would provide a more compatible
150 service than VA_LIST.
152 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
153 GetDebugPrintErrorLevel (), then print the message specified by Format and
154 the associated variable argument list to the debug output device.
156 If Format is NULL, then ASSERT().
158 @param ErrorLevel The error level of the debug message.
159 @param Format Format string for the debug message to print.
160 @param BaseListMarker BASE_LIST marker for the variable argument list.
167 IN CONST CHAR8
*Format
,
168 IN BASE_LIST BaseListMarker
171 DebugPrintMarker (ErrorLevel
, Format
, mVaListNull
, BaseListMarker
);
176 Prints an assert message containing a filename, line number, and description.
177 This may be followed by a breakpoint or a dead loop.
179 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
180 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
181 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
182 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
183 CpuDeadLoop() is called. If neither of these bits are set, then this function
184 returns immediately after the message is printed to the debug output device.
185 DebugAssert() must actively prevent recursion. If DebugAssert() is called while
186 processing another DebugAssert(), then DebugAssert() must return immediately.
188 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
189 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
191 @param FileName The pointer to the name of the source file that generated
192 the assert condition.
193 @param LineNumber The line number in the source file that generated the
195 @param Description The pointer to the description of the assert condition.
201 IN CONST CHAR8
*FileName
,
203 IN CONST CHAR8
*Description
206 CHAR16 Buffer
[MAX_DEBUG_MESSAGE_LENGTH
];
209 // Generate the ASSERT() message in Unicode format
211 UnicodeSPrintAsciiFormat (
214 "ASSERT [%a] %a(%d): %a\n",
222 // Send the print string to the Console Output device
224 if ((gST
!= NULL
) && (gST
->ConOut
!= NULL
)) {
225 gST
->ConOut
->OutputString (gST
->ConOut
, Buffer
);
229 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
231 if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED
) != 0) {
233 } else if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED
) != 0) {
240 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
242 This function fills Length bytes of Buffer with the value specified by
243 PcdDebugClearMemoryValue, and returns Buffer.
245 If Buffer is NULL, then ASSERT().
246 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
248 @param Buffer The pointer to the target buffer to be filled with PcdDebugClearMemoryValue.
249 @param Length The number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
251 @return Buffer The pointer to the target buffer filled with PcdDebugClearMemoryValue.
262 // If Buffer is NULL, then ASSERT().
264 ASSERT (Buffer
!= NULL
);
267 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer
269 return SetMem (Buffer
, Length
, PcdGet8(PcdDebugClearMemoryValue
));
274 Returns TRUE if ASSERT() macros are enabled.
276 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
277 PcdDebugProperyMask is set. Otherwise FALSE is returned.
279 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
280 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
289 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
) != 0);
294 Returns TRUE if DEBUG() macros are enabled.
296 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
297 PcdDebugProperyMask is set. Otherwise FALSE is returned.
299 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
300 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
309 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
) != 0);
314 Returns TRUE if DEBUG_CODE() macros are enabled.
316 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
317 PcdDebugProperyMask is set. Otherwise FALSE is returned.
319 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
320 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
329 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED
) != 0);
334 Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.
336 This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of
337 PcdDebugProperyMask is set. Otherwise FALSE is returned.
339 @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
340 @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
345 DebugClearMemoryEnabled (
349 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED
) != 0);
353 Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel.
355 This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel.
357 @retval TRUE Current ErrorLevel is supported.
358 @retval FALSE Current ErrorLevel is not supported.
363 DebugPrintLevelEnabled (
364 IN CONST UINTN ErrorLevel
367 return (BOOLEAN
) ((ErrorLevel
& PcdGet32(PcdFixedDebugPrintErrorLevel
)) != 0);