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