]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Include/Library/DebugLib.h
Library classes updated in INF
[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
d80b2f71 3 \r
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
6 \r
3e5c3238 7Copyright (c) 2006 - 2008, Intel Corporation<BR>\r
50a64e5b 8All rights reserved. This program and the accompanying materials\r
9are licensed and made available under the terms and conditions of the BSD License\r
10which accompanies this distribution. The full text of the license may be found at\r
11http://opensource.org/licenses/bsd-license.php\r
fb3df220 12\r
50a64e5b 13THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
14WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
fb3df220 15\r
16**/\r
17\r
18#ifndef __DEBUG_LIB_H__\r
19#define __DEBUG_LIB_H__\r
20\r
21//\r
22// Declare bits for PcdDebugPropertyMask\r
23//\r
24#define DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED 0x01\r
25#define DEBUG_PROPERTY_DEBUG_PRINT_ENABLED 0x02\r
26#define DEBUG_PROPERTY_DEBUG_CODE_ENABLED 0x04\r
27#define DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED 0x08\r
28#define DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED 0x10\r
29#define DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED 0x20\r
30\r
31//\r
32// Declare bits for PcdDebugPrintErrorLevel and the ErrorLevel parameter of DebugPrint()\r
33//\r
34#define DEBUG_INIT 0x00000001 // Initialization\r
35#define DEBUG_WARN 0x00000002 // Warnings\r
36#define DEBUG_LOAD 0x00000004 // Load events\r
37#define DEBUG_FS 0x00000008 // EFI File system\r
38#define DEBUG_POOL 0x00000010 // Alloc & Free's\r
39#define DEBUG_PAGE 0x00000020 // Alloc & Free's\r
40#define DEBUG_INFO 0x00000040 // Verbose\r
c759eb45 41#define DEBUG_DISPATCH 0x00000080 // PEI/DXE Dispatchers\r
fb3df220 42#define DEBUG_VARIABLE 0x00000100 // Variable\r
43#define DEBUG_BM 0x00000400 // Boot Manager\r
44#define DEBUG_BLKIO 0x00001000 // BlkIo Driver\r
45#define DEBUG_NET 0x00004000 // SNI Driver\r
46#define DEBUG_UNDI 0x00010000 // UNDI Driver\r
47#define DEBUG_LOADFILE 0x00020000 // UNDI Driver\r
48#define DEBUG_EVENT 0x00080000 // Event messages\r
49#define DEBUG_ERROR 0x80000000 // Error\r
50\r
51//\r
52// Aliases of debug message mask bits\r
53//\r
54#define EFI_D_INIT DEBUG_INIT\r
55#define EFI_D_WARN DEBUG_WARN\r
56#define EFI_D_LOAD DEBUG_LOAD\r
57#define EFI_D_FS DEBUG_FS\r
58#define EFI_D_POOL DEBUG_POOL\r
59#define EFI_D_PAGE DEBUG_PAGE\r
60#define EFI_D_INFO DEBUG_INFO\r
c759eb45 61#define EFI_D_DISPATCH DEBUG_DISPATCH\r
fb3df220 62#define EFI_D_VARIABLE DEBUG_VARIABLE\r
63#define EFI_D_BM DEBUG_BM\r
64#define EFI_D_BLKIO DEBUG_BLKIO\r
65#define EFI_D_NET DEBUG_NET\r
66#define EFI_D_UNDI DEBUG_UNDI\r
67#define EFI_D_LOADFILE DEBUG_LOADFILE\r
68#define EFI_D_EVENT DEBUG_EVENT\r
69#define EFI_D_ERROR DEBUG_ERROR\r
70\r
71/**\r
fb3df220 72 Prints a debug message to the debug output device if the specified error level is enabled.\r
73\r
74 If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print \r
75 the message specified by Format and the associated variable argument list to \r
76 the debug output device.\r
77\r
78 If Format is NULL, then ASSERT().\r
79\r
80 @param ErrorLevel The error level of the debug message.\r
81 @param Format Format string for the debug message to print.\r
285010e7 82 @param ... Variable argument list whose contents are accessed \r
83 based on the format string specified by Format.\r
fb3df220 84\r
85**/\r
86VOID\r
87EFIAPI\r
88DebugPrint (\r
89 IN UINTN ErrorLevel,\r
90 IN CONST CHAR8 *Format,\r
91 ...\r
92 );\r
93\r
94\r
95/**\r
fb3df220 96 Prints an assert message containing a filename, line number, and description. \r
97 This may be followed by a breakpoint or a dead loop.\r
98\r
99 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"\r
100 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of \r
101 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if \r
102 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then \r
103 CpuDeadLoop() is called. If neither of these bits are set, then this function \r
104 returns immediately after the message is printed to the debug output device.\r
584125bc 105 DebugAssert() must actively prevent recursion. If DebugAssert() is called while\r
fb3df220 106 processing another DebugAssert(), then DebugAssert() must return immediately.\r
107\r
584125bc 108 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r
584125bc 109 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r
fb3df220 110\r
111 @param FileName Pointer to the name of the source file that generated the assert condition.\r
112 @param LineNumber The line number in the source file that generated the assert condition\r
113 @param Description Pointer to the description of the assert condition.\r
114\r
115**/\r
116VOID\r
117EFIAPI\r
118DebugAssert (\r
119 IN CONST CHAR8 *FileName,\r
120 IN UINTN LineNumber,\r
121 IN CONST CHAR8 *Description\r
122 );\r
123\r
124\r
125/**\r
fb3df220 126 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r
127\r
128 This function fills Length bytes of Buffer with the value specified by \r
129 PcdDebugClearMemoryValue, and returns Buffer.\r
130\r
131 If Buffer is NULL, then ASSERT().\r
584125bc 132 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT(). \r
fb3df220 133\r
eceb3a4c 134 @param Buffer Pointer to the target buffer to be filled with PcdDebugClearMemoryValue.\r
fb3df220 135 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue. \r
136\r
eceb3a4c 137 @return Buffer Pointer to the target buffer filled with PcdDebugClearMemoryValue.\r
fb3df220 138\r
139**/\r
140VOID *\r
141EFIAPI\r
142DebugClearMemory (\r
143 OUT VOID *Buffer,\r
144 IN UINTN Length\r
145 );\r
146\r
147\r
148/**\r
fb3df220 149 Returns TRUE if ASSERT() macros are enabled.\r
150\r
151 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of \r
152 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
153\r
154 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.\r
155 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.\r
156\r
157**/\r
158BOOLEAN\r
159EFIAPI\r
160DebugAssertEnabled (\r
161 VOID\r
162 );\r
163\r
164\r
3e5c3238 165/** \r
166 Returns TRUE if DEBUG() macros are enabled.\r
fb3df220 167\r
168 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of \r
169 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
170\r
171 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.\r
172 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.\r
173\r
174**/\r
175BOOLEAN\r
176EFIAPI\r
177DebugPrintEnabled (\r
178 VOID\r
179 );\r
180\r
181\r
3e5c3238 182/** \r
183 Returns TRUE if DEBUG_CODE() macros are enabled.\r
fb3df220 184\r
185 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of \r
186 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
187\r
188 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.\r
189 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.\r
190\r
191**/\r
192BOOLEAN\r
193EFIAPI\r
194DebugCodeEnabled (\r
195 VOID\r
196 );\r
197\r
198\r
3e5c3238 199/** \r
200 Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.\r
fb3df220 201\r
eceb3a4c 202 This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of \r
fb3df220 203 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
204\r
eceb3a4c
LG
205 @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.\r
206 @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.\r
fb3df220 207\r
208**/\r
209BOOLEAN\r
210EFIAPI\r
211DebugClearMemoryEnabled (\r
212 VOID\r
213 );\r
214\r
215\r
3e5c3238 216/** \r
fb3df220 217 Internal worker macro that calls DebugAssert().\r
218\r
219 This macro calls DebugAssert() passing in the filename, line number, and \r
220 expression that evailated to FALSE.\r
221\r
222 @param Expression Boolean expression that evailated to FALSE\r
223\r
224**/\r
225#define _ASSERT(Expression) DebugAssert (__FILE__, __LINE__, #Expression)\r
226\r
227\r
3e5c3238 228/** \r
fb3df220 229 Internal worker macro that calls DebugPrint().\r
230\r
231 This macro calls DebugPrint() passing in the debug error level, a format \r
232 string, and a variable argument list.\r
233\r
234 @param Expression Expression containing an error level, a format string, \r
235 and a variable argument list based on the format string.\r
236\r
237**/\r
238#define _DEBUG(Expression) DebugPrint Expression\r
239\r
240\r
3e5c3238 241/** \r
fb3df220 242 Macro that calls DebugAssert() if a expression evaluates to FALSE.\r
243\r
244 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set, \r
245 then this macro evaluates the Boolean expression specified by Expression. If \r
246 Expression evaluates to FALSE, then DebugAssert() is called passing in the \r
247 source filename, source line number, and Expression.\r
248\r
249 @param Expression Boolean expression\r
250\r
251**/\r
252#define ASSERT(Expression) \\r
253 do { \\r
254 if (DebugAssertEnabled ()) { \\r
255 if (!(Expression)) { \\r
256 _ASSERT (Expression); \\r
257 } \\r
258 } \\r
259 } while (FALSE)\r
260\r
261\r
3e5c3238 262/** \r
fb3df220 263 Macro that calls DebugPrint().\r
264\r
265 If the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set, \r
266 then this macro passes Expression to DebugPrint().\r
267\r
268 @param Expression Expression containing an error level, a format string, \r
269 and a variable argument list based on the format string.\r
270 \r
271\r
272**/\r
273#define DEBUG(Expression) \\r
274 do { \\r
275 if (DebugPrintEnabled ()) { \\r
276 _DEBUG (Expression); \\r
277 } \\r
278 } while (FALSE)\r
279\r
280\r
3e5c3238 281/** \r
fb3df220 282 Macro that calls DebugAssert() if an EFI_STATUS evaluates to an error code.\r
283\r
284 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set, \r
285 then this macro evaluates the EFI_STATUS value specified by StatusParameter. \r
286 If StatusParameter is an error code, then DebugAssert() is called passing in \r
287 the source filename, source line number, and StatusParameter.\r
288\r
289 @param StatusParameter EFI_STATUS value to evaluate.\r
290\r
291**/\r
292#define ASSERT_EFI_ERROR(StatusParameter) \\r
293 do { \\r
294 if (DebugAssertEnabled ()) { \\r
295 if (EFI_ERROR (StatusParameter)) { \\r
296 DEBUG ((EFI_D_ERROR, "\nASSERT_EFI_ERROR (Status = %r)\n", StatusParameter)); \\r
297 _ASSERT (!EFI_ERROR (StatusParameter)); \\r
298 } \\r
299 } \\r
300 } while (FALSE)\r
301\r
302\r
3e5c3238 303/** \r
fb3df220 304 Macro that calls DebugAssert() if a protocol is already installed in the \r
305 handle database.\r
306\r
307 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear, \r
308 then return.\r
309\r
310 If Handle is NULL, then a check is made to see if the protocol specified by Guid \r
311 is present on any handle in the handle database. If Handle is not NULL, then \r
312 a check is made to see if the protocol specified by Guid is present on the \r
313 handle specified by Handle. If the check finds the protocol, then DebugAssert() \r
314 is called passing in the source filename, source line number, and Guid.\r
315\r
316 If Guid is NULL, then ASSERT().\r
317\r
318 @param Handle The handle to check for the protocol. This is an optional \r
319 parameter that may be NULL. If it is NULL, then the entire \r
320 handle database is searched.\r
321\r
322 @param Guid Pointer to a protocol GUID.\r
323\r
324**/\r
325#define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid) \\r
326 do { \\r
327 if (DebugAssertEnabled ()) { \\r
328 VOID *Instance; \\r
329 ASSERT (Guid != NULL); \\r
330 if (Handle == NULL) { \\r
331 if (!EFI_ERROR (gBS->LocateProtocol ((EFI_GUID *)Guid, NULL, &Instance))) { \\r
332 _ASSERT (Guid already installed in database); \\r
333 } \\r
334 } else { \\r
335 if (!EFI_ERROR (gBS->HandleProtocol (Handle, (EFI_GUID *)Guid, &Instance))) { \\r
336 _ASSERT (Guid already installed on Handle); \\r
337 } \\r
338 } \\r
339 } \\r
340 } while (FALSE)\r
341\r
342\r
343/**\r
344 Macro that marks the beginning of debug source code.\r
345\r
346 If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set, \r
347 then this macro marks the beginning of source code that is included in a module.\r
348 Otherwise, the source lines between DEBUG_CODE_BEGIN() and DEBUG_CODE_END() \r
349 are not included in a module.\r
350\r
351**/\r
352#define DEBUG_CODE_BEGIN() do { if (DebugCodeEnabled ()) { UINT8 __DebugCodeLocal\r
353\r
354\r
3e5c3238 355/** \r
fb3df220 356 Macro that marks the end of debug source code.\r
357\r
358 If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set, \r
359 then this macro marks the end of source code that is included in a module. \r
360 Otherwise, the source lines between DEBUG_CODE_BEGIN() and DEBUG_CODE_END() \r
361 are not included in a module.\r
362\r
363**/\r
364#define DEBUG_CODE_END() __DebugCodeLocal = 0; __DebugCodeLocal++; } } while (FALSE)\r
365\r
366\r
3e5c3238 367/** \r
fb3df220 368 Macro that declares a section of debug source code.\r
369\r
370 If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set, \r
371 then the source code specified by Expression is included in a module. \r
372 Otherwise, the source specified by Expression is not included in a module.\r
373\r
374**/\r
375#define DEBUG_CODE(Expression) \\r
376 DEBUG_CODE_BEGIN (); \\r
377 Expression \\r
378 DEBUG_CODE_END ()\r
379\r
380\r
3e5c3238 381/** \r
fb3df220 382 Macro that calls DebugClearMemory() to clear a buffer to a default value.\r
383\r
384 If the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set, \r
385 then this macro calls DebugClearMemory() passing in Address and Length.\r
386\r
387 @param Address Pointer to a buffer.\r
388 @param Length The number of bytes in the buffer to set.\r
389\r
390**/\r
391#define DEBUG_CLEAR_MEMORY(Address, Length) \\r
392 do { \\r
393 if (DebugClearMemoryEnabled ()) { \\r
394 DebugClearMemory (Address, Length); \\r
395 } \\r
396 } while (FALSE)\r
397\r
398\r
399/**\r
fb3df220 400 Macro that calls DebugAssert() if the containing record does not have a \r
401 matching signature. If the signatures matches, then a pointer to the data \r
402 structure that contains a specified field of that data structure is returned. \r
403 This is a light weight method hide information by placing a public data \r
404 structure inside a larger private data structure and using a pointer to the \r
405 public data structure to retrieve a pointer to the private data structure.\r
406\r
407 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear, \r
408 then this macro computes the offset, in bytes, of field specified by Field \r
409 from the beginning of the data structure specified by TYPE. This offset is \r
410 subtracted from Record, and is used to return a pointer to a data structure \r
411 of the type specified by TYPE.\r
412\r
413 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set, \r
414 then this macro computes the offset, in bytes, of field specified by Field from \r
415 the beginning of the data structure specified by TYPE. This offset is \r
416 subtracted from Record, and is used to compute a pointer to a data structure of \r
417 the type specified by TYPE. The Signature field of the data structure specified \r
418 by TYPE is compared to TestSignature. If the signatures match, then a pointer \r
419 to the pointer to a data structure of the type specified by TYPE is returned. \r
420 If the signatures do not match, then DebugAssert() is called with a description \r
421 of "CR has a bad signature" and Record is returned. \r
422\r
423 If the data type specified by TYPE does not contain the field specified by Field, \r
424 then the module will not compile.\r
425\r
426 If TYPE does not contain a field called Signature, then the module will not \r
427 compile.\r
428\r
429 @param Record Pointer to the field specified by Field within a data \r
430 structure of type TYPE.\r
431\r
432 @param TYPE The name of the data structure type to return This \r
433 data structure must contain the field specified by Field. \r
434\r
435 @param Field The name of the field in the data structure specified \r
436 by TYPE to which Record points.\r
437\r
438 @param TestSignature The 32-bit signature value to match.\r
439\r
440**/\r
22ce9dc5 441#define CR(Record, TYPE, Field, TestSignature) \\r
442 (DebugAssertEnabled () && (BASE_CR (Record, TYPE, Field)->Signature != TestSignature)) ? \\r
443 (TYPE *) (_ASSERT (CR has Bad Signature), Record) : \\r
444 BASE_CR (Record, TYPE, Field)\r
fb3df220 445 \r
446#endif\r