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