DebugLib.h 24 KB

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