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 <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 /* Main message: try to use string from AslMessages first */
329 MsgLength = strlen (MainMessage);
332 /* Use the secondary/extra message as main message */
334 MainMessage = Enode->Message;
340 MsgLength = strlen (MainMessage);
344 if (Gbl_VerboseErrors && !PrematureEOF)
346 SourceColumn = Enode->Column + Enode->FilenameLength + 6 + 2;
347 ErrorColumn = ASL_ERROR_LEVEL_LENGTH + 5 + 2 + 1;
349 if ((MsgLength + ErrorColumn) < (SourceColumn - 1))
351 fprintf (OutputFile, "%*s%s",
352 (int) ((SourceColumn - 1) - ErrorColumn),
357 fprintf (OutputFile, "%*s %s",
358 (int) ((SourceColumn - ErrorColumn) + 1), "^",
364 fprintf (OutputFile, " %s", MainMessage);
367 /* Print the extra info message if present */
371 fprintf (OutputFile, " (%s)", ExtraMessage);
376 fprintf (OutputFile, " and premature End-Of-File");
379 fprintf (OutputFile, "\n");
380 if (Gbl_VerboseErrors)
382 fprintf (OutputFile, "\n");
387 fprintf (OutputFile, " %s %s\n\n", MainMessage, ExtraMessage);
393 /*******************************************************************************
395 * FUNCTION: AePrintErrorLog
397 * PARAMETERS: FileId - Where to output the error log
401 * DESCRIPTION: Print the entire contents of the error log
403 ******************************************************************************/
409 ASL_ERROR_MSG *Enode = Gbl_ErrorLog;
412 /* Walk the error node list */
416 AePrintException (FileId, Enode, NULL);
422 /*******************************************************************************
424 * FUNCTION: AslCommonError
426 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
427 * MessageId - Index into global message buffer
428 * CurrentLineNumber - Actual file line number
429 * LogicalLineNumber - Cumulative line number
430 * LogicalByteOffset - Byte offset in source file
431 * Column - Column in current line
432 * Filename - source filename
433 * ExtraMessage - additional error message
437 * DESCRIPTION: Create a new error node and add it to the error log
439 ******************************************************************************/
445 UINT32 CurrentLineNumber,
446 UINT32 LogicalLineNumber,
447 UINT32 LogicalByteOffset,
453 char *MessageBuffer = NULL;
454 ASL_ERROR_MSG *Enode;
457 Enode = UtLocalCalloc (sizeof (ASL_ERROR_MSG));
461 /* Allocate a buffer for the message and a new error node */
463 MessageSize = strlen (ExtraMessage) + 1;
464 MessageBuffer = UtLocalCalloc (MessageSize);
466 /* Keep a copy of the extra message */
468 ACPI_STRCPY (MessageBuffer, ExtraMessage);
471 /* Initialize the error node */
475 Enode->Filename = Filename;
476 Enode->FilenameLength = strlen (Filename);
477 if (Enode->FilenameLength < 6)
479 Enode->FilenameLength = 6;
483 Enode->MessageId = MessageId;
484 Enode->Level = Level;
485 Enode->LineNumber = CurrentLineNumber;
486 Enode->LogicalLineNumber = LogicalLineNumber;
487 Enode->LogicalByteOffset = LogicalByteOffset;
488 Enode->Column = Column;
489 Enode->Message = MessageBuffer;
491 /* Add the new node to the error node list */
493 AeAddToErrorLog (Enode);
497 /* stderr is a file, send error to it immediately */
499 AePrintException (ASL_FILE_STDERR, Enode, NULL);
502 Gbl_ExceptionCount[Level]++;
503 if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
505 printf ("\nMaximum error count (%u) exceeded\n", ASL_MAX_ERROR_COUNT);
508 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,
546 if (Gbl_WarningLevel < Level)
559 AslCommonError (Level, MessageId, Op->Asl.LineNumber,
560 Op->Asl.LogicalLineNumber,
561 Op->Asl.LogicalByteOffset,
563 Op->Asl.Filename, ExtraMessage);
567 AslCommonError (Level, MessageId, 0,
568 0, 0, 0, NULL, ExtraMessage);
573 /*******************************************************************************
575 * FUNCTION: AslCoreSubsystemError
577 * PARAMETERS: Op - Parse node where error happened
578 * Status - The ACPI CA Exception
579 * ExtraMessage - additional error message
580 * Abort - TRUE -> Abort compilation
584 * DESCRIPTION: Error reporting routine for exceptions returned by the ACPI
587 ******************************************************************************/
590 AslCoreSubsystemError (
591 ACPI_PARSE_OBJECT *Op,
597 sprintf (MsgBuffer, "%s %s", AcpiFormatException (Status), ExtraMessage);
601 AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, Op->Asl.LineNumber,
602 Op->Asl.LogicalLineNumber,
603 Op->Asl.LogicalByteOffset,
605 Op->Asl.Filename, MsgBuffer);
609 AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, 0,
610 0, 0, 0, NULL, MsgBuffer);
620 /*******************************************************************************
622 * FUNCTION: AslCompilererror
624 * PARAMETERS: CompilerMessage - Error message from the parser
626 * RETURN: Status (0 for now)
628 * DESCRIPTION: Report an error situation discovered in a production
629 * NOTE: don't change the name of this function, it is called
630 * from the auto-generated parser.
632 ******************************************************************************/
636 const char *CompilerMessage)
639 AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, Gbl_CurrentLineNumber,
640 Gbl_LogicalLineNumber, Gbl_CurrentLineOffset,
641 Gbl_CurrentColumn, Gbl_Files[ASL_FILE_INPUT].Filename,
642 ACPI_CAST_PTR (char, CompilerMessage));