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
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/SemihostLib.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
32 Prints a debug message to the debug output device if the specified error level is enabled.
34 If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print
35 the message specified by Format and the associated variable argument list to
36 the debug output device.
38 If Format is NULL, then ASSERT().
40 @param ErrorLevel The error level of the debug message.
41 @param Format Format string for the debug message to print.
48 IN CONST CHAR8
*Format
,
54 VA_START (Marker
, Format
);
55 DebugVPrint (ErrorLevel
, Format
, Marker
);
61 Prints a debug message to the debug output device if the specified
62 error level is enabled base on Null-terminated format string and a
63 VA_LIST argument list or a BASE_LIST argument list.
65 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
66 GetDebugPrintErrorLevel (), then print the message specified by Format and
67 the associated variable argument list to the debug output device.
69 If Format is NULL, then ASSERT().
71 @param ErrorLevel The error level of the debug message.
72 @param Format Format string for the debug message to print.
73 @param VaListMarker VA_LIST marker for the variable argument list.
74 @param BaseListMarker BASE_LIST marker for the variable argument list.
80 IN CONST CHAR8
*Format
,
81 IN VA_LIST VaListMarker
,
82 IN BASE_LIST BaseListMarker
85 CHAR8 AsciiBuffer
[MAX_DEBUG_MESSAGE_LENGTH
];
88 // If Format is NULL, then ASSERT().
90 ASSERT (Format
!= NULL
);
93 // Check driver debug mask value and global mask
95 if ((ErrorLevel
& PcdGet32(PcdDebugPrintErrorLevel
)) == 0) {
100 // Convert the DEBUG() message to a Unicode String
102 if (BaseListMarker
== NULL
) {
103 AsciiVSPrint (AsciiBuffer
, sizeof (AsciiBuffer
), Format
, VaListMarker
);
105 AsciiBSPrint (AsciiBuffer
, sizeof (AsciiBuffer
), Format
, BaseListMarker
);
108 SemihostWriteString (AsciiBuffer
);
113 Prints a debug message to the debug output device if the specified
114 error level is enabled.
116 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
117 GetDebugPrintErrorLevel (), then print the message specified by Format and
118 the associated variable argument list to the debug output device.
120 If Format is NULL, then ASSERT().
122 @param ErrorLevel The error level of the debug message.
123 @param Format Format string for the debug message to print.
124 @param VaListMarker VA_LIST marker for the variable argument list.
131 IN CONST CHAR8
*Format
,
132 IN VA_LIST VaListMarker
135 DebugPrintMarker (ErrorLevel
, Format
, VaListMarker
, NULL
);
140 Prints a debug message to the debug output device if the specified
141 error level is enabled.
142 This function use BASE_LIST which would provide a more compatible
143 service than VA_LIST.
145 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
146 GetDebugPrintErrorLevel (), then print the message specified by Format and
147 the associated variable argument list to the debug output device.
149 If Format is NULL, then ASSERT().
151 @param ErrorLevel The error level of the debug message.
152 @param Format Format string for the debug message to print.
153 @param BaseListMarker BASE_LIST marker for the variable argument list.
160 IN CONST CHAR8
*Format
,
161 IN BASE_LIST BaseListMarker
164 DebugPrintMarker (ErrorLevel
, Format
, mVaListNull
, BaseListMarker
);
170 Prints an assert message containing a filename, line number, and description.
171 This may be followed by a breakpoint or a dead loop.
173 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
174 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
175 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
176 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
177 CpuDeadLoop() is called. If neither of these bits are set, then this function
178 returns immediately after the message is printed to the debug output device.
179 DebugAssert() must actively prevent recusrsion. If DebugAssert() is called while
180 processing another DebugAssert(), then DebugAssert() must return immediately.
182 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
184 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
186 @param FileName Pointer to the name of the source file that generated the assert condition.
187 @param LineNumber The line number in the source file that generated the assert condition
188 @param Description Pointer to the description of the assert condition.
194 IN CONST CHAR8
*FileName
,
196 IN CONST CHAR8
*Description
199 CHAR8 AsciiBuffer
[MAX_DEBUG_MESSAGE_LENGTH
];
202 // Generate the ASSERT() message in Unicode format
204 AsciiSPrint (AsciiBuffer
, sizeof (AsciiBuffer
), "ASSERT %a(%d): %a\n", FileName
, LineNumber
, Description
);
206 SemihostWriteString (AsciiBuffer
);
209 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
211 if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED
) != 0) {
213 } else if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED
) != 0) {
221 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
223 This function fills Length bytes of Buffer with the value specified by
224 PcdDebugClearMemoryValue, and returns Buffer.
226 If Buffer is NULL, then ASSERT().
228 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
230 @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.
231 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
244 // If Buffer is NULL, then ASSERT().
246 ASSERT (Buffer
!= NULL
);
249 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer
251 return SetMem (Buffer
, Length
, PcdGet8(PcdDebugClearMemoryValue
));
257 Returns TRUE if ASSERT() macros are enabled.
259 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
260 PcdDebugProperyMask is set. Otherwise FALSE is returned.
262 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
263 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
272 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
) != 0);
278 Returns TRUE if DEBUG()macros are enabled.
280 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
281 PcdDebugProperyMask is set. Otherwise FALSE is returned.
283 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
284 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
293 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
) != 0);
299 Returns TRUE if DEBUG_CODE()macros are enabled.
301 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
302 PcdDebugProperyMask is set. Otherwise FALSE is returned.
304 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
305 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
314 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED
) != 0);
320 Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.
322 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of
323 PcdDebugProperyMask is set. Otherwise FALSE is returned.
325 @retval TRUE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
326 @retval FALSE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
331 DebugClearMemoryEnabled (
335 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED
) != 0);