2 /******************************************************************************
4 * Module Name: aslerror - Error handling and statistics
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2012, Intel Corp.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
45 #define ASL_EXCEPTIONS
46 #include "aslcompiler.h"
48 #define _COMPONENT ACPI_COMPILER
49 ACPI_MODULE_NAME ("aslerror")
51 /* Local prototypes */
55 ASL_ERROR_MSG *Enode);
58 /*******************************************************************************
60 * FUNCTION: AeClearErrorLog
66 * DESCRIPTION: Empty the error list
68 ******************************************************************************/
74 ASL_ERROR_MSG *Enode = Gbl_ErrorLog;
77 /* Walk the error node list */
90 /*******************************************************************************
92 * FUNCTION: AeAddToErrorLog
94 * PARAMETERS: Enode - An error node to add to the log
98 * DESCRIPTION: Add a new error node to the error log. The error log is
99 * ordered by the "logical" line number (cumulative line number
100 * including all include files.)
102 ******************************************************************************/
106 ASL_ERROR_MSG *Enode)
112 /* If Gbl_ErrorLog is null, this is the first error node */
116 Gbl_ErrorLog = Enode;
121 * Walk error list until we find a line number greater than ours.
122 * List is sorted according to line number.
128 (Next->LogicalLineNumber <= Enode->LogicalLineNumber))
134 /* Found our place in the list */
144 Gbl_ErrorLog = Enode;
149 /*******************************************************************************
151 * FUNCTION: AePrintException
153 * PARAMETERS: FileId - ID of output file
154 * Enode - Error node to print
155 * Header - Additional text before each message
159 * DESCRIPTION: Print the contents of an error node.
161 * NOTE: We don't use the FlxxxFile I/O functions here because on error
162 * they abort the compiler and call this function! Since we
163 * are reporting errors here, we ignore most output errors and
164 * just try to get out as much as we can.
166 ******************************************************************************/
171 ASL_ERROR_MSG *Enode,
183 FILE *SourceFile = NULL;
185 BOOLEAN PrematureEOF = FALSE;
194 * Only listing files have a header, and remarks/optimizations
199 /* Ignore remarks if requested */
201 switch (Enode->Level)
204 if (!Gbl_DisplayRemarks)
210 case ASL_OPTIMIZATION:
211 if (!Gbl_DisplayOptimizations)
222 /* Get the file handles */
224 OutputFile = Gbl_Files[FileId].Handle;
227 if (!Enode->SourceLine)
229 /* Use the merged header/source file if present, otherwise use input file */
231 SourceFile = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
234 SourceFile = Gbl_Files[ASL_FILE_INPUT].Handle;
239 /* Determine if the error occurred at source file EOF */
241 fseek (SourceFile, 0, SEEK_END);
242 FileSize = ftell (SourceFile);
244 if ((long) Enode->LogicalByteOffset >= FileSize)
253 fprintf (OutputFile, "%s", Header);
256 /* Print filename and line number if present and valid */
260 if (Gbl_VerboseErrors)
262 fprintf (OutputFile, "%-8s", Enode->Filename);
264 if (Enode->LineNumber)
266 if (Enode->SourceLine)
268 fprintf (OutputFile, " %6u: %s",
269 Enode->LineNumber, Enode->SourceLine);
273 fprintf (OutputFile, " %6u: ", Enode->LineNumber);
276 * If not at EOF, get the corresponding source code line and
277 * display it. Don't attempt this if we have a premature EOF
283 * Seek to the offset in the combined source file, read
284 * the source line, and write it to the output.
286 Actual = fseek (SourceFile, (long) Enode->LogicalByteOffset,
291 "[*** iASL: Seek error on source code temp file %s ***]",
292 Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
296 RActual = fread (&SourceByte, 1, 1, SourceFile);
300 "[*** iASL: Read error on source code temp file %s ***]",
301 Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
304 else while (RActual && SourceByte && (SourceByte != '\n'))
306 fwrite (&SourceByte, 1, 1, OutputFile);
307 RActual = fread (&SourceByte, 1, 1, SourceFile);
312 fprintf (OutputFile, "\n");
319 * Less verbose version of the error message, enabled via the
320 * -vi switch. The format is compatible with MS Visual Studio.
322 fprintf (OutputFile, "%s", Enode->Filename);
324 if (Enode->LineNumber)
326 fprintf (OutputFile, "(%u) : ",
332 /* NULL message ID, just print the raw message */
334 if (Enode->MessageId == 0)
336 fprintf (OutputFile, "%s\n", Enode->Message);
340 /* Decode the message ID */
342 if (Gbl_VerboseErrors)
344 fprintf (OutputFile, "%s %4.4d - ",
345 AslErrorLevel[Enode->Level],
346 Enode->MessageId + ((Enode->Level+1) * 1000));
350 fprintf (OutputFile, "%s %4.4d:",
351 AslErrorLevelIde[Enode->Level],
352 Enode->MessageId + ((Enode->Level+1) * 1000));
355 MainMessage = AslMessages[Enode->MessageId];
356 ExtraMessage = Enode->Message;
358 if (Enode->LineNumber)
360 /* Main message: try to use string from AslMessages first */
367 MsgLength = strlen (MainMessage);
370 /* Use the secondary/extra message as main message */
372 MainMessage = Enode->Message;
378 MsgLength = strlen (MainMessage);
382 if (Gbl_VerboseErrors && !PrematureEOF)
384 SourceColumn = Enode->Column + Enode->FilenameLength + 6 + 2;
385 ErrorColumn = ASL_ERROR_LEVEL_LENGTH + 5 + 2 + 1;
387 if ((MsgLength + ErrorColumn) < (SourceColumn - 1))
389 fprintf (OutputFile, "%*s%s",
390 (int) ((SourceColumn - 1) - ErrorColumn),
395 fprintf (OutputFile, "%*s %s",
396 (int) ((SourceColumn - ErrorColumn) + 1), "^",
402 fprintf (OutputFile, " %s", MainMessage);
405 /* Print the extra info message if present */
409 fprintf (OutputFile, " (%s)", ExtraMessage);
414 fprintf (OutputFile, " and premature End-Of-File");
417 fprintf (OutputFile, "\n");
418 if (Gbl_VerboseErrors)
420 fprintf (OutputFile, "\n");
425 fprintf (OutputFile, " %s %s\n\n", MainMessage, ExtraMessage);
431 /*******************************************************************************
433 * FUNCTION: AePrintErrorLog
435 * PARAMETERS: FileId - Where to output the error log
439 * DESCRIPTION: Print the entire contents of the error log
441 ******************************************************************************/
447 ASL_ERROR_MSG *Enode = Gbl_ErrorLog;
450 /* Walk the error node list */
454 AePrintException (FileId, Enode, NULL);
460 /*******************************************************************************
462 * FUNCTION: AslCommonError2
464 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
465 * MessageId - Index into global message buffer
466 * LineNumber - Actual file line number
467 * Column - Column in current line
468 * SourceLine - Actual source code line
469 * Filename - source filename
470 * ExtraMessage - additional error message
474 * DESCRIPTION: Create a new error node and add it to the error log
476 ******************************************************************************/
488 char *MessageBuffer = NULL;
490 ASL_ERROR_MSG *Enode;
493 Enode = UtLocalCalloc (sizeof (ASL_ERROR_MSG));
497 /* Allocate a buffer for the message and a new error node */
499 MessageBuffer = UtLocalCalloc (strlen (ExtraMessage) + 1);
501 /* Keep a copy of the extra message */
503 ACPI_STRCPY (MessageBuffer, ExtraMessage);
506 LineBuffer = UtLocalCalloc (strlen (SourceLine) + 1);
507 ACPI_STRCPY (LineBuffer, SourceLine);
509 /* Initialize the error node */
513 Enode->Filename = Filename;
514 Enode->FilenameLength = strlen (Filename);
515 if (Enode->FilenameLength < 6)
517 Enode->FilenameLength = 6;
521 Enode->MessageId = MessageId;
522 Enode->Level = Level;
523 Enode->LineNumber = LineNumber;
524 Enode->LogicalLineNumber = LineNumber;
525 Enode->LogicalByteOffset = 0;
526 Enode->Column = Column;
527 Enode->Message = MessageBuffer;
528 Enode->SourceLine = LineBuffer;
530 /* Add the new node to the error node list */
532 AeAddToErrorLog (Enode);
536 /* stderr is a file, send error to it immediately */
538 AePrintException (ASL_FILE_STDERR, Enode, NULL);
541 Gbl_ExceptionCount[Level]++;
545 /*******************************************************************************
547 * FUNCTION: AslCommonError
549 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
550 * MessageId - Index into global message buffer
551 * CurrentLineNumber - Actual file line number
552 * LogicalLineNumber - Cumulative line number
553 * LogicalByteOffset - Byte offset in source file
554 * Column - Column in current line
555 * Filename - source filename
556 * ExtraMessage - additional error message
560 * DESCRIPTION: Create a new error node and add it to the error log
562 ******************************************************************************/
568 UINT32 CurrentLineNumber,
569 UINT32 LogicalLineNumber,
570 UINT32 LogicalByteOffset,
576 char *MessageBuffer = NULL;
577 ASL_ERROR_MSG *Enode;
580 Enode = UtLocalCalloc (sizeof (ASL_ERROR_MSG));
584 /* Allocate a buffer for the message and a new error node */
586 MessageSize = strlen (ExtraMessage) + 1;
587 MessageBuffer = UtLocalCalloc (MessageSize);
589 /* Keep a copy of the extra message */
591 ACPI_STRCPY (MessageBuffer, ExtraMessage);
594 /* Initialize the error node */
598 Enode->Filename = Filename;
599 Enode->FilenameLength = strlen (Filename);
600 if (Enode->FilenameLength < 6)
602 Enode->FilenameLength = 6;
606 Enode->MessageId = MessageId;
607 Enode->Level = Level;
608 Enode->LineNumber = CurrentLineNumber;
609 Enode->LogicalLineNumber = LogicalLineNumber;
610 Enode->LogicalByteOffset = LogicalByteOffset;
611 Enode->Column = Column;
612 Enode->Message = MessageBuffer;
613 Enode->SourceLine = NULL;
615 /* Add the new node to the error node list */
617 AeAddToErrorLog (Enode);
621 /* stderr is a file, send error to it immediately */
623 AePrintException (ASL_FILE_STDERR, Enode, NULL);
626 Gbl_ExceptionCount[Level]++;
627 if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
629 printf ("\nMaximum error count (%u) exceeded\n", ASL_MAX_ERROR_COUNT);
632 Gbl_NextError = Gbl_ErrorLog;
642 /*******************************************************************************
646 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
647 * MessageId - Index into global message buffer
648 * Op - Parse node where error happened
649 * ExtraMessage - additional error message
653 * DESCRIPTION: Main error reporting routine for the ASL compiler (all code
654 * except the parser.)
656 ******************************************************************************/
662 ACPI_PARSE_OBJECT *Op,
670 if (Gbl_WarningLevel < Level)
682 AslCommonError (Level, MessageId, Op->Asl.LineNumber,
683 Op->Asl.LogicalLineNumber,
684 Op->Asl.LogicalByteOffset,
686 Op->Asl.Filename, ExtraMessage);
690 AslCommonError (Level, MessageId, 0,
691 0, 0, 0, NULL, ExtraMessage);
696 /*******************************************************************************
698 * FUNCTION: AslCoreSubsystemError
700 * PARAMETERS: Op - Parse node where error happened
701 * Status - The ACPI CA Exception
702 * ExtraMessage - additional error message
703 * Abort - TRUE -> Abort compilation
707 * DESCRIPTION: Error reporting routine for exceptions returned by the ACPI
710 ******************************************************************************/
713 AslCoreSubsystemError (
714 ACPI_PARSE_OBJECT *Op,
720 sprintf (MsgBuffer, "%s %s", AcpiFormatException (Status), ExtraMessage);
724 AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, Op->Asl.LineNumber,
725 Op->Asl.LogicalLineNumber,
726 Op->Asl.LogicalByteOffset,
728 Op->Asl.Filename, MsgBuffer);
732 AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, 0,
733 0, 0, 0, NULL, MsgBuffer);
743 /*******************************************************************************
745 * FUNCTION: AslCompilererror
747 * PARAMETERS: CompilerMessage - Error message from the parser
749 * RETURN: Status (0 for now)
751 * DESCRIPTION: Report an error situation discovered in a production
752 * NOTE: don't change the name of this function, it is called
753 * from the auto-generated parser.
755 ******************************************************************************/
759 const char *CompilerMessage)
762 AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, Gbl_CurrentLineNumber,
763 Gbl_LogicalLineNumber, Gbl_CurrentLineOffset,
764 Gbl_CurrentColumn, Gbl_Files[ASL_FILE_INPUT].Filename,
765 ACPI_CAST_PTR (char, CompilerMessage));