2 /******************************************************************************
4 * Module Name: aslerror - Error handling and statistics
7 *****************************************************************************/
9 /******************************************************************************
13 * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
14 * All rights reserved.
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights. You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code. No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
39 * The above copyright and patent license is granted only if the following
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision. In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change. Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee. Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution. In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
74 * 3.4. Intel retains all right, title, and interest in and to the Original
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
82 * 4. Disclaimer and Export Compliance
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government. In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
116 *****************************************************************************/
118 #define ASL_EXCEPTIONS
119 #include <contrib/dev/acpica/compiler/aslcompiler.h>
121 #define _COMPONENT ACPI_COMPILER
122 ACPI_MODULE_NAME ("aslerror")
124 /* Local prototypes */
128 ASL_ERROR_MSG *Enode);
131 /*******************************************************************************
133 * FUNCTION: AeAddToErrorLog
135 * PARAMETERS: Enode - An error node to add to the log
139 * DESCRIPTION: Add a new error node to the error log. The error log is
140 * ordered by the "logical" line number (cumulative line number
141 * including all include files.)
143 ******************************************************************************/
147 ASL_ERROR_MSG *Enode)
155 Gbl_ErrorLog = Enode;
159 /* List is sorted according to line number */
163 Gbl_ErrorLog = Enode;
167 /* Walk error list until we find a line number greater than ours */
173 (Next->LogicalLineNumber <= Enode->LogicalLineNumber))
179 /* Found our place in the list */
189 Gbl_ErrorLog = Enode;
194 /*******************************************************************************
196 * FUNCTION: AePrintException
198 * PARAMETERS: FileId - ID of output file
199 * Enode - Error node to print
200 * Header - Additional text before each message
204 * DESCRIPTION: Print the contents of an error node.
206 * NOTE: We don't use the FlxxxFile I/O functions here because on error
207 * they abort the compiler and call this function! Since we
208 * are reporting errors here, we ignore most output errors and
209 * just try to get out as much as we can.
211 ******************************************************************************/
216 ASL_ERROR_MSG *Enode,
232 * Only listing files have a header, and remarks/optimizations
237 /* Ignore remarks if requested */
239 switch (Enode->Level)
242 if (!Gbl_DisplayRemarks)
248 case ASL_OPTIMIZATION:
249 if (!Gbl_DisplayOptimizations)
260 /* Get the file handles */
262 OutputFile = Gbl_Files[FileId].Handle;
263 SourceFile = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
267 fprintf (OutputFile, "%s", Header);
270 /* Print filename and line number if present and valid */
274 if (Gbl_VerboseErrors)
276 fprintf (OutputFile, "%6s", Enode->Filename);
278 if (Enode->LineNumber)
280 fprintf (OutputFile, "%6u: ", Enode->LineNumber);
283 * Seek to the offset in the combined source file, read the source
284 * line, and write it to the output.
286 Actual = fseek (SourceFile, (long) Enode->LogicalByteOffset,
291 "[*** iASL: Seek error on source code temp file ***]");
295 RActual = fread (&SourceByte, 1, 1, SourceFile);
299 "[*** iASL: Read error on source code temp file ***]");
302 else while (RActual && SourceByte && (SourceByte != '\n'))
304 fwrite (&SourceByte, 1, 1, OutputFile);
305 RActual = fread (&SourceByte, 1, 1, SourceFile);
308 fprintf (OutputFile, "\n");
313 fprintf (OutputFile, "%s", Enode->Filename);
315 if (Enode->LineNumber)
317 fprintf (OutputFile, "(%u) : ", Enode->LineNumber);
322 /* NULL message ID, just print the raw message */
324 if (Enode->MessageId == 0)
326 fprintf (OutputFile, "%s\n", Enode->Message);
330 /* Decode the message ID */
332 fprintf (OutputFile, "%s %4.4d -",
333 AslErrorLevel[Enode->Level],
334 Enode->MessageId + ((Enode->Level+1) * 1000));
336 MainMessage = AslMessages[Enode->MessageId];
337 ExtraMessage = Enode->Message;
339 if (Enode->LineNumber)
341 MsgLength = strlen (MainMessage);
344 MainMessage = Enode->Message;
346 MsgLength = strlen (MainMessage);
350 if (Gbl_VerboseErrors)
352 SourceColumn = Enode->Column + Enode->FilenameLength + 6 + 2;
353 ErrorColumn = ASL_ERROR_LEVEL_LENGTH + 5 + 2 + 1;
355 if ((MsgLength + ErrorColumn) < (SourceColumn - 1))
357 fprintf (OutputFile, "%*s%s",
358 (int) ((SourceColumn - 1) - ErrorColumn),
363 fprintf (OutputFile, "%*s %s",
364 (int) ((SourceColumn - ErrorColumn) + 1), "^",
370 fprintf (OutputFile, " %s", MainMessage);
373 /* Print the extra info message if present */
377 fprintf (OutputFile, " (%s)", ExtraMessage);
380 fprintf (OutputFile, "\n");
381 if (Gbl_VerboseErrors)
383 fprintf (OutputFile, "\n");
388 fprintf (OutputFile, " %s %s\n\n", MainMessage, ExtraMessage);
394 /*******************************************************************************
396 * FUNCTION: AePrintErrorLog
398 * PARAMETERS: FileId - Where to output the error log
402 * DESCRIPTION: Print the entire contents of the error log
404 ******************************************************************************/
410 ASL_ERROR_MSG *Enode = Gbl_ErrorLog;
413 /* Walk the error node list */
417 AePrintException (FileId, Enode, NULL);
423 /*******************************************************************************
425 * FUNCTION: AslCommonError
427 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
428 * MessageId - Index into global message buffer
429 * CurrentLineNumber - Actual file line number
430 * LogicalLineNumber - Cumulative line number
431 * LogicalByteOffset - Byte offset in source file
432 * Column - Column in current line
433 * Filename - source filename
434 * ExtraMessage - additional error message
438 * DESCRIPTION: Create a new error node and add it to the error log
440 ******************************************************************************/
446 UINT32 CurrentLineNumber,
447 UINT32 LogicalLineNumber,
448 UINT32 LogicalByteOffset,
454 char *MessageBuffer = NULL;
455 ASL_ERROR_MSG *Enode;
458 Enode = UtLocalCalloc (sizeof (ASL_ERROR_MSG));
462 /* Allocate a buffer for the message and a new error node */
464 MessageSize = strlen (ExtraMessage) + 1;
465 MessageBuffer = UtLocalCalloc (MessageSize);
467 /* Keep a copy of the extra message */
469 ACPI_STRCPY (MessageBuffer, ExtraMessage);
472 /* Initialize the error node */
476 Enode->Filename = Filename;
477 Enode->FilenameLength = strlen (Filename);
478 if (Enode->FilenameLength < 6)
480 Enode->FilenameLength = 6;
484 Enode->MessageId = MessageId;
485 Enode->Level = Level;
486 Enode->LineNumber = CurrentLineNumber;
487 Enode->LogicalLineNumber = LogicalLineNumber;
488 Enode->LogicalByteOffset = LogicalByteOffset;
489 Enode->Column = Column;
490 Enode->Message = MessageBuffer;
492 /* Add the new node to the error node list */
494 AeAddToErrorLog (Enode);
498 /* stderr is a file, send error to it immediately */
500 AePrintException (ASL_FILE_STDERR, Enode, NULL);
503 Gbl_ExceptionCount[Level]++;
504 if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
506 printf ("\nMaximum error count (%d) exceeded.\n", ASL_MAX_ERROR_COUNT);
509 Gbl_NextError = Gbl_ErrorLog;
518 /*******************************************************************************
522 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
523 * MessageId - Index into global message buffer
524 * Op - Parse node where error happened
525 * ExtraMessage - additional error message
529 * DESCRIPTION: Main error reporting routine for the ASL compiler (all code
530 * except the parser.)
532 ******************************************************************************/
538 ACPI_PARSE_OBJECT *Op,
544 AslCommonError (Level, MessageId, Op->Asl.LineNumber,
545 Op->Asl.LogicalLineNumber,
546 Op->Asl.LogicalByteOffset,
548 Op->Asl.Filename, ExtraMessage);
552 AslCommonError (Level, MessageId, 0,
553 0, 0, 0, NULL, ExtraMessage);
558 /*******************************************************************************
560 * FUNCTION: AslCoreSubsystemError
562 * PARAMETERS: Op - Parse node where error happened
563 * Status - The ACPI CA Exception
564 * ExtraMessage - additional error message
565 * Abort - TRUE -> Abort compilation
569 * DESCRIPTION: Error reporting routine for exceptions returned by the ACPI
572 ******************************************************************************/
575 AslCoreSubsystemError (
576 ACPI_PARSE_OBJECT *Op,
582 sprintf (MsgBuffer, "%s %s", AcpiFormatException (Status), ExtraMessage);
586 AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, Op->Asl.LineNumber,
587 Op->Asl.LogicalLineNumber,
588 Op->Asl.LogicalByteOffset,
590 Op->Asl.Filename, MsgBuffer);
594 AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, 0,
595 0, 0, 0, NULL, MsgBuffer);
605 /*******************************************************************************
607 * FUNCTION: AslCompilererror
609 * PARAMETERS: CompilerMessage - Error message from the parser
611 * RETURN: Status (0 for now)
613 * DESCRIPTION: Report an error situation discovered in a production
614 * NOTE: don't change the name of this function, it is called
615 * from the auto-generated parser.
617 ******************************************************************************/
621 char *CompilerMessage)
624 AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, Gbl_CurrentLineNumber,
625 Gbl_LogicalLineNumber, Gbl_CurrentLineOffset,
626 Gbl_CurrentColumn, Gbl_Files[ASL_FILE_INPUT].Filename,