TianoCore EDK2 master
Loading...
Searching...
No Matches
DebugLib.c
Go to the documentation of this file.
1
10#include <Uefi.h>
11#include <Library/DebugLib.h>
12#include <Library/PrintLib.h>
13#include <Library/PcdLib.h>
14#include <Library/BaseLib.h>
16#include <Library/SemihostLib.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
23//
24// VA_LIST can not initialize to NULL for all compiler, so we use this to
25// indicate a null VA_LIST
26//
27VA_LIST mVaListNull;
28
43VOID
44EFIAPI
46 IN UINTN ErrorLevel,
47 IN CONST CHAR8 *Format,
48 ...
49 )
50{
51 VA_LIST Marker;
52
53 VA_START (Marker, Format);
54 DebugVPrint (ErrorLevel, Format, Marker);
55 VA_END (Marker);
56}
57
75VOID
77 IN UINTN ErrorLevel,
78 IN CONST CHAR8 *Format,
79 IN VA_LIST VaListMarker,
80 IN BASE_LIST BaseListMarker
81 )
82{
83 CHAR8 AsciiBuffer[MAX_DEBUG_MESSAGE_LENGTH];
84
85 //
86 // If Format is NULL, then ASSERT().
87 //
88 ASSERT (Format != NULL);
89
90 //
91 // Check driver debug mask value and global mask
92 //
93 if ((ErrorLevel & PcdGet32 (PcdDebugPrintErrorLevel)) == 0) {
94 return;
95 }
96
97 //
98 // Convert the DEBUG() message to a Unicode String
99 //
100 if (BaseListMarker == NULL) {
101 AsciiVSPrint (AsciiBuffer, sizeof (AsciiBuffer), Format, VaListMarker);
102 } else {
103 AsciiBSPrint (AsciiBuffer, sizeof (AsciiBuffer), Format, BaseListMarker);
104 }
105
106 SemihostWriteString (AsciiBuffer);
107}
108
124VOID
125EFIAPI
127 IN UINTN ErrorLevel,
128 IN CONST CHAR8 *Format,
129 IN VA_LIST VaListMarker
130 )
131{
132 DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL);
133}
134
152VOID
153EFIAPI
155 IN UINTN ErrorLevel,
156 IN CONST CHAR8 *Format,
157 IN BASE_LIST BaseListMarker
158 )
159{
160 DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker);
161}
162
186VOID
187EFIAPI
189 IN CONST CHAR8 *FileName,
190 IN UINTN LineNumber,
191 IN CONST CHAR8 *Description
192 )
193{
194 CHAR8 AsciiBuffer[MAX_DEBUG_MESSAGE_LENGTH];
195
196 //
197 // Generate the ASSERT() message in Unicode format
198 //
199 AsciiSPrint (AsciiBuffer, sizeof (AsciiBuffer), "ASSERT %a(%d): %a\n", FileName, LineNumber, Description);
200
201 SemihostWriteString (AsciiBuffer);
202
203 //
204 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
205 //
206 if ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {
207 CpuBreakpoint ();
208 } else if ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {
209 CpuDeadLoop ();
210 }
211}
212
230VOID *
231EFIAPI
233 OUT VOID *Buffer,
234 IN UINTN Length
235 )
236{
237 //
238 // If Buffer is NULL, then ASSERT().
239 //
240 ASSERT (Buffer != NULL);
241
242 //
243 // SetMem() checks for the ASSERT() condition on Length and returns Buffer
244 //
245 return SetMem (Buffer, Length, PcdGet8 (PcdDebugClearMemoryValue));
246}
247
259BOOLEAN
260EFIAPI
262 VOID
263 )
264{
265 return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);
266}
267
279BOOLEAN
280EFIAPI
282 VOID
283 )
284{
285 return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);
286}
287
299BOOLEAN
300EFIAPI
302 VOID
303 )
304{
305 return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);
306}
307
319BOOLEAN
320EFIAPI
322 VOID
323 )
324{
325 return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);
326}
UINT64 UINTN
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
#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
VOID EFIAPI CpuDeadLoop(VOID)
Definition: CpuDeadLoop.c:23
VOID EFIAPI CpuBreakpoint(VOID)
Definition: CpuBreakpoint.c:26
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
Definition: SetMemWrapper.c:38
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
UINTN EFIAPI AsciiSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
Definition: PrintLib.c:813
#define PcdGet8(TokenName)
Definition: PcdLib.h:336
#define PcdGet32(TokenName)
Definition: PcdLib.h:362