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