1 /******************************************************************************
2 *
3 * Module Name: aslerror - Error handling and statistics
4 *
5 *****************************************************************************/
6
7 /******************************************************************************
8 *
9 * 1. Copyright Notice
10 *
11 * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12 * All rights reserved.
13 *
14 * 2. License
15 *
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
20 *
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
27 *
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
36 *
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
39 *
40 * 3. Conditions
41 *
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
53 *
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
65 *
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
71 *
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
74 *
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
79 *
80 * 4. Disclaimer and Export Compliance
81 *
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
89 *
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
98 *
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
113 *
114 *****************************************************************************
115 *
116 * Alternatively, you may choose to be licensed under the terms of the
117 * following license:
118 *
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
121 * are met:
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
133 *
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145 *
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
149 *
150 *****************************************************************************/
151
152 #include "aslcompiler.h"
153
154 #define _COMPONENT ACPI_COMPILER
155 ACPI_MODULE_NAME ("aslerror")
156
157 /* Local prototypes */
158
159 static void
160 AeAddToErrorLog (
161 ASL_ERROR_MSG *Enode);
162
163 static BOOLEAN
164 AslIsExceptionExpected (
165 UINT8 Level,
166 UINT16 MessageId);
167
168 static BOOLEAN
169 AslIsExceptionDisabled (
170 UINT8 Level,
171 UINT16 MessageId);
172
173 static void AslInitEnode (
174 ASL_ERROR_MSG **Enode,
175 UINT8 Level,
176 UINT16 MessageId,
177 UINT32 LineNumber,
178 UINT32 LogicalLineNumber,
179 UINT32 LogicalByteOffset,
180 UINT32 Column,
181 char *Filename,
182 char *Message,
183 char *SourceLine,
184 ASL_ERROR_MSG *SubError);
185
186 static void
187 AslLogNewError (
188 UINT8 Level,
189 UINT16 MessageId,
190 UINT32 LineNumber,
191 UINT32 LogicalLineNumber,
192 UINT32 LogicalByteOffset,
193 UINT32 Column,
194 char *Filename,
195 char *Message,
196 char *SourceLine,
197 ASL_ERROR_MSG *SubError);
198
199 static void
200 AePrintSubError (
201 FILE *OutputFile,
202 ASL_ERROR_MSG *Enode);
203
204
205 /*******************************************************************************
206 *
207 * FUNCTION: AslAbort
208 *
209 * PARAMETERS: None
210 *
211 * RETURN: None
212 *
213 * DESCRIPTION: Dump the error log and abort the compiler. Used for serious
214 * I/O errors.
215 *
216 ******************************************************************************/
217
218 void
AslAbort(void)219 AslAbort (
220 void)
221 {
222
223 AePrintErrorLog (ASL_FILE_STDERR);
224 if (Gbl_DebugFlag)
225 {
226 /* Print error summary to stdout also */
227
228 AePrintErrorLog (ASL_FILE_STDOUT);
229 }
230
231 exit (1);
232 }
233
234
235 /*******************************************************************************
236 *
237 * FUNCTION: AeClearErrorLog
238 *
239 * PARAMETERS: None
240 *
241 * RETURN: None
242 *
243 * DESCRIPTION: Empty the error list
244 *
245 ******************************************************************************/
246
247 void
AeClearErrorLog(void)248 AeClearErrorLog (
249 void)
250 {
251 ASL_ERROR_MSG *Enode = Gbl_ErrorLog;
252 ASL_ERROR_MSG *Next;
253
254
255 /* Walk the error node list */
256
257 while (Enode)
258 {
259 Next = Enode->Next;
260 ACPI_FREE (Enode);
261 Enode = Next;
262 }
263
264 Gbl_ErrorLog = NULL;
265 }
266
267
268 /*******************************************************************************
269 *
270 * FUNCTION: AeAddToErrorLog
271 *
272 * PARAMETERS: Enode - An error node to add to the log
273 *
274 * RETURN: None
275 *
276 * DESCRIPTION: Add a new error node to the error log. The error log is
277 * ordered by the "logical" line number (cumulative line number
278 * including all include files.)
279 *
280 ******************************************************************************/
281
282 static void
AeAddToErrorLog(ASL_ERROR_MSG * Enode)283 AeAddToErrorLog (
284 ASL_ERROR_MSG *Enode)
285 {
286 ASL_ERROR_MSG *Next;
287 ASL_ERROR_MSG *Prev;
288
289
290 /* If Gbl_ErrorLog is null, this is the first error node */
291
292 if (!Gbl_ErrorLog)
293 {
294 Gbl_ErrorLog = Enode;
295 return;
296 }
297
298 /*
299 * Walk error list until we find a line number greater than ours.
300 * List is sorted according to line number.
301 */
302 Prev = NULL;
303 Next = Gbl_ErrorLog;
304
305 while ((Next) && (Next->LogicalLineNumber <= Enode->LogicalLineNumber))
306 {
307 Prev = Next;
308 Next = Next->Next;
309 }
310
311 /* Found our place in the list */
312
313 Enode->Next = Next;
314
315 if (Prev)
316 {
317 Prev->Next = Enode;
318 }
319 else
320 {
321 Gbl_ErrorLog = Enode;
322 }
323 }
324
325
326 /*******************************************************************************
327 *
328 * FUNCTION: AeDecodeErrorMessageId
329 *
330 * PARAMETERS: OutputFile - Output file
331 * Enode - Error node to print
332 * PrematureEOF - True = PrematureEOF has been reached
333 * Total - Total legth of line
334 *
335 * RETURN: None
336 *
337 * DESCRIPTION: Print the source line of an error.
338 *
339 ******************************************************************************/
340
341 static void
AeDecodeErrorMessageId(FILE * OutputFile,ASL_ERROR_MSG * Enode,BOOLEAN PrematureEOF,UINT32 Total)342 AeDecodeErrorMessageId (
343 FILE *OutputFile,
344 ASL_ERROR_MSG *Enode,
345 BOOLEAN PrematureEOF,
346 UINT32 Total)
347 {
348 UINT32 MsgLength;
349 const char *MainMessage;
350 char *ExtraMessage;
351 UINT32 SourceColumn;
352 UINT32 ErrorColumn;
353
354
355 fprintf (OutputFile, "%s %4.4d -",
356 AeDecodeExceptionLevel (Enode->Level),
357 AeBuildFullExceptionCode (Enode->Level, Enode->MessageId));
358
359 MainMessage = AeDecodeMessageId (Enode->MessageId);
360 ExtraMessage = Enode->Message;
361
362 /* If a NULL line number, just print the decoded message */
363
364 if (!Enode->LineNumber)
365 {
366 fprintf (OutputFile, " %s %s\n\n", MainMessage, ExtraMessage);
367 return;
368 }
369
370 MsgLength = strlen (MainMessage);
371 if (MsgLength == 0)
372 {
373 /* Use the secondary/extra message as main message */
374
375 MainMessage = Enode->Message;
376 if (!MainMessage)
377 {
378 MainMessage = "";
379 }
380
381 MsgLength = strlen (MainMessage);
382 ExtraMessage = NULL;
383 }
384
385 if (Gbl_VerboseErrors && !PrematureEOF)
386 {
387 if (Total >= 256)
388 {
389 fprintf (OutputFile, " %s",
390 MainMessage);
391 }
392 else
393 {
394 SourceColumn = Enode->Column + Enode->FilenameLength + 6 + 2;
395 ErrorColumn = ASL_ERROR_LEVEL_LENGTH + 5 + 2 + 1;
396
397 if ((MsgLength + ErrorColumn) < (SourceColumn - 1))
398 {
399 fprintf (OutputFile, "%*s%s",
400 (int) ((SourceColumn - 1) - ErrorColumn),
401 MainMessage, " ^ ");
402 }
403 else
404 {
405 fprintf (OutputFile, "%*s %s",
406 (int) ((SourceColumn - ErrorColumn) + 1), "^",
407 MainMessage);
408 }
409 }
410 }
411 else
412 {
413 fprintf (OutputFile, " %s", MainMessage);
414 }
415
416 /* Print the extra info message if present */
417
418 if (ExtraMessage)
419 {
420 fprintf (OutputFile, " (%s)", ExtraMessage);
421 }
422
423 if (PrematureEOF)
424 {
425 fprintf (OutputFile, " and premature End-Of-File");
426 }
427
428 fprintf (OutputFile, "\n");
429 if (Gbl_VerboseErrors && !Enode->SubError)
430 {
431 fprintf (OutputFile, "\n");
432 }
433 }
434
435
436 /*******************************************************************************
437 *
438 * FUNCTION: AePrintErrorSourceLine
439 *
440 * PARAMETERS: OutputFile - Output file
441 * Enode - Error node to print
442 * PrematureEOF - True = PrematureEOF has been reached
443 * Total - amount of characters printed so far
444 *
445 *
446 * RETURN: Status
447 *
448 * DESCRIPTION: Print the source line of an error.
449 *
450 ******************************************************************************/
451
452 static ACPI_STATUS
AePrintErrorSourceLine(FILE * OutputFile,ASL_ERROR_MSG * Enode,BOOLEAN * PrematureEOF,UINT32 * Total)453 AePrintErrorSourceLine (
454 FILE *OutputFile,
455 ASL_ERROR_MSG *Enode,
456 BOOLEAN *PrematureEOF,
457 UINT32 *Total)
458 {
459 UINT8 SourceByte;
460 int Actual;
461 size_t RActual;
462 FILE *SourceFile = NULL;
463 long FileSize;
464
465
466 if (!Enode->SourceLine)
467 {
468 /*
469 * Use the merged header/source file if present, otherwise
470 * use input file
471 */
472 SourceFile = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
473 if (!SourceFile)
474 {
475 SourceFile = Gbl_Files[ASL_FILE_INPUT].Handle;
476 }
477
478 if (SourceFile)
479 {
480 /* Determine if the error occurred at source file EOF */
481
482 fseek (SourceFile, 0, SEEK_END);
483 FileSize = ftell (SourceFile);
484
485 if ((long) Enode->LogicalByteOffset >= FileSize)
486 {
487 *PrematureEOF = TRUE;
488 }
489 }
490 else
491 {
492 fprintf (OutputFile,
493 "[*** iASL: Source File Does not exist ***]\n");
494 return AE_IO_ERROR;
495 }
496 }
497
498 /* Print filename and line number if present and valid */
499
500 if (Gbl_VerboseErrors)
501 {
502 fprintf (OutputFile, "%-8s", Enode->Filename);
503
504 if (Enode->SourceLine && Enode->LineNumber)
505 {
506 fprintf (OutputFile, " %6u: %s",
507 Enode->LineNumber, Enode->SourceLine);
508 }
509 else if (Enode->LineNumber)
510 {
511 fprintf (OutputFile, " %6u: ", Enode->LineNumber);
512
513 /*
514 * If not at EOF, get the corresponding source code line
515 * and display it. Don't attempt this if we have a
516 * premature EOF condition.
517 */
518 if (*PrematureEOF)
519 {
520 fprintf (OutputFile, "\n");
521 return AE_OK;
522 }
523 /*
524 * Seek to the offset in the combined source file,
525 * read the source line, and write it to the output.
526 */
527 Actual = fseek (SourceFile,
528 (long) Enode->LogicalByteOffset, (int) SEEK_SET);
529 if (Actual)
530 {
531 fprintf (OutputFile,
532 "[*** iASL: Seek error on source code temp file %s ***]",
533 Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
534
535 fprintf (OutputFile, "\n");
536 return AE_OK;
537 }
538 RActual = fread (&SourceByte, 1, 1, SourceFile);
539 if (RActual != 1)
540 {
541 fprintf (OutputFile,
542 "[*** iASL: Read error on source code temp file %s ***]",
543 Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
544 return AE_IO_ERROR;
545 }
546 /* Read/write the source line, up to the maximum line length */
547
548 while (RActual && SourceByte && (SourceByte != '\n'))
549 {
550 if (*Total < 256)
551 {
552 /* After the max line length, we will just read the line, no write */
553
554 if (fwrite (&SourceByte, 1, 1, OutputFile) != 1)
555 {
556 printf ("[*** iASL: Write error on output file ***]\n");
557 return AE_IO_ERROR;
558 }
559 }
560 else if (*Total == 256)
561 {
562 fprintf (OutputFile,
563 "\n[*** iASL: Very long input line, message below refers to column %u ***]",
564 Enode->Column);
565 }
566
567 RActual = fread (&SourceByte, 1, 1, SourceFile);
568 if (RActual != 1)
569 {
570 fprintf (OutputFile,
571 "[*** iASL: Read error on source code temp file %s ***]",
572 Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
573
574 return AE_IO_ERROR;
575 }
576 *Total += 1;
577 }
578
579 fprintf (OutputFile, "\n");
580 }
581 }
582 else
583 {
584 /*
585 * Less verbose version of the error message, enabled via the
586 * -vi switch. The format is compatible with MS Visual Studio.
587 */
588 fprintf (OutputFile, "%s", Enode->Filename);
589
590 if (Enode->LineNumber)
591 {
592 fprintf (OutputFile, "(%u) : ",
593 Enode->LineNumber);
594 }
595 }
596
597 return AE_OK;
598 }
599
600 /*******************************************************************************
601 *
602 * FUNCTION: AePrintException
603 *
604 * PARAMETERS: FileId - ID of output file
605 * Enode - Error node to print
606 * Header - Additional text before each message
607 *
608 * RETURN: None
609 *
610 * DESCRIPTION: Print the contents of an error node.
611 *
612 * NOTE: We don't use the FlxxxFile I/O functions here because on error
613 * they abort the compiler and call this function! Since we
614 * are reporting errors here, we ignore most output errors and
615 * just try to get out as much as we can.
616 *
617 ******************************************************************************/
618
619 void
AePrintException(UINT32 FileId,ASL_ERROR_MSG * Enode,char * Header)620 AePrintException (
621 UINT32 FileId,
622 ASL_ERROR_MSG *Enode,
623 char *Header)
624 {
625 FILE *OutputFile;
626 BOOLEAN PrematureEOF = FALSE;
627 UINT32 Total = 0;
628 ACPI_STATUS Status;
629 ASL_ERROR_MSG *Child = Enode->SubError;
630
631
632 if (Gbl_NoErrors)
633 {
634 return;
635 }
636
637 /*
638 * Only listing files have a header, and remarks/optimizations
639 * are always output
640 */
641 if (!Header)
642 {
643 /* Ignore remarks if requested */
644
645 switch (Enode->Level)
646 {
647 case ASL_WARNING:
648 case ASL_WARNING2:
649 case ASL_WARNING3:
650
651 if (!Gbl_DisplayWarnings)
652 {
653 return;
654 }
655 break;
656
657 case ASL_REMARK:
658
659 if (!Gbl_DisplayRemarks)
660 {
661 return;
662 }
663 break;
664
665 case ASL_OPTIMIZATION:
666
667 if (!Gbl_DisplayOptimizations)
668 {
669 return;
670 }
671 break;
672
673 default:
674
675 break;
676 }
677 }
678
679 /* Get the various required file handles */
680
681 OutputFile = Gbl_Files[FileId].Handle;
682
683 if (Header)
684 {
685 fprintf (OutputFile, "%s", Header);
686 }
687
688 if (!Enode->Filename)
689 {
690 AeDecodeErrorMessageId (OutputFile, Enode, PrematureEOF, Total);
691 return;
692 }
693
694 Status = AePrintErrorSourceLine (OutputFile, Enode, &PrematureEOF, &Total);
695 if (ACPI_FAILURE (Status))
696 {
697 return;
698 }
699
700 /* If a NULL message ID, just print the raw message */
701
702 if (Enode->MessageId == 0)
703 {
704 fprintf (OutputFile, "%s\n", Enode->Message);
705 return;
706 }
707
708 AeDecodeErrorMessageId (OutputFile, Enode, PrematureEOF, Total);
709
710 while (Child)
711 {
712 fprintf (OutputFile, "\n");
713 AePrintSubError (OutputFile, Child);
714 Child = Child->SubError;
715 }
716 }
717
718
719 /*******************************************************************************
720 *
721 * FUNCTION: AePrintSubError
722 *
723 * PARAMETERS: OutputFile - Output file
724 * Enode - Error node to print
725 *
726 * RETURN: None
727 *
728 * DESCRIPTION: Print the contents of an error nodes. This function is tailored
729 * to print error nodes that are SubErrors within ASL_ERROR_MSG
730 *
731 ******************************************************************************/
732
733 static void
AePrintSubError(FILE * OutputFile,ASL_ERROR_MSG * Enode)734 AePrintSubError (
735 FILE *OutputFile,
736 ASL_ERROR_MSG *Enode)
737 {
738 UINT32 Total = 0;
739 BOOLEAN PrematureEOF = FALSE;
740 const char *MainMessage;
741
742
743 MainMessage = AeDecodeMessageId (Enode->MessageId);
744
745 fprintf (OutputFile, " %s%s", MainMessage, "\n ");
746 (void) AePrintErrorSourceLine (OutputFile, Enode, &PrematureEOF, &Total);
747 fprintf (OutputFile, "\n");
748 }
749
750
751 /*******************************************************************************
752 *
753 * FUNCTION: AePrintErrorLog
754 *
755 * PARAMETERS: FileId - Where to output the error log
756 *
757 * RETURN: None
758 *
759 * DESCRIPTION: Print the entire contents of the error log
760 *
761 ******************************************************************************/
762
763 void
AePrintErrorLog(UINT32 FileId)764 AePrintErrorLog (
765 UINT32 FileId)
766 {
767 ASL_ERROR_MSG *Enode = Gbl_ErrorLog;
768
769
770 /* Walk the error node list */
771
772 while (Enode)
773 {
774 AePrintException (FileId, Enode, NULL);
775 Enode = Enode->Next;
776 }
777 }
778
779
780 /*******************************************************************************
781 *
782 * FUNCTION: AslInitEnode
783 *
784 * PARAMETERS: InputEnode - Input Error node to initialize
785 * Level - Seriousness (Warning/error, etc.)
786 * MessageId - Index into global message buffer
787 * CurrentLineNumber - Actual file line number
788 * LogicalLineNumber - Cumulative line number
789 * LogicalByteOffset - Byte offset in source file
790 * Column - Column in current line
791 * Filename - source filename
792 * ExtraMessage - additional error message
793 * SourceLine - Line of error source code
794 * SubError - SubError of this InputEnode
795 *
796 * RETURN: None
797 *
798 * DESCRIPTION: Initialize an Error node
799 *
800 ******************************************************************************/
801
AslInitEnode(ASL_ERROR_MSG ** InputEnode,UINT8 Level,UINT16 MessageId,UINT32 LineNumber,UINT32 LogicalLineNumber,UINT32 LogicalByteOffset,UINT32 Column,char * Filename,char * ExtraMessage,char * SourceLine,ASL_ERROR_MSG * SubError)802 static void AslInitEnode (
803 ASL_ERROR_MSG **InputEnode,
804 UINT8 Level,
805 UINT16 MessageId,
806 UINT32 LineNumber,
807 UINT32 LogicalLineNumber,
808 UINT32 LogicalByteOffset,
809 UINT32 Column,
810 char *Filename,
811 char *ExtraMessage,
812 char *SourceLine,
813 ASL_ERROR_MSG *SubError)
814 {
815 ASL_ERROR_MSG *Enode;
816
817
818 *InputEnode = UtLocalCalloc (sizeof (ASL_ERROR_MSG));
819 Enode = *InputEnode;
820 Enode->Level = Level;
821 Enode->MessageId = MessageId;
822 Enode->LineNumber = LineNumber;
823 Enode->LogicalLineNumber = LogicalLineNumber;
824 Enode->LogicalByteOffset = LogicalByteOffset;
825 Enode->Column = Column;
826 Enode->SubError = SubError;
827 Enode->Message = NULL;
828 Enode->SourceLine = NULL;
829 Enode->Filename = NULL;
830
831 if (ExtraMessage)
832 {
833 /* Allocate a buffer for the message and a new error node */
834
835 Enode->Message = UtLocalCacheCalloc (strlen (ExtraMessage) + 1);
836
837 /* Keep a copy of the extra message */
838
839 strcpy (Enode->Message, ExtraMessage);
840 }
841
842 if (SourceLine)
843 {
844 Enode->SourceLine = UtLocalCalloc (strlen (SourceLine) + 1);
845 strcpy (Enode->SourceLine, SourceLine);
846 }
847
848
849 if (Filename)
850 {
851 Enode->Filename = Filename;
852 Enode->FilenameLength = strlen (Filename);
853 if (Enode->FilenameLength < 6)
854 {
855 Enode->FilenameLength = 6;
856 }
857 }
858 }
859
860
861 /*******************************************************************************
862 *
863 * FUNCTION: AslCommonError2
864 *
865 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
866 * MessageId - Index into global message buffer
867 * LineNumber - Actual file line number
868 * Column - Column in current line
869 * SourceLine - Actual source code line
870 * Filename - source filename
871 * ExtraMessage - additional error message
872 *
873 * RETURN: None
874 *
875 * DESCRIPTION: Create a new error node and add it to the error log
876 *
877 ******************************************************************************/
878
879 void
AslCommonError2(UINT8 Level,UINT16 MessageId,UINT32 LineNumber,UINT32 Column,char * SourceLine,char * Filename,char * ExtraMessage)880 AslCommonError2 (
881 UINT8 Level,
882 UINT16 MessageId,
883 UINT32 LineNumber,
884 UINT32 Column,
885 char *SourceLine,
886 char *Filename,
887 char *ExtraMessage)
888 {
889 AslLogNewError (Level, MessageId, LineNumber, LineNumber, 0, Column,
890 Filename, ExtraMessage, SourceLine, NULL);
891 }
892
893
894 /*******************************************************************************
895 *
896 * FUNCTION: AslCommonError
897 *
898 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
899 * MessageId - Index into global message buffer
900 * CurrentLineNumber - Actual file line number
901 * LogicalLineNumber - Cumulative line number
902 * LogicalByteOffset - Byte offset in source file
903 * Column - Column in current line
904 * Filename - source filename
905 * ExtraMessage - additional error message
906 *
907 * RETURN: None
908 *
909 * DESCRIPTION: Create a new error node and add it to the error log
910 *
911 ******************************************************************************/
912
913 void
AslCommonError(UINT8 Level,UINT16 MessageId,UINT32 CurrentLineNumber,UINT32 LogicalLineNumber,UINT32 LogicalByteOffset,UINT32 Column,char * Filename,char * ExtraMessage)914 AslCommonError (
915 UINT8 Level,
916 UINT16 MessageId,
917 UINT32 CurrentLineNumber,
918 UINT32 LogicalLineNumber,
919 UINT32 LogicalByteOffset,
920 UINT32 Column,
921 char *Filename,
922 char *ExtraMessage)
923 {
924 /* Check if user wants to ignore this exception */
925
926 if (AslIsExceptionIgnored (Level, MessageId))
927 {
928 return;
929 }
930
931 AslLogNewError (Level, MessageId, CurrentLineNumber, LogicalLineNumber,
932 LogicalByteOffset, Column, Filename, ExtraMessage,
933 NULL, NULL);
934 }
935
936
937 /*******************************************************************************
938 *
939 * FUNCTION: AslLogNewError
940 *
941 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
942 * MessageId - Index into global message buffer
943 * CurrentLineNumber - Actual file line number
944 * LogicalLineNumber - Cumulative line number
945 * LogicalByteOffset - Byte offset in source file
946 * Column - Column in current line
947 * Filename - source filename
948 * Message - additional error message
949 * SourceLine - Actual line of source code
950 * SubError - Sub-error associated with this error
951 *
952 * RETURN: None
953 *
954 * DESCRIPTION: Create a new error node and add it to the error log
955 *
956 ******************************************************************************/
957 static void
AslLogNewError(UINT8 Level,UINT16 MessageId,UINT32 LineNumber,UINT32 LogicalLineNumber,UINT32 LogicalByteOffset,UINT32 Column,char * Filename,char * Message,char * SourceLine,ASL_ERROR_MSG * SubError)958 AslLogNewError (
959 UINT8 Level,
960 UINT16 MessageId,
961 UINT32 LineNumber,
962 UINT32 LogicalLineNumber,
963 UINT32 LogicalByteOffset,
964 UINT32 Column,
965 char *Filename,
966 char *Message,
967 char *SourceLine,
968 ASL_ERROR_MSG *SubError)
969 {
970 ASL_ERROR_MSG *Enode = NULL;
971
972
973 AslInitEnode (&Enode, Level, MessageId, LineNumber, LogicalLineNumber,
974 LogicalByteOffset, Column, Filename, Message, SourceLine,
975 SubError);
976
977 /* Add the new node to the error node list */
978
979 AeAddToErrorLog (Enode);
980
981 if (Gbl_DebugFlag)
982 {
983 /* stderr is a file, send error to it immediately */
984
985 AePrintException (ASL_FILE_STDERR, Enode, NULL);
986 }
987
988 Gbl_ExceptionCount[Level]++;
989 if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
990 {
991 printf ("\nMaximum error count (%u) exceeded\n", ASL_MAX_ERROR_COUNT);
992
993 Gbl_SourceLine = 0;
994 Gbl_NextError = Gbl_ErrorLog;
995 CmCleanupAndExit ();
996 exit(1);
997 }
998
999 return;
1000 }
1001
1002 /*******************************************************************************
1003 *
1004 * FUNCTION: AslIsExceptionIgnored
1005 *
1006 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
1007 * MessageId - Index into global message buffer
1008 *
1009 * RETURN: BOOLEAN
1010 *
1011 * DESCRIPTION: Check if a particular exception is ignored. In this case it
1012 * means that the exception is (expected or disabled.
1013 *
1014 ******************************************************************************/
1015
1016 BOOLEAN
AslIsExceptionIgnored(UINT8 Level,UINT16 MessageId)1017 AslIsExceptionIgnored (
1018 UINT8 Level,
1019 UINT16 MessageId)
1020 {
1021 BOOLEAN ExceptionIgnored;
1022
1023
1024 /* Note: this allows exception to be disabled and expected */
1025
1026 ExceptionIgnored = AslIsExceptionDisabled (Level, MessageId);
1027 ExceptionIgnored |= AslIsExceptionExpected (Level, MessageId);
1028
1029 return (Gbl_AllExceptionsDisabled || ExceptionIgnored);
1030 }
1031
1032
1033 /*******************************************************************************
1034 *
1035 * FUNCTION: AslCheckExpectException
1036 *
1037 * PARAMETERS: none
1038 *
1039 * RETURN: none
1040 *
1041 * DESCRIPTION: Check the global expected messages table and raise an error
1042 * for each message that has not been received.
1043 *
1044 ******************************************************************************/
1045
1046 void
AslCheckExpectedExceptions(void)1047 AslCheckExpectedExceptions (
1048 void)
1049 {
1050 UINT8 i;
1051
1052
1053 for (i = 0; i < Gbl_ExpectedMessagesIndex; ++i)
1054 {
1055 if (!Gbl_ExpectedMessages[i].MessageReceived)
1056 {
1057 AslError (ASL_ERROR, ASL_MSG_EXCEPTION_NOT_RECEIVED, NULL,
1058 Gbl_ExpectedMessages[i].MessageIdStr);
1059 }
1060 }
1061 }
1062
1063
1064 /*******************************************************************************
1065 *
1066 * FUNCTION: AslExpectException
1067 *
1068 * PARAMETERS: MessageIdString - ID of excepted exception during compile
1069 *
1070 * RETURN: Status
1071 *
1072 * DESCRIPTION: Enter a message ID into the global expected messages table
1073 * If these messages are not raised during the compilation, throw
1074 * an error.
1075 *
1076 ******************************************************************************/
1077
1078 ACPI_STATUS
AslExpectException(char * MessageIdString)1079 AslExpectException (
1080 char *MessageIdString)
1081 {
1082 UINT32 MessageId;
1083
1084
1085 /* Convert argument to an integer and validate it */
1086
1087 MessageId = (UINT32) strtoul (MessageIdString, NULL, 0);
1088
1089 if (MessageId > 6999)
1090 {
1091 printf ("\"%s\" is not a valid warning/remark/erro ID\n",
1092 MessageIdString);
1093 return (AE_BAD_PARAMETER);
1094 }
1095
1096 /* Insert value into the global expected message array */
1097
1098 if (Gbl_ExpectedMessagesIndex >= ASL_MAX_EXPECTED_MESSAGES)
1099 {
1100 printf ("Too many messages have been registered as expected (max %u)\n",
1101 ASL_MAX_DISABLED_MESSAGES);
1102 return (AE_LIMIT);
1103 }
1104
1105 Gbl_ExpectedMessages[Gbl_ExpectedMessagesIndex].MessageId = MessageId;
1106 Gbl_ExpectedMessages[Gbl_ExpectedMessagesIndex].MessageIdStr = MessageIdString;
1107 Gbl_ExpectedMessages[Gbl_ExpectedMessagesIndex].MessageReceived = FALSE;
1108 Gbl_ExpectedMessagesIndex++;
1109 return (AE_OK);
1110 }
1111
1112
1113 /*******************************************************************************
1114 *
1115 * FUNCTION: AslDisableException
1116 *
1117 * PARAMETERS: MessageIdString - ID to be disabled
1118 *
1119 * RETURN: Status
1120 *
1121 * DESCRIPTION: Enter a message ID into the global disabled messages table
1122 *
1123 ******************************************************************************/
1124
1125 ACPI_STATUS
AslDisableException(char * MessageIdString)1126 AslDisableException (
1127 char *MessageIdString)
1128 {
1129 UINT32 MessageId;
1130
1131
1132 /* Convert argument to an integer and validate it */
1133
1134 MessageId = (UINT32) strtoul (MessageIdString, NULL, 0);
1135
1136 if ((MessageId < 2000) || (MessageId > 6999))
1137 {
1138 printf ("\"%s\" is not a valid warning/remark/error ID\n",
1139 MessageIdString);
1140 return (AE_BAD_PARAMETER);
1141 }
1142
1143 /* Insert value into the global disabled message array */
1144
1145 if (Gbl_DisabledMessagesIndex >= ASL_MAX_DISABLED_MESSAGES)
1146 {
1147 printf ("Too many messages have been disabled (max %u)\n",
1148 ASL_MAX_DISABLED_MESSAGES);
1149 return (AE_LIMIT);
1150 }
1151
1152 Gbl_DisabledMessages[Gbl_DisabledMessagesIndex] = MessageId;
1153 Gbl_DisabledMessagesIndex++;
1154 return (AE_OK);
1155 }
1156
1157
1158 /*******************************************************************************
1159 *
1160 * FUNCTION: AslIsExceptionDisabled
1161 *
1162 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
1163 * MessageId - Index into global message buffer
1164 *
1165 * RETURN: TRUE if exception/message should be ignored
1166 *
1167 * DESCRIPTION: Check if the user has specified options such that this
1168 * exception should be ignored
1169 *
1170 ******************************************************************************/
1171
1172 static BOOLEAN
AslIsExceptionExpected(UINT8 Level,UINT16 MessageId)1173 AslIsExceptionExpected (
1174 UINT8 Level,
1175 UINT16 MessageId)
1176 {
1177 UINT32 EncodedMessageId;
1178 UINT32 i;
1179
1180
1181 /* Mark this exception as received */
1182
1183 EncodedMessageId = AeBuildFullExceptionCode (Level, MessageId);
1184 for (i = 0; i < Gbl_ExpectedMessagesIndex; i++)
1185 {
1186 /* Simple implementation via fixed array */
1187
1188 if (EncodedMessageId == Gbl_ExpectedMessages[i].MessageId)
1189 {
1190 return (Gbl_ExpectedMessages[i].MessageReceived = TRUE);
1191 }
1192 }
1193
1194 return (FALSE);
1195 }
1196
1197
1198 /*******************************************************************************
1199 *
1200 * FUNCTION: AslIsExceptionDisabled
1201 *
1202 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
1203 * MessageId - Index into global message buffer
1204 *
1205 * RETURN: TRUE if exception/message should be ignored
1206 *
1207 * DESCRIPTION: Check if the user has specified options such that this
1208 * exception should be ignored
1209 *
1210 ******************************************************************************/
1211
1212 static BOOLEAN
AslIsExceptionDisabled(UINT8 Level,UINT16 MessageId)1213 AslIsExceptionDisabled (
1214 UINT8 Level,
1215 UINT16 MessageId)
1216 {
1217 UINT32 EncodedMessageId;
1218 UINT32 i;
1219
1220
1221 switch (Level)
1222 {
1223 case ASL_WARNING2:
1224 case ASL_WARNING3:
1225
1226 /* Check for global disable via -w1/-w2/-w3 options */
1227
1228 if (Level > Gbl_WarningLevel)
1229 {
1230 return (TRUE);
1231 }
1232 /* Fall through */
1233
1234 case ASL_WARNING:
1235 case ASL_REMARK:
1236 case ASL_ERROR:
1237 /*
1238 * Ignore this error/warning/remark if it has been disabled by
1239 * the user (-vw option)
1240 */
1241 EncodedMessageId = AeBuildFullExceptionCode (Level, MessageId);
1242 for (i = 0; i < Gbl_DisabledMessagesIndex; i++)
1243 {
1244 /* Simple implementation via fixed array */
1245
1246 if (EncodedMessageId == Gbl_DisabledMessages[i])
1247 {
1248 return (TRUE);
1249 }
1250 }
1251 break;
1252
1253 default:
1254 break;
1255 }
1256
1257 return (FALSE);
1258 }
1259
1260
1261 /*******************************************************************************
1262 *
1263 * FUNCTION: AslDualParseOpError
1264 *
1265 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
1266 * MainMsgId - Index into global message buffer
1267 * MainOp - Parse node where error happened
1268 * MainMsg - Message pertaining to the MainOp
1269 * SubMsgId - Index into global message buffer
1270 * SubOp - Additional parse node for better message
1271 * SubMsg - Message pertainint to SubOp
1272 *
1273 *
1274 * RETURN: None
1275 *
1276 * DESCRIPTION: Main error reporting routine for the ASL compiler for error
1277 * messages that point to multiple parse objects.
1278 *
1279 ******************************************************************************/
1280
1281 void
AslDualParseOpError(UINT8 Level,UINT16 MainMsgId,ACPI_PARSE_OBJECT * MainOp,char * MainMsg,UINT16 SubMsgId,ACPI_PARSE_OBJECT * SubOp,char * SubMsg)1282 AslDualParseOpError (
1283 UINT8 Level,
1284 UINT16 MainMsgId,
1285 ACPI_PARSE_OBJECT *MainOp,
1286 char *MainMsg,
1287 UINT16 SubMsgId,
1288 ACPI_PARSE_OBJECT *SubOp,
1289 char *SubMsg)
1290 {
1291 ASL_ERROR_MSG *SubEnode = NULL;
1292
1293
1294 /* Check if user wants to ignore this exception */
1295
1296 if (AslIsExceptionIgnored (Level, MainMsgId) || !MainOp)
1297 {
1298 return;
1299 }
1300
1301 if (SubOp)
1302 {
1303 AslInitEnode (&SubEnode, Level, SubMsgId, SubOp->Asl.LineNumber,
1304 SubOp->Asl.LogicalLineNumber, SubOp->Asl.LogicalByteOffset,
1305 SubOp->Asl.Column, SubOp->Asl.Filename, SubMsg,
1306 NULL, NULL);
1307 }
1308
1309 AslLogNewError (Level, MainMsgId, MainOp->Asl.LineNumber,
1310 MainOp->Asl.LogicalLineNumber, MainOp->Asl.LogicalByteOffset,
1311 MainOp->Asl.Column, MainOp->Asl.Filename, MainMsg,
1312 NULL, SubEnode);
1313 }
1314
1315
1316 /*******************************************************************************
1317 *
1318 * FUNCTION: AslError
1319 *
1320 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
1321 * MessageId - Index into global message buffer
1322 * Op - Parse node where error happened
1323 * ExtraMessage - additional error message
1324 *
1325 * RETURN: None
1326 *
1327 * DESCRIPTION: Main error reporting routine for the ASL compiler (all code
1328 * except the parser.)
1329 *
1330 ******************************************************************************/
1331
1332 void
AslError(UINT8 Level,UINT16 MessageId,ACPI_PARSE_OBJECT * Op,char * ExtraMessage)1333 AslError (
1334 UINT8 Level,
1335 UINT16 MessageId,
1336 ACPI_PARSE_OBJECT *Op,
1337 char *ExtraMessage)
1338 {
1339 if (Op)
1340 {
1341 AslCommonError (Level, MessageId, Op->Asl.LineNumber,
1342 Op->Asl.LogicalLineNumber,
1343 Op->Asl.LogicalByteOffset,
1344 Op->Asl.Column,
1345 Op->Asl.Filename, ExtraMessage);
1346 }
1347 else
1348 {
1349 AslCommonError (Level, MessageId, 0,
1350 0, 0, 0, NULL, ExtraMessage);
1351 }
1352 }
1353
1354
1355 /*******************************************************************************
1356 *
1357 * FUNCTION: AslCoreSubsystemError
1358 *
1359 * PARAMETERS: Op - Parse node where error happened
1360 * Status - The ACPICA Exception
1361 * ExtraMessage - additional error message
1362 * Abort - TRUE -> Abort compilation
1363 *
1364 * RETURN: None
1365 *
1366 * DESCRIPTION: Error reporting routine for exceptions returned by the ACPICA
1367 * core subsystem.
1368 *
1369 ******************************************************************************/
1370
1371 void
AslCoreSubsystemError(ACPI_PARSE_OBJECT * Op,ACPI_STATUS Status,char * ExtraMessage,BOOLEAN Abort)1372 AslCoreSubsystemError (
1373 ACPI_PARSE_OBJECT *Op,
1374 ACPI_STATUS Status,
1375 char *ExtraMessage,
1376 BOOLEAN Abort)
1377 {
1378
1379 sprintf (MsgBuffer, "%s %s", AcpiFormatException (Status), ExtraMessage);
1380
1381 if (Op)
1382 {
1383 AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION,
1384 Op->Asl.LineNumber,
1385 Op->Asl.LogicalLineNumber,
1386 Op->Asl.LogicalByteOffset,
1387 Op->Asl.Column,
1388 Op->Asl.Filename, MsgBuffer);
1389 }
1390 else
1391 {
1392 AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION,
1393 0, 0, 0, 0, NULL, MsgBuffer);
1394 }
1395
1396 if (Abort)
1397 {
1398 AslAbort ();
1399 }
1400 }
1401
1402
1403 /*******************************************************************************
1404 *
1405 * FUNCTION: AslCompilererror
1406 *
1407 * PARAMETERS: CompilerMessage - Error message from the parser
1408 *
1409 * RETURN: Status (0 for now)
1410 *
1411 * DESCRIPTION: Report an error situation discovered in a production
1412 * NOTE: don't change the name of this function, it is called
1413 * from the auto-generated parser.
1414 *
1415 ******************************************************************************/
1416
1417 int
AslCompilererror(const char * CompilerMessage)1418 AslCompilererror (
1419 const char *CompilerMessage)
1420 {
1421
1422 Gbl_SyntaxError++;
1423
1424 AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, Gbl_CurrentLineNumber,
1425 Gbl_LogicalLineNumber, Gbl_CurrentLineOffset,
1426 Gbl_CurrentColumn, Gbl_Files[ASL_FILE_INPUT].Filename,
1427 ACPI_CAST_PTR (char, CompilerMessage));
1428
1429 return (0);
1430 }
1431