aslerror.c revision 1.6 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: aslerror - Error handling and statistics
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.2 christos /*
8 1.6 christos * Copyright (C) 2000 - 2016, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.2 christos * Redistribution and use in source and binary forms, with or without
12 1.2 christos * modification, are permitted provided that the following conditions
13 1.2 christos * are met:
14 1.2 christos * 1. Redistributions of source code must retain the above copyright
15 1.2 christos * notice, this list of conditions, and the following disclaimer,
16 1.2 christos * without modification.
17 1.2 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.2 christos * substantially similar to the "NO WARRANTY" disclaimer below
19 1.2 christos * ("Disclaimer") and any redistribution must be conditioned upon
20 1.2 christos * including a substantially similar Disclaimer requirement for further
21 1.2 christos * binary redistribution.
22 1.2 christos * 3. Neither the names of the above-listed copyright holders nor the names
23 1.2 christos * of any contributors may be used to endorse or promote products derived
24 1.2 christos * from this software without specific prior written permission.
25 1.2 christos *
26 1.2 christos * Alternatively, this software may be distributed under the terms of the
27 1.2 christos * GNU General Public License ("GPL") version 2 as published by the Free
28 1.2 christos * Software Foundation.
29 1.2 christos *
30 1.2 christos * NO WARRANTY
31 1.2 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.2 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.2 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.2 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.2 christos * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.2 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.2 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.2 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.2 christos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.2 christos * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.2 christos * POSSIBILITY OF SUCH DAMAGES.
42 1.2 christos */
43 1.1 jruoho
44 1.1 jruoho #include "aslcompiler.h"
45 1.1 jruoho
46 1.1 jruoho #define _COMPONENT ACPI_COMPILER
47 1.1 jruoho ACPI_MODULE_NAME ("aslerror")
48 1.1 jruoho
49 1.1 jruoho /* Local prototypes */
50 1.1 jruoho
51 1.1 jruoho static void
52 1.1 jruoho AeAddToErrorLog (
53 1.1 jruoho ASL_ERROR_MSG *Enode);
54 1.1 jruoho
55 1.1 jruoho
56 1.2 christos /*******************************************************************************
57 1.2 christos *
58 1.3 christos * FUNCTION: AslAbort
59 1.3 christos *
60 1.3 christos * PARAMETERS: None
61 1.3 christos *
62 1.3 christos * RETURN: None
63 1.3 christos *
64 1.3 christos * DESCRIPTION: Dump the error log and abort the compiler. Used for serious
65 1.3 christos * I/O errors.
66 1.3 christos *
67 1.3 christos ******************************************************************************/
68 1.3 christos
69 1.3 christos void
70 1.3 christos AslAbort (
71 1.3 christos void)
72 1.3 christos {
73 1.3 christos
74 1.3 christos AePrintErrorLog (ASL_FILE_STDERR);
75 1.3 christos if (Gbl_DebugFlag)
76 1.3 christos {
77 1.3 christos /* Print error summary to stdout also */
78 1.3 christos
79 1.3 christos AePrintErrorLog (ASL_FILE_STDOUT);
80 1.3 christos }
81 1.3 christos
82 1.3 christos exit (1);
83 1.3 christos }
84 1.3 christos
85 1.3 christos
86 1.3 christos /*******************************************************************************
87 1.3 christos *
88 1.2 christos * FUNCTION: AeClearErrorLog
89 1.2 christos *
90 1.2 christos * PARAMETERS: None
91 1.2 christos *
92 1.2 christos * RETURN: None
93 1.2 christos *
94 1.2 christos * DESCRIPTION: Empty the error list
95 1.2 christos *
96 1.2 christos ******************************************************************************/
97 1.2 christos
98 1.1 jruoho void
99 1.1 jruoho AeClearErrorLog (
100 1.1 jruoho void)
101 1.1 jruoho {
102 1.1 jruoho ASL_ERROR_MSG *Enode = Gbl_ErrorLog;
103 1.1 jruoho ASL_ERROR_MSG *Next;
104 1.1 jruoho
105 1.1 jruoho /* Walk the error node list */
106 1.1 jruoho
107 1.1 jruoho while (Enode)
108 1.1 jruoho {
109 1.1 jruoho Next = Enode->Next;
110 1.1 jruoho ACPI_FREE (Enode);
111 1.1 jruoho Enode = Next;
112 1.1 jruoho }
113 1.1 jruoho
114 1.1 jruoho Gbl_ErrorLog = NULL;
115 1.1 jruoho }
116 1.1 jruoho
117 1.1 jruoho
118 1.1 jruoho /*******************************************************************************
119 1.1 jruoho *
120 1.1 jruoho * FUNCTION: AeAddToErrorLog
121 1.1 jruoho *
122 1.1 jruoho * PARAMETERS: Enode - An error node to add to the log
123 1.1 jruoho *
124 1.1 jruoho * RETURN: None
125 1.1 jruoho *
126 1.2 christos * DESCRIPTION: Add a new error node to the error log. The error log is
127 1.1 jruoho * ordered by the "logical" line number (cumulative line number
128 1.1 jruoho * including all include files.)
129 1.1 jruoho *
130 1.1 jruoho ******************************************************************************/
131 1.1 jruoho
132 1.1 jruoho static void
133 1.1 jruoho AeAddToErrorLog (
134 1.1 jruoho ASL_ERROR_MSG *Enode)
135 1.1 jruoho {
136 1.1 jruoho ASL_ERROR_MSG *Next;
137 1.1 jruoho ASL_ERROR_MSG *Prev;
138 1.1 jruoho
139 1.1 jruoho
140 1.1 jruoho /* If Gbl_ErrorLog is null, this is the first error node */
141 1.1 jruoho
142 1.1 jruoho if (!Gbl_ErrorLog)
143 1.1 jruoho {
144 1.1 jruoho Gbl_ErrorLog = Enode;
145 1.1 jruoho return;
146 1.1 jruoho }
147 1.1 jruoho
148 1.1 jruoho /*
149 1.1 jruoho * Walk error list until we find a line number greater than ours.
150 1.1 jruoho * List is sorted according to line number.
151 1.1 jruoho */
152 1.1 jruoho Prev = NULL;
153 1.1 jruoho Next = Gbl_ErrorLog;
154 1.1 jruoho
155 1.1 jruoho while ((Next) &&
156 1.1 jruoho (Next->LogicalLineNumber <= Enode->LogicalLineNumber))
157 1.1 jruoho {
158 1.1 jruoho Prev = Next;
159 1.1 jruoho Next = Next->Next;
160 1.1 jruoho }
161 1.1 jruoho
162 1.1 jruoho /* Found our place in the list */
163 1.1 jruoho
164 1.1 jruoho Enode->Next = Next;
165 1.1 jruoho
166 1.1 jruoho if (Prev)
167 1.1 jruoho {
168 1.1 jruoho Prev->Next = Enode;
169 1.1 jruoho }
170 1.1 jruoho else
171 1.1 jruoho {
172 1.1 jruoho Gbl_ErrorLog = Enode;
173 1.1 jruoho }
174 1.1 jruoho }
175 1.1 jruoho
176 1.1 jruoho
177 1.1 jruoho /*******************************************************************************
178 1.1 jruoho *
179 1.1 jruoho * FUNCTION: AePrintException
180 1.1 jruoho *
181 1.1 jruoho * PARAMETERS: FileId - ID of output file
182 1.1 jruoho * Enode - Error node to print
183 1.1 jruoho * Header - Additional text before each message
184 1.1 jruoho *
185 1.1 jruoho * RETURN: None
186 1.1 jruoho *
187 1.1 jruoho * DESCRIPTION: Print the contents of an error node.
188 1.1 jruoho *
189 1.1 jruoho * NOTE: We don't use the FlxxxFile I/O functions here because on error
190 1.1 jruoho * they abort the compiler and call this function! Since we
191 1.1 jruoho * are reporting errors here, we ignore most output errors and
192 1.1 jruoho * just try to get out as much as we can.
193 1.1 jruoho *
194 1.1 jruoho ******************************************************************************/
195 1.1 jruoho
196 1.1 jruoho void
197 1.1 jruoho AePrintException (
198 1.1 jruoho UINT32 FileId,
199 1.1 jruoho ASL_ERROR_MSG *Enode,
200 1.1 jruoho char *Header)
201 1.1 jruoho {
202 1.1 jruoho UINT8 SourceByte;
203 1.1 jruoho int Actual;
204 1.1 jruoho size_t RActual;
205 1.1 jruoho UINT32 MsgLength;
206 1.3 christos const char *MainMessage;
207 1.1 jruoho char *ExtraMessage;
208 1.1 jruoho UINT32 SourceColumn;
209 1.1 jruoho UINT32 ErrorColumn;
210 1.1 jruoho FILE *OutputFile;
211 1.2 christos FILE *SourceFile = NULL;
212 1.2 christos long FileSize;
213 1.2 christos BOOLEAN PrematureEOF = FALSE;
214 1.2 christos UINT32 Total = 0;
215 1.1 jruoho
216 1.1 jruoho
217 1.1 jruoho if (Gbl_NoErrors)
218 1.1 jruoho {
219 1.1 jruoho return;
220 1.1 jruoho }
221 1.1 jruoho
222 1.1 jruoho /*
223 1.1 jruoho * Only listing files have a header, and remarks/optimizations
224 1.1 jruoho * are always output
225 1.1 jruoho */
226 1.1 jruoho if (!Header)
227 1.1 jruoho {
228 1.1 jruoho /* Ignore remarks if requested */
229 1.1 jruoho
230 1.1 jruoho switch (Enode->Level)
231 1.1 jruoho {
232 1.2 christos case ASL_WARNING:
233 1.2 christos case ASL_WARNING2:
234 1.2 christos case ASL_WARNING3:
235 1.2 christos
236 1.2 christos if (!Gbl_DisplayWarnings)
237 1.2 christos {
238 1.2 christos return;
239 1.2 christos }
240 1.2 christos break;
241 1.2 christos
242 1.1 jruoho case ASL_REMARK:
243 1.2 christos
244 1.1 jruoho if (!Gbl_DisplayRemarks)
245 1.1 jruoho {
246 1.1 jruoho return;
247 1.1 jruoho }
248 1.1 jruoho break;
249 1.1 jruoho
250 1.1 jruoho case ASL_OPTIMIZATION:
251 1.2 christos
252 1.1 jruoho if (!Gbl_DisplayOptimizations)
253 1.1 jruoho {
254 1.1 jruoho return;
255 1.1 jruoho }
256 1.1 jruoho break;
257 1.1 jruoho
258 1.1 jruoho default:
259 1.2 christos
260 1.1 jruoho break;
261 1.1 jruoho }
262 1.1 jruoho }
263 1.1 jruoho
264 1.2 christos /* Get the various required file handles */
265 1.1 jruoho
266 1.1 jruoho OutputFile = Gbl_Files[FileId].Handle;
267 1.2 christos
268 1.2 christos if (!Enode->SourceLine)
269 1.2 christos {
270 1.6 christos /*
271 1.6 christos * Use the merged header/source file if present, otherwise
272 1.6 christos * use input file
273 1.6 christos */
274 1.2 christos SourceFile = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
275 1.2 christos if (!SourceFile)
276 1.2 christos {
277 1.2 christos SourceFile = Gbl_Files[ASL_FILE_INPUT].Handle;
278 1.2 christos }
279 1.2 christos
280 1.2 christos if (SourceFile)
281 1.2 christos {
282 1.2 christos /* Determine if the error occurred at source file EOF */
283 1.2 christos
284 1.2 christos fseek (SourceFile, 0, SEEK_END);
285 1.2 christos FileSize = ftell (SourceFile);
286 1.2 christos
287 1.2 christos if ((long) Enode->LogicalByteOffset >= FileSize)
288 1.2 christos {
289 1.2 christos PrematureEOF = TRUE;
290 1.2 christos }
291 1.2 christos }
292 1.2 christos }
293 1.1 jruoho
294 1.1 jruoho if (Header)
295 1.1 jruoho {
296 1.1 jruoho fprintf (OutputFile, "%s", Header);
297 1.1 jruoho }
298 1.1 jruoho
299 1.1 jruoho /* Print filename and line number if present and valid */
300 1.1 jruoho
301 1.1 jruoho if (Enode->Filename)
302 1.1 jruoho {
303 1.1 jruoho if (Gbl_VerboseErrors)
304 1.1 jruoho {
305 1.2 christos fprintf (OutputFile, "%-8s", Enode->Filename);
306 1.1 jruoho
307 1.1 jruoho if (Enode->LineNumber)
308 1.1 jruoho {
309 1.2 christos if (Enode->SourceLine)
310 1.1 jruoho {
311 1.2 christos fprintf (OutputFile, " %6u: %s",
312 1.2 christos Enode->LineNumber, Enode->SourceLine);
313 1.1 jruoho }
314 1.1 jruoho else
315 1.1 jruoho {
316 1.2 christos fprintf (OutputFile, " %6u: ", Enode->LineNumber);
317 1.2 christos
318 1.2 christos /*
319 1.6 christos * If not at EOF, get the corresponding source code line
320 1.6 christos * and display it. Don't attempt this if we have a
321 1.6 christos * premature EOF condition.
322 1.2 christos */
323 1.2 christos if (!PrematureEOF)
324 1.1 jruoho {
325 1.2 christos /*
326 1.6 christos * Seek to the offset in the combined source file,
327 1.6 christos * read the source line, and write it to the output.
328 1.2 christos */
329 1.6 christos Actual = fseek (SourceFile,
330 1.6 christos (long) Enode->LogicalByteOffset, (int) SEEK_SET);
331 1.2 christos if (Actual)
332 1.2 christos {
333 1.2 christos fprintf (OutputFile,
334 1.2 christos "[*** iASL: Seek error on source code temp file %s ***]",
335 1.2 christos Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
336 1.2 christos }
337 1.2 christos else
338 1.2 christos {
339 1.2 christos RActual = fread (&SourceByte, 1, 1, SourceFile);
340 1.2 christos if (RActual != 1)
341 1.2 christos {
342 1.2 christos fprintf (OutputFile,
343 1.2 christos "[*** iASL: Read error on source code temp file %s ***]",
344 1.2 christos Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
345 1.2 christos }
346 1.2 christos else
347 1.2 christos {
348 1.2 christos /* Read/write the source line, up to the maximum line length */
349 1.2 christos
350 1.2 christos while (RActual && SourceByte && (SourceByte != '\n'))
351 1.2 christos {
352 1.2 christos if (Total < 256)
353 1.2 christos {
354 1.2 christos /* After the max line length, we will just read the line, no write */
355 1.2 christos
356 1.2 christos if (fwrite (&SourceByte, 1, 1, OutputFile) != 1)
357 1.2 christos {
358 1.2 christos printf ("[*** iASL: Write error on output file ***]\n");
359 1.2 christos return;
360 1.2 christos }
361 1.2 christos }
362 1.2 christos else if (Total == 256)
363 1.2 christos {
364 1.2 christos fprintf (OutputFile,
365 1.2 christos "\n[*** iASL: Very long input line, message below refers to column %u ***]",
366 1.2 christos Enode->Column);
367 1.2 christos }
368 1.2 christos
369 1.2 christos RActual = fread (&SourceByte, 1, 1, SourceFile);
370 1.2 christos if (RActual != 1)
371 1.2 christos {
372 1.2 christos fprintf (OutputFile,
373 1.2 christos "[*** iASL: Read error on source code temp file %s ***]",
374 1.2 christos Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
375 1.2 christos return;
376 1.2 christos }
377 1.2 christos Total++;
378 1.2 christos }
379 1.2 christos }
380 1.2 christos }
381 1.1 jruoho }
382 1.1 jruoho
383 1.2 christos fprintf (OutputFile, "\n");
384 1.1 jruoho }
385 1.1 jruoho }
386 1.1 jruoho }
387 1.1 jruoho else
388 1.1 jruoho {
389 1.2 christos /*
390 1.2 christos * Less verbose version of the error message, enabled via the
391 1.2 christos * -vi switch. The format is compatible with MS Visual Studio.
392 1.2 christos */
393 1.1 jruoho fprintf (OutputFile, "%s", Enode->Filename);
394 1.1 jruoho
395 1.1 jruoho if (Enode->LineNumber)
396 1.1 jruoho {
397 1.2 christos fprintf (OutputFile, "(%u) : ",
398 1.2 christos Enode->LineNumber);
399 1.1 jruoho }
400 1.1 jruoho }
401 1.1 jruoho }
402 1.1 jruoho
403 1.3 christos /* If a NULL message ID, just print the raw message */
404 1.1 jruoho
405 1.1 jruoho if (Enode->MessageId == 0)
406 1.1 jruoho {
407 1.1 jruoho fprintf (OutputFile, "%s\n", Enode->Message);
408 1.3 christos return;
409 1.3 christos }
410 1.3 christos
411 1.3 christos /* Decode the message ID */
412 1.3 christos
413 1.3 christos fprintf (OutputFile, "%s %4.4d -",
414 1.3 christos AeDecodeExceptionLevel (Enode->Level),
415 1.3 christos AeBuildFullExceptionCode (Enode->Level, Enode->MessageId));
416 1.3 christos
417 1.3 christos MainMessage = AeDecodeMessageId (Enode->MessageId);
418 1.3 christos ExtraMessage = Enode->Message;
419 1.3 christos
420 1.3 christos /* If a NULL line number, just print the decoded message */
421 1.3 christos
422 1.3 christos if (!Enode->LineNumber)
423 1.3 christos {
424 1.3 christos fprintf (OutputFile, " %s %s\n\n", MainMessage, ExtraMessage);
425 1.3 christos return;
426 1.1 jruoho }
427 1.3 christos
428 1.3 christos MsgLength = strlen (MainMessage);
429 1.3 christos if (MsgLength == 0)
430 1.1 jruoho {
431 1.3 christos /* Use the secondary/extra message as main message */
432 1.1 jruoho
433 1.3 christos MainMessage = Enode->Message;
434 1.3 christos if (!MainMessage)
435 1.2 christos {
436 1.3 christos MainMessage = "";
437 1.2 christos }
438 1.3 christos
439 1.3 christos MsgLength = strlen (MainMessage);
440 1.3 christos ExtraMessage = NULL;
441 1.3 christos }
442 1.3 christos
443 1.3 christos if (Gbl_VerboseErrors && !PrematureEOF)
444 1.3 christos {
445 1.3 christos if (Total >= 256)
446 1.2 christos {
447 1.3 christos fprintf (OutputFile, " %s",
448 1.3 christos MainMessage);
449 1.2 christos }
450 1.3 christos else
451 1.1 jruoho {
452 1.3 christos SourceColumn = Enode->Column + Enode->FilenameLength + 6 + 2;
453 1.3 christos ErrorColumn = ASL_ERROR_LEVEL_LENGTH + 5 + 2 + 1;
454 1.2 christos
455 1.3 christos if ((MsgLength + ErrorColumn) < (SourceColumn - 1))
456 1.2 christos {
457 1.3 christos fprintf (OutputFile, "%*s%s",
458 1.3 christos (int) ((SourceColumn - 1) - ErrorColumn),
459 1.3 christos MainMessage, " ^ ");
460 1.1 jruoho }
461 1.1 jruoho else
462 1.1 jruoho {
463 1.3 christos fprintf (OutputFile, "%*s %s",
464 1.3 christos (int) ((SourceColumn - ErrorColumn) + 1), "^",
465 1.3 christos MainMessage);
466 1.1 jruoho }
467 1.3 christos }
468 1.3 christos }
469 1.3 christos else
470 1.3 christos {
471 1.3 christos fprintf (OutputFile, " %s", MainMessage);
472 1.3 christos }
473 1.1 jruoho
474 1.3 christos /* Print the extra info message if present */
475 1.1 jruoho
476 1.3 christos if (ExtraMessage)
477 1.3 christos {
478 1.3 christos fprintf (OutputFile, " (%s)", ExtraMessage);
479 1.3 christos }
480 1.1 jruoho
481 1.3 christos if (PrematureEOF)
482 1.3 christos {
483 1.3 christos fprintf (OutputFile, " and premature End-Of-File");
484 1.3 christos }
485 1.2 christos
486 1.3 christos fprintf (OutputFile, "\n");
487 1.3 christos if (Gbl_VerboseErrors)
488 1.3 christos {
489 1.3 christos fprintf (OutputFile, "\n");
490 1.1 jruoho }
491 1.1 jruoho }
492 1.1 jruoho
493 1.1 jruoho
494 1.1 jruoho /*******************************************************************************
495 1.1 jruoho *
496 1.1 jruoho * FUNCTION: AePrintErrorLog
497 1.1 jruoho *
498 1.1 jruoho * PARAMETERS: FileId - Where to output the error log
499 1.1 jruoho *
500 1.1 jruoho * RETURN: None
501 1.1 jruoho *
502 1.1 jruoho * DESCRIPTION: Print the entire contents of the error log
503 1.1 jruoho *
504 1.1 jruoho ******************************************************************************/
505 1.1 jruoho
506 1.1 jruoho void
507 1.1 jruoho AePrintErrorLog (
508 1.1 jruoho UINT32 FileId)
509 1.1 jruoho {
510 1.1 jruoho ASL_ERROR_MSG *Enode = Gbl_ErrorLog;
511 1.1 jruoho
512 1.1 jruoho
513 1.1 jruoho /* Walk the error node list */
514 1.1 jruoho
515 1.1 jruoho while (Enode)
516 1.1 jruoho {
517 1.1 jruoho AePrintException (FileId, Enode, NULL);
518 1.1 jruoho Enode = Enode->Next;
519 1.1 jruoho }
520 1.1 jruoho }
521 1.1 jruoho
522 1.1 jruoho
523 1.1 jruoho /*******************************************************************************
524 1.1 jruoho *
525 1.2 christos * FUNCTION: AslCommonError2
526 1.2 christos *
527 1.2 christos * PARAMETERS: Level - Seriousness (Warning/error, etc.)
528 1.2 christos * MessageId - Index into global message buffer
529 1.2 christos * LineNumber - Actual file line number
530 1.2 christos * Column - Column in current line
531 1.2 christos * SourceLine - Actual source code line
532 1.2 christos * Filename - source filename
533 1.2 christos * ExtraMessage - additional error message
534 1.2 christos *
535 1.2 christos * RETURN: None
536 1.2 christos *
537 1.2 christos * DESCRIPTION: Create a new error node and add it to the error log
538 1.2 christos *
539 1.2 christos ******************************************************************************/
540 1.2 christos
541 1.2 christos void
542 1.2 christos AslCommonError2 (
543 1.2 christos UINT8 Level,
544 1.3 christos UINT16 MessageId,
545 1.2 christos UINT32 LineNumber,
546 1.2 christos UINT32 Column,
547 1.2 christos char *SourceLine,
548 1.2 christos char *Filename,
549 1.2 christos char *ExtraMessage)
550 1.2 christos {
551 1.2 christos char *MessageBuffer = NULL;
552 1.2 christos char *LineBuffer;
553 1.2 christos ASL_ERROR_MSG *Enode;
554 1.2 christos
555 1.2 christos
556 1.2 christos Enode = UtLocalCalloc (sizeof (ASL_ERROR_MSG));
557 1.2 christos
558 1.2 christos if (ExtraMessage)
559 1.2 christos {
560 1.2 christos /* Allocate a buffer for the message and a new error node */
561 1.2 christos
562 1.3 christos MessageBuffer = UtStringCacheCalloc (strlen (ExtraMessage) + 1);
563 1.2 christos
564 1.2 christos /* Keep a copy of the extra message */
565 1.2 christos
566 1.5 christos strcpy (MessageBuffer, ExtraMessage);
567 1.2 christos }
568 1.2 christos
569 1.2 christos LineBuffer = UtLocalCalloc (strlen (SourceLine) + 1);
570 1.5 christos strcpy (LineBuffer, SourceLine);
571 1.2 christos
572 1.2 christos /* Initialize the error node */
573 1.2 christos
574 1.2 christos if (Filename)
575 1.2 christos {
576 1.3 christos Enode->Filename = Filename;
577 1.2 christos Enode->FilenameLength = strlen (Filename);
578 1.2 christos if (Enode->FilenameLength < 6)
579 1.2 christos {
580 1.2 christos Enode->FilenameLength = 6;
581 1.2 christos }
582 1.2 christos }
583 1.2 christos
584 1.2 christos Enode->MessageId = MessageId;
585 1.2 christos Enode->Level = Level;
586 1.2 christos Enode->LineNumber = LineNumber;
587 1.2 christos Enode->LogicalLineNumber = LineNumber;
588 1.2 christos Enode->LogicalByteOffset = 0;
589 1.2 christos Enode->Column = Column;
590 1.2 christos Enode->Message = MessageBuffer;
591 1.2 christos Enode->SourceLine = LineBuffer;
592 1.2 christos
593 1.2 christos /* Add the new node to the error node list */
594 1.2 christos
595 1.2 christos AeAddToErrorLog (Enode);
596 1.2 christos
597 1.2 christos if (Gbl_DebugFlag)
598 1.2 christos {
599 1.2 christos /* stderr is a file, send error to it immediately */
600 1.2 christos
601 1.2 christos AePrintException (ASL_FILE_STDERR, Enode, NULL);
602 1.2 christos }
603 1.2 christos
604 1.2 christos Gbl_ExceptionCount[Level]++;
605 1.2 christos }
606 1.2 christos
607 1.2 christos
608 1.2 christos /*******************************************************************************
609 1.2 christos *
610 1.1 jruoho * FUNCTION: AslCommonError
611 1.1 jruoho *
612 1.1 jruoho * PARAMETERS: Level - Seriousness (Warning/error, etc.)
613 1.1 jruoho * MessageId - Index into global message buffer
614 1.1 jruoho * CurrentLineNumber - Actual file line number
615 1.1 jruoho * LogicalLineNumber - Cumulative line number
616 1.1 jruoho * LogicalByteOffset - Byte offset in source file
617 1.1 jruoho * Column - Column in current line
618 1.1 jruoho * Filename - source filename
619 1.1 jruoho * ExtraMessage - additional error message
620 1.1 jruoho *
621 1.1 jruoho * RETURN: None
622 1.1 jruoho *
623 1.1 jruoho * DESCRIPTION: Create a new error node and add it to the error log
624 1.1 jruoho *
625 1.1 jruoho ******************************************************************************/
626 1.1 jruoho
627 1.1 jruoho void
628 1.1 jruoho AslCommonError (
629 1.1 jruoho UINT8 Level,
630 1.3 christos UINT16 MessageId,
631 1.1 jruoho UINT32 CurrentLineNumber,
632 1.1 jruoho UINT32 LogicalLineNumber,
633 1.1 jruoho UINT32 LogicalByteOffset,
634 1.1 jruoho UINT32 Column,
635 1.1 jruoho char *Filename,
636 1.1 jruoho char *ExtraMessage)
637 1.1 jruoho {
638 1.1 jruoho char *MessageBuffer = NULL;
639 1.1 jruoho ASL_ERROR_MSG *Enode;
640 1.1 jruoho
641 1.1 jruoho
642 1.1 jruoho Enode = UtLocalCalloc (sizeof (ASL_ERROR_MSG));
643 1.1 jruoho
644 1.1 jruoho if (ExtraMessage)
645 1.1 jruoho {
646 1.1 jruoho /* Allocate a buffer for the message and a new error node */
647 1.1 jruoho
648 1.3 christos MessageBuffer = UtStringCacheCalloc (strlen (ExtraMessage) + 1);
649 1.1 jruoho
650 1.1 jruoho /* Keep a copy of the extra message */
651 1.1 jruoho
652 1.5 christos strcpy (MessageBuffer, ExtraMessage);
653 1.1 jruoho }
654 1.1 jruoho
655 1.1 jruoho /* Initialize the error node */
656 1.1 jruoho
657 1.1 jruoho if (Filename)
658 1.1 jruoho {
659 1.3 christos Enode->Filename = Filename;
660 1.1 jruoho Enode->FilenameLength = strlen (Filename);
661 1.1 jruoho if (Enode->FilenameLength < 6)
662 1.1 jruoho {
663 1.1 jruoho Enode->FilenameLength = 6;
664 1.1 jruoho }
665 1.1 jruoho }
666 1.1 jruoho
667 1.1 jruoho Enode->MessageId = MessageId;
668 1.1 jruoho Enode->Level = Level;
669 1.1 jruoho Enode->LineNumber = CurrentLineNumber;
670 1.1 jruoho Enode->LogicalLineNumber = LogicalLineNumber;
671 1.1 jruoho Enode->LogicalByteOffset = LogicalByteOffset;
672 1.1 jruoho Enode->Column = Column;
673 1.1 jruoho Enode->Message = MessageBuffer;
674 1.2 christos Enode->SourceLine = NULL;
675 1.1 jruoho
676 1.1 jruoho /* Add the new node to the error node list */
677 1.1 jruoho
678 1.1 jruoho AeAddToErrorLog (Enode);
679 1.1 jruoho
680 1.1 jruoho if (Gbl_DebugFlag)
681 1.1 jruoho {
682 1.1 jruoho /* stderr is a file, send error to it immediately */
683 1.1 jruoho
684 1.1 jruoho AePrintException (ASL_FILE_STDERR, Enode, NULL);
685 1.1 jruoho }
686 1.1 jruoho
687 1.1 jruoho Gbl_ExceptionCount[Level]++;
688 1.1 jruoho if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
689 1.1 jruoho {
690 1.1 jruoho printf ("\nMaximum error count (%u) exceeded\n", ASL_MAX_ERROR_COUNT);
691 1.1 jruoho
692 1.1 jruoho Gbl_SourceLine = 0;
693 1.1 jruoho Gbl_NextError = Gbl_ErrorLog;
694 1.1 jruoho CmCleanupAndExit ();
695 1.1 jruoho exit(1);
696 1.1 jruoho }
697 1.1 jruoho
698 1.1 jruoho return;
699 1.1 jruoho }
700 1.1 jruoho
701 1.1 jruoho
702 1.1 jruoho /*******************************************************************************
703 1.1 jruoho *
704 1.2 christos * FUNCTION: AslDisableException
705 1.2 christos *
706 1.2 christos * PARAMETERS: MessageIdString - ID to be disabled
707 1.2 christos *
708 1.2 christos * RETURN: Status
709 1.2 christos *
710 1.2 christos * DESCRIPTION: Enter a message ID into the global disabled messages table
711 1.2 christos *
712 1.2 christos ******************************************************************************/
713 1.2 christos
714 1.2 christos ACPI_STATUS
715 1.2 christos AslDisableException (
716 1.2 christos char *MessageIdString)
717 1.2 christos {
718 1.2 christos UINT32 MessageId;
719 1.2 christos
720 1.2 christos
721 1.2 christos /* Convert argument to an integer and validate it */
722 1.2 christos
723 1.2 christos MessageId = (UINT32) strtoul (MessageIdString, NULL, 0);
724 1.2 christos
725 1.2 christos if ((MessageId < 2000) || (MessageId > 5999))
726 1.2 christos {
727 1.2 christos printf ("\"%s\" is not a valid warning/remark ID\n",
728 1.2 christos MessageIdString);
729 1.2 christos return (AE_BAD_PARAMETER);
730 1.2 christos }
731 1.2 christos
732 1.2 christos /* Insert value into the global disabled message array */
733 1.2 christos
734 1.2 christos if (Gbl_DisabledMessagesIndex >= ASL_MAX_DISABLED_MESSAGES)
735 1.2 christos {
736 1.2 christos printf ("Too many messages have been disabled (max %u)\n",
737 1.2 christos ASL_MAX_DISABLED_MESSAGES);
738 1.2 christos return (AE_LIMIT);
739 1.2 christos }
740 1.2 christos
741 1.2 christos Gbl_DisabledMessages[Gbl_DisabledMessagesIndex] = MessageId;
742 1.2 christos Gbl_DisabledMessagesIndex++;
743 1.2 christos return (AE_OK);
744 1.2 christos }
745 1.2 christos
746 1.2 christos
747 1.2 christos /*******************************************************************************
748 1.2 christos *
749 1.2 christos * FUNCTION: AslIsExceptionDisabled
750 1.2 christos *
751 1.2 christos * PARAMETERS: Level - Seriousness (Warning/error, etc.)
752 1.2 christos * MessageId - Index into global message buffer
753 1.2 christos *
754 1.2 christos * RETURN: TRUE if exception/message should be ignored
755 1.2 christos *
756 1.2 christos * DESCRIPTION: Check if the user has specified options such that this
757 1.2 christos * exception should be ignored
758 1.2 christos *
759 1.2 christos ******************************************************************************/
760 1.2 christos
761 1.2 christos BOOLEAN
762 1.2 christos AslIsExceptionDisabled (
763 1.2 christos UINT8 Level,
764 1.3 christos UINT16 MessageId)
765 1.2 christos {
766 1.2 christos UINT32 EncodedMessageId;
767 1.2 christos UINT32 i;
768 1.2 christos
769 1.2 christos
770 1.2 christos switch (Level)
771 1.2 christos {
772 1.2 christos case ASL_WARNING2:
773 1.2 christos case ASL_WARNING3:
774 1.2 christos
775 1.2 christos /* Check for global disable via -w1/-w2/-w3 options */
776 1.2 christos
777 1.2 christos if (Level > Gbl_WarningLevel)
778 1.2 christos {
779 1.2 christos return (TRUE);
780 1.2 christos }
781 1.2 christos /* Fall through */
782 1.2 christos
783 1.2 christos case ASL_WARNING:
784 1.2 christos case ASL_REMARK:
785 1.2 christos /*
786 1.2 christos * Ignore this warning/remark if it has been disabled by
787 1.2 christos * the user (-vw option)
788 1.2 christos */
789 1.3 christos EncodedMessageId = AeBuildFullExceptionCode (Level, MessageId);
790 1.2 christos for (i = 0; i < Gbl_DisabledMessagesIndex; i++)
791 1.2 christos {
792 1.2 christos /* Simple implementation via fixed array */
793 1.2 christos
794 1.2 christos if (EncodedMessageId == Gbl_DisabledMessages[i])
795 1.2 christos {
796 1.2 christos return (TRUE);
797 1.2 christos }
798 1.2 christos }
799 1.2 christos break;
800 1.2 christos
801 1.2 christos default:
802 1.2 christos break;
803 1.2 christos }
804 1.2 christos
805 1.2 christos return (FALSE);
806 1.2 christos }
807 1.2 christos
808 1.2 christos
809 1.2 christos /*******************************************************************************
810 1.2 christos *
811 1.1 jruoho * FUNCTION: AslError
812 1.1 jruoho *
813 1.1 jruoho * PARAMETERS: Level - Seriousness (Warning/error, etc.)
814 1.1 jruoho * MessageId - Index into global message buffer
815 1.1 jruoho * Op - Parse node where error happened
816 1.1 jruoho * ExtraMessage - additional error message
817 1.1 jruoho *
818 1.1 jruoho * RETURN: None
819 1.1 jruoho *
820 1.1 jruoho * DESCRIPTION: Main error reporting routine for the ASL compiler (all code
821 1.1 jruoho * except the parser.)
822 1.1 jruoho *
823 1.1 jruoho ******************************************************************************/
824 1.1 jruoho
825 1.1 jruoho void
826 1.1 jruoho AslError (
827 1.1 jruoho UINT8 Level,
828 1.3 christos UINT16 MessageId,
829 1.1 jruoho ACPI_PARSE_OBJECT *Op,
830 1.1 jruoho char *ExtraMessage)
831 1.1 jruoho {
832 1.1 jruoho
833 1.2 christos /* Check if user wants to ignore this exception */
834 1.2 christos
835 1.3 christos if (Gbl_AllExceptionsDisabled ||
836 1.3 christos AslIsExceptionDisabled (Level, MessageId))
837 1.1 jruoho {
838 1.2 christos return;
839 1.1 jruoho }
840 1.1 jruoho
841 1.1 jruoho if (Op)
842 1.1 jruoho {
843 1.1 jruoho AslCommonError (Level, MessageId, Op->Asl.LineNumber,
844 1.2 christos Op->Asl.LogicalLineNumber,
845 1.2 christos Op->Asl.LogicalByteOffset,
846 1.2 christos Op->Asl.Column,
847 1.2 christos Op->Asl.Filename, ExtraMessage);
848 1.1 jruoho }
849 1.1 jruoho else
850 1.1 jruoho {
851 1.1 jruoho AslCommonError (Level, MessageId, 0,
852 1.2 christos 0, 0, 0, NULL, ExtraMessage);
853 1.1 jruoho }
854 1.1 jruoho }
855 1.1 jruoho
856 1.1 jruoho
857 1.1 jruoho /*******************************************************************************
858 1.1 jruoho *
859 1.1 jruoho * FUNCTION: AslCoreSubsystemError
860 1.1 jruoho *
861 1.1 jruoho * PARAMETERS: Op - Parse node where error happened
862 1.3 christos * Status - The ACPICA Exception
863 1.1 jruoho * ExtraMessage - additional error message
864 1.1 jruoho * Abort - TRUE -> Abort compilation
865 1.1 jruoho *
866 1.1 jruoho * RETURN: None
867 1.1 jruoho *
868 1.3 christos * DESCRIPTION: Error reporting routine for exceptions returned by the ACPICA
869 1.3 christos * core subsystem.
870 1.1 jruoho *
871 1.1 jruoho ******************************************************************************/
872 1.1 jruoho
873 1.1 jruoho void
874 1.1 jruoho AslCoreSubsystemError (
875 1.1 jruoho ACPI_PARSE_OBJECT *Op,
876 1.1 jruoho ACPI_STATUS Status,
877 1.1 jruoho char *ExtraMessage,
878 1.1 jruoho BOOLEAN Abort)
879 1.1 jruoho {
880 1.1 jruoho
881 1.2 christos snprintf (MsgBuffer, sizeof(MsgBuffer), "%s %s", AcpiFormatException (Status), ExtraMessage);
882 1.1 jruoho
883 1.1 jruoho if (Op)
884 1.1 jruoho {
885 1.6 christos AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION,
886 1.6 christos Op->Asl.LineNumber,
887 1.6 christos Op->Asl.LogicalLineNumber,
888 1.6 christos Op->Asl.LogicalByteOffset,
889 1.6 christos Op->Asl.Column,
890 1.6 christos Op->Asl.Filename, MsgBuffer);
891 1.1 jruoho }
892 1.1 jruoho else
893 1.1 jruoho {
894 1.6 christos AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION,
895 1.6 christos 0, 0, 0, 0, NULL, MsgBuffer);
896 1.1 jruoho }
897 1.1 jruoho
898 1.1 jruoho if (Abort)
899 1.1 jruoho {
900 1.1 jruoho AslAbort ();
901 1.1 jruoho }
902 1.1 jruoho }
903 1.1 jruoho
904 1.1 jruoho
905 1.1 jruoho /*******************************************************************************
906 1.1 jruoho *
907 1.1 jruoho * FUNCTION: AslCompilererror
908 1.1 jruoho *
909 1.1 jruoho * PARAMETERS: CompilerMessage - Error message from the parser
910 1.1 jruoho *
911 1.1 jruoho * RETURN: Status (0 for now)
912 1.1 jruoho *
913 1.1 jruoho * DESCRIPTION: Report an error situation discovered in a production
914 1.1 jruoho * NOTE: don't change the name of this function, it is called
915 1.1 jruoho * from the auto-generated parser.
916 1.1 jruoho *
917 1.1 jruoho ******************************************************************************/
918 1.1 jruoho
919 1.1 jruoho int
920 1.1 jruoho AslCompilererror (
921 1.2 christos const char *CompilerMessage)
922 1.1 jruoho {
923 1.1 jruoho
924 1.4 christos Gbl_SyntaxError++;
925 1.4 christos
926 1.1 jruoho AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, Gbl_CurrentLineNumber,
927 1.2 christos Gbl_LogicalLineNumber, Gbl_CurrentLineOffset,
928 1.2 christos Gbl_CurrentColumn, Gbl_Files[ASL_FILE_INPUT].Filename,
929 1.2 christos ACPI_CAST_PTR (char, CompilerMessage));
930 1.1 jruoho
931 1.2 christos return (0);
932 1.1 jruoho }
933