]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiDebugLibStdErr/DebugLib.c
Make MDE package pass intel IPF compiler with /W4 /WX switched on.
[mirror_edk2.git] / MdePkg / Library / UefiDebugLibStdErr / DebugLib.c
CommitLineData
878ddf1f 1/** @file\r
2 UEFI Debug Library that uses PrintLib to send messages to STDERR.\r
3\r
4 Copyright (c) 2006, Intel Corporation<BR>\r
5 All rights reserved. This program and the accompanying materials \r
6 are licensed and made available under the terms and conditions of the BSD License \r
7 which accompanies this distribution. The full text of the license may be found at \r
8 http://opensource.org/licenses/bsd-license.php \r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
12\r
13**/\r
14\r
15//\r
16// Define the maximum debug and assert message length that this library supports \r
17//\r
18#define MAX_DEBUG_MESSAGE_LENGTH 0x100\r
19\r
20\r
21/**\r
22\r
23 Prints a debug message to the debug output device if the specified error level is enabled.\r
24\r
25 If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print \r
26 the message specified by Format and the associated variable argument list to \r
27 the debug output device.\r
28\r
29 If Format is NULL, then ASSERT().\r
30\r
31 @param ErrorLevel The error level of the debug message.\r
32 @param Format Format string for the debug message to print.\r
33\r
34**/\r
35VOID\r
36EFIAPI\r
37DebugPrint (\r
f53ab57c 38 IN UINTN ErrorLevel,\r
39 IN CONST CHAR8 *Format,\r
878ddf1f 40 ...\r
41 )\r
42{\r
43 CHAR16 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
44 VA_LIST Marker;\r
45\r
46 //\r
47 // If Format is NULL, then ASSERT().\r
48 //\r
49 ASSERT (Format != NULL);\r
50\r
51 //\r
52 // Check driver debug mask value and global mask\r
53 //\r
54 if ((ErrorLevel & PcdGet32(PcdDebugPrintErrorLevel)) == 0) {\r
55 return;\r
56 }\r
57\r
58 //\r
59 // Convert the DEBUG() message to a Unicode String\r
60 //\r
61 VA_START (Marker, Format);\r
62 UnicodeVSPrintAsciiFormat (Buffer, sizeof (Buffer), Format, Marker);\r
63 VA_END (Marker);\r
64\r
65 //\r
66 // Send the print string to the Standard Error device\r
67 //\r
68 if (gST->StdErr != NULL) {\r
69 gST->StdErr->OutputString (gST->StdErr, Buffer);\r
70 }\r
71}\r
72\r
73\r
74/**\r
75\r
76 Prints an assert message containing a filename, line number, and description. \r
77 This may be followed by a breakpoint or a dead loop.\r
78\r
8960cdeb 79 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n" \r
878ddf1f 80 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of \r
81 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if \r
82 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then \r
83 CpuDeadLoop() is called. If neither of these bits are set, then this function \r
84 returns immediately after the message is printed to the debug output device.\r
85 DebugAssert() must actively prevent recusrsion. If DebugAssert() is called while\r
86 processing another DebugAssert(), then DebugAssert() must return immediately.\r
87\r
8960cdeb 88 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r
878ddf1f 89\r
8960cdeb 90 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r
878ddf1f 91\r
92 @param FileName Pointer to the name of the source file that generated the assert condition.\r
93 @param LineNumber The line number in the source file that generated the assert condition\r
94 @param Description Pointer to the description of the assert condition.\r
95\r
96**/\r
97VOID\r
98EFIAPI\r
99DebugAssert (\r
f53ab57c 100 IN CONST CHAR8 *FileName,\r
cd14fe3d 101 IN UINTN LineNumber,\r
f53ab57c 102 IN CONST CHAR8 *Description\r
878ddf1f 103 )\r
104{\r
105 CHAR16 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
106\r
107 //\r
108 // Generate the ASSERT() message in Unicode format\r
109 //\r
110 UnicodeSPrintAsciiFormat (Buffer, sizeof (Buffer), "ASSERT %s(%d): %s\n", FileName, LineNumber, Description);\r
111\r
112 //\r
113 // Send the print string to the Standard Error device\r
114 //\r
115 if (gST->StdErr != NULL) {\r
116 gST->StdErr->OutputString (gST->StdErr, Buffer);\r
117 }\r
118\r
119 //\r
120 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r
121 //\r
122 if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r
123 CpuBreakpoint ();\r
124 } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r
125 CpuDeadLoop ();\r
126 }\r
127}\r
128\r
129\r
130/**\r
131\r
132 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r
133\r
134 This function fills Length bytes of Buffer with the value specified by \r
135 PcdDebugClearMemoryValue, and returns Buffer.\r
136\r
137 If Buffer is NULL, then ASSERT().\r
138\r
511710d6 139 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). \r
878ddf1f 140\r
141 @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.\r
142 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue. \r
143\r
144 @return Buffer\r
145\r
146**/\r
147VOID *\r
148EFIAPI\r
149DebugClearMemory (\r
150 OUT VOID *Buffer,\r
151 IN UINTN Length\r
152 )\r
153{\r
154 //\r
155 // If Buffer is NULL, then ASSERT().\r
156 //\r
157 ASSERT (Buffer != NULL);\r
158\r
159 //\r
160 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer\r
161 //\r
162 return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));\r
163}\r
164\r
165\r
166/**\r
167 \r
168 Returns TRUE if ASSERT() macros are enabled.\r
169\r
170 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of \r
171 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
172\r
173 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.\r
174 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.\r
175\r
176**/\r
177BOOLEAN\r
178EFIAPI\r
179DebugAssertEnabled (\r
180 VOID\r
181 )\r
182{\r
58251024 183 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);\r
878ddf1f 184}\r
185\r
186\r
187/**\r
188 \r
189 Returns TRUE if DEBUG()macros are enabled.\r
190\r
191 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of \r
192 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
193\r
194 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.\r
195 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.\r
196\r
197**/\r
198BOOLEAN\r
199EFIAPI\r
200DebugPrintEnabled (\r
201 VOID\r
202 )\r
203{\r
58251024 204 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);\r
878ddf1f 205}\r
206\r
207\r
208/**\r
209 \r
210 Returns TRUE if DEBUG_CODE()macros are enabled.\r
211\r
212 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of \r
213 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
214\r
215 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.\r
216 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.\r
217\r
218**/\r
219BOOLEAN\r
220EFIAPI\r
221DebugCodeEnabled (\r
222 VOID\r
223 )\r
224{\r
58251024 225 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
878ddf1f 226}\r
227\r
228\r
229/**\r
230 \r
231 Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.\r
232\r
233 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of \r
234 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
235\r
236 @retval TRUE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.\r
237 @retval FALSE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.\r
238\r
239**/\r
240BOOLEAN\r
241EFIAPI\r
242DebugClearMemoryEnabled (\r
243 VOID\r
244 )\r
245{\r
58251024 246 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r
878ddf1f 247}\r