aslerror.c revision 126372
1
2/******************************************************************************
3 *
4 * Module Name: aslerror - Error handling and statistics
5 *              $Revision: 83 $
6 *
7 *****************************************************************************/
8
9/******************************************************************************
10 *
11 * 1. Copyright Notice
12 *
13 * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp.
14 * All rights reserved.
15 *
16 * 2. License
17 *
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
21 * property rights.
22 *
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
29 *
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;
38 *
39 * The above copyright and patent license is granted only if the following
40 * conditions are met:
41 *
42 * 3. Conditions
43 *
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.
55 *
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
66 * make.
67 *
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
72 * distribution.
73 *
74 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * Intel Code.
76 *
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.
81 *
82 * 4. Disclaimer and Export Compliance
83 *
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
90 * PARTICULAR PURPOSE.
91 *
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
99 * LIMITED REMEDY.
100 *
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.
115 *
116 *****************************************************************************/
117
118#define ASL_EXCEPTIONS
119#include "aslcompiler.h"
120
121#define _COMPONENT          ACPI_COMPILER
122        ACPI_MODULE_NAME    ("aslerror")
123
124
125/*******************************************************************************
126 *
127 * FUNCTION:    AeAddToErrorLog
128 *
129 * PARAMETERS:  Enode       - An error node to add to the log
130 *
131 * RETURN:      None
132 *
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.)
136 *
137 ******************************************************************************/
138
139void
140AeAddToErrorLog (
141    ASL_ERROR_MSG           *Enode)
142{
143    ASL_ERROR_MSG           *Next;
144    ASL_ERROR_MSG           *Prev;
145
146
147    if (!Gbl_ErrorLog)
148    {
149        Gbl_ErrorLog = Enode;
150        return;
151    }
152
153    /* List is sorted according to line number */
154
155    if (!Gbl_ErrorLog)
156    {
157        Gbl_ErrorLog = Enode;
158        return;
159    }
160
161    /* Walk error list until we find a line number greater than ours */
162
163    Prev = NULL;
164    Next = Gbl_ErrorLog;
165
166    while ((Next) &&
167           (Next->LogicalLineNumber <= Enode->LogicalLineNumber))
168    {
169        Prev = Next;
170        Next = Next->Next;
171    }
172
173    /* Found our place in the list */
174
175    Enode->Next = Next;
176
177    if (Prev)
178    {
179        Prev->Next = Enode;
180    }
181    else
182    {
183        Gbl_ErrorLog = Enode;
184    }
185}
186
187
188/*******************************************************************************
189 *
190 * FUNCTION:    AePrintException
191 *
192 * PARAMETERS:  Where           - Where to send the message
193 *              Enode           - Error node to print
194 *              Header          - Additional text before each message
195 *
196 * RETURN:      None
197 *
198 * DESCRIPTION: Print the contents of an error node.
199 *
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.
204 *
205 ******************************************************************************/
206
207void
208AePrintException (
209    UINT32                  FileId,
210    ASL_ERROR_MSG           *Enode,
211    char                    *Header)
212{
213    UINT8                   SourceByte;
214    UINT32                  Actual;
215    UINT32                  MsgLength;
216    char                    *MainMessage;
217    char                    *ExtraMessage;
218    UINT32                  SourceColumn;
219    UINT32                  ErrorColumn;
220    FILE                    *OutputFile;
221    FILE                    *SourceFile;
222
223
224    /* Only listing files have a header, and remarks/optimizations are always output */
225
226    if (!Header)
227    {
228        /* Ignore remarks if requested */
229
230        switch (Enode->Level)
231        {
232        case ASL_REMARK:
233            if (!Gbl_DisplayRemarks)
234            {
235                return;
236            }
237            break;
238
239        case ASL_OPTIMIZATION:
240            if (!Gbl_DisplayOptimizations)
241            {
242                return;
243            }
244            break;
245
246        default:
247            break;
248        }
249    }
250
251    /* Get the file handles */
252
253    OutputFile = Gbl_Files[FileId].Handle;
254    SourceFile = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
255
256    if (Header)
257    {
258        fprintf (OutputFile, "%s", Header);
259    }
260
261    /* Print filename and line number if present and valid */
262
263    if (Enode->Filename)
264    {
265        if (Gbl_VerboseErrors)
266        {
267            fprintf (OutputFile, "%6s", Enode->Filename);
268
269            if (Enode->LineNumber)
270            {
271                fprintf (OutputFile, "%6u: ", Enode->LineNumber);
272
273                /*
274                 * Seek to the offset in the combined source file, read the source
275                 * line, and write it to the output.
276                 */
277                Actual = fseek (SourceFile, (long) Enode->LogicalByteOffset, SEEK_SET);
278                if (Actual)
279                {
280                    fprintf (OutputFile, "[*** iASL: Seek error on source code temp file ***]");
281                }
282                else
283                {
284                    Actual = fread (&SourceByte, 1, 1, SourceFile);
285                    if (!Actual)
286                    {
287                        fprintf (OutputFile, "[*** iASL: Read error on source code temp file ***]");
288                    }
289
290                    else while (Actual && SourceByte && (SourceByte != '\n'))
291                    {
292                        fwrite (&SourceByte, 1, 1, OutputFile);
293                        Actual = fread (&SourceByte, 1, 1, SourceFile);
294                    }
295                }
296                fprintf (OutputFile, "\n");
297            }
298        }
299        else
300        {
301            fprintf (OutputFile, "%s", Enode->Filename);
302
303            if (Enode->LineNumber)
304            {
305                fprintf (OutputFile, "(%u) : ", Enode->LineNumber);
306            }
307        }
308    }
309
310    /* NULL message ID, just print the raw message */
311
312    if (Enode->MessageId == 0)
313    {
314        fprintf (OutputFile, "%s\n", Enode->Message);
315    }
316    else
317    {
318        /* Decode the message ID */
319
320        fprintf (OutputFile, "%s %4.4d -",
321                    AslErrorLevel[Enode->Level],
322                    Enode->MessageId + ((Enode->Level+1) * 1000));
323
324        MainMessage = AslMessages[Enode->MessageId];
325        ExtraMessage = Enode->Message;
326
327        if (Enode->LineNumber)
328        {
329            MsgLength = strlen (MainMessage);
330            if (MsgLength == 0)
331            {
332                MainMessage = Enode->Message;
333
334                MsgLength = strlen (MainMessage);
335                ExtraMessage = NULL;
336            }
337
338            if (Gbl_VerboseErrors)
339            {
340                SourceColumn = Enode->Column + Enode->FilenameLength + 6 + 2;
341                ErrorColumn = ASL_ERROR_LEVEL_LENGTH + 5 + 2 + 1;
342
343                if ((MsgLength + ErrorColumn) < (SourceColumn - 1))
344                {
345                    fprintf (OutputFile, "%*s%s",
346                        (int) ((SourceColumn - 1) - ErrorColumn),
347                        MainMessage, " ^ ");
348                }
349                else
350                {
351                    fprintf (OutputFile, "%*s %s",
352                        (int) ((SourceColumn - ErrorColumn) + 1), "^",
353                        MainMessage);
354                }
355            }
356            else
357            {
358                fprintf (OutputFile, " %s", MainMessage);
359            }
360
361            /* Print the extra info message if present */
362
363            if (ExtraMessage)
364            {
365                fprintf (OutputFile, " (%s)", ExtraMessage);
366            }
367
368            fprintf (OutputFile, "\n");
369            if (Gbl_VerboseErrors)
370            {
371                fprintf (OutputFile, "\n");
372            }
373        }
374        else
375        {
376            fprintf (OutputFile, " %s %s\n\n",
377                        MainMessage,
378                        ExtraMessage);
379        }
380    }
381}
382
383
384/*******************************************************************************
385 *
386 * FUNCTION:    AePrintErrorLog
387 *
388 * PARAMETERS:  FileId           - Where to output the error log
389 *
390 * RETURN:      None
391 *
392 * DESCRIPTION: Print the entire contents of the error log
393 *
394 ******************************************************************************/
395
396void
397AePrintErrorLog (
398    UINT32                  FileId)
399{
400    ASL_ERROR_MSG           *Enode = Gbl_ErrorLog;
401
402
403    /* Walk the error node list */
404
405    while (Enode)
406    {
407        AePrintException (FileId, Enode, NULL);
408        Enode = Enode->Next;
409    }
410}
411
412
413/*******************************************************************************
414 *
415 * FUNCTION:    AslCommonError
416 *
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
425 *
426 * RETURN:      New error node for this error
427 *
428 * DESCRIPTION: Create a new error node and add it to the error log
429 *
430 ******************************************************************************/
431
432void
433AslCommonError (
434    UINT8                   Level,
435    UINT8                   MessageId,
436    UINT32                  CurrentLineNumber,
437    UINT32                  LogicalLineNumber,
438    UINT32                  LogicalByteOffset,
439    UINT32                  Column,
440    char                    *Filename,
441    char                    *ExtraMessage)
442{
443    UINT32                  MessageSize;
444    char                    *MessageBuffer = NULL;
445    ASL_ERROR_MSG           *Enode;
446
447
448    Enode = UtLocalCalloc (sizeof (ASL_ERROR_MSG));
449
450    if (ExtraMessage)
451    {
452        /* Allocate a buffer for the message and a new error node */
453
454        MessageSize   = strlen (ExtraMessage) + 1;
455        MessageBuffer = UtLocalCalloc (MessageSize);
456
457        /* Keep a copy of the extra message */
458
459        ACPI_STRCPY (MessageBuffer, ExtraMessage);
460    }
461
462    /* Initialize the error node */
463
464    if (Filename)
465    {
466        Enode->Filename       = Filename;
467        Enode->FilenameLength = strlen (Filename);
468        if (Enode->FilenameLength < 6)
469        {
470            Enode->FilenameLength = 6;
471        }
472    }
473
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;
481
482    /* Add the new node to the error node list */
483
484    AeAddToErrorLog (Enode);
485
486    if (Gbl_DebugFlag)
487    {
488        /* stderr is a file, send error to it immediately */
489
490        AePrintException (ASL_FILE_STDERR, Enode, NULL);
491    }
492
493    Gbl_ExceptionCount[Level]++;
494    if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
495    {
496        printf ("\nMaximum error count (%d) exceeded.\n", ASL_MAX_ERROR_COUNT);
497
498        Gbl_SourceLine = 0;
499        Gbl_NextError = Gbl_ErrorLog;
500        CmDoOutputFiles ();
501        CmCleanupAndExit ();
502    }
503
504    return;
505}
506
507
508/*******************************************************************************
509 *
510 * FUNCTION:    AslError
511 *
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
516 *
517 * RETURN:      None
518 *
519 * DESCRIPTION: Main error reporting routine for the ASL compiler (all code
520 *              except the parser.)
521 *
522 ******************************************************************************/
523
524void
525AslError (
526    UINT8                   Level,
527    UINT8                   MessageId,
528    ACPI_PARSE_OBJECT       *Op,
529    char                    *ExtraMessage)
530{
531
532    if (Op)
533    {
534        AslCommonError (Level, MessageId, Op->Asl.LineNumber,
535                        Op->Asl.LogicalLineNumber,
536                        Op->Asl.LogicalByteOffset,
537                        Op->Asl.Column,
538                        Op->Asl.Filename, ExtraMessage);
539    }
540    else
541    {
542        AslCommonError (Level, MessageId, 0,
543                        0, 0, 0, NULL, ExtraMessage);
544    }
545}
546
547
548/*******************************************************************************
549 *
550 * FUNCTION:    AslCoreSubsystemError
551 *
552 * PARAMETERS:  Op                  - Parse node where error happened
553 *              Status              - The ACPI CA Exception
554 *              ExtraMessage        - additional error message
555 *              Abort               - TRUE -> Abort compilation
556 *
557 * RETURN:      None
558 *
559 * DESCRIPTION: Error reporting routine for exceptions returned by the ACPI
560 *              CA core subsystem.
561 *
562 ******************************************************************************/
563
564void
565AslCoreSubsystemError (
566    ACPI_PARSE_OBJECT       *Op,
567    ACPI_STATUS             Status,
568    char                    *ExtraMessage,
569    BOOLEAN                 Abort)
570{
571
572    sprintf (MsgBuffer, "%s %s", AcpiFormatException (Status), ExtraMessage);
573
574    if (Op)
575    {
576        AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, Op->Asl.LineNumber,
577                        Op->Asl.LogicalLineNumber,
578                        Op->Asl.LogicalByteOffset,
579                        Op->Asl.Column,
580                        Op->Asl.Filename, MsgBuffer);
581    }
582    else
583    {
584        AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, 0,
585                        0, 0, 0, NULL, MsgBuffer);
586    }
587
588    if (Abort)
589    {
590        AslAbort ();
591    }
592}
593
594
595/*******************************************************************************
596 *
597 * FUNCTION:    AslCompilererror
598 *
599 * PARAMETERS:  CompilerMessage         - Error message from the parser
600 *
601 * RETURN:      Status?
602 *
603 * DESCRIPTION: Report an error situation discovered in a production
604 *               NOTE: don't change the name of this function.
605 *
606 ******************************************************************************/
607
608int
609AslCompilererror (
610    char                    *CompilerMessage)
611{
612
613    AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, Gbl_CurrentLineNumber,
614                    Gbl_LogicalLineNumber, Gbl_CurrentLineOffset,
615                    Gbl_CurrentColumn, Gbl_Files[ASL_FILE_INPUT].Filename,
616                    CompilerMessage);
617
618    return 0;
619}
620
621
622