TianoCore EDK2 master
Loading...
Searching...
No Matches
DebugLib.c
Go to the documentation of this file.
1
8#include <Base.h>
9#include <Library/DebugLib.h>
10#include <Library/BaseLib.h>
11#include <Library/PrintLib.h>
12#include <Library/PcdLib.h>
17
18//
19// Define the maximum debug and assert message length that this library supports
20//
21#define MAX_DEBUG_MESSAGE_LENGTH 0x100
22
23CONST CHAR8 *mHexTable = "0123456789ABCDEF";
24
25//
26// VA_LIST can not initialize to NULL for all compiler, so we use this to
27// indicate a null VA_LIST
28//
29VA_LIST mVaListNull;
30
36UINTN *
37EFIAPI
39 VOID
40 );
41
57VOID
58EFIAPI
60 IN UINTN ErrorLevel,
61 IN CONST CHAR8 *Format,
62 ...
63 )
64{
65 VA_LIST Marker;
66
67 VA_START (Marker, Format);
68 DebugVPrint (ErrorLevel, Format, Marker);
69 VA_END (Marker);
70}
71
89VOID
91 IN UINTN ErrorLevel,
92 IN CONST CHAR8 *Format,
93 IN VA_LIST VaListMarker,
94 IN BASE_LIST BaseListMarker
95 )
96{
97 CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];
98
99 //
100 // If Format is NULL, then ASSERT().
101 //
103 return;
104 }
105
106 //
107 // Check driver debug mask value and global mask
108 //
109 if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) {
110 return;
111 }
112
113 //
114 // If Format is NULL, then ASSERT().
115 //
116 ASSERT (Format != NULL);
117
118 //
119 // Convert the DEBUG() message to an ASCII String
120 //
121 if (BaseListMarker == NULL) {
122 AsciiVSPrint (Buffer, sizeof (Buffer), Format, VaListMarker);
123 } else {
124 AsciiBSPrint (Buffer, sizeof (Buffer), Format, BaseListMarker);
125 }
126
127 //
128 // Send the print string to a Serial Port
129 //
130 SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));
131}
132
148VOID
149EFIAPI
151 IN UINTN ErrorLevel,
152 IN CONST CHAR8 *Format,
153 IN VA_LIST VaListMarker
154 )
155{
156 DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL);
157}
158
176VOID
177EFIAPI
179 IN UINTN ErrorLevel,
180 IN CONST CHAR8 *Format,
181 IN BASE_LIST BaseListMarker
182 )
183{
184 DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker);
185}
186
194VOID
196 UINTN Value,
197 CHAR8 *Buffer
198 )
199{
200 INTN Idx;
201
202 for (Idx = (sizeof (UINTN) * 2) - 1; Idx >= 0; Idx--) {
203 Buffer[Idx] = mHexTable[Value & 0x0F];
204 Value >>= 4;
205 }
206}
207
225VOID
227 VOID
228 )
229{
230 CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];
231 UINTN *Frame;
232
233 Frame = (UINTN *)GetStackFramePointer ();
234
235 //
236 // Generate the ASSERT() message in Ascii format
237 //
238 if (sizeof (UINTN) == sizeof (UINT32)) {
240 Buffer,
241 sizeof (Buffer) / sizeof (CHAR8),
242 "-> EBP:0x00000000 EIP:0x00000000\n",
243 sizeof (Buffer) / sizeof (CHAR8) - 1
244 );
245 } else {
247 Buffer,
248 sizeof (Buffer) / sizeof (CHAR8),
249 "-> RBP:0x0000000000000000 RIP:0x0000000000000000\n",
250 sizeof (Buffer) / sizeof (CHAR8) - 1
251 );
252 }
253
254 SerialPortWrite ((UINT8 *)"ASSERT DUMP:\n", 13);
255 while (Frame != NULL) {
256 FillHex ((UINTN)Frame, Buffer + 9);
257 FillHex (Frame[1], Buffer + 9 + (sizeof (UINTN) * 2) + 8);
258 SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));
259 if ((Frame[0] > (UINTN)Frame) && (Frame[0] < (UINTN)Frame + 0x00100000)) {
260 Frame = (UINTN *)Frame[0];
261 } else {
262 Frame = NULL;
263 }
264 }
265
266 //
267 // Dead loop
268 //
269 CpuDeadLoop ();
270}
271
293VOID
294EFIAPI
296 IN CONST CHAR8 *FileName,
297 IN UINTN LineNumber,
298 IN CONST CHAR8 *Description
299 )
300{
302}
303
319VOID *
320EFIAPI
322 OUT VOID *Buffer,
323 IN UINTN Length
324 )
325{
326 return Buffer;
327}
328
339BOOLEAN
340EFIAPI
342 VOID
343 )
344{
345 return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);
346}
347
358BOOLEAN
359EFIAPI
361 VOID
362 )
363{
364 return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);
365}
366
377BOOLEAN
378EFIAPI
380 VOID
381 )
382{
383 return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);
384}
385
396BOOLEAN
397EFIAPI
399 VOID
400 )
401{
402 return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);
403}
404
414BOOLEAN
415EFIAPI
417 IN CONST UINTN ErrorLevel
418 )
419{
420 return (BOOLEAN)((ErrorLevel & PcdGet32 (PcdFixedDebugPrintErrorLevel)) != 0);
421}
UINT64 UINTN
INT64 INTN
VOID EFIAPI DebugAssert(IN CONST CHAR8 *FileName, IN UINTN LineNumber, IN CONST CHAR8 *Description)
Definition: DebugLib.c:188
VOID EFIAPI DebugVPrint(IN UINTN ErrorLevel, IN CONST CHAR8 *Format, IN VA_LIST VaListMarker)
Definition: DebugLib.c:126
VOID DebugPrintMarker(IN UINTN ErrorLevel, IN CONST CHAR8 *Format, IN VA_LIST VaListMarker, IN BASE_LIST BaseListMarker)
Definition: DebugLib.c:76
VOID EFIAPI DebugBPrint(IN UINTN ErrorLevel, IN CONST CHAR8 *Format, IN BASE_LIST BaseListMarker)
Definition: DebugLib.c:154
VOID *EFIAPI DebugClearMemory(OUT VOID *Buffer, IN UINTN Length)
Definition: DebugLib.c:232
VOID EFIAPI DebugPrint(IN UINTN ErrorLevel, IN CONST CHAR8 *Format,...)
Definition: DebugLib.c:45
BOOLEAN EFIAPI DebugCodeEnabled(VOID)
Definition: DebugLib.c:301
BOOLEAN EFIAPI DebugClearMemoryEnabled(VOID)
Definition: DebugLib.c:321
BOOLEAN EFIAPI DebugPrintEnabled(VOID)
Definition: DebugLib.c:281
BOOLEAN EFIAPI DebugAssertEnabled(VOID)
Definition: DebugLib.c:261
UINTN EFIAPI SerialPortWrite(IN UINT8 *Buffer, IN UINTN NumberOfBytes)
Definition: SerialPortLib.c:52
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define VA_START(Marker, Parameter)
Definition: Base.h:661
CHAR8 * VA_LIST
Definition: Base.h:643
#define IN
Definition: Base.h:279
UINTN * BASE_LIST
Definition: Base.h:711
#define OUT
Definition: Base.h:284
#define VA_END(Marker)
Definition: Base.h:691
RETURN_STATUS EFIAPI AsciiStrnCpyS(OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source, IN UINTN Length)
Definition: SafeString.c:1875
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
Definition: String.c:633
VOID EFIAPI CpuDeadLoop(VOID)
Definition: CpuDeadLoop.c:23
UINT8 EFIAPI GetDebugPrintDeviceEnable(VOID)
UINT32 EFIAPI GetDebugPrintErrorLevel(VOID)
BOOLEAN EFIAPI DebugPrintLevelEnabled(IN CONST UINTN ErrorLevel)
Definition: DebugLib.c:416
VOID DebugAssertInternal(VOID)
Definition: DebugLib.c:226
VOID FillHex(UINTN Value, CHAR8 *Buffer)
Definition: DebugLib.c:195
UINTN *EFIAPI GetStackFramePointer(VOID)
UINTN EFIAPI AsciiBSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString, IN BASE_LIST Marker)
Definition: PrintLib.c:763
UINTN EFIAPI AsciiVSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString, IN VA_LIST Marker)
Definition: PrintLib.c:702
#define PcdGet8(TokenName)
Definition: PcdLib.h:336
#define PcdGet32(TokenName)
Definition: PcdLib.h:362