]>
Commit | Line | Data |
---|---|---|
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 | 11 | Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.<BR>\r |
9344f092 | 12 | SPDX-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 | |
2f88bd3a | 51 | #define DEBUG_ERROR 0x80000000 // Error\r |
fb3df220 | 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 | |
124 | VOID\r | |
125 | EFIAPI\r | |
126 | DebugPrint (\r | |
127 | IN UINTN ErrorLevel,\r | |
128 | IN CONST CHAR8 *Format,\r | |
129 | ...\r | |
130 | );\r | |
131 | \r | |
b87a9a76 BB |
132 | /**\r |
133 | Prints a debug message to the debug output device if the specified\r | |
134 | error level is enabled.\r | |
135 | \r | |
136 | If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r | |
137 | GetDebugPrintErrorLevel (), then print the message specified by Format and\r | |
138 | the associated variable argument list to the debug output device.\r | |
139 | \r | |
140 | If Format is NULL, then ASSERT().\r | |
141 | \r | |
142 | @param ErrorLevel The error level of the debug message.\r | |
143 | @param Format Format string for the debug message to print.\r | |
144 | @param VaListMarker VA_LIST marker for the variable argument list.\r | |
145 | \r | |
146 | **/\r | |
147 | VOID\r | |
148 | EFIAPI\r | |
149 | DebugVPrint (\r | |
2f88bd3a MK |
150 | IN UINTN ErrorLevel,\r |
151 | IN CONST CHAR8 *Format,\r | |
152 | IN VA_LIST VaListMarker\r | |
b87a9a76 BB |
153 | );\r |
154 | \r | |
b87a9a76 BB |
155 | /**\r |
156 | Prints a debug message to the debug output device if the specified\r | |
157 | error level is enabled.\r | |
158 | This function use BASE_LIST which would provide a more compatible\r | |
159 | service than VA_LIST.\r | |
160 | \r | |
161 | If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r | |
162 | GetDebugPrintErrorLevel (), then print the message specified by Format and\r | |
163 | the associated variable argument list to the debug output device.\r | |
164 | \r | |
165 | If Format is NULL, then ASSERT().\r | |
166 | \r | |
167 | @param ErrorLevel The error level of the debug message.\r | |
168 | @param Format Format string for the debug message to print.\r | |
169 | @param BaseListMarker BASE_LIST marker for the variable argument list.\r | |
170 | \r | |
171 | **/\r | |
172 | VOID\r | |
173 | EFIAPI\r | |
174 | DebugBPrint (\r | |
2f88bd3a MK |
175 | IN UINTN ErrorLevel,\r |
176 | IN CONST CHAR8 *Format,\r | |
177 | IN BASE_LIST BaseListMarker\r | |
b87a9a76 BB |
178 | );\r |
179 | \r | |
fb3df220 | 180 | /**\r |
9095d37b | 181 | Prints an assert message containing a filename, line number, and description.\r |
fb3df220 | 182 | This may be followed by a breakpoint or a dead loop.\r |
183 | \r | |
184 | Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"\r | |
9095d37b LG |
185 | to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of\r |
186 | PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if\r | |
187 | DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then\r | |
188 | CpuDeadLoop() is called. If neither of these bits are set, then this function\r | |
fb3df220 | 189 | returns immediately after the message is printed to the debug output device.\r |
584125bc | 190 | DebugAssert() must actively prevent recursion. If DebugAssert() is called while\r |
fb3df220 | 191 | processing another DebugAssert(), then DebugAssert() must return immediately.\r |
192 | \r | |
584125bc | 193 | If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r |
584125bc | 194 | If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r |
fb3df220 | 195 | \r |
af2dc6a7 | 196 | @param FileName The pointer to the name of the source file that generated the assert condition.\r |
fb3df220 | 197 | @param LineNumber The line number in the source file that generated the assert condition\r |
af2dc6a7 | 198 | @param Description The pointer to the description of the assert condition.\r |
fb3df220 | 199 | \r |
200 | **/\r | |
201 | VOID\r | |
202 | EFIAPI\r | |
203 | DebugAssert (\r | |
204 | IN CONST CHAR8 *FileName,\r | |
205 | IN UINTN LineNumber,\r | |
206 | IN CONST CHAR8 *Description\r | |
207 | );\r | |
208 | \r | |
fb3df220 | 209 | /**\r |
fb3df220 | 210 | Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r |
211 | \r | |
9095d37b | 212 | This function fills Length bytes of Buffer with the value specified by\r |
fb3df220 | 213 | PcdDebugClearMemoryValue, and returns Buffer.\r |
214 | \r | |
215 | If Buffer is NULL, then ASSERT().\r | |
9095d37b | 216 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r |
fb3df220 | 217 | \r |
af2dc6a7 | 218 | @param Buffer The pointer to the target buffer to be filled with PcdDebugClearMemoryValue.\r |
9095d37b | 219 | @param Length The number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.\r |
fb3df220 | 220 | \r |
af2dc6a7 | 221 | @return Buffer The pointer to the target buffer filled with PcdDebugClearMemoryValue.\r |
fb3df220 | 222 | \r |
223 | **/\r | |
224 | VOID *\r | |
225 | EFIAPI\r | |
226 | DebugClearMemory (\r | |
227 | OUT VOID *Buffer,\r | |
228 | IN UINTN Length\r | |
229 | );\r | |
230 | \r | |
fb3df220 | 231 | /**\r |
fb3df220 | 232 | Returns TRUE if ASSERT() macros are enabled.\r |
233 | \r | |
9095d37b | 234 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of\r |
af2dc6a7 | 235 | PcdDebugProperyMask is set. Otherwise, FALSE is returned.\r |
fb3df220 | 236 | \r |
237 | @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.\r | |
238 | @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.\r | |
239 | \r | |
240 | **/\r | |
241 | BOOLEAN\r | |
242 | EFIAPI\r | |
243 | DebugAssertEnabled (\r | |
244 | VOID\r | |
245 | );\r | |
246 | \r | |
9095d37b | 247 | /**\r |
3e5c3238 | 248 | Returns TRUE if DEBUG() macros are enabled.\r |
fb3df220 | 249 | \r |
9095d37b | 250 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of\r |
af2dc6a7 | 251 | PcdDebugProperyMask is set. Otherwise, FALSE is returned.\r |
fb3df220 | 252 | \r |
253 | @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.\r | |
254 | @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.\r | |
255 | \r | |
256 | **/\r | |
257 | BOOLEAN\r | |
258 | EFIAPI\r | |
259 | DebugPrintEnabled (\r | |
260 | VOID\r | |
261 | );\r | |
262 | \r | |
9095d37b | 263 | /**\r |
3e5c3238 | 264 | Returns TRUE if DEBUG_CODE() macros are enabled.\r |
fb3df220 | 265 | \r |
9095d37b | 266 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of\r |
af2dc6a7 | 267 | PcdDebugProperyMask is set. Otherwise, FALSE is returned.\r |
fb3df220 | 268 | \r |
269 | @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.\r | |
270 | @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.\r | |
271 | \r | |
272 | **/\r | |
273 | BOOLEAN\r | |
274 | EFIAPI\r | |
275 | DebugCodeEnabled (\r | |
276 | VOID\r | |
277 | );\r | |
278 | \r | |
9095d37b | 279 | /**\r |
3e5c3238 | 280 | Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.\r |
fb3df220 | 281 | \r |
9095d37b | 282 | This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of\r |
af2dc6a7 | 283 | PcdDebugProperyMask is set. Otherwise, FALSE is returned.\r |
fb3df220 | 284 | \r |
eceb3a4c LG |
285 | @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.\r |
286 | @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.\r | |
fb3df220 | 287 | \r |
288 | **/\r | |
289 | BOOLEAN\r | |
290 | EFIAPI\r | |
291 | DebugClearMemoryEnabled (\r | |
292 | VOID\r | |
293 | );\r | |
294 | \r | |
5ea9d0c3 LG |
295 | /**\r |
296 | Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel.\r | |
297 | \r | |
298 | This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel.\r | |
299 | \r | |
300 | @retval TRUE Current ErrorLevel is supported.\r | |
301 | @retval FALSE Current ErrorLevel is not supported.\r | |
302 | \r | |
303 | **/\r | |
304 | BOOLEAN\r | |
305 | EFIAPI\r | |
306 | DebugPrintLevelEnabled (\r | |
2f88bd3a | 307 | IN CONST UINTN ErrorLevel\r |
5ea9d0c3 | 308 | );\r |
fb3df220 | 309 | \r |
9095d37b | 310 | /**\r |
fb3df220 | 311 | Internal worker macro that calls DebugAssert().\r |
312 | \r | |
1a2f870c | 313 | This macro calls DebugAssert(), passing in the filename, line number, and an\r |
314 | expression that evaluated to FALSE.\r | |
fb3df220 | 315 | \r |
1a2f870c | 316 | @param Expression Boolean expression that evaluated to FALSE\r |
fb3df220 | 317 | \r |
318 | **/\r | |
75e92c13 | 319 | #if defined (EDKII_UNIT_TEST_FRAMEWORK_ENABLED)\r |
2f88bd3a | 320 | \r |
75e92c13 MK |
321 | /**\r |
322 | Unit test library replacement for DebugAssert() in DebugLib.\r | |
323 | \r | |
324 | If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r | |
325 | If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r | |
326 | \r | |
327 | @param FileName The pointer to the name of the source file that generated the assert condition.\r | |
328 | @param LineNumber The line number in the source file that generated the assert condition\r | |
329 | @param Description The pointer to the description of the assert condition.\r | |
330 | \r | |
331 | **/\r | |
332 | VOID\r | |
333 | EFIAPI\r | |
334 | UnitTestDebugAssert (\r | |
335 | IN CONST CHAR8 *FileName,\r | |
336 | IN UINTN LineNumber,\r | |
337 | IN CONST CHAR8 *Description\r | |
338 | );\r | |
339 | \r | |
c1b073a9 MK |
340 | #if defined (_ASSERT)\r |
341 | #undef _ASSERT\r | |
342 | #endif\r | |
2f88bd3a | 343 | #if defined (__clang__) && defined (__FILE_NAME__)\r |
48452993 | 344 | #define _ASSERT(Expression) UnitTestDebugAssert (__FILE_NAME__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))\r |
2f88bd3a | 345 | #else\r |
48452993 | 346 | #define _ASSERT(Expression) UnitTestDebugAssert (__FILE__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))\r |
2f88bd3a | 347 | #endif\r |
75e92c13 | 348 | #else\r |
2f88bd3a | 349 | #if defined (__clang__) && defined (__FILE_NAME__)\r |
48452993 | 350 | #define _ASSERT(Expression) DebugAssert (__FILE_NAME__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))\r |
2f88bd3a | 351 | #else\r |
48452993 | 352 | #define _ASSERT(Expression) DebugAssert (__FILE__, DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))\r |
2f88bd3a | 353 | #endif\r |
75e92c13 | 354 | #endif\r |
fb3df220 | 355 | \r |
9095d37b | 356 | /**\r |
fb3df220 | 357 | Internal worker macro that calls DebugPrint().\r |
358 | \r | |
9095d37b | 359 | This macro calls DebugPrint() passing in the debug error level, a format\r |
fb3df220 | 360 | string, and a variable argument list.\r |
79142ebf | 361 | __VA_ARGS__ is not supported by EBC compiler, Microsoft Visual Studio .NET 2003\r |
6e6f5e03 | 362 | and Microsoft Windows Server 2003 Driver Development Kit (Microsoft WINDDK) version 3790.1830.\r |
fb3df220 | 363 | \r |
9095d37b | 364 | @param Expression Expression containing an error level, a format string,\r |
fb3df220 | 365 | and a variable argument list based on the format string.\r |
366 | \r | |
367 | **/\r | |
fb3df220 | 368 | \r |
2f88bd3a MK |
369 | #if !defined (MDE_CPU_EBC) && (!defined (_MSC_VER) || _MSC_VER > 1400)\r |
370 | #define _DEBUG_PRINT(PrintLevel, ...) \\r | |
5ea9d0c3 LG |
371 | do { \\r |
372 | if (DebugPrintLevelEnabled (PrintLevel)) { \\r | |
373 | DebugPrint (PrintLevel, ##__VA_ARGS__); \\r | |
374 | } \\r | |
375 | } while (FALSE)\r | |
2f88bd3a | 376 | #define _DEBUG(Expression) _DEBUG_PRINT Expression\r |
5ea9d0c3 | 377 | #else\r |
2f88bd3a | 378 | #define _DEBUG(Expression) DebugPrint Expression\r |
5ea9d0c3 | 379 | #endif\r |
fb3df220 | 380 | \r |
9095d37b | 381 | /**\r |
1a2f870c | 382 | Macro that calls DebugAssert() if an expression evaluates to FALSE.\r |
fb3df220 | 383 | \r |
9095d37b LG |
384 | If MDEPKG_NDEBUG is not defined and the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED\r |
385 | bit of PcdDebugProperyMask is set, then this macro evaluates the Boolean\r | |
386 | expression specified by Expression. If Expression evaluates to FALSE, then\r | |
387 | DebugAssert() is called passing in the source filename, source line number,\r | |
c9ec7047 | 388 | and Expression.\r |
fb3df220 | 389 | \r |
af2dc6a7 | 390 | @param Expression Boolean expression.\r |
fb3df220 | 391 | \r |
392 | **/\r | |
2f88bd3a MK |
393 | #if !defined (MDEPKG_NDEBUG)\r |
394 | #define ASSERT(Expression) \\r | |
c9ec7047 | 395 | do { \\r |
396 | if (DebugAssertEnabled ()) { \\r | |
397 | if (!(Expression)) { \\r | |
398 | _ASSERT (Expression); \\r | |
90eda6fc | 399 | ANALYZER_UNREACHABLE (); \\r |
c9ec7047 | 400 | } \\r |
401 | } \\r | |
402 | } while (FALSE)\r | |
403 | #else\r | |
2f88bd3a | 404 | #define ASSERT(Expression)\r |
c9ec7047 | 405 | #endif\r |
fb3df220 | 406 | \r |
9095d37b | 407 | /**\r |
fb3df220 | 408 | Macro that calls DebugPrint().\r |
409 | \r | |
9095d37b LG |
410 | If MDEPKG_NDEBUG is not defined and the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED\r |
411 | bit of PcdDebugProperyMask is set, then this macro passes Expression to\r | |
c9ec7047 | 412 | DebugPrint().\r |
fb3df220 | 413 | \r |
9095d37b | 414 | @param Expression Expression containing an error level, a format string,\r |
fb3df220 | 415 | and a variable argument list based on the format string.\r |
9095d37b | 416 | \r |
fb3df220 | 417 | \r |
418 | **/\r | |
2f88bd3a MK |
419 | #if !defined (MDEPKG_NDEBUG)\r |
420 | #define DEBUG(Expression) \\r | |
c9ec7047 | 421 | do { \\r |
422 | if (DebugPrintEnabled ()) { \\r | |
423 | _DEBUG (Expression); \\r | |
424 | } \\r | |
425 | } while (FALSE)\r | |
426 | #else\r | |
2f88bd3a | 427 | #define DEBUG(Expression)\r |
c9ec7047 | 428 | #endif\r |
fb3df220 | 429 | \r |
9095d37b | 430 | /**\r |
fb3df220 | 431 | Macro that calls DebugAssert() if an EFI_STATUS evaluates to an error code.\r |
432 | \r | |
9095d37b LG |
433 | If MDEPKG_NDEBUG is not defined and the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED\r |
434 | bit of PcdDebugProperyMask is set, then this macro evaluates the EFI_STATUS\r | |
435 | value specified by StatusParameter. If StatusParameter is an error code,\r | |
436 | then DebugAssert() is called passing in the source filename, source line\r | |
c9ec7047 | 437 | number, and StatusParameter.\r |
fb3df220 | 438 | \r |
439 | @param StatusParameter EFI_STATUS value to evaluate.\r | |
440 | \r | |
441 | **/\r | |
2f88bd3a MK |
442 | #if !defined (MDEPKG_NDEBUG)\r |
443 | #define ASSERT_EFI_ERROR(StatusParameter) \\r | |
c9ec7047 | 444 | do { \\r |
445 | if (DebugAssertEnabled ()) { \\r | |
446 | if (EFI_ERROR (StatusParameter)) { \\r | |
5f289f3a | 447 | DEBUG ((DEBUG_ERROR, "\nASSERT_EFI_ERROR (Status = %r)\n", StatusParameter)); \\r |
c9ec7047 | 448 | _ASSERT (!EFI_ERROR (StatusParameter)); \\r |
449 | } \\r | |
450 | } \\r | |
451 | } while (FALSE)\r | |
452 | #else\r | |
2f88bd3a | 453 | #define ASSERT_EFI_ERROR(StatusParameter)\r |
c9ec7047 | 454 | #endif\r |
fb3df220 | 455 | \r |
08bcaf20 LE |
456 | /**\r |
457 | Macro that calls DebugAssert() if a RETURN_STATUS evaluates to an error code.\r | |
458 | \r | |
459 | If MDEPKG_NDEBUG is not defined and the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED\r | |
460 | bit of PcdDebugProperyMask is set, then this macro evaluates the\r | |
461 | RETURN_STATUS value specified by StatusParameter. If StatusParameter is an\r | |
462 | error code, then DebugAssert() is called passing in the source filename,\r | |
463 | source line number, and StatusParameter.\r | |
464 | \r | |
465 | @param StatusParameter RETURN_STATUS value to evaluate.\r | |
466 | \r | |
467 | **/\r | |
2f88bd3a MK |
468 | #if !defined (MDEPKG_NDEBUG)\r |
469 | #define ASSERT_RETURN_ERROR(StatusParameter) \\r | |
08bcaf20 LE |
470 | do { \\r |
471 | if (DebugAssertEnabled ()) { \\r | |
472 | if (RETURN_ERROR (StatusParameter)) { \\r | |
473 | DEBUG ((DEBUG_ERROR, "\nASSERT_RETURN_ERROR (Status = %r)\n", \\r | |
474 | StatusParameter)); \\r | |
475 | _ASSERT (!RETURN_ERROR (StatusParameter)); \\r | |
476 | } \\r | |
477 | } \\r | |
478 | } while (FALSE)\r | |
479 | #else\r | |
2f88bd3a | 480 | #define ASSERT_RETURN_ERROR(StatusParameter)\r |
08bcaf20 LE |
481 | #endif\r |
482 | \r | |
9095d37b LG |
483 | /**\r |
484 | Macro that calls DebugAssert() if a protocol is already installed in the\r | |
fb3df220 | 485 | handle database.\r |
486 | \r | |
9095d37b | 487 | If MDEPKG_NDEBUG is defined or the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit\r |
c9ec7047 | 488 | of PcdDebugProperyMask is clear, then return.\r |
fb3df220 | 489 | \r |
9095d37b LG |
490 | If Handle is NULL, then a check is made to see if the protocol specified by Guid\r |
491 | is present on any handle in the handle database. If Handle is not NULL, then\r | |
492 | a check is made to see if the protocol specified by Guid is present on the\r | |
493 | handle specified by Handle. If the check finds the protocol, then DebugAssert()\r | |
fb3df220 | 494 | is called passing in the source filename, source line number, and Guid.\r |
495 | \r | |
496 | If Guid is NULL, then ASSERT().\r | |
497 | \r | |
9095d37b LG |
498 | @param Handle The handle to check for the protocol. This is an optional\r |
499 | parameter that may be NULL. If it is NULL, then the entire\r | |
fb3df220 | 500 | handle database is searched.\r |
501 | \r | |
af2dc6a7 | 502 | @param Guid The pointer to a protocol GUID.\r |
fb3df220 | 503 | \r |
504 | **/\r | |
2f88bd3a MK |
505 | #if !defined (MDEPKG_NDEBUG)\r |
506 | #define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid) \\r | |
c9ec7047 | 507 | do { \\r |
508 | if (DebugAssertEnabled ()) { \\r | |
509 | VOID *Instance; \\r | |
510 | ASSERT (Guid != NULL); \\r | |
511 | if (Handle == NULL) { \\r | |
512 | if (!EFI_ERROR (gBS->LocateProtocol ((EFI_GUID *)Guid, NULL, &Instance))) { \\r | |
513 | _ASSERT (Guid already installed in database); \\r | |
514 | } \\r | |
515 | } else { \\r | |
516 | if (!EFI_ERROR (gBS->HandleProtocol (Handle, (EFI_GUID *)Guid, &Instance))) { \\r | |
517 | _ASSERT (Guid already installed on Handle); \\r | |
518 | } \\r | |
519 | } \\r | |
520 | } \\r | |
521 | } while (FALSE)\r | |
522 | #else\r | |
2f88bd3a | 523 | #define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid)\r |
c9ec7047 | 524 | #endif\r |
fb3df220 | 525 | \r |
526 | /**\r | |
527 | Macro that marks the beginning of debug source code.\r | |
528 | \r | |
9095d37b | 529 | If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set,\r |
fb3df220 | 530 | then this macro marks the beginning of source code that is included in a module.\r |
9095d37b | 531 | Otherwise, the source lines between DEBUG_CODE_BEGIN() and DEBUG_CODE_END()\r |
fb3df220 | 532 | are not included in a module.\r |
533 | \r | |
534 | **/\r | |
535 | #define DEBUG_CODE_BEGIN() do { if (DebugCodeEnabled ()) { UINT8 __DebugCodeLocal\r | |
536 | \r | |
9095d37b | 537 | /**\r |
af2dc6a7 | 538 | The macro that marks the end of debug source code.\r |
fb3df220 | 539 | \r |
9095d37b LG |
540 | If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set,\r |
541 | then this macro marks the end of source code that is included in a module.\r | |
542 | Otherwise, the source lines between DEBUG_CODE_BEGIN() and DEBUG_CODE_END()\r | |
fb3df220 | 543 | are not included in a module.\r |
544 | \r | |
545 | **/\r | |
2f88bd3a | 546 | #define DEBUG_CODE_END() __DebugCodeLocal = 0; __DebugCodeLocal++; } } while (FALSE)\r |
fb3df220 | 547 | \r |
9095d37b | 548 | /**\r |
af2dc6a7 | 549 | The macro that declares a section of debug source code.\r |
fb3df220 | 550 | \r |
9095d37b LG |
551 | If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set,\r |
552 | then the source code specified by Expression is included in a module.\r | |
fb3df220 | 553 | Otherwise, the source specified by Expression is not included in a module.\r |
554 | \r | |
555 | **/\r | |
556 | #define DEBUG_CODE(Expression) \\r | |
557 | DEBUG_CODE_BEGIN (); \\r | |
558 | Expression \\r | |
559 | DEBUG_CODE_END ()\r | |
560 | \r | |
9095d37b | 561 | /**\r |
af2dc6a7 | 562 | The macro that calls DebugClearMemory() to clear a buffer to a default value.\r |
fb3df220 | 563 | \r |
9095d37b | 564 | If the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set,\r |
fb3df220 | 565 | then this macro calls DebugClearMemory() passing in Address and Length.\r |
566 | \r | |
af2dc6a7 | 567 | @param Address The pointer to a buffer.\r |
fb3df220 | 568 | @param Length The number of bytes in the buffer to set.\r |
569 | \r | |
570 | **/\r | |
571 | #define DEBUG_CLEAR_MEMORY(Address, Length) \\r | |
572 | do { \\r | |
573 | if (DebugClearMemoryEnabled ()) { \\r | |
574 | DebugClearMemory (Address, Length); \\r | |
575 | } \\r | |
576 | } while (FALSE)\r | |
577 | \r | |
fb3df220 | 578 | /**\r |
9095d37b LG |
579 | Macro that calls DebugAssert() if the containing record does not have a\r |
580 | matching signature. If the signatures matches, then a pointer to the data\r | |
581 | structure that contains a specified field of that data structure is returned.\r | |
582 | This is a lightweight method hide information by placing a public data\r | |
583 | structure inside a larger private data structure and using a pointer to the\r | |
fb3df220 | 584 | public data structure to retrieve a pointer to the private data structure.\r |
585 | \r | |
9095d37b | 586 | If MDEPKG_NDEBUG is defined or the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit\r |
c9ec7047 | 587 | of PcdDebugProperyMask is clear, then this macro computes the offset, in bytes,\r |
9095d37b LG |
588 | of the field specified by Field from the beginning of the data structure specified\r |
589 | by TYPE. This offset is subtracted from Record, and is used to return a pointer\r | |
c9ec7047 | 590 | to a data structure of the type specified by TYPE.\r |
591 | \r | |
592 | If MDEPKG_NDEBUG is not defined and the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit\r | |
9095d37b LG |
593 | of PcdDebugProperyMask is set, then this macro computes the offset, in bytes,\r |
594 | of field specified by Field from the beginning of the data structure specified\r | |
c9ec7047 | 595 | by TYPE. This offset is subtracted from Record, and is used to compute a pointer\r |
9095d37b LG |
596 | to a data structure of the type specified by TYPE. The Signature field of the\r |
597 | data structure specified by TYPE is compared to TestSignature. If the signatures\r | |
598 | match, then a pointer to the pointer to a data structure of the type specified by\r | |
599 | TYPE is returned. If the signatures do not match, then DebugAssert() is called\r | |
600 | with a description of "CR has a bad signature" and Record is returned.\r | |
fb3df220 | 601 | \r |
9095d37b | 602 | If the data type specified by TYPE does not contain the field specified by Field,\r |
fb3df220 | 603 | then the module will not compile.\r |
604 | \r | |
9095d37b | 605 | If TYPE does not contain a field called Signature, then the module will not\r |
fb3df220 | 606 | compile.\r |
607 | \r | |
9095d37b | 608 | @param Record The pointer to the field specified by Field within a data\r |
fb3df220 | 609 | structure of type TYPE.\r |
610 | \r | |
9095d37b LG |
611 | @param TYPE The name of the data structure type to return This\r |
612 | data structure must contain the field specified by Field.\r | |
fb3df220 | 613 | \r |
9095d37b | 614 | @param Field The name of the field in the data structure specified\r |
fb3df220 | 615 | by TYPE to which Record points.\r |
616 | \r | |
617 | @param TestSignature The 32-bit signature value to match.\r | |
618 | \r | |
619 | **/\r | |
2f88bd3a MK |
620 | #if !defined (MDEPKG_NDEBUG)\r |
621 | #define CR(Record, TYPE, Field, TestSignature) \\r | |
c9ec7047 | 622 | (DebugAssertEnabled () && (BASE_CR (Record, TYPE, Field)->Signature != TestSignature)) ? \\r |
623 | (TYPE *) (_ASSERT (CR has Bad Signature), Record) : \\r | |
624 | BASE_CR (Record, TYPE, Field)\r | |
625 | #else\r | |
2f88bd3a | 626 | #define CR(Record, TYPE, Field, TestSignature) \\r |
c9ec7047 | 627 | BASE_CR (Record, TYPE, Field)\r |
628 | #endif\r | |
9095d37b | 629 | \r |
fb3df220 | 630 | #endif\r |