2 UEFI Debug Library that uses PrintLib to send messages to STDERR.
4 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
5 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/DebugLib.h>
12 #include <Library/PrintLib.h>
13 #include <Library/PcdLib.h>
14 #include <Library/BaseLib.h>
15 #include <Library/BaseMemoryLib.h>
16 #include <Library/SemihostLib.h>
19 // Define the maximum debug and assert message length that this library supports
21 #define MAX_DEBUG_MESSAGE_LENGTH 0x100
24 // VA_LIST can not initialize to NULL for all compiler, so we use this to
25 // 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 PcdDebugPrintErrorLevel, then print
34 the message specified by Format and the associated variable argument list to
35 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.
47 IN CONST CHAR8
*Format
,
53 VA_START (Marker
, Format
);
54 DebugVPrint (ErrorLevel
, Format
, Marker
);
59 Prints a debug message to the debug output device if the specified
60 error level is enabled base on Null-terminated format string and a
61 VA_LIST argument list or a BASE_LIST argument list.
63 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
64 GetDebugPrintErrorLevel (), then print the message specified by Format and
65 the associated variable argument list to the debug output device.
67 If Format is NULL, then ASSERT().
69 @param ErrorLevel The error level of the debug message.
70 @param Format Format string for the debug message to print.
71 @param VaListMarker VA_LIST marker for the variable argument list.
72 @param BaseListMarker BASE_LIST marker for the variable argument list.
78 IN CONST CHAR8
*Format
,
79 IN VA_LIST VaListMarker
,
80 IN BASE_LIST BaseListMarker
83 CHAR8 AsciiBuffer
[MAX_DEBUG_MESSAGE_LENGTH
];
86 // If Format is NULL, then ASSERT().
88 ASSERT (Format
!= NULL
);
91 // Check driver debug mask value and global mask
93 if ((ErrorLevel
& PcdGet32 (PcdDebugPrintErrorLevel
)) == 0) {
98 // Convert the DEBUG() message to a Unicode String
100 if (BaseListMarker
== NULL
) {
101 AsciiVSPrint (AsciiBuffer
, sizeof (AsciiBuffer
), Format
, VaListMarker
);
103 AsciiBSPrint (AsciiBuffer
, sizeof (AsciiBuffer
), Format
, BaseListMarker
);
106 SemihostWriteString (AsciiBuffer
);
110 Prints a debug message to the debug output device if the specified
111 error level is enabled.
113 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
114 GetDebugPrintErrorLevel (), then print the message specified by Format and
115 the associated variable argument list to the debug output device.
117 If Format is NULL, then ASSERT().
119 @param ErrorLevel The error level of the debug message.
120 @param Format Format string for the debug message to print.
121 @param VaListMarker VA_LIST marker for the variable argument list.
128 IN CONST CHAR8
*Format
,
129 IN VA_LIST VaListMarker
132 DebugPrintMarker (ErrorLevel
, Format
, VaListMarker
, NULL
);
136 Prints a debug message to the debug output device if the specified
137 error level is enabled.
138 This function use BASE_LIST which would provide a more compatible
139 service than VA_LIST.
141 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
142 GetDebugPrintErrorLevel (), then print the message specified by Format and
143 the associated variable argument list to the debug output device.
145 If Format is NULL, then ASSERT().
147 @param ErrorLevel The error level of the debug message.
148 @param Format Format string for the debug message to print.
149 @param BaseListMarker BASE_LIST marker for the variable argument list.
156 IN CONST CHAR8
*Format
,
157 IN BASE_LIST BaseListMarker
160 DebugPrintMarker (ErrorLevel
, Format
, mVaListNull
, BaseListMarker
);
165 Prints an assert message containing a filename, line number, and description.
166 This may be followed by a breakpoint or a dead loop.
168 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
169 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
170 PcdDebugPropertyMask is set then CpuBreakpoint() is called. Otherwise, if
171 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugPropertyMask is set then
172 CpuDeadLoop() is called. If neither of these bits are set, then this function
173 returns immediately after the message is printed to the debug output device.
174 DebugAssert() must actively prevent recursion. If DebugAssert() is called while
175 processing another DebugAssert(), then DebugAssert() must return immediately.
177 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
179 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
181 @param FileName Pointer to the name of the source file that generated the assert condition.
182 @param LineNumber The line number in the source file that generated the assert condition
183 @param Description Pointer to the description of the assert condition.
189 IN CONST CHAR8
*FileName
,
191 IN CONST CHAR8
*Description
194 CHAR8 AsciiBuffer
[MAX_DEBUG_MESSAGE_LENGTH
];
197 // Generate the ASSERT() message in Unicode format
199 AsciiSPrint (AsciiBuffer
, sizeof (AsciiBuffer
), "ASSERT %a(%d): %a\n", FileName
, LineNumber
, Description
);
201 SemihostWriteString (AsciiBuffer
);
204 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
206 if ((PcdGet8 (PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED
) != 0) {
208 } else if ((PcdGet8 (PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED
) != 0) {
215 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
217 This function fills Length bytes of Buffer with the value specified by
218 PcdDebugClearMemoryValue, and returns Buffer.
220 If Buffer is NULL, then ASSERT().
222 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
224 @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.
225 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
238 // If Buffer is NULL, then ASSERT().
240 ASSERT (Buffer
!= NULL
);
243 // SetMem() checks for the ASSERT() condition on Length and returns Buffer
245 return SetMem (Buffer
, Length
, PcdGet8 (PcdDebugClearMemoryValue
));
250 Returns TRUE if ASSERT() macros are enabled.
252 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
253 PcdDebugPropertyMask is set. Otherwise FALSE is returned.
255 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugPropertyMask is set.
256 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugPropertyMask is clear.
265 return (BOOLEAN
)((PcdGet8 (PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
) != 0);
270 Returns TRUE if DEBUG()macros are enabled.
272 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
273 PcdDebugPropertyMask is set. Otherwise FALSE is returned.
275 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugPropertyMask is set.
276 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugPropertyMask is clear.
285 return (BOOLEAN
)((PcdGet8 (PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
) != 0);
290 Returns TRUE if DEBUG_CODE()macros are enabled.
292 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
293 PcdDebugPropertyMask is set. Otherwise FALSE is returned.
295 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugPropertyMask is set.
296 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugPropertyMask is clear.
305 return (BOOLEAN
)((PcdGet8 (PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED
) != 0);
310 Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.
312 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of
313 PcdDebugPropertyMask is set. Otherwise FALSE is returned.
315 @retval TRUE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugPropertyMask is set.
316 @retval FALSE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugPropertyMask is clear.
321 DebugClearMemoryEnabled (
325 return (BOOLEAN
)((PcdGet8 (PcdDebugPropertyMask
) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED
) != 0);