1 /******************************************************************************
3 * Module Name: aslerror - Error handling and statistics
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include "aslcompiler.h"
46 #define _COMPONENT ACPI_COMPILER
47 ACPI_MODULE_NAME ("aslerror")
49 /* Local prototypes */
53 ASL_ERROR_MSG *Enode);
56 /*******************************************************************************
64 * DESCRIPTION: Dump the error log and abort the compiler. Used for serious
67 ******************************************************************************/
74 AePrintErrorLog (ASL_FILE_STDERR);
77 /* Print error summary to stdout also */
79 AePrintErrorLog (ASL_FILE_STDOUT);
86 /*******************************************************************************
88 * FUNCTION: AeClearErrorLog
94 * DESCRIPTION: Empty the error list
96 ******************************************************************************/
102 ASL_ERROR_MSG *Enode = Gbl_ErrorLog;
105 /* Walk the error node list */
118 /*******************************************************************************
120 * FUNCTION: AeAddToErrorLog
122 * PARAMETERS: Enode - An error node to add to the log
126 * DESCRIPTION: Add a new error node to the error log. The error log is
127 * ordered by the "logical" line number (cumulative line number
128 * including all include files.)
130 ******************************************************************************/
134 ASL_ERROR_MSG *Enode)
140 /* If Gbl_ErrorLog is null, this is the first error node */
144 Gbl_ErrorLog = Enode;
149 * Walk error list until we find a line number greater than ours.
150 * List is sorted according to line number.
156 (Next->LogicalLineNumber <= Enode->LogicalLineNumber))
162 /* Found our place in the list */
172 Gbl_ErrorLog = Enode;
177 /*******************************************************************************
179 * FUNCTION: AePrintException
181 * PARAMETERS: FileId - ID of output file
182 * Enode - Error node to print
183 * Header - Additional text before each message
187 * DESCRIPTION: Print the contents of an error node.
189 * NOTE: We don't use the FlxxxFile I/O functions here because on error
190 * they abort the compiler and call this function! Since we
191 * are reporting errors here, we ignore most output errors and
192 * just try to get out as much as we can.
194 ******************************************************************************/
199 ASL_ERROR_MSG *Enode,
206 const char *MainMessage;
211 FILE *SourceFile = NULL;
213 BOOLEAN PrematureEOF = FALSE;
223 * Only listing files have a header, and remarks/optimizations
228 /* Ignore remarks if requested */
230 switch (Enode->Level)
236 if (!Gbl_DisplayWarnings)
244 if (!Gbl_DisplayRemarks)
250 case ASL_OPTIMIZATION:
252 if (!Gbl_DisplayOptimizations)
264 /* Get the various required file handles */
266 OutputFile = Gbl_Files[FileId].Handle;
268 if (!Enode->SourceLine)
271 * Use the merged header/source file if present, otherwise
274 SourceFile = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
277 SourceFile = Gbl_Files[ASL_FILE_INPUT].Handle;
282 /* Determine if the error occurred at source file EOF */
284 fseek (SourceFile, 0, SEEK_END);
285 FileSize = ftell (SourceFile);
287 if ((long) Enode->LogicalByteOffset >= FileSize)
296 fprintf (OutputFile, "%s", Header);
299 /* Print filename and line number if present and valid */
303 if (Gbl_VerboseErrors)
305 fprintf (OutputFile, "%-8s", Enode->Filename);
307 if (Enode->LineNumber)
309 if (Enode->SourceLine)
311 fprintf (OutputFile, " %6u: %s",
312 Enode->LineNumber, Enode->SourceLine);
316 fprintf (OutputFile, " %6u: ", Enode->LineNumber);
319 * If not at EOF, get the corresponding source code line
320 * and display it. Don't attempt this if we have a
321 * premature EOF condition.
326 * Seek to the offset in the combined source file,
327 * read the source line, and write it to the output.
329 Actual = fseek (SourceFile,
330 (long) Enode->LogicalByteOffset, (int) SEEK_SET);
334 "[*** iASL: Seek error on source code temp file %s ***]",
335 Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
339 RActual = fread (&SourceByte, 1, 1, SourceFile);
343 "[*** iASL: Read error on source code temp file %s ***]",
344 Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
348 /* Read/write the source line, up to the maximum line length */
350 while (RActual && SourceByte && (SourceByte != '\n'))
354 /* After the max line length, we will just read the line, no write */
356 if (fwrite (&SourceByte, 1, 1, OutputFile) != 1)
358 printf ("[*** iASL: Write error on output file ***]\n");
362 else if (Total == 256)
365 "\n[*** iASL: Very long input line, message below refers to column %u ***]",
369 RActual = fread (&SourceByte, 1, 1, SourceFile);
373 "[*** iASL: Read error on source code temp file %s ***]",
374 Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
383 fprintf (OutputFile, "\n");
390 * Less verbose version of the error message, enabled via the
391 * -vi switch. The format is compatible with MS Visual Studio.
393 fprintf (OutputFile, "%s", Enode->Filename);
395 if (Enode->LineNumber)
397 fprintf (OutputFile, "(%u) : ",
403 /* If a NULL message ID, just print the raw message */
405 if (Enode->MessageId == 0)
407 fprintf (OutputFile, "%s\n", Enode->Message);
411 /* Decode the message ID */
413 fprintf (OutputFile, "%s %4.4d -",
414 AeDecodeExceptionLevel (Enode->Level),
415 AeBuildFullExceptionCode (Enode->Level, Enode->MessageId));
417 MainMessage = AeDecodeMessageId (Enode->MessageId);
418 ExtraMessage = Enode->Message;
420 /* If a NULL line number, just print the decoded message */
422 if (!Enode->LineNumber)
424 fprintf (OutputFile, " %s %s\n\n", MainMessage, ExtraMessage);
428 MsgLength = strlen (MainMessage);
431 /* Use the secondary/extra message as main message */
433 MainMessage = Enode->Message;
439 MsgLength = strlen (MainMessage);
443 if (Gbl_VerboseErrors && !PrematureEOF)
447 fprintf (OutputFile, " %s",
452 SourceColumn = Enode->Column + Enode->FilenameLength + 6 + 2;
453 ErrorColumn = ASL_ERROR_LEVEL_LENGTH + 5 + 2 + 1;
455 if ((MsgLength + ErrorColumn) < (SourceColumn - 1))
457 fprintf (OutputFile, "%*s%s",
458 (int) ((SourceColumn - 1) - ErrorColumn),
463 fprintf (OutputFile, "%*s %s",
464 (int) ((SourceColumn - ErrorColumn) + 1), "^",
471 fprintf (OutputFile, " %s", MainMessage);
474 /* Print the extra info message if present */
478 fprintf (OutputFile, " (%s)", ExtraMessage);
483 fprintf (OutputFile, " and premature End-Of-File");
486 fprintf (OutputFile, "\n");
487 if (Gbl_VerboseErrors)
489 fprintf (OutputFile, "\n");
494 /*******************************************************************************
496 * FUNCTION: AePrintErrorLog
498 * PARAMETERS: FileId - Where to output the error log
502 * DESCRIPTION: Print the entire contents of the error log
504 ******************************************************************************/
510 ASL_ERROR_MSG *Enode = Gbl_ErrorLog;
513 /* Walk the error node list */
517 AePrintException (FileId, Enode, NULL);
523 /*******************************************************************************
525 * FUNCTION: AslCommonError2
527 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
528 * MessageId - Index into global message buffer
529 * LineNumber - Actual file line number
530 * Column - Column in current line
531 * SourceLine - Actual source code line
532 * Filename - source filename
533 * ExtraMessage - additional error message
537 * DESCRIPTION: Create a new error node and add it to the error log
539 ******************************************************************************/
551 char *MessageBuffer = NULL;
553 ASL_ERROR_MSG *Enode;
556 Enode = UtLocalCalloc (sizeof (ASL_ERROR_MSG));
560 /* Allocate a buffer for the message and a new error node */
562 MessageBuffer = UtStringCacheCalloc (strlen (ExtraMessage) + 1);
564 /* Keep a copy of the extra message */
566 strcpy (MessageBuffer, ExtraMessage);
569 LineBuffer = UtLocalCalloc (strlen (SourceLine) + 1);
570 strcpy (LineBuffer, SourceLine);
572 /* Initialize the error node */
576 Enode->Filename = Filename;
577 Enode->FilenameLength = strlen (Filename);
578 if (Enode->FilenameLength < 6)
580 Enode->FilenameLength = 6;
584 Enode->MessageId = MessageId;
585 Enode->Level = Level;
586 Enode->LineNumber = LineNumber;
587 Enode->LogicalLineNumber = LineNumber;
588 Enode->LogicalByteOffset = 0;
589 Enode->Column = Column;
590 Enode->Message = MessageBuffer;
591 Enode->SourceLine = LineBuffer;
593 /* Add the new node to the error node list */
595 AeAddToErrorLog (Enode);
599 /* stderr is a file, send error to it immediately */
601 AePrintException (ASL_FILE_STDERR, Enode, NULL);
604 Gbl_ExceptionCount[Level]++;
608 /*******************************************************************************
610 * FUNCTION: AslCommonError
612 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
613 * MessageId - Index into global message buffer
614 * CurrentLineNumber - Actual file line number
615 * LogicalLineNumber - Cumulative line number
616 * LogicalByteOffset - Byte offset in source file
617 * Column - Column in current line
618 * Filename - source filename
619 * ExtraMessage - additional error message
623 * DESCRIPTION: Create a new error node and add it to the error log
625 ******************************************************************************/
631 UINT32 CurrentLineNumber,
632 UINT32 LogicalLineNumber,
633 UINT32 LogicalByteOffset,
638 char *MessageBuffer = NULL;
639 ASL_ERROR_MSG *Enode;
642 Enode = UtLocalCalloc (sizeof (ASL_ERROR_MSG));
646 /* Allocate a buffer for the message and a new error node */
648 MessageBuffer = UtStringCacheCalloc (strlen (ExtraMessage) + 1);
650 /* Keep a copy of the extra message */
652 strcpy (MessageBuffer, ExtraMessage);
655 /* Initialize the error node */
659 Enode->Filename = Filename;
660 Enode->FilenameLength = strlen (Filename);
661 if (Enode->FilenameLength < 6)
663 Enode->FilenameLength = 6;
667 Enode->MessageId = MessageId;
668 Enode->Level = Level;
669 Enode->LineNumber = CurrentLineNumber;
670 Enode->LogicalLineNumber = LogicalLineNumber;
671 Enode->LogicalByteOffset = LogicalByteOffset;
672 Enode->Column = Column;
673 Enode->Message = MessageBuffer;
674 Enode->SourceLine = NULL;
676 /* Add the new node to the error node list */
678 AeAddToErrorLog (Enode);
682 /* stderr is a file, send error to it immediately */
684 AePrintException (ASL_FILE_STDERR, Enode, NULL);
687 Gbl_ExceptionCount[Level]++;
688 if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
690 printf ("\nMaximum error count (%u) exceeded\n", ASL_MAX_ERROR_COUNT);
693 Gbl_NextError = Gbl_ErrorLog;
702 /*******************************************************************************
704 * FUNCTION: AslDisableException
706 * PARAMETERS: MessageIdString - ID to be disabled
710 * DESCRIPTION: Enter a message ID into the global disabled messages table
712 ******************************************************************************/
715 AslDisableException (
716 char *MessageIdString)
721 /* Convert argument to an integer and validate it */
723 MessageId = (UINT32) strtoul (MessageIdString, NULL, 0);
725 if ((MessageId < 2000) || (MessageId > 5999))
727 printf ("\"%s\" is not a valid warning/remark ID\n",
729 return (AE_BAD_PARAMETER);
732 /* Insert value into the global disabled message array */
734 if (Gbl_DisabledMessagesIndex >= ASL_MAX_DISABLED_MESSAGES)
736 printf ("Too many messages have been disabled (max %u)\n",
737 ASL_MAX_DISABLED_MESSAGES);
741 Gbl_DisabledMessages[Gbl_DisabledMessagesIndex] = MessageId;
742 Gbl_DisabledMessagesIndex++;
747 /*******************************************************************************
749 * FUNCTION: AslIsExceptionDisabled
751 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
752 * MessageId - Index into global message buffer
754 * RETURN: TRUE if exception/message should be ignored
756 * DESCRIPTION: Check if the user has specified options such that this
757 * exception should be ignored
759 ******************************************************************************/
762 AslIsExceptionDisabled (
766 UINT32 EncodedMessageId;
775 /* Check for global disable via -w1/-w2/-w3 options */
777 if (Level > Gbl_WarningLevel)
786 * Ignore this warning/remark if it has been disabled by
787 * the user (-vw option)
789 EncodedMessageId = AeBuildFullExceptionCode (Level, MessageId);
790 for (i = 0; i < Gbl_DisabledMessagesIndex; i++)
792 /* Simple implementation via fixed array */
794 if (EncodedMessageId == Gbl_DisabledMessages[i])
809 /*******************************************************************************
813 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
814 * MessageId - Index into global message buffer
815 * Op - Parse node where error happened
816 * ExtraMessage - additional error message
820 * DESCRIPTION: Main error reporting routine for the ASL compiler (all code
821 * except the parser.)
823 ******************************************************************************/
829 ACPI_PARSE_OBJECT *Op,
833 /* Check if user wants to ignore this exception */
835 if (Gbl_AllExceptionsDisabled ||
836 AslIsExceptionDisabled (Level, MessageId))
843 AslCommonError (Level, MessageId, Op->Asl.LineNumber,
844 Op->Asl.LogicalLineNumber,
845 Op->Asl.LogicalByteOffset,
847 Op->Asl.Filename, ExtraMessage);
851 AslCommonError (Level, MessageId, 0,
852 0, 0, 0, NULL, ExtraMessage);
857 /*******************************************************************************
859 * FUNCTION: AslCoreSubsystemError
861 * PARAMETERS: Op - Parse node where error happened
862 * Status - The ACPICA Exception
863 * ExtraMessage - additional error message
864 * Abort - TRUE -> Abort compilation
868 * DESCRIPTION: Error reporting routine for exceptions returned by the ACPICA
871 ******************************************************************************/
874 AslCoreSubsystemError (
875 ACPI_PARSE_OBJECT *Op,
881 sprintf (MsgBuffer, "%s %s", AcpiFormatException (Status), ExtraMessage);
885 AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION,
887 Op->Asl.LogicalLineNumber,
888 Op->Asl.LogicalByteOffset,
890 Op->Asl.Filename, MsgBuffer);
894 AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION,
895 0, 0, 0, 0, NULL, MsgBuffer);
905 /*******************************************************************************
907 * FUNCTION: AslCompilererror
909 * PARAMETERS: CompilerMessage - Error message from the parser
911 * RETURN: Status (0 for now)
913 * DESCRIPTION: Report an error situation discovered in a production
914 * NOTE: don't change the name of this function, it is called
915 * from the auto-generated parser.
917 ******************************************************************************/
921 const char *CompilerMessage)
926 AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, Gbl_CurrentLineNumber,
927 Gbl_LogicalLineNumber, Gbl_CurrentLineOffset,
928 Gbl_CurrentColumn, Gbl_Files[ASL_FILE_INPUT].Filename,
929 ACPI_CAST_PTR (char, CompilerMessage));