]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Library/DebugLib.h
Add in a new debug mask bit EFI_D_DEPEX. It is used to enable the debug message relat...
[mirror_edk2.git] / MdePkg / Include / Library / DebugLib.h
1 /** @file
2 Public include file for the Debug Library
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_DEPEX 0x00000080 // PEI or DXE Dependency Evaluation
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_DEPEX DEBUG_DEPEX
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 ... The variable argument list.
81
82 **/
83 VOID
84 EFIAPI
85 DebugPrint (
86 IN UINTN ErrorLevel,
87 IN CONST CHAR8 *Format,
88 ...
89 );
90
91
92 /**
93
94 Prints an assert message containing a filename, line number, and description.
95 This may be followed by a breakpoint or a dead loop.
96
97 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
98 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
99 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
100 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
101 CpuDeadLoop() is called. If neither of these bits are set, then this function
102 returns immediately after the message is printed to the debug output device.
103 DebugAssert() must actively prevent recursion. If DebugAssert() is called while
104 processing another DebugAssert(), then DebugAssert() must return immediately.
105
106 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
107
108 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
109
110 @param FileName Pointer to the name of the source file that generated the assert condition.
111 @param LineNumber The line number in the source file that generated the assert condition
112 @param Description Pointer to the description of the assert condition.
113
114 **/
115 VOID
116 EFIAPI
117 DebugAssert (
118 IN CONST CHAR8 *FileName,
119 IN UINTN LineNumber,
120 IN CONST CHAR8 *Description
121 );
122
123
124 /**
125
126 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
127
128 This function fills Length bytes of Buffer with the value specified by
129 PcdDebugClearMemoryValue, and returns Buffer.
130
131 If Buffer is NULL, then ASSERT().
132
133 If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
134
135 @param Buffer Pointer to the target buffer to be filled with PcdDebugClearMemoryValue.
136 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
137
138 @return Buffer Pointer to the target buffer filled with PcdDebugClearMemoryValue.
139
140 **/
141 VOID *
142 EFIAPI
143 DebugClearMemory (
144 OUT VOID *Buffer,
145 IN UINTN Length
146 );
147
148
149 /**
150
151 Returns TRUE if ASSERT() macros are enabled.
152
153 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
154 PcdDebugProperyMask is set. Otherwise FALSE is returned.
155
156 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
157 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
158
159 **/
160 BOOLEAN
161 EFIAPI
162 DebugAssertEnabled (
163 VOID
164 );
165
166
167 /**
168
169 Returns TRUE if DEBUG()macros are enabled.
170
171 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
172 PcdDebugProperyMask is set. Otherwise FALSE is returned.
173
174 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
175 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
176
177 **/
178 BOOLEAN
179 EFIAPI
180 DebugPrintEnabled (
181 VOID
182 );
183
184
185 /**
186
187 Returns TRUE if DEBUG_CODE()macros are enabled.
188
189 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
190 PcdDebugProperyMask is set. Otherwise FALSE is returned.
191
192 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
193 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
194
195 **/
196 BOOLEAN
197 EFIAPI
198 DebugCodeEnabled (
199 VOID
200 );
201
202
203 /**
204
205 Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.
206
207 This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of
208 PcdDebugProperyMask is set. Otherwise FALSE is returned.
209
210 @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
211 @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
212
213 **/
214 BOOLEAN
215 EFIAPI
216 DebugClearMemoryEnabled (
217 VOID
218 );
219
220
221 /**
222
223 Internal worker macro that calls DebugAssert().
224
225 This macro calls DebugAssert() passing in the filename, line number, and
226 expression that evailated to FALSE.
227
228 @param Expression Boolean expression that evailated to FALSE
229
230 **/
231 #define _ASSERT(Expression) DebugAssert (__FILE__, __LINE__, #Expression)
232
233
234 /**
235
236 Internal worker macro that calls DebugPrint().
237
238 This macro calls DebugPrint() passing in the debug error level, a format
239 string, and a variable argument list.
240
241 @param Expression Expression containing an error level, a format string,
242 and a variable argument list based on the format string.
243
244 **/
245 #define _DEBUG(Expression) DebugPrint Expression
246
247
248 /**
249
250 Macro that calls DebugAssert() if a expression evaluates to FALSE.
251
252 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set,
253 then this macro evaluates the Boolean expression specified by Expression. If
254 Expression evaluates to FALSE, then DebugAssert() is called passing in the
255 source filename, source line number, and Expression.
256
257 @param Expression Boolean expression
258
259 **/
260 #define ASSERT(Expression) \
261 do { \
262 if (DebugAssertEnabled ()) { \
263 if (!(Expression)) { \
264 _ASSERT (Expression); \
265 } \
266 } \
267 } while (FALSE)
268
269
270 /**
271
272 Macro that calls DebugPrint().
273
274 If the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set,
275 then this macro passes Expression to DebugPrint().
276
277 @param Expression Expression containing an error level, a format string,
278 and a variable argument list based on the format string.
279
280
281 **/
282 #define DEBUG(Expression) \
283 do { \
284 if (DebugPrintEnabled ()) { \
285 _DEBUG (Expression); \
286 } \
287 } while (FALSE)
288
289
290 /**
291
292 Macro that calls DebugAssert() if an EFI_STATUS evaluates to an error code.
293
294 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set,
295 then this macro evaluates the EFI_STATUS value specified by StatusParameter.
296 If StatusParameter is an error code, then DebugAssert() is called passing in
297 the source filename, source line number, and StatusParameter.
298
299 @param StatusParameter EFI_STATUS value to evaluate.
300
301 **/
302 #define ASSERT_EFI_ERROR(StatusParameter) \
303 do { \
304 if (DebugAssertEnabled ()) { \
305 if (EFI_ERROR (StatusParameter)) { \
306 DEBUG ((EFI_D_ERROR, "\nASSERT_EFI_ERROR (Status = %r)\n", StatusParameter)); \
307 _ASSERT (!EFI_ERROR (StatusParameter)); \
308 } \
309 } \
310 } while (FALSE)
311
312
313 /**
314
315 Macro that calls DebugAssert() if a protocol is already installed in the
316 handle database.
317
318 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear,
319 then return.
320
321 If Handle is NULL, then a check is made to see if the protocol specified by Guid
322 is present on any handle in the handle database. If Handle is not NULL, then
323 a check is made to see if the protocol specified by Guid is present on the
324 handle specified by Handle. If the check finds the protocol, then DebugAssert()
325 is called passing in the source filename, source line number, and Guid.
326
327 If Guid is NULL, then ASSERT().
328
329 @param Handle The handle to check for the protocol. This is an optional
330 parameter that may be NULL. If it is NULL, then the entire
331 handle database is searched.
332
333 @param Guid Pointer to a protocol GUID.
334
335 **/
336 #define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid) \
337 do { \
338 if (DebugAssertEnabled ()) { \
339 VOID *Instance; \
340 ASSERT (Guid != NULL); \
341 if (Handle == NULL) { \
342 if (!EFI_ERROR (gBS->LocateProtocol ((EFI_GUID *)Guid, NULL, &Instance))) { \
343 _ASSERT (Guid already installed in database); \
344 } \
345 } else { \
346 if (!EFI_ERROR (gBS->HandleProtocol (Handle, (EFI_GUID *)Guid, &Instance))) { \
347 _ASSERT (Guid already installed on Handle); \
348 } \
349 } \
350 } \
351 } while (FALSE)
352
353
354 /**
355 Macro that marks the beginning of debug source code.
356
357 If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set,
358 then this macro marks the beginning of source code that is included in a module.
359 Otherwise, the source lines between DEBUG_CODE_BEGIN() and DEBUG_CODE_END()
360 are not included in a module.
361
362 **/
363 #define DEBUG_CODE_BEGIN() do { if (DebugCodeEnabled ()) { UINT8 __DebugCodeLocal
364
365
366 /**
367
368 Macro that marks the end of debug source code.
369
370 If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set,
371 then this macro marks the end of source code that is included in a module.
372 Otherwise, the source lines between DEBUG_CODE_BEGIN() and DEBUG_CODE_END()
373 are not included in a module.
374
375 **/
376 #define DEBUG_CODE_END() __DebugCodeLocal = 0; __DebugCodeLocal++; } } while (FALSE)
377
378
379 /**
380
381 Macro that declares a section of debug source code.
382
383 If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set,
384 then the source code specified by Expression is included in a module.
385 Otherwise, the source specified by Expression is not included in a module.
386
387 **/
388 #define DEBUG_CODE(Expression) \
389 DEBUG_CODE_BEGIN (); \
390 Expression \
391 DEBUG_CODE_END ()
392
393
394 /**
395
396 Macro that calls DebugClearMemory() to clear a buffer to a default value.
397
398 If the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set,
399 then this macro calls DebugClearMemory() passing in Address and Length.
400
401 @param Address Pointer to a buffer.
402 @param Length The number of bytes in the buffer to set.
403
404 **/
405 #define DEBUG_CLEAR_MEMORY(Address, Length) \
406 do { \
407 if (DebugClearMemoryEnabled ()) { \
408 DebugClearMemory (Address, Length); \
409 } \
410 } while (FALSE)
411
412
413 /**
414
415 Macro that calls DebugAssert() if the containing record does not have a
416 matching signature. If the signatures matches, then a pointer to the data
417 structure that contains a specified field of that data structure is returned.
418 This is a light weight method hide information by placing a public data
419 structure inside a larger private data structure and using a pointer to the
420 public data structure to retrieve a pointer to the private data structure.
421
422 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear,
423 then this macro computes the offset, in bytes, of field specified by Field
424 from the beginning of the data structure specified by TYPE. This offset is
425 subtracted from Record, and is used to return a pointer to a data structure
426 of the type specified by TYPE.
427
428 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set,
429 then this macro computes the offset, in bytes, of field specified by Field from
430 the beginning of the data structure specified by TYPE. This offset is
431 subtracted from Record, and is used to compute a pointer to a data structure of
432 the type specified by TYPE. The Signature field of the data structure specified
433 by TYPE is compared to TestSignature. If the signatures match, then a pointer
434 to the pointer to a data structure of the type specified by TYPE is returned.
435 If the signatures do not match, then DebugAssert() is called with a description
436 of "CR has a bad signature" and Record is returned.
437
438 If the data type specified by TYPE does not contain the field specified by Field,
439 then the module will not compile.
440
441 If TYPE does not contain a field called Signature, then the module will not
442 compile.
443
444 @param Record Pointer to the field specified by Field within a data
445 structure of type TYPE.
446
447 @param TYPE The name of the data structure type to return This
448 data structure must contain the field specified by Field.
449
450 @param Field The name of the field in the data structure specified
451 by TYPE to which Record points.
452
453 @param TestSignature The 32-bit signature value to match.
454
455 **/
456 #define CR(Record, TYPE, Field, TestSignature) \
457 (DebugAssertEnabled () && (_CR (Record, TYPE, Field)->Signature != TestSignature)) ? \
458 (TYPE *) (_ASSERT (CR has Bad Signature), Record) : \
459 _CR (Record, TYPE, Field)
460
461 #endif