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