1 /******************************************************************************
3 * Module Name: aslerror - Error handling and statistics
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
12 * All rights reserved.
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
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
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;
37 * The above copyright and patent license is granted only if the following
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.
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
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
72 * 3.4. Intel retains all right, title, and interest in and to the Original
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.
80 * 4. Disclaimer and Export Compliance
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
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
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.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
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.
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.
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.
150 *****************************************************************************/
152 #include <contrib/dev/acpica/compiler/aslcompiler.h>
154 #define _COMPONENT ACPI_COMPILER
155 ACPI_MODULE_NAME ("aslerror")
157 /* Local prototypes */
161 ASL_ERROR_MSG *Enode);
164 /*******************************************************************************
172 * DESCRIPTION: Dump the error log and abort the compiler. Used for serious
175 ******************************************************************************/
182 AePrintErrorLog (ASL_FILE_STDERR);
185 /* Print error summary to stdout also */
187 AePrintErrorLog (ASL_FILE_STDOUT);
194 /*******************************************************************************
196 * FUNCTION: AeClearErrorLog
202 * DESCRIPTION: Empty the error list
204 ******************************************************************************/
210 ASL_ERROR_MSG *Enode = Gbl_ErrorLog;
213 /* Walk the error node list */
226 /*******************************************************************************
228 * FUNCTION: AeAddToErrorLog
230 * PARAMETERS: Enode - An error node to add to the log
234 * DESCRIPTION: Add a new error node to the error log. The error log is
235 * ordered by the "logical" line number (cumulative line number
236 * including all include files.)
238 ******************************************************************************/
242 ASL_ERROR_MSG *Enode)
248 /* If Gbl_ErrorLog is null, this is the first error node */
252 Gbl_ErrorLog = Enode;
257 * Walk error list until we find a line number greater than ours.
258 * List is sorted according to line number.
264 (Next->LogicalLineNumber <= Enode->LogicalLineNumber))
270 /* Found our place in the list */
280 Gbl_ErrorLog = Enode;
285 /*******************************************************************************
287 * FUNCTION: AePrintException
289 * PARAMETERS: FileId - ID of output file
290 * Enode - Error node to print
291 * Header - Additional text before each message
295 * DESCRIPTION: Print the contents of an error node.
297 * NOTE: We don't use the FlxxxFile I/O functions here because on error
298 * they abort the compiler and call this function! Since we
299 * are reporting errors here, we ignore most output errors and
300 * just try to get out as much as we can.
302 ******************************************************************************/
307 ASL_ERROR_MSG *Enode,
314 const char *MainMessage;
319 FILE *SourceFile = NULL;
321 BOOLEAN PrematureEOF = FALSE;
331 * Only listing files have a header, and remarks/optimizations
336 /* Ignore remarks if requested */
338 switch (Enode->Level)
344 if (!Gbl_DisplayWarnings)
352 if (!Gbl_DisplayRemarks)
358 case ASL_OPTIMIZATION:
360 if (!Gbl_DisplayOptimizations)
372 /* Get the various required file handles */
374 OutputFile = Gbl_Files[FileId].Handle;
376 if (!Enode->SourceLine)
379 * Use the merged header/source file if present, otherwise
382 SourceFile = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
385 SourceFile = Gbl_Files[ASL_FILE_INPUT].Handle;
390 /* Determine if the error occurred at source file EOF */
392 fseek (SourceFile, 0, SEEK_END);
393 FileSize = ftell (SourceFile);
395 if ((long) Enode->LogicalByteOffset >= FileSize)
404 fprintf (OutputFile, "%s", Header);
407 /* Print filename and line number if present and valid */
411 if (Gbl_VerboseErrors)
413 fprintf (OutputFile, "%-8s", Enode->Filename);
415 if (Enode->LineNumber)
417 if (Enode->SourceLine)
419 fprintf (OutputFile, " %6u: %s",
420 Enode->LineNumber, Enode->SourceLine);
424 fprintf (OutputFile, " %6u: ", Enode->LineNumber);
427 * If not at EOF, get the corresponding source code line
428 * and display it. Don't attempt this if we have a
429 * premature EOF condition.
434 * Seek to the offset in the combined source file,
435 * read the source line, and write it to the output.
437 Actual = fseek (SourceFile,
438 (long) Enode->LogicalByteOffset, (int) SEEK_SET);
442 "[*** iASL: Seek error on source code temp file %s ***]",
443 Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
447 RActual = fread (&SourceByte, 1, 1, SourceFile);
451 "[*** iASL: Read error on source code temp file %s ***]",
452 Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
456 /* Read/write the source line, up to the maximum line length */
458 while (RActual && SourceByte && (SourceByte != '\n'))
462 /* After the max line length, we will just read the line, no write */
464 if (fwrite (&SourceByte, 1, 1, OutputFile) != 1)
466 printf ("[*** iASL: Write error on output file ***]\n");
470 else if (Total == 256)
473 "\n[*** iASL: Very long input line, message below refers to column %u ***]",
477 RActual = fread (&SourceByte, 1, 1, SourceFile);
481 "[*** iASL: Read error on source code temp file %s ***]",
482 Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
491 fprintf (OutputFile, "\n");
498 * Less verbose version of the error message, enabled via the
499 * -vi switch. The format is compatible with MS Visual Studio.
501 fprintf (OutputFile, "%s", Enode->Filename);
503 if (Enode->LineNumber)
505 fprintf (OutputFile, "(%u) : ",
511 /* If a NULL message ID, just print the raw message */
513 if (Enode->MessageId == 0)
515 fprintf (OutputFile, "%s\n", Enode->Message);
519 /* Decode the message ID */
521 fprintf (OutputFile, "%s %4.4d -",
522 AeDecodeExceptionLevel (Enode->Level),
523 AeBuildFullExceptionCode (Enode->Level, Enode->MessageId));
525 MainMessage = AeDecodeMessageId (Enode->MessageId);
526 ExtraMessage = Enode->Message;
528 /* If a NULL line number, just print the decoded message */
530 if (!Enode->LineNumber)
532 fprintf (OutputFile, " %s %s\n\n", MainMessage, ExtraMessage);
536 MsgLength = strlen (MainMessage);
539 /* Use the secondary/extra message as main message */
541 MainMessage = Enode->Message;
547 MsgLength = strlen (MainMessage);
551 if (Gbl_VerboseErrors && !PrematureEOF)
555 fprintf (OutputFile, " %s",
560 SourceColumn = Enode->Column + Enode->FilenameLength + 6 + 2;
561 ErrorColumn = ASL_ERROR_LEVEL_LENGTH + 5 + 2 + 1;
563 if ((MsgLength + ErrorColumn) < (SourceColumn - 1))
565 fprintf (OutputFile, "%*s%s",
566 (int) ((SourceColumn - 1) - ErrorColumn),
571 fprintf (OutputFile, "%*s %s",
572 (int) ((SourceColumn - ErrorColumn) + 1), "^",
579 fprintf (OutputFile, " %s", MainMessage);
582 /* Print the extra info message if present */
586 fprintf (OutputFile, " (%s)", ExtraMessage);
591 fprintf (OutputFile, " and premature End-Of-File");
594 fprintf (OutputFile, "\n");
595 if (Gbl_VerboseErrors)
597 fprintf (OutputFile, "\n");
602 /*******************************************************************************
604 * FUNCTION: AePrintErrorLog
606 * PARAMETERS: FileId - Where to output the error log
610 * DESCRIPTION: Print the entire contents of the error log
612 ******************************************************************************/
618 ASL_ERROR_MSG *Enode = Gbl_ErrorLog;
621 /* Walk the error node list */
625 AePrintException (FileId, Enode, NULL);
631 /*******************************************************************************
633 * FUNCTION: AslCommonError2
635 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
636 * MessageId - Index into global message buffer
637 * LineNumber - Actual file line number
638 * Column - Column in current line
639 * SourceLine - Actual source code line
640 * Filename - source filename
641 * ExtraMessage - additional error message
645 * DESCRIPTION: Create a new error node and add it to the error log
647 ******************************************************************************/
659 char *MessageBuffer = NULL;
661 ASL_ERROR_MSG *Enode;
664 Enode = UtLocalCalloc (sizeof (ASL_ERROR_MSG));
668 /* Allocate a buffer for the message and a new error node */
670 MessageBuffer = UtStringCacheCalloc (strlen (ExtraMessage) + 1);
672 /* Keep a copy of the extra message */
674 strcpy (MessageBuffer, ExtraMessage);
677 LineBuffer = UtLocalCalloc (strlen (SourceLine) + 1);
678 strcpy (LineBuffer, SourceLine);
680 /* Initialize the error node */
684 Enode->Filename = Filename;
685 Enode->FilenameLength = strlen (Filename);
686 if (Enode->FilenameLength < 6)
688 Enode->FilenameLength = 6;
692 Enode->MessageId = MessageId;
693 Enode->Level = Level;
694 Enode->LineNumber = LineNumber;
695 Enode->LogicalLineNumber = LineNumber;
696 Enode->LogicalByteOffset = 0;
697 Enode->Column = Column;
698 Enode->Message = MessageBuffer;
699 Enode->SourceLine = LineBuffer;
701 /* Add the new node to the error node list */
703 AeAddToErrorLog (Enode);
707 /* stderr is a file, send error to it immediately */
709 AePrintException (ASL_FILE_STDERR, Enode, NULL);
712 Gbl_ExceptionCount[Level]++;
716 /*******************************************************************************
718 * FUNCTION: AslCommonError
720 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
721 * MessageId - Index into global message buffer
722 * CurrentLineNumber - Actual file line number
723 * LogicalLineNumber - Cumulative line number
724 * LogicalByteOffset - Byte offset in source file
725 * Column - Column in current line
726 * Filename - source filename
727 * ExtraMessage - additional error message
731 * DESCRIPTION: Create a new error node and add it to the error log
733 ******************************************************************************/
739 UINT32 CurrentLineNumber,
740 UINT32 LogicalLineNumber,
741 UINT32 LogicalByteOffset,
746 char *MessageBuffer = NULL;
747 ASL_ERROR_MSG *Enode;
750 Enode = UtLocalCalloc (sizeof (ASL_ERROR_MSG));
754 /* Allocate a buffer for the message and a new error node */
756 MessageBuffer = UtStringCacheCalloc (strlen (ExtraMessage) + 1);
758 /* Keep a copy of the extra message */
760 strcpy (MessageBuffer, ExtraMessage);
763 /* Initialize the error node */
767 Enode->Filename = Filename;
768 Enode->FilenameLength = strlen (Filename);
769 if (Enode->FilenameLength < 6)
771 Enode->FilenameLength = 6;
775 Enode->MessageId = MessageId;
776 Enode->Level = Level;
777 Enode->LineNumber = CurrentLineNumber;
778 Enode->LogicalLineNumber = LogicalLineNumber;
779 Enode->LogicalByteOffset = LogicalByteOffset;
780 Enode->Column = Column;
781 Enode->Message = MessageBuffer;
782 Enode->SourceLine = NULL;
784 /* Add the new node to the error node list */
786 AeAddToErrorLog (Enode);
790 /* stderr is a file, send error to it immediately */
792 AePrintException (ASL_FILE_STDERR, Enode, NULL);
795 Gbl_ExceptionCount[Level]++;
796 if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
798 printf ("\nMaximum error count (%u) exceeded\n", ASL_MAX_ERROR_COUNT);
801 Gbl_NextError = Gbl_ErrorLog;
810 /*******************************************************************************
812 * FUNCTION: AslDisableException
814 * PARAMETERS: MessageIdString - ID to be disabled
818 * DESCRIPTION: Enter a message ID into the global disabled messages table
820 ******************************************************************************/
823 AslDisableException (
824 char *MessageIdString)
829 /* Convert argument to an integer and validate it */
831 MessageId = (UINT32) strtoul (MessageIdString, NULL, 0);
833 if ((MessageId < 2000) || (MessageId > 5999))
835 printf ("\"%s\" is not a valid warning/remark ID\n",
837 return (AE_BAD_PARAMETER);
840 /* Insert value into the global disabled message array */
842 if (Gbl_DisabledMessagesIndex >= ASL_MAX_DISABLED_MESSAGES)
844 printf ("Too many messages have been disabled (max %u)\n",
845 ASL_MAX_DISABLED_MESSAGES);
849 Gbl_DisabledMessages[Gbl_DisabledMessagesIndex] = MessageId;
850 Gbl_DisabledMessagesIndex++;
855 /*******************************************************************************
857 * FUNCTION: AslIsExceptionDisabled
859 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
860 * MessageId - Index into global message buffer
862 * RETURN: TRUE if exception/message should be ignored
864 * DESCRIPTION: Check if the user has specified options such that this
865 * exception should be ignored
867 ******************************************************************************/
870 AslIsExceptionDisabled (
874 UINT32 EncodedMessageId;
883 /* Check for global disable via -w1/-w2/-w3 options */
885 if (Level > Gbl_WarningLevel)
894 * Ignore this warning/remark if it has been disabled by
895 * the user (-vw option)
897 EncodedMessageId = AeBuildFullExceptionCode (Level, MessageId);
898 for (i = 0; i < Gbl_DisabledMessagesIndex; i++)
900 /* Simple implementation via fixed array */
902 if (EncodedMessageId == Gbl_DisabledMessages[i])
917 /*******************************************************************************
921 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
922 * MessageId - Index into global message buffer
923 * Op - Parse node where error happened
924 * ExtraMessage - additional error message
928 * DESCRIPTION: Main error reporting routine for the ASL compiler (all code
929 * except the parser.)
931 ******************************************************************************/
937 ACPI_PARSE_OBJECT *Op,
941 /* Check if user wants to ignore this exception */
943 if (Gbl_AllExceptionsDisabled ||
944 AslIsExceptionDisabled (Level, MessageId))
951 AslCommonError (Level, MessageId, Op->Asl.LineNumber,
952 Op->Asl.LogicalLineNumber,
953 Op->Asl.LogicalByteOffset,
955 Op->Asl.Filename, ExtraMessage);
959 AslCommonError (Level, MessageId, 0,
960 0, 0, 0, NULL, ExtraMessage);
965 /*******************************************************************************
967 * FUNCTION: AslCoreSubsystemError
969 * PARAMETERS: Op - Parse node where error happened
970 * Status - The ACPICA Exception
971 * ExtraMessage - additional error message
972 * Abort - TRUE -> Abort compilation
976 * DESCRIPTION: Error reporting routine for exceptions returned by the ACPICA
979 ******************************************************************************/
982 AslCoreSubsystemError (
983 ACPI_PARSE_OBJECT *Op,
989 sprintf (MsgBuffer, "%s %s", AcpiFormatException (Status), ExtraMessage);
993 AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION,
995 Op->Asl.LogicalLineNumber,
996 Op->Asl.LogicalByteOffset,
998 Op->Asl.Filename, MsgBuffer);
1002 AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION,
1003 0, 0, 0, 0, NULL, MsgBuffer);
1013 /*******************************************************************************
1015 * FUNCTION: AslCompilererror
1017 * PARAMETERS: CompilerMessage - Error message from the parser
1019 * RETURN: Status (0 for now)
1021 * DESCRIPTION: Report an error situation discovered in a production
1022 * NOTE: don't change the name of this function, it is called
1023 * from the auto-generated parser.
1025 ******************************************************************************/
1029 const char *CompilerMessage)
1034 AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, Gbl_CurrentLineNumber,
1035 Gbl_LogicalLineNumber, Gbl_CurrentLineOffset,
1036 Gbl_CurrentColumn, Gbl_Files[ASL_FILE_INPUT].Filename,
1037 ACPI_CAST_PTR (char, CompilerMessage));