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