1 | /** @file
|
---|
2 | Provides services to print debug and assert messages to a debug output device.
|
---|
3 |
|
---|
4 | The Debug library supports debug print and asserts based on a combination of macros and code.
|
---|
5 | The debug library can be turned on and off so that the debug code does not increase the size of an image.
|
---|
6 |
|
---|
7 | Note that a reserved macro named MDEPKG_NDEBUG is introduced for the intention
|
---|
8 | of size reduction when compiler optimization is disabled. If MDEPKG_NDEBUG is
|
---|
9 | defined, then debug and assert related macros wrapped by it are the NULL implementations.
|
---|
10 |
|
---|
11 | Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.<BR>
|
---|
12 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
13 |
|
---|
14 | **/
|
---|
15 |
|
---|
16 | #ifndef __DEBUG_LIB_H__
|
---|
17 | #define __DEBUG_LIB_H__
|
---|
18 |
|
---|
19 | //
|
---|
20 | // Declare bits for PcdDebugPropertyMask
|
---|
21 | //
|
---|
22 | #define DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED 0x01
|
---|
23 | #define DEBUG_PROPERTY_DEBUG_PRINT_ENABLED 0x02
|
---|
24 | #define DEBUG_PROPERTY_DEBUG_CODE_ENABLED 0x04
|
---|
25 | #define DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED 0x08
|
---|
26 | #define DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED 0x10
|
---|
27 | #define DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED 0x20
|
---|
28 |
|
---|
29 | //
|
---|
30 | // Declare bits for PcdDebugPrintErrorLevel and the ErrorLevel parameter of DebugPrint()
|
---|
31 | //
|
---|
32 | #define DEBUG_INIT 0x00000001 // Initialization
|
---|
33 | #define DEBUG_WARN 0x00000002 // Warnings
|
---|
34 | #define DEBUG_LOAD 0x00000004 // Load events
|
---|
35 | #define DEBUG_FS 0x00000008 // EFI File system
|
---|
36 | #define DEBUG_POOL 0x00000010 // Alloc & Free (pool)
|
---|
37 | #define DEBUG_PAGE 0x00000020 // Alloc & Free (page)
|
---|
38 | #define DEBUG_INFO 0x00000040 // Informational debug messages
|
---|
39 | #define DEBUG_DISPATCH 0x00000080 // PEI/DXE/SMM Dispatchers
|
---|
40 | #define DEBUG_VARIABLE 0x00000100 // Variable
|
---|
41 | #define DEBUG_BM 0x00000400 // Boot Manager
|
---|
42 | #define DEBUG_BLKIO 0x00001000 // BlkIo Driver
|
---|
43 | #define DEBUG_NET 0x00004000 // Network Io Driver
|
---|
44 | #define DEBUG_UNDI 0x00010000 // UNDI Driver
|
---|
45 | #define DEBUG_LOADFILE 0x00020000 // LoadFile
|
---|
46 | #define DEBUG_EVENT 0x00080000 // Event messages
|
---|
47 | #define DEBUG_GCD 0x00100000 // Global Coherency Database changes
|
---|
48 | #define DEBUG_CACHE 0x00200000 // Memory range cachability changes
|
---|
49 | #define DEBUG_VERBOSE 0x00400000 // Detailed debug messages that may
|
---|
50 | // significantly impact boot performance
|
---|
51 | #define DEBUG_MANAGEABILITY 0x00800000 // Detailed debug and payload manageability messages
|
---|
52 | // related to modules such as Redfish, IPMI, MCTP etc.
|
---|
53 | #define DEBUG_ERROR 0x80000000 // Error
|
---|
54 |
|
---|
55 | //
|
---|
56 | // Aliases of debug message mask bits
|
---|
57 | //
|
---|
58 | #define EFI_D_INIT DEBUG_INIT
|
---|
59 | #define EFI_D_WARN DEBUG_WARN
|
---|
60 | #define EFI_D_LOAD DEBUG_LOAD
|
---|
61 | #define EFI_D_FS DEBUG_FS
|
---|
62 | #define EFI_D_POOL DEBUG_POOL
|
---|
63 | #define EFI_D_PAGE DEBUG_PAGE
|
---|
64 | #define EFI_D_INFO DEBUG_INFO
|
---|
65 | #define EFI_D_DISPATCH DEBUG_DISPATCH
|
---|
66 | #define EFI_D_VARIABLE DEBUG_VARIABLE
|
---|
67 | #define EFI_D_BM DEBUG_BM
|
---|
68 | #define EFI_D_BLKIO DEBUG_BLKIO
|
---|
69 | #define EFI_D_NET DEBUG_NET
|
---|
70 | #define EFI_D_UNDI DEBUG_UNDI
|
---|
71 | #define EFI_D_LOADFILE DEBUG_LOADFILE
|
---|
72 | #define EFI_D_EVENT DEBUG_EVENT
|
---|
73 | #define EFI_D_VERBOSE DEBUG_VERBOSE
|
---|
74 | #define EFI_D_ERROR DEBUG_ERROR
|
---|
75 |
|
---|
76 | //
|
---|
77 | // Source file line number.
|
---|
78 | // Default is use the to compiler provided __LINE__ macro value. The __LINE__
|
---|
79 | // mapping can be overriden by predefining DEBUG_LINE_NUMBER
|
---|
80 | //
|
---|
81 | // Defining DEBUG_LINE_NUMBER to a fixed value is useful when comparing builds
|
---|
82 | // across source code formatting changes that may add/remove lines in a source
|
---|
83 | // file.
|
---|
84 | //
|
---|
85 | #ifdef DEBUG_LINE_NUMBER
|
---|
86 | #else
|
---|
87 | #define DEBUG_LINE_NUMBER __LINE__
|
---|
88 | #endif
|
---|
89 |
|
---|
90 | /**
|
---|
91 | Macro that converts a Boolean expression to a Null-terminated ASCII string.
|
---|
92 |
|
---|
93 | The default is to use the C pre-processor stringizing operator '#' to add
|
---|
94 | quotes around the C expression. If DEBUG_EXPRESSION_STRING_VALUE is defined
|
---|
95 | then the C expression is converted to the fixed string value.
|
---|
96 |
|
---|
97 | Defining DEBUG_EXPRESSION_STRING_VALUE to a fixed value is useful when
|
---|
98 | comparing builds across source code formatting changes that may make
|
---|
99 | changes to spaces or parenthesis in a Boolean expression.
|
---|
100 |
|
---|
101 | @param Expression Boolean expression.
|
---|
102 |
|
---|
103 | **/
|
---|
104 |
|
---|
105 | #ifdef DEBUG_EXPRESSION_STRING_VALUE
|
---|
106 | #define DEBUG_EXPRESSION_STRING(Expression) DEBUG_EXPRESSION_STRING_VALUE
|
---|
107 | #else
|
---|
108 | #define DEBUG_EXPRESSION_STRING(Expression) #Expression
|
---|
109 | #endif
|
---|
110 |
|
---|
111 | /**
|
---|
112 | Prints a debug message to the debug output device if the specified error level is enabled.
|
---|
113 |
|
---|
114 | If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
|
---|
115 | GetDebugPrintErrorLevel (), then print the message specified by Format and the
|
---|
116 | associated variable argument list to the debug output device.
|
---|
117 |
|
---|
118 | If Format is NULL, then ASSERT().
|
---|
119 |
|
---|
120 | @param ErrorLevel The error level of the debug message.
|
---|
121 | @param Format The format string for the debug message to print.
|
---|
122 | @param ... The variable argument list whose contents are accessed
|
---|
123 | based on the format string specified by Format.
|
---|
124 |
|
---|
125 | **/
|
---|
126 | VOID
|
---|
127 | EFIAPI
|
---|
128 | DebugPrint (
|
---|
129 | IN UINTN ErrorLevel,
|
---|
130 | IN CONST CHAR8 *Format,
|
---|
131 | ...
|
---|
132 | );
|
---|
133 |
|
---|
134 | /**
|
---|
135 | Prints a debug message to the debug output device if the specified
|
---|
136 | error level is enabled.
|
---|
137 |
|
---|
138 | If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
|
---|
139 | GetDebugPrintErrorLevel (), then print the message specified by Format and
|
---|
140 | the associated variable argument list to the debug output device.
|
---|
141 |
|
---|
142 | If Format is NULL, then ASSERT().
|
---|
143 |
|
---|
144 | @param ErrorLevel The error level of the debug message.
|
---|
145 | @param Format Format string for the debug message to print.
|
---|
146 | @param VaListMarker VA_LIST marker for the variable argument list.
|
---|
147 |
|
---|
148 | **/
|
---|
149 | VOID
|
---|
150 | EFIAPI
|
---|
151 | DebugVPrint (
|
---|
152 | IN UINTN ErrorLevel,
|
---|
153 | IN CONST CHAR8 *Format,
|
---|
154 | IN VA_LIST VaListMarker
|
---|
155 | );
|
---|
156 |
|
---|
157 | /**
|
---|
158 | Prints a debug message to the debug output device if the specified
|
---|
159 | error level is enabled.
|
---|
160 | This function use BASE_LIST which would provide a more compatible
|
---|
161 | service than VA_LIST.
|
---|
162 |
|
---|
163 | If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
|
---|
164 | GetDebugPrintErrorLevel (), then print the message specified by Format and
|
---|
165 | the associated variable argument list to the debug output device.
|
---|
166 |
|
---|
167 | If Format is NULL, then ASSERT().
|
---|
168 |
|
---|
169 | @param ErrorLevel The error level of the debug message.
|
---|
170 | @param Format Format string for the debug message to print.
|
---|
171 | @param BaseListMarker BASE_LIST marker for the variable argument list.
|
---|
172 |
|
---|
173 | **/
|
---|
174 | VOID
|
---|
175 | EFIAPI
|
---|
176 | DebugBPrint (
|
---|
177 | IN UINTN ErrorLevel,
|
---|
178 | IN CONST CHAR8 *Format,
|
---|
179 | IN BASE_LIST BaseListMarker
|
---|
180 | );
|
---|
181 |
|
---|
182 | /**
|
---|
183 | Prints an assert message containing a filename, line number, and description.
|
---|
184 | This may be followed by a breakpoint or a dead loop.
|
---|
185 |
|
---|
186 | Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
|
---|
187 | to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
|
---|
188 | PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
|
---|
189 | DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
|
---|
190 | CpuDeadLoop() is called. If neither of these bits are set, then this function
|
---|
191 | returns immediately after the message is printed to the debug output device.
|
---|
192 | DebugAssert() must actively prevent recursion. If DebugAssert() is called while
|
---|
193 | processing another DebugAssert(), then DebugAssert() must return immediately.
|
---|
194 |
|
---|
195 | If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
|
---|
196 | If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
|
---|
197 |
|
---|
198 | @param FileName The pointer to the name of the source file that generated the assert condition.
|
---|
199 | @param LineNumber The line number in the source file that generated the assert condition
|
---|
200 | @param Description The pointer to the description of the assert condition.
|
---|
201 |
|
---|
202 | **/
|
---|
203 | VOID
|
---|
204 | EFIAPI
|
---|
205 | DebugAssert (
|
---|
206 | IN CONST CHAR8 *FileName,
|
---|
207 | IN UINTN LineNumber,
|
---|
208 | IN CONST CHAR8 *Description
|
---|
209 | );
|
---|
210 |
|
---|
211 | /**
|
---|
212 | Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
|
---|
213 |
|
---|
214 | This function fills Length bytes of Buffer with the value specified by
|
---|
215 | PcdDebugClearMemoryValue, and returns Buffer.
|
---|
216 |
|
---|
217 | If Buffer is NULL, then ASSERT().
|
---|
218 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
|
---|
219 |
|
---|
220 | @param Buffer The pointer to the target buffer to be filled with PcdDebugClearMemoryValue.
|
---|
221 | @param Length The number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
|
---|
222 |
|
---|
223 | @return Buffer The pointer to the target buffer filled with PcdDebugClearMemoryValue.
|
---|
224 |
|
---|
225 | **/
|
---|
226 | VOID *
|
---|
227 | EFIAPI
|
---|
228 | DebugClearMemory (
|
---|
229 | OUT VOID *Buffer,
|
---|
230 | IN UINTN Length
|
---|
231 | );
|
---|
232 |
|
---|
233 | /**
|
---|
234 | Returns TRUE if ASSERT() macros are enabled.
|
---|
235 |
|
---|
236 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
|
---|
237 | PcdDebugProperyMask is set. Otherwise, FALSE is returned.
|
---|
238 |
|
---|
239 | @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
|
---|
240 | @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
|
---|
241 |
|
---|
242 | **/
|
---|
243 | BOOLEAN
|
---|
244 | EFIAPI
|
---|
245 | DebugAssertEnabled (
|
---|
246 | VOID
|
---|
247 | );
|
---|
248 |
|
---|
249 | /**
|
---|
250 | Returns TRUE if DEBUG() macros are enabled.
|
---|
251 |
|
---|
252 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
|
---|
253 | PcdDebugProperyMask is set. Otherwise, FALSE is returned.
|
---|
254 |
|
---|
255 | @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
|
---|
256 | @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
|
---|
257 |
|
---|
258 | **/
|
---|
259 | BOOLEAN
|
---|
260 | EFIAPI
|
---|
261 | DebugPrintEnabled (
|
---|
262 | VOID
|
---|
263 | );
|
---|
264 |
|
---|
265 | /**
|
---|
266 | Returns TRUE if DEBUG_CODE() macros are enabled.
|
---|
267 |
|
---|
268 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
|
---|
269 | PcdDebugProperyMask is set. Otherwise, FALSE is returned.
|
---|
270 |
|
---|
271 | @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
|
---|
272 | @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
|
---|
273 |
|
---|
274 | **/
|
---|
275 | BOOLEAN
|
---|
276 | EFIAPI
|
---|
277 | DebugCodeEnabled (
|
---|
278 | VOID
|
---|
279 | );
|
---|
280 |
|
---|
281 | /**
|
---|
282 | Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.
|
---|
283 |
|
---|
284 | This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of
|
---|
285 | PcdDebugProperyMask is set. Otherwise, FALSE is returned.
|
---|
286 |
|
---|
287 | @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
|
---|
288 | @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
|
---|
289 |
|
---|
290 | **/
|
---|
291 | BOOLEAN
|
---|
292 | EFIAPI
|
---|
293 | DebugClearMemoryEnabled (
|
---|
294 | VOID
|
---|
295 | );
|
---|
296 |
|
---|
297 | /**
|
---|
298 | Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel.
|
---|
299 |
|
---|
300 | This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel.
|
---|
301 |
|
---|
302 | @retval TRUE Current ErrorLevel is supported.
|
---|
303 | @retval FALSE Current ErrorLevel is not supported.
|
---|
304 |
|
---|
305 | **/
|
---|
306 | BOOLEAN
|
---|
307 | EFIAPI
|
---|
308 | DebugPrintLevelEnabled (
|
---|
309 | IN CONST UINTN ErrorLevel
|
---|
310 | );
|
---|
311 |
|
---|
312 | /**
|
---|
313 | Internal worker macro that calls DebugAssert().
|
---|
314 |
|
---|
315 | This macro calls DebugAssert(), passing in the filename, line number, and an
|
---|
316 | expression that evaluated to FALSE.
|
---|
317 |
|
---|
318 | @param Expression Boolean expression that evaluated to FALSE
|
---|
319 |
|
---|
320 | **/
|
---|
321 | #if defined (EDKII_UNIT_TEST_FRAMEWORK_ENABLED)
|
---|
322 |
|
---|
323 | /**
|
---|
324 | Unit test library replacement for DebugAssert() in DebugLib.
|
---|
325 |
|
---|
326 | If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
|
---|
327 | If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
|
---|
328 |
|
---|
329 | @param FileName The pointer to the name of the source file that generated the assert condition.
|
---|
330 | @param LineNumber The line number in the source file that generated the assert condition
|
---|
331 | @param Description The pointer to the description of the assert condition.
|
---|
332 |
|
---|
333 | **/
|
---|
334 | VOID
|
---|
335 | EFIAPI
|
---|
336 | UnitTestDebugAssert (
|
---|
337 | IN CONST CHAR8 *FileName,
|
---|
338 | IN UINTN LineNumber,
|
---|
339 | IN CONST CHAR8 *Description
|
---|
340 | );
|
---|
341 |
|
---|
342 | #if defined (_ASSERT)
|
---|
343 | #undef _ASSERT
|
---|
344 | #endif
|
---|
345 | #if defined (__clang__) && defined (__FILE_NAME__)
|
---|
346 | #define _ASSERT(Expression) UnitTestDebugAssert (__FILE_NAME__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))
|
---|
347 | #else
|
---|
348 | #define _ASSERT(Expression) UnitTestDebugAssert (__FILE__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))
|
---|
349 | #endif
|
---|
350 | #else
|
---|
351 | #if defined (__clang__) && defined (__FILE_NAME__)
|
---|
352 | #define _ASSERT(Expression) DebugAssert (__FILE_NAME__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))
|
---|
353 | #else
|
---|
354 | #define _ASSERT(Expression) DebugAssert (__FILE__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))
|
---|
355 | #endif
|
---|
356 | #endif
|
---|
357 |
|
---|
358 | /**
|
---|
359 | Internal worker macro that calls DebugPrint().
|
---|
360 |
|
---|
361 | This macro calls DebugPrint() passing in the debug error level, a format
|
---|
362 | string, and a variable argument list.
|
---|
363 | __VA_ARGS__ is not supported by EBC compiler, Microsoft Visual Studio .NET 2003
|
---|
364 | and Microsoft Windows Server 2003 Driver Development Kit (Microsoft WINDDK) version 3790.1830.
|
---|
365 |
|
---|
366 | @param Expression Expression containing an error level, a format string,
|
---|
367 | and a variable argument list based on the format string.
|
---|
368 |
|
---|
369 | **/
|
---|
370 |
|
---|
371 | #if !defined (MDE_CPU_EBC) && (!defined (_MSC_VER) || _MSC_VER > 1400)
|
---|
372 | #define _DEBUG_PRINT(PrintLevel, ...) \
|
---|
373 | do { \
|
---|
374 | if (DebugPrintLevelEnabled (PrintLevel)) { \
|
---|
375 | DebugPrint (PrintLevel, ##__VA_ARGS__); \
|
---|
376 | } \
|
---|
377 | } while (FALSE)
|
---|
378 | #define _DEBUGLIB_DEBUG(Expression) _DEBUG_PRINT Expression
|
---|
379 | #else
|
---|
380 | #define _DEBUGLIB_DEBUG(Expression) DebugPrint Expression
|
---|
381 | #endif
|
---|
382 |
|
---|
383 | /**
|
---|
384 | Macro that calls DebugAssert() if an expression evaluates to FALSE.
|
---|
385 |
|
---|
386 | If MDEPKG_NDEBUG is not defined and the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
|
---|
387 | bit of PcdDebugProperyMask is set, then this macro evaluates the Boolean
|
---|
388 | expression specified by Expression. If Expression evaluates to FALSE, then
|
---|
389 | DebugAssert() is called passing in the source filename, source line number,
|
---|
390 | and Expression.
|
---|
391 |
|
---|
392 | @param Expression Boolean expression.
|
---|
393 |
|
---|
394 | **/
|
---|
395 | #if !defined (MDEPKG_NDEBUG)
|
---|
396 | #define ASSERT(Expression) \
|
---|
397 | do { \
|
---|
398 | if (DebugAssertEnabled ()) { \
|
---|
399 | if (!(Expression)) { \
|
---|
400 | _ASSERT (Expression); \
|
---|
401 | ANALYZER_UNREACHABLE (); \
|
---|
402 | } \
|
---|
403 | } \
|
---|
404 | } while (FALSE)
|
---|
405 | #else
|
---|
406 | #define ASSERT(Expression)
|
---|
407 | #endif
|
---|
408 |
|
---|
409 | /**
|
---|
410 | Macro that calls DebugPrint().
|
---|
411 |
|
---|
412 | If MDEPKG_NDEBUG is not defined and the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
|
---|
413 | bit of PcdDebugProperyMask is set, then this macro passes Expression to
|
---|
414 | DebugPrint().
|
---|
415 |
|
---|
416 | @param Expression Expression containing an error level, a format string,
|
---|
417 | and a variable argument list based on the format string.
|
---|
418 |
|
---|
419 |
|
---|
420 | **/
|
---|
421 | #if !defined (MDEPKG_NDEBUG)
|
---|
422 | #define DEBUG(Expression) \
|
---|
423 | do { \
|
---|
424 | if (DebugPrintEnabled ()) { \
|
---|
425 | _DEBUGLIB_DEBUG (Expression); \
|
---|
426 | } \
|
---|
427 | } while (FALSE)
|
---|
428 | #else
|
---|
429 | #define DEBUG(Expression)
|
---|
430 | #endif
|
---|
431 |
|
---|
432 | /**
|
---|
433 | Macro that calls DebugAssert() if an EFI_STATUS evaluates to an error code.
|
---|
434 |
|
---|
435 | If MDEPKG_NDEBUG is not defined and the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
|
---|
436 | bit of PcdDebugProperyMask is set, then this macro evaluates the EFI_STATUS
|
---|
437 | value specified by StatusParameter. If StatusParameter is an error code,
|
---|
438 | then DebugAssert() is called passing in the source filename, source line
|
---|
439 | number, and StatusParameter.
|
---|
440 |
|
---|
441 | @param StatusParameter EFI_STATUS value to evaluate.
|
---|
442 |
|
---|
443 | **/
|
---|
444 | #if !defined (MDEPKG_NDEBUG)
|
---|
445 | #define ASSERT_EFI_ERROR(StatusParameter) \
|
---|
446 | do { \
|
---|
447 | if (DebugAssertEnabled ()) { \
|
---|
448 | if (EFI_ERROR (StatusParameter)) { \
|
---|
449 | DEBUG ((DEBUG_ERROR, "\nASSERT_EFI_ERROR (Status = %r)\n", StatusParameter)); \
|
---|
450 | _ASSERT (!EFI_ERROR (StatusParameter)); \
|
---|
451 | } \
|
---|
452 | } \
|
---|
453 | } while (FALSE)
|
---|
454 | #else
|
---|
455 | #define ASSERT_EFI_ERROR(StatusParameter)
|
---|
456 | #endif
|
---|
457 |
|
---|
458 | /**
|
---|
459 | Macro that calls DebugAssert() if a RETURN_STATUS evaluates to an error code.
|
---|
460 |
|
---|
461 | If MDEPKG_NDEBUG is not defined and the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
|
---|
462 | bit of PcdDebugProperyMask is set, then this macro evaluates the
|
---|
463 | RETURN_STATUS value specified by StatusParameter. If StatusParameter is an
|
---|
464 | error code, then DebugAssert() is called passing in the source filename,
|
---|
465 | source line number, and StatusParameter.
|
---|
466 |
|
---|
467 | @param StatusParameter RETURN_STATUS value to evaluate.
|
---|
468 |
|
---|
469 | **/
|
---|
470 | #if !defined (MDEPKG_NDEBUG)
|
---|
471 | #define ASSERT_RETURN_ERROR(StatusParameter) \
|
---|
472 | do { \
|
---|
473 | if (DebugAssertEnabled ()) { \
|
---|
474 | if (RETURN_ERROR (StatusParameter)) { \
|
---|
475 | DEBUG ((DEBUG_ERROR, "\nASSERT_RETURN_ERROR (Status = %r)\n", \
|
---|
476 | StatusParameter)); \
|
---|
477 | _ASSERT (!RETURN_ERROR (StatusParameter)); \
|
---|
478 | } \
|
---|
479 | } \
|
---|
480 | } while (FALSE)
|
---|
481 | #else
|
---|
482 | #define ASSERT_RETURN_ERROR(StatusParameter)
|
---|
483 | #endif
|
---|
484 |
|
---|
485 | /**
|
---|
486 | Macro that calls DebugAssert() if a protocol is already installed in the
|
---|
487 | handle database.
|
---|
488 |
|
---|
489 | If MDEPKG_NDEBUG is defined or the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit
|
---|
490 | of PcdDebugProperyMask is clear, then return.
|
---|
491 |
|
---|
492 | If Handle is NULL, then a check is made to see if the protocol specified by Guid
|
---|
493 | is present on any handle in the handle database. If Handle is not NULL, then
|
---|
494 | a check is made to see if the protocol specified by Guid is present on the
|
---|
495 | handle specified by Handle. If the check finds the protocol, then DebugAssert()
|
---|
496 | is called passing in the source filename, source line number, and Guid.
|
---|
497 |
|
---|
498 | If Guid is NULL, then ASSERT().
|
---|
499 |
|
---|
500 | @param Handle The handle to check for the protocol. This is an optional
|
---|
501 | parameter that may be NULL. If it is NULL, then the entire
|
---|
502 | handle database is searched.
|
---|
503 |
|
---|
504 | @param Guid The pointer to a protocol GUID.
|
---|
505 |
|
---|
506 | **/
|
---|
507 | #if !defined (MDEPKG_NDEBUG)
|
---|
508 | #define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid) \
|
---|
509 | do { \
|
---|
510 | if (DebugAssertEnabled ()) { \
|
---|
511 | VOID *Instance; \
|
---|
512 | ASSERT (Guid != NULL); \
|
---|
513 | if (Handle == NULL) { \
|
---|
514 | if (!EFI_ERROR (gBS->LocateProtocol ((EFI_GUID *)Guid, NULL, &Instance))) { \
|
---|
515 | _ASSERT (Guid already installed in database); \
|
---|
516 | } \
|
---|
517 | } else { \
|
---|
518 | if (!EFI_ERROR (gBS->HandleProtocol (Handle, (EFI_GUID *)Guid, &Instance))) { \
|
---|
519 | _ASSERT (Guid already installed on Handle); \
|
---|
520 | } \
|
---|
521 | } \
|
---|
522 | } \
|
---|
523 | } while (FALSE)
|
---|
524 | #else
|
---|
525 | #define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid)
|
---|
526 | #endif
|
---|
527 |
|
---|
528 | /**
|
---|
529 | Macro that marks the beginning of debug source code.
|
---|
530 |
|
---|
531 | If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set,
|
---|
532 | then this macro marks the beginning of source code that is included in a module.
|
---|
533 | Otherwise, the source lines between DEBUG_CODE_BEGIN() and DEBUG_CODE_END()
|
---|
534 | are not included in a module.
|
---|
535 |
|
---|
536 | **/
|
---|
537 | #define DEBUG_CODE_BEGIN() do { if (DebugCodeEnabled ()) { UINT8 __DebugCodeLocal
|
---|
538 |
|
---|
539 | /**
|
---|
540 | The macro that marks the end of debug source code.
|
---|
541 |
|
---|
542 | If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set,
|
---|
543 | then this macro marks the end of source code that is included in a module.
|
---|
544 | Otherwise, the source lines between DEBUG_CODE_BEGIN() and DEBUG_CODE_END()
|
---|
545 | are not included in a module.
|
---|
546 |
|
---|
547 | **/
|
---|
548 | #define DEBUG_CODE_END() __DebugCodeLocal = 0; __DebugCodeLocal++; } } while (FALSE)
|
---|
549 |
|
---|
550 | /**
|
---|
551 | The macro that declares a section of debug source code.
|
---|
552 |
|
---|
553 | If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set,
|
---|
554 | then the source code specified by Expression is included in a module.
|
---|
555 | Otherwise, the source specified by Expression is not included in a module.
|
---|
556 |
|
---|
557 | **/
|
---|
558 | #define DEBUG_CODE(Expression) \
|
---|
559 | DEBUG_CODE_BEGIN (); \
|
---|
560 | Expression \
|
---|
561 | DEBUG_CODE_END ()
|
---|
562 |
|
---|
563 | /**
|
---|
564 | The macro that calls DebugClearMemory() to clear a buffer to a default value.
|
---|
565 |
|
---|
566 | If the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set,
|
---|
567 | then this macro calls DebugClearMemory() passing in Address and Length.
|
---|
568 |
|
---|
569 | @param Address The pointer to a buffer.
|
---|
570 | @param Length The number of bytes in the buffer to set.
|
---|
571 |
|
---|
572 | **/
|
---|
573 | #define DEBUG_CLEAR_MEMORY(Address, Length) \
|
---|
574 | do { \
|
---|
575 | if (DebugClearMemoryEnabled ()) { \
|
---|
576 | DebugClearMemory (Address, Length); \
|
---|
577 | } \
|
---|
578 | } while (FALSE)
|
---|
579 |
|
---|
580 | /**
|
---|
581 | Macro that calls DebugAssert() if the containing record does not have a
|
---|
582 | matching signature. If the signatures matches, then a pointer to the data
|
---|
583 | structure that contains a specified field of that data structure is returned.
|
---|
584 | This is a lightweight method hide information by placing a public data
|
---|
585 | structure inside a larger private data structure and using a pointer to the
|
---|
586 | public data structure to retrieve a pointer to the private data structure.
|
---|
587 |
|
---|
588 | If MDEPKG_NDEBUG is defined or the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit
|
---|
589 | of PcdDebugProperyMask is clear, then this macro computes the offset, in bytes,
|
---|
590 | of the field specified by Field from the beginning of the data structure specified
|
---|
591 | by TYPE. This offset is subtracted from Record, and is used to return a pointer
|
---|
592 | to a data structure of the type specified by TYPE.
|
---|
593 |
|
---|
594 | If MDEPKG_NDEBUG is not defined and the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit
|
---|
595 | of PcdDebugProperyMask is set, then this macro computes the offset, in bytes,
|
---|
596 | of field specified by Field from the beginning of the data structure specified
|
---|
597 | by TYPE. This offset is subtracted from Record, and is used to compute a pointer
|
---|
598 | to a data structure of the type specified by TYPE. The Signature field of the
|
---|
599 | data structure specified by TYPE is compared to TestSignature. If the signatures
|
---|
600 | match, then a pointer to the pointer to a data structure of the type specified by
|
---|
601 | TYPE is returned. If the signatures do not match, then DebugAssert() is called
|
---|
602 | with a description of "CR has a bad signature" and Record is returned.
|
---|
603 |
|
---|
604 | If the data type specified by TYPE does not contain the field specified by Field,
|
---|
605 | then the module will not compile.
|
---|
606 |
|
---|
607 | If TYPE does not contain a field called Signature, then the module will not
|
---|
608 | compile.
|
---|
609 |
|
---|
610 | @param Record The pointer to the field specified by Field within a data
|
---|
611 | structure of type TYPE.
|
---|
612 |
|
---|
613 | @param TYPE The name of the data structure type to return This
|
---|
614 | data structure must contain the field specified by Field.
|
---|
615 |
|
---|
616 | @param Field The name of the field in the data structure specified
|
---|
617 | by TYPE to which Record points.
|
---|
618 |
|
---|
619 | @param TestSignature The 32-bit signature value to match.
|
---|
620 |
|
---|
621 | **/
|
---|
622 | #if !defined (MDEPKG_NDEBUG)
|
---|
623 | #define CR(Record, TYPE, Field, TestSignature) \
|
---|
624 | (DebugAssertEnabled () && (BASE_CR (Record, TYPE, Field)->Signature != TestSignature)) ? \
|
---|
625 | (TYPE *) (_ASSERT (CR has Bad Signature), Record) : \
|
---|
626 | BASE_CR (Record, TYPE, Field)
|
---|
627 | #else
|
---|
628 | #define CR(Record, TYPE, Field, TestSignature) \
|
---|
629 | BASE_CR (Record, TYPE, Field)
|
---|
630 | #endif
|
---|
631 |
|
---|
632 | #if defined(VBOX)
|
---|
633 | VOID EFIAPI VBoxLogWorker(const char *pszFormat, ...);
|
---|
634 |
|
---|
635 | /** See RT_XSTR */
|
---|
636 | # define VBOX_XSTR(str) VBOX_STR(str)
|
---|
637 | /** See RT_STR */
|
---|
638 | # define VBOX_STR(str) #str
|
---|
639 | # if defined(EFI_LOG_ENABLED)
|
---|
640 | # define VBoxLogFlowFuncEnter() DEBUG((DEBUG_INFO, "%a:" VBOX_XSTR(__LINE__) ": ENTER\n", __FUNCTION__))
|
---|
641 | # define VBoxLogFlowFuncLeave() DEBUG((DEBUG_INFO, "%a:" VBOX_XSTR(__LINE__) ": LEAVE\n", __FUNCTION__))
|
---|
642 | # define VBoxLogFlowFuncMark() DEBUG((DEBUG_INFO, "%a:" VBOX_XSTR(__LINE__) "\n", __FUNCTION__))
|
---|
643 | # define VBoxLogFlowFuncLeaveRC(rc) \
|
---|
644 | do { \
|
---|
645 | EFI_STATUS rcLog = (rc); \
|
---|
646 | VBoxLog(("%a:" VBOX_XSTR(__LINE__) ": LEAVE " #rc "=0x%x (%r)\n", __FUNCTION__, rcLog, rcLog)); \
|
---|
647 | } while (0)
|
---|
648 | # define VBoxLogFlowFuncMarkVar(var, varfmt) \
|
---|
649 | DEBUG((DEBUG_INFO, "%a:" VBOX_XSTR(__LINE__) ": " #var "=" varfmt "\n", __FUNCTION__, (var)))
|
---|
650 | # define VBoxLogFlowFuncMarkRC(rc) \
|
---|
651 | do { \
|
---|
652 | EFI_STATUS rcLog = (rc); \
|
---|
653 | VBoxLog(("%a:" VBOX_XSTR(__LINE__) ": " #rc "=0x%x (%r)\n", __FUNCTION__, rcLog, rcLog)); \
|
---|
654 | } while (0)
|
---|
655 | # define VBoxLog(a) VBoxLogWorker a
|
---|
656 | # else /* !EFI_LOG_ENABLED */
|
---|
657 | # define VBoxLogFlowFuncEnter() do {} while (0)
|
---|
658 | # define VBoxLogFlowFuncLeave() do {} while (0)
|
---|
659 | # define VBoxLogFlowFuncLeaveRC(rc) do {} while (0)
|
---|
660 | # define VBoxLogFlowFuncMark() do {} while (0)
|
---|
661 | # define VBoxLogFlowFuncMarkVar(var, varfmt) do {} while (0)
|
---|
662 | # define VBoxLogFlowFuncMarkRC(rc) do {} while (0)
|
---|
663 | # define VBoxLog(a) do {} while (0)
|
---|
664 | # endif /* !EFI_LOG_ENABLED */
|
---|
665 | #endif /* VBOX */
|
---|
666 | #endif
|
---|