2 /******************************************************************************
4 * Module Name: aslerror - Error handling and statistics
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2011, 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 <contrib/dev/acpica/compiler/aslcompiler.h>
48 #define _COMPONENT ACPI_COMPILER
49 ACPI_MODULE_NAME ("aslerror")
51 /* Local prototypes */
55 ASL_ERROR_MSG *Enode);
62 ASL_ERROR_MSG *Enode = Gbl_ErrorLog;
65 /* Walk the error node list */
78 /*******************************************************************************
80 * FUNCTION: AeAddToErrorLog
82 * PARAMETERS: Enode - An error node to add to the log
86 * DESCRIPTION: Add a new error node to the error log. The error log is
87 * ordered by the "logical" line number (cumulative line number
88 * including all include files.)
90 ******************************************************************************/
100 /* If Gbl_ErrorLog is null, this is the first error node */
104 Gbl_ErrorLog = Enode;
109 * Walk error list until we find a line number greater than ours.
110 * List is sorted according to line number.
116 (Next->LogicalLineNumber <= Enode->LogicalLineNumber))
122 /* Found our place in the list */
132 Gbl_ErrorLog = Enode;
137 /*******************************************************************************
139 * FUNCTION: AePrintException
141 * PARAMETERS: FileId - ID of output file
142 * Enode - Error node to print
143 * Header - Additional text before each message
147 * DESCRIPTION: Print the contents of an error node.
149 * NOTE: We don't use the FlxxxFile I/O functions here because on error
150 * they abort the compiler and call this function! Since we
151 * are reporting errors here, we ignore most output errors and
152 * just try to get out as much as we can.
154 ******************************************************************************/
159 ASL_ERROR_MSG *Enode,
173 BOOLEAN PrematureEOF = FALSE;
182 * Only listing files have a header, and remarks/optimizations
187 /* Ignore remarks if requested */
189 switch (Enode->Level)
192 if (!Gbl_DisplayRemarks)
198 case ASL_OPTIMIZATION:
199 if (!Gbl_DisplayOptimizations)
210 /* Get the file handles */
212 OutputFile = Gbl_Files[FileId].Handle;
214 /* Use the merged header/source file if present, otherwise use input file */
216 SourceFile = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
219 SourceFile = Gbl_Files[ASL_FILE_INPUT].Handle;
224 /* Determine if the error occurred at source file EOF */
226 fseek (SourceFile, 0, SEEK_END);
227 FileSize = ftell (SourceFile);
229 if ((long) Enode->LogicalByteOffset >= FileSize)
237 fprintf (OutputFile, "%s", Header);
240 /* Print filename and line number if present and valid */
244 if (Gbl_VerboseErrors)
246 fprintf (OutputFile, "%6s", Enode->Filename);
248 if (Enode->LineNumber)
250 fprintf (OutputFile, " %6u: ", Enode->LineNumber);
253 * If not at EOF, get the corresponding source code line and
254 * display it. Don't attempt this if we have a premature EOF
260 * Seek to the offset in the combined source file, read
261 * the source line, and write it to the output.
263 Actual = fseek (SourceFile, (long) Enode->LogicalByteOffset,
268 "[*** iASL: Seek error on source code temp file %s ***]",
269 Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
273 RActual = fread (&SourceByte, 1, 1, SourceFile);
277 "[*** iASL: Read error on source code temp file %s ***]",
278 Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
281 else while (RActual && SourceByte && (SourceByte != '\n'))
283 fwrite (&SourceByte, 1, 1, OutputFile);
284 RActual = fread (&SourceByte, 1, 1, SourceFile);
289 fprintf (OutputFile, "\n");
294 fprintf (OutputFile, "%s", Enode->Filename);
296 if (Enode->LineNumber)
298 fprintf (OutputFile, "(%u) : ", Enode->LineNumber);
303 /* NULL message ID, just print the raw message */
305 if (Enode->MessageId == 0)
307 fprintf (OutputFile, "%s\n", Enode->Message);
311 /* Decode the message ID */
313 fprintf (OutputFile, "%s %4.4d - ",
314 AslErrorLevel[Enode->Level],
315 Enode->MessageId + ((Enode->Level+1) * 1000));
317 MainMessage = AslMessages[Enode->MessageId];
318 ExtraMessage = Enode->Message;
320 if (Enode->LineNumber)
322 MsgLength = strlen (MainMessage);
325 MainMessage = Enode->Message;
327 MsgLength = strlen (MainMessage);
331 if (Gbl_VerboseErrors && !PrematureEOF)
333 SourceColumn = Enode->Column + Enode->FilenameLength + 6 + 2;
334 ErrorColumn = ASL_ERROR_LEVEL_LENGTH + 5 + 2 + 1;
336 if ((MsgLength + ErrorColumn) < (SourceColumn - 1))
338 fprintf (OutputFile, "%*s%s",
339 (int) ((SourceColumn - 1) - ErrorColumn),
344 fprintf (OutputFile, "%*s %s",
345 (int) ((SourceColumn - ErrorColumn) + 1), "^",
351 fprintf (OutputFile, " %s", MainMessage);
354 /* Print the extra info message if present */
358 fprintf (OutputFile, " (%s)", ExtraMessage);
363 fprintf (OutputFile, " and premature End-Of-File");
366 fprintf (OutputFile, "\n");
367 if (Gbl_VerboseErrors)
369 fprintf (OutputFile, "\n");
374 fprintf (OutputFile, " %s %s\n\n", MainMessage, ExtraMessage);
380 /*******************************************************************************
382 * FUNCTION: AePrintErrorLog
384 * PARAMETERS: FileId - Where to output the error log
388 * DESCRIPTION: Print the entire contents of the error log
390 ******************************************************************************/
396 ASL_ERROR_MSG *Enode = Gbl_ErrorLog;
399 /* Walk the error node list */
403 AePrintException (FileId, Enode, NULL);
409 /*******************************************************************************
411 * FUNCTION: AslCommonError
413 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
414 * MessageId - Index into global message buffer
415 * CurrentLineNumber - Actual file line number
416 * LogicalLineNumber - Cumulative line number
417 * LogicalByteOffset - Byte offset in source file
418 * Column - Column in current line
419 * Filename - source filename
420 * ExtraMessage - additional error message
424 * DESCRIPTION: Create a new error node and add it to the error log
426 ******************************************************************************/
432 UINT32 CurrentLineNumber,
433 UINT32 LogicalLineNumber,
434 UINT32 LogicalByteOffset,
440 char *MessageBuffer = NULL;
441 ASL_ERROR_MSG *Enode;
444 Enode = UtLocalCalloc (sizeof (ASL_ERROR_MSG));
448 /* Allocate a buffer for the message and a new error node */
450 MessageSize = strlen (ExtraMessage) + 1;
451 MessageBuffer = UtLocalCalloc (MessageSize);
453 /* Keep a copy of the extra message */
455 ACPI_STRCPY (MessageBuffer, ExtraMessage);
458 /* Initialize the error node */
462 Enode->Filename = Filename;
463 Enode->FilenameLength = strlen (Filename);
464 if (Enode->FilenameLength < 6)
466 Enode->FilenameLength = 6;
470 Enode->MessageId = MessageId;
471 Enode->Level = Level;
472 Enode->LineNumber = CurrentLineNumber;
473 Enode->LogicalLineNumber = LogicalLineNumber;
474 Enode->LogicalByteOffset = LogicalByteOffset;
475 Enode->Column = Column;
476 Enode->Message = MessageBuffer;
478 /* Add the new node to the error node list */
480 AeAddToErrorLog (Enode);
484 /* stderr is a file, send error to it immediately */
486 AePrintException (ASL_FILE_STDERR, Enode, NULL);
489 Gbl_ExceptionCount[Level]++;
490 if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
492 printf ("\nMaximum error count (%u) exceeded\n", ASL_MAX_ERROR_COUNT);
495 Gbl_NextError = Gbl_ErrorLog;
505 /*******************************************************************************
509 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
510 * MessageId - Index into global message buffer
511 * Op - Parse node where error happened
512 * ExtraMessage - additional error message
516 * DESCRIPTION: Main error reporting routine for the ASL compiler (all code
517 * except the parser.)
519 ******************************************************************************/
525 ACPI_PARSE_OBJECT *Op,
533 if (Gbl_WarningLevel < Level)
546 AslCommonError (Level, MessageId, Op->Asl.LineNumber,
547 Op->Asl.LogicalLineNumber,
548 Op->Asl.LogicalByteOffset,
550 Op->Asl.Filename, ExtraMessage);
554 AslCommonError (Level, MessageId, 0,
555 0, 0, 0, NULL, ExtraMessage);
560 /*******************************************************************************
562 * FUNCTION: AslCoreSubsystemError
564 * PARAMETERS: Op - Parse node where error happened
565 * Status - The ACPI CA Exception
566 * ExtraMessage - additional error message
567 * Abort - TRUE -> Abort compilation
571 * DESCRIPTION: Error reporting routine for exceptions returned by the ACPI
574 ******************************************************************************/
577 AslCoreSubsystemError (
578 ACPI_PARSE_OBJECT *Op,
584 sprintf (MsgBuffer, "%s %s", AcpiFormatException (Status), ExtraMessage);
588 AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, Op->Asl.LineNumber,
589 Op->Asl.LogicalLineNumber,
590 Op->Asl.LogicalByteOffset,
592 Op->Asl.Filename, MsgBuffer);
596 AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, 0,
597 0, 0, 0, NULL, MsgBuffer);
607 /*******************************************************************************
609 * FUNCTION: AslCompilererror
611 * PARAMETERS: CompilerMessage - Error message from the parser
613 * RETURN: Status (0 for now)
615 * DESCRIPTION: Report an error situation discovered in a production
616 * NOTE: don't change the name of this function, it is called
617 * from the auto-generated parser.
619 ******************************************************************************/
623 char *CompilerMessage)
626 AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, Gbl_CurrentLineNumber,
627 Gbl_LogicalLineNumber, Gbl_CurrentLineOffset,
628 Gbl_CurrentColumn, Gbl_Files[ASL_FILE_INPUT].Filename,