]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdePkg/Library/UefiDebugLibStdErr/DebugLib.c
MdePkg: Apply uncrustify changes
[mirror_edk2.git] / MdePkg / Library / UefiDebugLibStdErr / DebugLib.c
... / ...
CommitLineData
1/** @file\r
2 UEFI Debug Lib that sends messages to the Standard Error Device in the EFI System Table.\r
3\r
4 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
6\r
7**/\r
8\r
9#include <Uefi.h>\r
10\r
11#include <Library/DebugLib.h>\r
12#include <Library/PrintLib.h>\r
13#include <Library/PcdLib.h>\r
14#include <Library/BaseLib.h>\r
15#include <Library/BaseMemoryLib.h>\r
16#include <Library/DebugPrintErrorLevelLib.h>\r
17\r
18//\r
19// Define the maximum debug and assert message length that this library supports\r
20//\r
21#define MAX_DEBUG_MESSAGE_LENGTH 0x100\r
22\r
23//\r
24// VA_LIST can not initialize to NULL for all compiler, so we use this to\r
25// indicate a null VA_LIST\r
26//\r
27VA_LIST mVaListNull;\r
28\r
29extern BOOLEAN mPostEBS;\r
30extern EFI_SYSTEM_TABLE *mDebugST;\r
31\r
32/**\r
33 Prints a debug message to the debug output device if the specified error level is enabled.\r
34\r
35 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r
36 GetDebugPrintErrorLevel (), then print the message specified by Format and the\r
37 associated variable argument list to the debug output device.\r
38\r
39 If Format is NULL, then ASSERT().\r
40\r
41 @param ErrorLevel The error level of the debug message.\r
42 @param Format The format string for the debug message to print.\r
43 @param ... The variable argument list whose contents are accessed\r
44 based on the format string specified by Format.\r
45\r
46**/\r
47VOID\r
48EFIAPI\r
49DebugPrint (\r
50 IN UINTN ErrorLevel,\r
51 IN CONST CHAR8 *Format,\r
52 ...\r
53 )\r
54{\r
55 VA_LIST Marker;\r
56\r
57 VA_START (Marker, Format);\r
58 DebugVPrint (ErrorLevel, Format, Marker);\r
59 VA_END (Marker);\r
60}\r
61\r
62/**\r
63 Prints a debug message to the debug output device if the specified\r
64 error level is enabled base on Null-terminated format string and a\r
65 VA_LIST argument list or a BASE_LIST argument list.\r
66\r
67 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r
68 GetDebugPrintErrorLevel (), then print the message specified by Format and\r
69 the associated variable argument list to the debug output device.\r
70\r
71 If Format is NULL, then ASSERT().\r
72\r
73 @param ErrorLevel The error level of the debug message.\r
74 @param Format Format string for the debug message to print.\r
75 @param VaListMarker VA_LIST marker for the variable argument list.\r
76 @param BaseListMarker BASE_LIST marker for the variable argument list.\r
77\r
78**/\r
79VOID\r
80DebugPrintMarker (\r
81 IN UINTN ErrorLevel,\r
82 IN CONST CHAR8 *Format,\r
83 IN VA_LIST VaListMarker,\r
84 IN BASE_LIST BaseListMarker\r
85 )\r
86{\r
87 CHAR16 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
88\r
89 if (!mPostEBS) {\r
90 //\r
91 // If Format is NULL, then ASSERT().\r
92 //\r
93 ASSERT (Format != NULL);\r
94\r
95 //\r
96 // Check driver debug mask value and global mask\r
97 //\r
98 if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) {\r
99 return;\r
100 }\r
101\r
102 //\r
103 // Convert the DEBUG() message to a Unicode String\r
104 //\r
105 if (BaseListMarker == NULL) {\r
106 UnicodeVSPrintAsciiFormat (Buffer, sizeof (Buffer), Format, VaListMarker);\r
107 } else {\r
108 UnicodeBSPrintAsciiFormat (Buffer, sizeof (Buffer), Format, BaseListMarker);\r
109 }\r
110\r
111 //\r
112 // Send the print string to the Standard Error device\r
113 //\r
114 if ((mDebugST != NULL) && (mDebugST->StdErr != NULL)) {\r
115 mDebugST->StdErr->OutputString (mDebugST->StdErr, Buffer);\r
116 }\r
117 }\r
118}\r
119\r
120/**\r
121 Prints a debug message to the debug output device if the specified\r
122 error level is enabled.\r
123\r
124 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r
125 GetDebugPrintErrorLevel (), then print the message specified by Format and\r
126 the associated variable argument list to the debug output device.\r
127\r
128 If Format is NULL, then ASSERT().\r
129\r
130 @param ErrorLevel The error level of the debug message.\r
131 @param Format Format string for the debug message to print.\r
132 @param VaListMarker VA_LIST marker for the variable argument list.\r
133\r
134**/\r
135VOID\r
136EFIAPI\r
137DebugVPrint (\r
138 IN UINTN ErrorLevel,\r
139 IN CONST CHAR8 *Format,\r
140 IN VA_LIST VaListMarker\r
141 )\r
142{\r
143 DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL);\r
144}\r
145\r
146/**\r
147 Prints a debug message to the debug output device if the specified\r
148 error level is enabled.\r
149 This function use BASE_LIST which would provide a more compatible\r
150 service than VA_LIST.\r
151\r
152 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r
153 GetDebugPrintErrorLevel (), then print the message specified by Format and\r
154 the associated variable argument list to the debug output device.\r
155\r
156 If Format is NULL, then ASSERT().\r
157\r
158 @param ErrorLevel The error level of the debug message.\r
159 @param Format Format string for the debug message to print.\r
160 @param BaseListMarker BASE_LIST marker for the variable argument list.\r
161\r
162**/\r
163VOID\r
164EFIAPI\r
165DebugBPrint (\r
166 IN UINTN ErrorLevel,\r
167 IN CONST CHAR8 *Format,\r
168 IN BASE_LIST BaseListMarker\r
169 )\r
170{\r
171 DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker);\r
172}\r
173\r
174/**\r
175 Prints an assert message containing a filename, line number, and description.\r
176 This may be followed by a breakpoint or a dead loop.\r
177\r
178 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"\r
179 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of\r
180 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if\r
181 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then\r
182 CpuDeadLoop() is called. If neither of these bits are set, then this function\r
183 returns immediately after the message is printed to the debug output device.\r
184 DebugAssert() must actively prevent recursion. If DebugAssert() is called while\r
185 processing another DebugAssert(), then DebugAssert() must return immediately.\r
186\r
187 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r
188 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r
189\r
190 @param FileName The pointer to the name of the source file that generated\r
191 the assert condition.\r
192 @param LineNumber The line number in the source file that generated the\r
193 assert condition\r
194 @param Description The pointer to the description of the assert condition.\r
195\r
196**/\r
197VOID\r
198EFIAPI\r
199DebugAssert (\r
200 IN CONST CHAR8 *FileName,\r
201 IN UINTN LineNumber,\r
202 IN CONST CHAR8 *Description\r
203 )\r
204{\r
205 CHAR16 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
206\r
207 if (!mPostEBS) {\r
208 //\r
209 // Generate the ASSERT() message in Unicode format\r
210 //\r
211 UnicodeSPrintAsciiFormat (\r
212 Buffer,\r
213 sizeof (Buffer),\r
214 "ASSERT [%a] %a(%d): %a\n",\r
215 gEfiCallerBaseName,\r
216 FileName,\r
217 LineNumber,\r
218 Description\r
219 );\r
220\r
221 //\r
222 // Send the print string to the Standard Error device\r
223 //\r
224 if ((mDebugST != NULL) && (mDebugST->StdErr != NULL)) {\r
225 mDebugST->StdErr->OutputString (mDebugST->StdErr, Buffer);\r
226 }\r
227\r
228 //\r
229 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r
230 //\r
231 if ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r
232 CpuBreakpoint ();\r
233 } else if ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r
234 CpuDeadLoop ();\r
235 }\r
236 }\r
237}\r
238\r
239/**\r
240 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r
241\r
242 This function fills Length bytes of Buffer with the value specified by\r
243 PcdDebugClearMemoryValue, and returns Buffer.\r
244\r
245 If Buffer is NULL, then ASSERT().\r
246 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
247\r
248 @param Buffer The pointer to the target buffer to be filled with PcdDebugClearMemoryValue.\r
249 @param Length The number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.\r
250\r
251 @return Buffer The pointer to the target buffer filled with PcdDebugClearMemoryValue.\r
252\r
253**/\r
254VOID *\r
255EFIAPI\r
256DebugClearMemory (\r
257 OUT VOID *Buffer,\r
258 IN UINTN Length\r
259 )\r
260{\r
261 //\r
262 // If Buffer is NULL, then ASSERT().\r
263 //\r
264 ASSERT (Buffer != NULL);\r
265\r
266 //\r
267 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer\r
268 //\r
269 return SetMem (Buffer, Length, PcdGet8 (PcdDebugClearMemoryValue));\r
270}\r
271\r
272/**\r
273 Returns TRUE if ASSERT() macros are enabled.\r
274\r
275 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of\r
276 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
277\r
278 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.\r
279 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.\r
280\r
281**/\r
282BOOLEAN\r
283EFIAPI\r
284DebugAssertEnabled (\r
285 VOID\r
286 )\r
287{\r
288 return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);\r
289}\r
290\r
291/**\r
292 Returns TRUE if DEBUG() macros are enabled.\r
293\r
294 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of\r
295 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
296\r
297 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.\r
298 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.\r
299\r
300**/\r
301BOOLEAN\r
302EFIAPI\r
303DebugPrintEnabled (\r
304 VOID\r
305 )\r
306{\r
307 return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);\r
308}\r
309\r
310/**\r
311 Returns TRUE if DEBUG_CODE() macros are enabled.\r
312\r
313 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of\r
314 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
315\r
316 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.\r
317 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.\r
318\r
319**/\r
320BOOLEAN\r
321EFIAPI\r
322DebugCodeEnabled (\r
323 VOID\r
324 )\r
325{\r
326 return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
327}\r
328\r
329/**\r
330 Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.\r
331\r
332 This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of\r
333 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
334\r
335 @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.\r
336 @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.\r
337\r
338**/\r
339BOOLEAN\r
340EFIAPI\r
341DebugClearMemoryEnabled (\r
342 VOID\r
343 )\r
344{\r
345 return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r
346}\r
347\r
348/**\r
349 Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel.\r
350\r
351 This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel.\r
352\r
353 @retval TRUE Current ErrorLevel is supported.\r
354 @retval FALSE Current ErrorLevel is not supported.\r
355\r
356**/\r
357BOOLEAN\r
358EFIAPI\r
359DebugPrintLevelEnabled (\r
360 IN CONST UINTN ErrorLevel\r
361 )\r
362{\r
363 return (BOOLEAN)((ErrorLevel & PcdGet32 (PcdFixedDebugPrintErrorLevel)) != 0);\r
364}\r