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 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <Library/DebugLib.h>
19 #include <Library/PrintLib.h>
20 #include <Library/PcdLib.h>
21 #include <Library/BaseLib.h>
22 #include <Library/BaseMemoryLib.h>
23 #include <Library/SemihostLib.h>
26 // Define the maximum debug and assert message length that this library supports
28 #define MAX_DEBUG_MESSAGE_LENGTH 0x100
31 // VA_LIST can not initialize to NULL for all compiler, so we use this to
32 // indicate a null VA_LIST
38 Prints a debug message to the debug output device if the specified error level is enabled.
40 If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print
41 the message specified by Format and the associated variable argument list to
42 the debug output device.
44 If Format is NULL, then ASSERT().
46 @param ErrorLevel The error level of the debug message.
47 @param Format Format string for the debug message to print.
54 IN CONST CHAR8
*Format
,
60 VA_START (Marker
, Format
);
61 DebugVPrint (ErrorLevel
, Format
, Marker
);
67 Prints a debug message to the debug output device if the specified
68 error level is enabled base on Null-terminated format string and a
69 VA_LIST argument list or a BASE_LIST argument list.
71 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
72 GetDebugPrintErrorLevel (), then print the message specified by Format and
73 the associated variable argument list to the debug output device.
75 If Format is NULL, then ASSERT().
77 @param ErrorLevel The error level of the debug message.
78 @param Format Format string for the debug message to print.
79 @param VaListMarker VA_LIST marker for the variable argument list.
80 @param BaseListMarker BASE_LIST marker for the variable argument list.
86 IN CONST CHAR8
*Format
,
87 IN VA_LIST VaListMarker
,
88 IN BASE_LIST BaseListMarker
91 CHAR8 AsciiBuffer
[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
& PcdGet32(PcdDebugPrintErrorLevel
)) == 0) {
106 // Convert the DEBUG() message to a Unicode String
108 if (BaseListMarker
== NULL
) {
109 AsciiVSPrint (AsciiBuffer
, sizeof (AsciiBuffer
), Format
, VaListMarker
);
111 AsciiBSPrint (AsciiBuffer
, sizeof (AsciiBuffer
), Format
, BaseListMarker
);
114 SemihostWriteString (AsciiBuffer
);
119 Prints a debug message to the debug output device if the specified
120 error level is enabled.
122 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
123 GetDebugPrintErrorLevel (), then print the message specified by Format and
124 the associated variable argument list to the debug output device.
126 If Format is NULL, then ASSERT().
128 @param ErrorLevel The error level of the debug message.
129 @param Format Format string for the debug message to print.
130 @param VaListMarker VA_LIST marker for the variable argument list.
137 IN CONST CHAR8
*Format
,
138 IN VA_LIST VaListMarker
141 DebugPrintMarker (ErrorLevel
, Format
, VaListMarker
, NULL
);
146 Prints a debug message to the debug output device if the specified
147 error level is enabled.
148 This function use BASE_LIST which would provide a more compatible
149 service than VA_LIST.
151 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
152 GetDebugPrintErrorLevel (), then print the message specified by Format and
153 the associated variable argument list to the debug output device.
155 If Format is NULL, then ASSERT().
157 @param ErrorLevel The error level of the debug message.
158 @param Format Format string for the debug message to print.
159 @param BaseListMarker BASE_LIST marker for the variable argument list.
166 IN CONST CHAR8
*Format
,
167 IN BASE_LIST BaseListMarker
170 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 recusrsion. 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.
190 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
192 @param FileName Pointer to the name of the source file that generated the assert condition.
193 @param LineNumber The line number in the source file that generated the assert condition
194 @param Description Pointer to the description of the assert condition.
200 IN CONST CHAR8
*FileName
,
202 IN CONST CHAR8
*Description
205 CHAR8 AsciiBuffer
[MAX_DEBUG_MESSAGE_LENGTH
];
208 // Generate the ASSERT() message in Unicode format
210 AsciiSPrint (AsciiBuffer
, sizeof (AsciiBuffer
), "ASSERT %a(%d): %a\n", FileName
, LineNumber
, Description
);
212 SemihostWriteString (AsciiBuffer
);
215 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
217 if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED
) != 0) {
219 } else if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED
) != 0) {
227 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
229 This function fills Length bytes of Buffer with the value specified by
230 PcdDebugClearMemoryValue, and returns Buffer.
232 If Buffer is NULL, then ASSERT().
234 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
236 @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.
237 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
250 // If Buffer is NULL, then ASSERT().
252 ASSERT (Buffer
!= NULL
);
255 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer
257 return SetMem (Buffer
, Length
, PcdGet8(PcdDebugClearMemoryValue
));
263 Returns TRUE if ASSERT() macros are enabled.
265 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
266 PcdDebugProperyMask is set. Otherwise FALSE is returned.
268 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
269 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
278 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
) != 0);
284 Returns TRUE if DEBUG()macros are enabled.
286 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
287 PcdDebugProperyMask is set. Otherwise FALSE is returned.
289 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
290 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
299 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
) != 0);
305 Returns TRUE if DEBUG_CODE()macros are enabled.
307 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
308 PcdDebugProperyMask is set. Otherwise FALSE is returned.
310 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
311 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
320 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED
) != 0);
326 Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.
328 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of
329 PcdDebugProperyMask is set. Otherwise FALSE is returned.
331 @retval TRUE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
332 @retval FALSE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
337 DebugClearMemoryEnabled (
341 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED
) != 0);