]> git.proxmox.com Git - mirror_edk2.git/blame - OldMdePkg/Library/UefiDebugLibStdErr/DebugLib.c
correct on bug in DebugLib instance.
[mirror_edk2.git] / OldMdePkg / Library / UefiDebugLibStdErr / DebugLib.c
CommitLineData
878ddf1f 1/** @file\r
2 UEFI Debug Library that uses PrintLib to send messages to STDERR.\r
3\r
abb23475 4 Copyright (c) 2006 - 2007, Intel Corporation<BR>\r
878ddf1f 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
fe123a5e 44 CHAR8 AsciiBuffer[MAX_DEBUG_MESSAGE_LENGTH];\r
878ddf1f 45 VA_LIST Marker;\r
46\r
47 //\r
48 // If Format is NULL, then ASSERT().\r
49 //\r
50 ASSERT (Format != NULL);\r
51\r
52 //\r
53 // Check driver debug mask value and global mask\r
54 //\r
55 if ((ErrorLevel & PcdGet32(PcdDebugPrintErrorLevel)) == 0) {\r
56 return;\r
57 }\r
58\r
59 //\r
60 // Convert the DEBUG() message to a Unicode String\r
61 //\r
62 VA_START (Marker, Format);\r
fe123a5e 63 AsciiVSPrint (AsciiBuffer, sizeof (AsciiBuffer), Format, Marker);\r
64 AsciiStrToUnicodeStr (AsciiBuffer, Buffer);\r
878ddf1f 65 VA_END (Marker);\r
66\r
67 //\r
68 // Send the print string to the Standard Error device\r
69 //\r
abb23475 70 if ((gST != NULL) && (gST->StdErr != NULL)) {\r
878ddf1f 71 gST->StdErr->OutputString (gST->StdErr, Buffer);\r
72 }\r
73}\r
74\r
75\r
76/**\r
77\r
78 Prints an assert message containing a filename, line number, and description. \r
79 This may be followed by a breakpoint or a dead loop.\r
80\r
8960cdeb 81 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n" \r
878ddf1f 82 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of \r
83 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if \r
84 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then \r
85 CpuDeadLoop() is called. If neither of these bits are set, then this function \r
86 returns immediately after the message is printed to the debug output device.\r
87 DebugAssert() must actively prevent recusrsion. If DebugAssert() is called while\r
88 processing another DebugAssert(), then DebugAssert() must return immediately.\r
89\r
8960cdeb 90 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r
878ddf1f 91\r
8960cdeb 92 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r
878ddf1f 93\r
94 @param FileName Pointer to the name of the source file that generated the assert condition.\r
95 @param LineNumber The line number in the source file that generated the assert condition\r
96 @param Description Pointer to the description of the assert condition.\r
97\r
98**/\r
99VOID\r
100EFIAPI\r
101DebugAssert (\r
f53ab57c 102 IN CONST CHAR8 *FileName,\r
cd14fe3d 103 IN UINTN LineNumber,\r
f53ab57c 104 IN CONST CHAR8 *Description\r
878ddf1f 105 )\r
106{\r
107 CHAR16 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
fe123a5e 108 CHAR8 AsciiBuffer[MAX_DEBUG_MESSAGE_LENGTH];\r
878ddf1f 109\r
110 //\r
111 // Generate the ASSERT() message in Unicode format\r
112 //\r
fe123a5e 113 AsciiSPrint (AsciiBuffer, sizeof (AsciiBuffer), "ASSERT %a(%d): %a\n", FileName, LineNumber, Description);\r
114 AsciiStrToUnicodeStr (AsciiBuffer, Buffer);\r
878ddf1f 115\r
116 //\r
117 // Send the print string to the Standard Error device\r
118 //\r
abb23475 119 if ((gST != NULL) && (gST->StdErr != NULL)) {\r
878ddf1f 120 gST->StdErr->OutputString (gST->StdErr, Buffer);\r
121 }\r
122\r
123 //\r
124 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r
125 //\r
126 if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r
127 CpuBreakpoint ();\r
128 } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r
129 CpuDeadLoop ();\r
130 }\r
131}\r
132\r
133\r
134/**\r
135\r
136 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r
137\r
138 This function fills Length bytes of Buffer with the value specified by \r
139 PcdDebugClearMemoryValue, and returns Buffer.\r
140\r
141 If Buffer is NULL, then ASSERT().\r
142\r
511710d6 143 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). \r
878ddf1f 144\r
145 @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.\r
146 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue. \r
147\r
148 @return Buffer\r
149\r
150**/\r
151VOID *\r
152EFIAPI\r
153DebugClearMemory (\r
154 OUT VOID *Buffer,\r
155 IN UINTN Length\r
156 )\r
157{\r
158 //\r
159 // If Buffer is NULL, then ASSERT().\r
160 //\r
161 ASSERT (Buffer != NULL);\r
162\r
163 //\r
164 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer\r
165 //\r
166 return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));\r
167}\r
168\r
169\r
170/**\r
171 \r
172 Returns TRUE if ASSERT() macros are enabled.\r
173\r
174 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of \r
175 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
176\r
177 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.\r
178 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.\r
179\r
180**/\r
181BOOLEAN\r
182EFIAPI\r
183DebugAssertEnabled (\r
184 VOID\r
185 )\r
186{\r
58251024 187 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);\r
878ddf1f 188}\r
189\r
190\r
191/**\r
192 \r
193 Returns TRUE if DEBUG()macros are enabled.\r
194\r
195 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of \r
196 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
197\r
198 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.\r
199 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.\r
200\r
201**/\r
202BOOLEAN\r
203EFIAPI\r
204DebugPrintEnabled (\r
205 VOID\r
206 )\r
207{\r
58251024 208 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);\r
878ddf1f 209}\r
210\r
211\r
212/**\r
213 \r
214 Returns TRUE if DEBUG_CODE()macros are enabled.\r
215\r
216 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of \r
217 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
218\r
219 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.\r
220 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.\r
221\r
222**/\r
223BOOLEAN\r
224EFIAPI\r
225DebugCodeEnabled (\r
226 VOID\r
227 )\r
228{\r
58251024 229 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
878ddf1f 230}\r
231\r
232\r
233/**\r
234 \r
235 Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.\r
236\r
237 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of \r
238 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
239\r
240 @retval TRUE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.\r
241 @retval FALSE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.\r
242\r
243**/\r
244BOOLEAN\r
245EFIAPI\r
246DebugClearMemoryEnabled (\r
247 VOID\r
248 )\r
249{\r
58251024 250 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r
878ddf1f 251}\r