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 "aslcompiler.h"
121 #define _COMPONENT ACPI_COMPILER
122 ACPI_MODULE_NAME ("aslerror")
125 /*******************************************************************************
127 * FUNCTION: AeAddToErrorLog
129 * PARAMETERS: Enode - An error node to add to the log
133 * DESCRIPTION: Add a new error node to the error log. The error log is
134 * ordered by the "logical" line number (cumulative line number
135 * including all include files.)
137 ******************************************************************************/
141 ASL_ERROR_MSG *Enode)
149 Gbl_ErrorLog = Enode;
153 /* List is sorted according to line number */
157 Gbl_ErrorLog = Enode;
161 /* Walk error list until we find a line number greater than ours */
167 (Next->LogicalLineNumber <= Enode->LogicalLineNumber))
173 /* Found our place in the list */
183 Gbl_ErrorLog = Enode;
188 /*******************************************************************************
190 * FUNCTION: AePrintException
192 * PARAMETERS: Where - Where to send the message
193 * Enode - Error node to print
194 * Header - Additional text before each message
198 * DESCRIPTION: Print the contents of an error node.
200 * NOTE: We don't use the FlxxxFile I/O functions here because on error
201 * they abort the compiler and call this function! Since we
202 * are reporting errors here, we ignore most output errors and
203 * just try to get out as much as we can.
205 ******************************************************************************/
210 ASL_ERROR_MSG *Enode,
224 /* Only listing files have a header, and remarks/optimizations are always output */
228 /* Ignore remarks if requested */
230 switch (Enode->Level)
233 if (!Gbl_DisplayRemarks)
239 case ASL_OPTIMIZATION:
240 if (!Gbl_DisplayOptimizations)
251 /* Get the file handles */
253 OutputFile = Gbl_Files[FileId].Handle;
254 SourceFile = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
258 fprintf (OutputFile, "%s", Header);
261 /* Print filename and line number if present and valid */
265 if (Gbl_VerboseErrors)
267 fprintf (OutputFile, "%6s", Enode->Filename);
269 if (Enode->LineNumber)
271 fprintf (OutputFile, "%6u: ", Enode->LineNumber);
274 * Seek to the offset in the combined source file, read the source
275 * line, and write it to the output.
277 Actual = fseek (SourceFile, (long) Enode->LogicalByteOffset, SEEK_SET);
280 fprintf (OutputFile, "[*** iASL: Seek error on source code temp file ***]");
284 Actual = fread (&SourceByte, 1, 1, SourceFile);
287 fprintf (OutputFile, "[*** iASL: Read error on source code temp file ***]");
290 else while (Actual && SourceByte && (SourceByte != '\n'))
292 fwrite (&SourceByte, 1, 1, OutputFile);
293 Actual = fread (&SourceByte, 1, 1, SourceFile);
296 fprintf (OutputFile, "\n");
301 fprintf (OutputFile, "%s", Enode->Filename);
303 if (Enode->LineNumber)
305 fprintf (OutputFile, "(%u) : ", Enode->LineNumber);
310 /* NULL message ID, just print the raw message */
312 if (Enode->MessageId == 0)
314 fprintf (OutputFile, "%s\n", Enode->Message);
318 /* Decode the message ID */
320 fprintf (OutputFile, "%s %4.4d -",
321 AslErrorLevel[Enode->Level],
322 Enode->MessageId + ((Enode->Level+1) * 1000));
324 MainMessage = AslMessages[Enode->MessageId];
325 ExtraMessage = Enode->Message;
327 if (Enode->LineNumber)
329 MsgLength = strlen (MainMessage);
332 MainMessage = Enode->Message;
334 MsgLength = strlen (MainMessage);
338 if (Gbl_VerboseErrors)
340 SourceColumn = Enode->Column + Enode->FilenameLength + 6 + 2;
341 ErrorColumn = ASL_ERROR_LEVEL_LENGTH + 5 + 2 + 1;
343 if ((MsgLength + ErrorColumn) < (SourceColumn - 1))
345 fprintf (OutputFile, "%*s%s",
346 (int) ((SourceColumn - 1) - ErrorColumn),
351 fprintf (OutputFile, "%*s %s",
352 (int) ((SourceColumn - ErrorColumn) + 1), "^",
358 fprintf (OutputFile, " %s", MainMessage);
361 /* Print the extra info message if present */
365 fprintf (OutputFile, " (%s)", ExtraMessage);
368 fprintf (OutputFile, "\n");
369 if (Gbl_VerboseErrors)
371 fprintf (OutputFile, "\n");
376 fprintf (OutputFile, " %s %s\n\n",
384 /*******************************************************************************
386 * FUNCTION: AePrintErrorLog
388 * PARAMETERS: FileId - Where to output the error log
392 * DESCRIPTION: Print the entire contents of the error log
394 ******************************************************************************/
400 ASL_ERROR_MSG *Enode = Gbl_ErrorLog;
403 /* Walk the error node list */
407 AePrintException (FileId, Enode, NULL);
413 /*******************************************************************************
415 * FUNCTION: AslCommonError
417 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
418 * MessageId - Index into global message buffer
419 * CurrentLineNumber - Actual file line number
420 * LogicalLineNumber - Cumulative line number
421 * LogicalByteOffset - Byte offset in source file
422 * Column - Column in current line
423 * Filename - source filename
424 * ExtraMessage - additional error message
426 * RETURN: New error node for this error
428 * DESCRIPTION: Create a new error node and add it to the error log
430 ******************************************************************************/
436 UINT32 CurrentLineNumber,
437 UINT32 LogicalLineNumber,
438 UINT32 LogicalByteOffset,
444 char *MessageBuffer = NULL;
445 ASL_ERROR_MSG *Enode;
448 Enode = UtLocalCalloc (sizeof (ASL_ERROR_MSG));
452 /* Allocate a buffer for the message and a new error node */
454 MessageSize = strlen (ExtraMessage) + 1;
455 MessageBuffer = UtLocalCalloc (MessageSize);
457 /* Keep a copy of the extra message */
459 ACPI_STRCPY (MessageBuffer, ExtraMessage);
462 /* Initialize the error node */
466 Enode->Filename = Filename;
467 Enode->FilenameLength = strlen (Filename);
468 if (Enode->FilenameLength < 6)
470 Enode->FilenameLength = 6;
474 Enode->MessageId = MessageId;
475 Enode->Level = Level;
476 Enode->LineNumber = CurrentLineNumber;
477 Enode->LogicalLineNumber = LogicalLineNumber;
478 Enode->LogicalByteOffset = LogicalByteOffset;
479 Enode->Column = Column;
480 Enode->Message = MessageBuffer;
482 /* Add the new node to the error node list */
484 AeAddToErrorLog (Enode);
488 /* stderr is a file, send error to it immediately */
490 AePrintException (ASL_FILE_STDERR, Enode, NULL);
493 Gbl_ExceptionCount[Level]++;
494 if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
496 printf ("\nMaximum error count (%d) exceeded.\n", ASL_MAX_ERROR_COUNT);
499 Gbl_NextError = Gbl_ErrorLog;
508 /*******************************************************************************
512 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
513 * MessageId - Index into global message buffer
514 * Op - Parse node where error happened
515 * ExtraMessage - additional error message
519 * DESCRIPTION: Main error reporting routine for the ASL compiler (all code
520 * except the parser.)
522 ******************************************************************************/
528 ACPI_PARSE_OBJECT *Op,
534 AslCommonError (Level, MessageId, Op->Asl.LineNumber,
535 Op->Asl.LogicalLineNumber,
536 Op->Asl.LogicalByteOffset,
538 Op->Asl.Filename, ExtraMessage);
542 AslCommonError (Level, MessageId, 0,
543 0, 0, 0, NULL, ExtraMessage);
548 /*******************************************************************************
550 * FUNCTION: AslCoreSubsystemError
552 * PARAMETERS: Op - Parse node where error happened
553 * Status - The ACPI CA Exception
554 * ExtraMessage - additional error message
555 * Abort - TRUE -> Abort compilation
559 * DESCRIPTION: Error reporting routine for exceptions returned by the ACPI
562 ******************************************************************************/
565 AslCoreSubsystemError (
566 ACPI_PARSE_OBJECT *Op,
572 sprintf (MsgBuffer, "%s %s", AcpiFormatException (Status), ExtraMessage);
576 AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, Op->Asl.LineNumber,
577 Op->Asl.LogicalLineNumber,
578 Op->Asl.LogicalByteOffset,
580 Op->Asl.Filename, MsgBuffer);
584 AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, 0,
585 0, 0, 0, NULL, MsgBuffer);
595 /*******************************************************************************
597 * FUNCTION: AslCompilererror
599 * PARAMETERS: CompilerMessage - Error message from the parser
603 * DESCRIPTION: Report an error situation discovered in a production
604 * NOTE: don't change the name of this function.
606 ******************************************************************************/
610 char *CompilerMessage)
613 AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, Gbl_CurrentLineNumber,
614 Gbl_LogicalLineNumber, Gbl_CurrentLineOffset,
615 Gbl_CurrentColumn, Gbl_Files[ASL_FILE_INPUT].Filename,