Home | History | Annotate | Line # | Download | only in compiler
aslerror.c revision 1.3
      1  1.1    jruoho /******************************************************************************
      2  1.1    jruoho  *
      3  1.1    jruoho  * Module Name: aslerror - Error handling and statistics
      4  1.1    jruoho  *
      5  1.1    jruoho  *****************************************************************************/
      6  1.1    jruoho 
      7  1.2  christos /*
      8  1.3  christos  * Copyright (C) 2000 - 2014, Intel Corp.
      9  1.1    jruoho  * All rights reserved.
     10  1.1    jruoho  *
     11  1.2  christos  * Redistribution and use in source and binary forms, with or without
     12  1.2  christos  * modification, are permitted provided that the following conditions
     13  1.2  christos  * are met:
     14  1.2  christos  * 1. Redistributions of source code must retain the above copyright
     15  1.2  christos  *    notice, this list of conditions, and the following disclaimer,
     16  1.2  christos  *    without modification.
     17  1.2  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.2  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.2  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.2  christos  *    including a substantially similar Disclaimer requirement for further
     21  1.2  christos  *    binary redistribution.
     22  1.2  christos  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.2  christos  *    of any contributors may be used to endorse or promote products derived
     24  1.2  christos  *    from this software without specific prior written permission.
     25  1.2  christos  *
     26  1.2  christos  * Alternatively, this software may be distributed under the terms of the
     27  1.2  christos  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.2  christos  * Software Foundation.
     29  1.2  christos  *
     30  1.2  christos  * NO WARRANTY
     31  1.2  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.2  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.2  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.2  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.2  christos  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.2  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.2  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.2  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.2  christos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.2  christos  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.2  christos  * POSSIBILITY OF SUCH DAMAGES.
     42  1.2  christos  */
     43  1.1    jruoho 
     44  1.1    jruoho #include "aslcompiler.h"
     45  1.1    jruoho 
     46  1.1    jruoho #define _COMPONENT          ACPI_COMPILER
     47  1.1    jruoho         ACPI_MODULE_NAME    ("aslerror")
     48  1.1    jruoho 
     49  1.1    jruoho /* Local prototypes */
     50  1.1    jruoho 
     51  1.1    jruoho static void
     52  1.1    jruoho AeAddToErrorLog (
     53  1.1    jruoho     ASL_ERROR_MSG           *Enode);
     54  1.1    jruoho 
     55  1.1    jruoho 
     56  1.2  christos /*******************************************************************************
     57  1.2  christos  *
     58  1.3  christos  * FUNCTION:    AslAbort
     59  1.3  christos  *
     60  1.3  christos  * PARAMETERS:  None
     61  1.3  christos  *
     62  1.3  christos  * RETURN:      None
     63  1.3  christos  *
     64  1.3  christos  * DESCRIPTION: Dump the error log and abort the compiler. Used for serious
     65  1.3  christos  *              I/O errors.
     66  1.3  christos  *
     67  1.3  christos  ******************************************************************************/
     68  1.3  christos 
     69  1.3  christos void
     70  1.3  christos AslAbort (
     71  1.3  christos     void)
     72  1.3  christos {
     73  1.3  christos 
     74  1.3  christos     AePrintErrorLog (ASL_FILE_STDERR);
     75  1.3  christos     if (Gbl_DebugFlag)
     76  1.3  christos     {
     77  1.3  christos         /* Print error summary to stdout also */
     78  1.3  christos 
     79  1.3  christos         AePrintErrorLog (ASL_FILE_STDOUT);
     80  1.3  christos     }
     81  1.3  christos 
     82  1.3  christos     exit (1);
     83  1.3  christos }
     84  1.3  christos 
     85  1.3  christos 
     86  1.3  christos /*******************************************************************************
     87  1.3  christos  *
     88  1.2  christos  * FUNCTION:    AeClearErrorLog
     89  1.2  christos  *
     90  1.2  christos  * PARAMETERS:  None
     91  1.2  christos  *
     92  1.2  christos  * RETURN:      None
     93  1.2  christos  *
     94  1.2  christos  * DESCRIPTION: Empty the error list
     95  1.2  christos  *
     96  1.2  christos  ******************************************************************************/
     97  1.2  christos 
     98  1.1    jruoho void
     99  1.1    jruoho AeClearErrorLog (
    100  1.1    jruoho     void)
    101  1.1    jruoho {
    102  1.1    jruoho     ASL_ERROR_MSG           *Enode = Gbl_ErrorLog;
    103  1.1    jruoho     ASL_ERROR_MSG           *Next;
    104  1.1    jruoho 
    105  1.1    jruoho     /* Walk the error node list */
    106  1.1    jruoho 
    107  1.1    jruoho     while (Enode)
    108  1.1    jruoho     {
    109  1.1    jruoho         Next = Enode->Next;
    110  1.1    jruoho         ACPI_FREE (Enode);
    111  1.1    jruoho         Enode = Next;
    112  1.1    jruoho     }
    113  1.1    jruoho 
    114  1.1    jruoho     Gbl_ErrorLog = NULL;
    115  1.1    jruoho }
    116  1.1    jruoho 
    117  1.1    jruoho 
    118  1.1    jruoho /*******************************************************************************
    119  1.1    jruoho  *
    120  1.1    jruoho  * FUNCTION:    AeAddToErrorLog
    121  1.1    jruoho  *
    122  1.1    jruoho  * PARAMETERS:  Enode       - An error node to add to the log
    123  1.1    jruoho  *
    124  1.1    jruoho  * RETURN:      None
    125  1.1    jruoho  *
    126  1.2  christos  * DESCRIPTION: Add a new error node to the error log. The error log is
    127  1.1    jruoho  *              ordered by the "logical" line number (cumulative line number
    128  1.1    jruoho  *              including all include files.)
    129  1.1    jruoho  *
    130  1.1    jruoho  ******************************************************************************/
    131  1.1    jruoho 
    132  1.1    jruoho static void
    133  1.1    jruoho AeAddToErrorLog (
    134  1.1    jruoho     ASL_ERROR_MSG           *Enode)
    135  1.1    jruoho {
    136  1.1    jruoho     ASL_ERROR_MSG           *Next;
    137  1.1    jruoho     ASL_ERROR_MSG           *Prev;
    138  1.1    jruoho 
    139  1.1    jruoho 
    140  1.1    jruoho     /* If Gbl_ErrorLog is null, this is the first error node */
    141  1.1    jruoho 
    142  1.1    jruoho     if (!Gbl_ErrorLog)
    143  1.1    jruoho     {
    144  1.1    jruoho         Gbl_ErrorLog = Enode;
    145  1.1    jruoho         return;
    146  1.1    jruoho     }
    147  1.1    jruoho 
    148  1.1    jruoho     /*
    149  1.1    jruoho      * Walk error list until we find a line number greater than ours.
    150  1.1    jruoho      * List is sorted according to line number.
    151  1.1    jruoho      */
    152  1.1    jruoho     Prev = NULL;
    153  1.1    jruoho     Next = Gbl_ErrorLog;
    154  1.1    jruoho 
    155  1.1    jruoho     while ((Next) &&
    156  1.1    jruoho            (Next->LogicalLineNumber <= Enode->LogicalLineNumber))
    157  1.1    jruoho     {
    158  1.1    jruoho         Prev = Next;
    159  1.1    jruoho         Next = Next->Next;
    160  1.1    jruoho     }
    161  1.1    jruoho 
    162  1.1    jruoho     /* Found our place in the list */
    163  1.1    jruoho 
    164  1.1    jruoho     Enode->Next = Next;
    165  1.1    jruoho 
    166  1.1    jruoho     if (Prev)
    167  1.1    jruoho     {
    168  1.1    jruoho         Prev->Next = Enode;
    169  1.1    jruoho     }
    170  1.1    jruoho     else
    171  1.1    jruoho     {
    172  1.1    jruoho         Gbl_ErrorLog = Enode;
    173  1.1    jruoho     }
    174  1.1    jruoho }
    175  1.1    jruoho 
    176  1.1    jruoho 
    177  1.1    jruoho /*******************************************************************************
    178  1.1    jruoho  *
    179  1.1    jruoho  * FUNCTION:    AePrintException
    180  1.1    jruoho  *
    181  1.1    jruoho  * PARAMETERS:  FileId          - ID of output file
    182  1.1    jruoho  *              Enode           - Error node to print
    183  1.1    jruoho  *              Header          - Additional text before each message
    184  1.1    jruoho  *
    185  1.1    jruoho  * RETURN:      None
    186  1.1    jruoho  *
    187  1.1    jruoho  * DESCRIPTION: Print the contents of an error node.
    188  1.1    jruoho  *
    189  1.1    jruoho  * NOTE:        We don't use the FlxxxFile I/O functions here because on error
    190  1.1    jruoho  *              they abort the compiler and call this function!  Since we
    191  1.1    jruoho  *              are reporting errors here, we ignore most output errors and
    192  1.1    jruoho  *              just try to get out as much as we can.
    193  1.1    jruoho  *
    194  1.1    jruoho  ******************************************************************************/
    195  1.1    jruoho 
    196  1.1    jruoho void
    197  1.1    jruoho AePrintException (
    198  1.1    jruoho     UINT32                  FileId,
    199  1.1    jruoho     ASL_ERROR_MSG           *Enode,
    200  1.1    jruoho     char                    *Header)
    201  1.1    jruoho {
    202  1.1    jruoho     UINT8                   SourceByte;
    203  1.1    jruoho     int                     Actual;
    204  1.1    jruoho     size_t                  RActual;
    205  1.1    jruoho     UINT32                  MsgLength;
    206  1.3  christos     const char              *MainMessage;
    207  1.1    jruoho     char                    *ExtraMessage;
    208  1.1    jruoho     UINT32                  SourceColumn;
    209  1.1    jruoho     UINT32                  ErrorColumn;
    210  1.1    jruoho     FILE                    *OutputFile;
    211  1.2  christos     FILE                    *SourceFile = NULL;
    212  1.2  christos     long                    FileSize;
    213  1.2  christos     BOOLEAN                 PrematureEOF = FALSE;
    214  1.2  christos     UINT32                  Total = 0;
    215  1.1    jruoho 
    216  1.1    jruoho 
    217  1.1    jruoho     if (Gbl_NoErrors)
    218  1.1    jruoho     {
    219  1.1    jruoho         return;
    220  1.1    jruoho     }
    221  1.1    jruoho 
    222  1.1    jruoho     /*
    223  1.1    jruoho      * Only listing files have a header, and remarks/optimizations
    224  1.1    jruoho      * are always output
    225  1.1    jruoho      */
    226  1.1    jruoho     if (!Header)
    227  1.1    jruoho     {
    228  1.1    jruoho         /* Ignore remarks if requested */
    229  1.1    jruoho 
    230  1.1    jruoho         switch (Enode->Level)
    231  1.1    jruoho         {
    232  1.2  christos         case ASL_WARNING:
    233  1.2  christos         case ASL_WARNING2:
    234  1.2  christos         case ASL_WARNING3:
    235  1.2  christos 
    236  1.2  christos             if (!Gbl_DisplayWarnings)
    237  1.2  christos             {
    238  1.2  christos                 return;
    239  1.2  christos             }
    240  1.2  christos             break;
    241  1.2  christos 
    242  1.1    jruoho         case ASL_REMARK:
    243  1.2  christos 
    244  1.1    jruoho             if (!Gbl_DisplayRemarks)
    245  1.1    jruoho             {
    246  1.1    jruoho                 return;
    247  1.1    jruoho             }
    248  1.1    jruoho             break;
    249  1.1    jruoho 
    250  1.1    jruoho         case ASL_OPTIMIZATION:
    251  1.2  christos 
    252  1.1    jruoho             if (!Gbl_DisplayOptimizations)
    253  1.1    jruoho             {
    254  1.1    jruoho                 return;
    255  1.1    jruoho             }
    256  1.1    jruoho             break;
    257  1.1    jruoho 
    258  1.1    jruoho         default:
    259  1.2  christos 
    260  1.1    jruoho             break;
    261  1.1    jruoho         }
    262  1.1    jruoho     }
    263  1.1    jruoho 
    264  1.2  christos     /* Get the various required file handles */
    265  1.1    jruoho 
    266  1.1    jruoho     OutputFile = Gbl_Files[FileId].Handle;
    267  1.2  christos 
    268  1.2  christos     if (!Enode->SourceLine)
    269  1.2  christos     {
    270  1.2  christos         /* Use the merged header/source file if present, otherwise use input file */
    271  1.2  christos 
    272  1.2  christos         SourceFile = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
    273  1.2  christos         if (!SourceFile)
    274  1.2  christos         {
    275  1.2  christos             SourceFile = Gbl_Files[ASL_FILE_INPUT].Handle;
    276  1.2  christos         }
    277  1.2  christos 
    278  1.2  christos         if (SourceFile)
    279  1.2  christos         {
    280  1.2  christos             /* Determine if the error occurred at source file EOF */
    281  1.2  christos 
    282  1.2  christos             fseek (SourceFile, 0, SEEK_END);
    283  1.2  christos             FileSize = ftell (SourceFile);
    284  1.2  christos 
    285  1.2  christos             if ((long) Enode->LogicalByteOffset >= FileSize)
    286  1.2  christos             {
    287  1.2  christos                 PrematureEOF = TRUE;
    288  1.2  christos             }
    289  1.2  christos         }
    290  1.2  christos     }
    291  1.1    jruoho 
    292  1.1    jruoho     if (Header)
    293  1.1    jruoho     {
    294  1.1    jruoho         fprintf (OutputFile, "%s", Header);
    295  1.1    jruoho     }
    296  1.1    jruoho 
    297  1.1    jruoho     /* Print filename and line number if present and valid */
    298  1.1    jruoho 
    299  1.1    jruoho     if (Enode->Filename)
    300  1.1    jruoho     {
    301  1.1    jruoho         if (Gbl_VerboseErrors)
    302  1.1    jruoho         {
    303  1.2  christos             fprintf (OutputFile, "%-8s", Enode->Filename);
    304  1.1    jruoho 
    305  1.1    jruoho             if (Enode->LineNumber)
    306  1.1    jruoho             {
    307  1.2  christos                 if (Enode->SourceLine)
    308  1.1    jruoho                 {
    309  1.2  christos                     fprintf (OutputFile, " %6u: %s",
    310  1.2  christos                         Enode->LineNumber, Enode->SourceLine);
    311  1.1    jruoho                 }
    312  1.1    jruoho                 else
    313  1.1    jruoho                 {
    314  1.2  christos                     fprintf (OutputFile, " %6u: ", Enode->LineNumber);
    315  1.2  christos 
    316  1.2  christos                     /*
    317  1.2  christos                      * If not at EOF, get the corresponding source code line and
    318  1.2  christos                      * display it. Don't attempt this if we have a premature EOF
    319  1.2  christos                      * condition.
    320  1.2  christos                      */
    321  1.2  christos                     if (!PrematureEOF)
    322  1.1    jruoho                     {
    323  1.2  christos                         /*
    324  1.2  christos                          * Seek to the offset in the combined source file, read
    325  1.2  christos                          * the source line, and write it to the output.
    326  1.2  christos                          */
    327  1.2  christos                         Actual = fseek (SourceFile, (long) Enode->LogicalByteOffset,
    328  1.2  christos                                     (int) SEEK_SET);
    329  1.2  christos                         if (Actual)
    330  1.2  christos                         {
    331  1.2  christos                             fprintf (OutputFile,
    332  1.2  christos                                 "[*** iASL: Seek error on source code temp file %s ***]",
    333  1.2  christos                                 Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
    334  1.2  christos                         }
    335  1.2  christos                         else
    336  1.2  christos                         {
    337  1.2  christos                             RActual = fread (&SourceByte, 1, 1, SourceFile);
    338  1.2  christos                             if (RActual != 1)
    339  1.2  christos                             {
    340  1.2  christos                                 fprintf (OutputFile,
    341  1.2  christos                                     "[*** iASL: Read error on source code temp file %s ***]",
    342  1.2  christos                                     Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
    343  1.2  christos                             }
    344  1.2  christos                             else
    345  1.2  christos                             {
    346  1.2  christos                                 /* Read/write the source line, up to the maximum line length */
    347  1.2  christos 
    348  1.2  christos                                 while (RActual && SourceByte && (SourceByte != '\n'))
    349  1.2  christos                                 {
    350  1.2  christos                                     if (Total < 256)
    351  1.2  christos                                     {
    352  1.2  christos                                         /* After the max line length, we will just read the line, no write */
    353  1.2  christos 
    354  1.2  christos                                         if (fwrite (&SourceByte, 1, 1, OutputFile) != 1)
    355  1.2  christos                                         {
    356  1.2  christos                                             printf ("[*** iASL: Write error on output file ***]\n");
    357  1.2  christos                                             return;
    358  1.2  christos                                         }
    359  1.2  christos                                     }
    360  1.2  christos                                     else if (Total == 256)
    361  1.2  christos                                     {
    362  1.2  christos                                         fprintf (OutputFile,
    363  1.2  christos                                             "\n[*** iASL: Very long input line, message below refers to column %u ***]",
    364  1.2  christos                                             Enode->Column);
    365  1.2  christos                                     }
    366  1.2  christos 
    367  1.2  christos                                     RActual = fread (&SourceByte, 1, 1, SourceFile);
    368  1.2  christos                                     if (RActual != 1)
    369  1.2  christos                                     {
    370  1.2  christos                                         fprintf (OutputFile,
    371  1.2  christos                                             "[*** iASL: Read error on source code temp file %s ***]",
    372  1.2  christos                                             Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
    373  1.2  christos                                         return;
    374  1.2  christos                                     }
    375  1.2  christos                                     Total++;
    376  1.2  christos                                 }
    377  1.2  christos                             }
    378  1.2  christos                         }
    379  1.1    jruoho                     }
    380  1.1    jruoho 
    381  1.2  christos                     fprintf (OutputFile, "\n");
    382  1.1    jruoho                 }
    383  1.1    jruoho             }
    384  1.1    jruoho         }
    385  1.1    jruoho         else
    386  1.1    jruoho         {
    387  1.2  christos             /*
    388  1.2  christos              * Less verbose version of the error message, enabled via the
    389  1.2  christos              * -vi switch. The format is compatible with MS Visual Studio.
    390  1.2  christos              */
    391  1.1    jruoho             fprintf (OutputFile, "%s", Enode->Filename);
    392  1.1    jruoho 
    393  1.1    jruoho             if (Enode->LineNumber)
    394  1.1    jruoho             {
    395  1.2  christos                 fprintf (OutputFile, "(%u) : ",
    396  1.2  christos                     Enode->LineNumber);
    397  1.1    jruoho             }
    398  1.1    jruoho         }
    399  1.1    jruoho     }
    400  1.1    jruoho 
    401  1.3  christos     /* If a NULL message ID, just print the raw message */
    402  1.1    jruoho 
    403  1.1    jruoho     if (Enode->MessageId == 0)
    404  1.1    jruoho     {
    405  1.1    jruoho         fprintf (OutputFile, "%s\n", Enode->Message);
    406  1.3  christos         return;
    407  1.3  christos     }
    408  1.3  christos 
    409  1.3  christos     /* Decode the message ID */
    410  1.3  christos 
    411  1.3  christos     fprintf (OutputFile, "%s %4.4d -",
    412  1.3  christos         AeDecodeExceptionLevel (Enode->Level),
    413  1.3  christos         AeBuildFullExceptionCode (Enode->Level, Enode->MessageId));
    414  1.3  christos 
    415  1.3  christos     MainMessage = AeDecodeMessageId (Enode->MessageId);
    416  1.3  christos     ExtraMessage = Enode->Message;
    417  1.3  christos 
    418  1.3  christos     /* If a NULL line number, just print the decoded message */
    419  1.3  christos 
    420  1.3  christos     if (!Enode->LineNumber)
    421  1.3  christos     {
    422  1.3  christos         fprintf (OutputFile, " %s %s\n\n", MainMessage, ExtraMessage);
    423  1.3  christos         return;
    424  1.1    jruoho     }
    425  1.3  christos 
    426  1.3  christos     MsgLength = strlen (MainMessage);
    427  1.3  christos     if (MsgLength == 0)
    428  1.1    jruoho     {
    429  1.3  christos         /* Use the secondary/extra message as main message */
    430  1.1    jruoho 
    431  1.3  christos         MainMessage = Enode->Message;
    432  1.3  christos         if (!MainMessage)
    433  1.2  christos         {
    434  1.3  christos             MainMessage = "";
    435  1.2  christos         }
    436  1.3  christos 
    437  1.3  christos         MsgLength = strlen (MainMessage);
    438  1.3  christos         ExtraMessage = NULL;
    439  1.3  christos     }
    440  1.3  christos 
    441  1.3  christos     if (Gbl_VerboseErrors && !PrematureEOF)
    442  1.3  christos     {
    443  1.3  christos         if (Total >= 256)
    444  1.2  christos         {
    445  1.3  christos             fprintf (OutputFile, "    %s",
    446  1.3  christos                 MainMessage);
    447  1.2  christos         }
    448  1.3  christos         else
    449  1.1    jruoho         {
    450  1.3  christos             SourceColumn = Enode->Column + Enode->FilenameLength + 6 + 2;
    451  1.3  christos             ErrorColumn = ASL_ERROR_LEVEL_LENGTH + 5 + 2 + 1;
    452  1.2  christos 
    453  1.3  christos             if ((MsgLength + ErrorColumn) < (SourceColumn - 1))
    454  1.2  christos             {
    455  1.3  christos                 fprintf (OutputFile, "%*s%s",
    456  1.3  christos                     (int) ((SourceColumn - 1) - ErrorColumn),
    457  1.3  christos                     MainMessage, " ^ ");
    458  1.1    jruoho             }
    459  1.1    jruoho             else
    460  1.1    jruoho             {
    461  1.3  christos                 fprintf (OutputFile, "%*s %s",
    462  1.3  christos                     (int) ((SourceColumn - ErrorColumn) + 1), "^",
    463  1.3  christos                     MainMessage);
    464  1.1    jruoho             }
    465  1.3  christos         }
    466  1.3  christos     }
    467  1.3  christos     else
    468  1.3  christos     {
    469  1.3  christos         fprintf (OutputFile, " %s", MainMessage);
    470  1.3  christos     }
    471  1.1    jruoho 
    472  1.3  christos     /* Print the extra info message if present */
    473  1.1    jruoho 
    474  1.3  christos     if (ExtraMessage)
    475  1.3  christos     {
    476  1.3  christos         fprintf (OutputFile, " (%s)", ExtraMessage);
    477  1.3  christos     }
    478  1.1    jruoho 
    479  1.3  christos     if (PrematureEOF)
    480  1.3  christos     {
    481  1.3  christos         fprintf (OutputFile, " and premature End-Of-File");
    482  1.3  christos     }
    483  1.2  christos 
    484  1.3  christos     fprintf (OutputFile, "\n");
    485  1.3  christos     if (Gbl_VerboseErrors)
    486  1.3  christos     {
    487  1.3  christos         fprintf (OutputFile, "\n");
    488  1.1    jruoho     }
    489  1.1    jruoho }
    490  1.1    jruoho 
    491  1.1    jruoho 
    492  1.1    jruoho /*******************************************************************************
    493  1.1    jruoho  *
    494  1.1    jruoho  * FUNCTION:    AePrintErrorLog
    495  1.1    jruoho  *
    496  1.1    jruoho  * PARAMETERS:  FileId           - Where to output the error log
    497  1.1    jruoho  *
    498  1.1    jruoho  * RETURN:      None
    499  1.1    jruoho  *
    500  1.1    jruoho  * DESCRIPTION: Print the entire contents of the error log
    501  1.1    jruoho  *
    502  1.1    jruoho  ******************************************************************************/
    503  1.1    jruoho 
    504  1.1    jruoho void
    505  1.1    jruoho AePrintErrorLog (
    506  1.1    jruoho     UINT32                  FileId)
    507  1.1    jruoho {
    508  1.1    jruoho     ASL_ERROR_MSG           *Enode = Gbl_ErrorLog;
    509  1.1    jruoho 
    510  1.1    jruoho 
    511  1.1    jruoho     /* Walk the error node list */
    512  1.1    jruoho 
    513  1.1    jruoho     while (Enode)
    514  1.1    jruoho     {
    515  1.1    jruoho         AePrintException (FileId, Enode, NULL);
    516  1.1    jruoho         Enode = Enode->Next;
    517  1.1    jruoho     }
    518  1.1    jruoho }
    519  1.1    jruoho 
    520  1.1    jruoho 
    521  1.1    jruoho /*******************************************************************************
    522  1.1    jruoho  *
    523  1.2  christos  * FUNCTION:    AslCommonError2
    524  1.2  christos  *
    525  1.2  christos  * PARAMETERS:  Level               - Seriousness (Warning/error, etc.)
    526  1.2  christos  *              MessageId           - Index into global message buffer
    527  1.2  christos  *              LineNumber          - Actual file line number
    528  1.2  christos  *              Column              - Column in current line
    529  1.2  christos  *              SourceLine          - Actual source code line
    530  1.2  christos  *              Filename            - source filename
    531  1.2  christos  *              ExtraMessage        - additional error message
    532  1.2  christos  *
    533  1.2  christos  * RETURN:      None
    534  1.2  christos  *
    535  1.2  christos  * DESCRIPTION: Create a new error node and add it to the error log
    536  1.2  christos  *
    537  1.2  christos  ******************************************************************************/
    538  1.2  christos 
    539  1.2  christos void
    540  1.2  christos AslCommonError2 (
    541  1.2  christos     UINT8                   Level,
    542  1.3  christos     UINT16                  MessageId,
    543  1.2  christos     UINT32                  LineNumber,
    544  1.2  christos     UINT32                  Column,
    545  1.2  christos     char                    *SourceLine,
    546  1.2  christos     char                    *Filename,
    547  1.2  christos     char                    *ExtraMessage)
    548  1.2  christos {
    549  1.2  christos     char                    *MessageBuffer = NULL;
    550  1.2  christos     char                    *LineBuffer;
    551  1.2  christos     ASL_ERROR_MSG           *Enode;
    552  1.2  christos 
    553  1.2  christos 
    554  1.2  christos     Enode = UtLocalCalloc (sizeof (ASL_ERROR_MSG));
    555  1.2  christos 
    556  1.2  christos     if (ExtraMessage)
    557  1.2  christos     {
    558  1.2  christos         /* Allocate a buffer for the message and a new error node */
    559  1.2  christos 
    560  1.3  christos         MessageBuffer = UtStringCacheCalloc (strlen (ExtraMessage) + 1);
    561  1.2  christos 
    562  1.2  christos         /* Keep a copy of the extra message */
    563  1.2  christos 
    564  1.2  christos         ACPI_STRCPY (MessageBuffer, ExtraMessage);
    565  1.2  christos     }
    566  1.2  christos 
    567  1.2  christos     LineBuffer = UtLocalCalloc (strlen (SourceLine) + 1);
    568  1.2  christos     ACPI_STRCPY (LineBuffer, SourceLine);
    569  1.2  christos 
    570  1.2  christos     /* Initialize the error node */
    571  1.2  christos 
    572  1.2  christos     if (Filename)
    573  1.2  christos     {
    574  1.3  christos         Enode->Filename = Filename;
    575  1.2  christos         Enode->FilenameLength = strlen (Filename);
    576  1.2  christos         if (Enode->FilenameLength < 6)
    577  1.2  christos         {
    578  1.2  christos             Enode->FilenameLength = 6;
    579  1.2  christos         }
    580  1.2  christos     }
    581  1.2  christos 
    582  1.2  christos     Enode->MessageId            = MessageId;
    583  1.2  christos     Enode->Level                = Level;
    584  1.2  christos     Enode->LineNumber           = LineNumber;
    585  1.2  christos     Enode->LogicalLineNumber    = LineNumber;
    586  1.2  christos     Enode->LogicalByteOffset    = 0;
    587  1.2  christos     Enode->Column               = Column;
    588  1.2  christos     Enode->Message              = MessageBuffer;
    589  1.2  christos     Enode->SourceLine           = LineBuffer;
    590  1.2  christos 
    591  1.2  christos     /* Add the new node to the error node list */
    592  1.2  christos 
    593  1.2  christos     AeAddToErrorLog (Enode);
    594  1.2  christos 
    595  1.2  christos     if (Gbl_DebugFlag)
    596  1.2  christos     {
    597  1.2  christos         /* stderr is a file, send error to it immediately */
    598  1.2  christos 
    599  1.2  christos         AePrintException (ASL_FILE_STDERR, Enode, NULL);
    600  1.2  christos     }
    601  1.2  christos 
    602  1.2  christos     Gbl_ExceptionCount[Level]++;
    603  1.2  christos }
    604  1.2  christos 
    605  1.2  christos 
    606  1.2  christos /*******************************************************************************
    607  1.2  christos  *
    608  1.1    jruoho  * FUNCTION:    AslCommonError
    609  1.1    jruoho  *
    610  1.1    jruoho  * PARAMETERS:  Level               - Seriousness (Warning/error, etc.)
    611  1.1    jruoho  *              MessageId           - Index into global message buffer
    612  1.1    jruoho  *              CurrentLineNumber   - Actual file line number
    613  1.1    jruoho  *              LogicalLineNumber   - Cumulative line number
    614  1.1    jruoho  *              LogicalByteOffset   - Byte offset in source file
    615  1.1    jruoho  *              Column              - Column in current line
    616  1.1    jruoho  *              Filename            - source filename
    617  1.1    jruoho  *              ExtraMessage        - additional error message
    618  1.1    jruoho  *
    619  1.1    jruoho  * RETURN:      None
    620  1.1    jruoho  *
    621  1.1    jruoho  * DESCRIPTION: Create a new error node and add it to the error log
    622  1.1    jruoho  *
    623  1.1    jruoho  ******************************************************************************/
    624  1.1    jruoho 
    625  1.1    jruoho void
    626  1.1    jruoho AslCommonError (
    627  1.1    jruoho     UINT8                   Level,
    628  1.3  christos     UINT16                  MessageId,
    629  1.1    jruoho     UINT32                  CurrentLineNumber,
    630  1.1    jruoho     UINT32                  LogicalLineNumber,
    631  1.1    jruoho     UINT32                  LogicalByteOffset,
    632  1.1    jruoho     UINT32                  Column,
    633  1.1    jruoho     char                    *Filename,
    634  1.1    jruoho     char                    *ExtraMessage)
    635  1.1    jruoho {
    636  1.1    jruoho     char                    *MessageBuffer = NULL;
    637  1.1    jruoho     ASL_ERROR_MSG           *Enode;
    638  1.1    jruoho 
    639  1.1    jruoho 
    640  1.1    jruoho     Enode = UtLocalCalloc (sizeof (ASL_ERROR_MSG));
    641  1.1    jruoho 
    642  1.1    jruoho     if (ExtraMessage)
    643  1.1    jruoho     {
    644  1.1    jruoho         /* Allocate a buffer for the message and a new error node */
    645  1.1    jruoho 
    646  1.3  christos         MessageBuffer = UtStringCacheCalloc (strlen (ExtraMessage) + 1);
    647  1.1    jruoho 
    648  1.1    jruoho         /* Keep a copy of the extra message */
    649  1.1    jruoho 
    650  1.1    jruoho         ACPI_STRCPY (MessageBuffer, ExtraMessage);
    651  1.1    jruoho     }
    652  1.1    jruoho 
    653  1.1    jruoho     /* Initialize the error node */
    654  1.1    jruoho 
    655  1.1    jruoho     if (Filename)
    656  1.1    jruoho     {
    657  1.3  christos         Enode->Filename = Filename;
    658  1.1    jruoho         Enode->FilenameLength = strlen (Filename);
    659  1.1    jruoho         if (Enode->FilenameLength < 6)
    660  1.1    jruoho         {
    661  1.1    jruoho             Enode->FilenameLength = 6;
    662  1.1    jruoho         }
    663  1.1    jruoho     }
    664  1.1    jruoho 
    665  1.1    jruoho     Enode->MessageId            = MessageId;
    666  1.1    jruoho     Enode->Level                = Level;
    667  1.1    jruoho     Enode->LineNumber           = CurrentLineNumber;
    668  1.1    jruoho     Enode->LogicalLineNumber    = LogicalLineNumber;
    669  1.1    jruoho     Enode->LogicalByteOffset    = LogicalByteOffset;
    670  1.1    jruoho     Enode->Column               = Column;
    671  1.1    jruoho     Enode->Message              = MessageBuffer;
    672  1.2  christos     Enode->SourceLine           = NULL;
    673  1.1    jruoho 
    674  1.1    jruoho     /* Add the new node to the error node list */
    675  1.1    jruoho 
    676  1.1    jruoho     AeAddToErrorLog (Enode);
    677  1.1    jruoho 
    678  1.1    jruoho     if (Gbl_DebugFlag)
    679  1.1    jruoho     {
    680  1.1    jruoho         /* stderr is a file, send error to it immediately */
    681  1.1    jruoho 
    682  1.1    jruoho         AePrintException (ASL_FILE_STDERR, Enode, NULL);
    683  1.1    jruoho     }
    684  1.1    jruoho 
    685  1.1    jruoho     Gbl_ExceptionCount[Level]++;
    686  1.1    jruoho     if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
    687  1.1    jruoho     {
    688  1.1    jruoho         printf ("\nMaximum error count (%u) exceeded\n", ASL_MAX_ERROR_COUNT);
    689  1.1    jruoho 
    690  1.1    jruoho         Gbl_SourceLine = 0;
    691  1.1    jruoho         Gbl_NextError = Gbl_ErrorLog;
    692  1.1    jruoho         CmCleanupAndExit ();
    693  1.1    jruoho         exit(1);
    694  1.1    jruoho     }
    695  1.1    jruoho 
    696  1.1    jruoho     return;
    697  1.1    jruoho }
    698  1.1    jruoho 
    699  1.1    jruoho 
    700  1.1    jruoho /*******************************************************************************
    701  1.1    jruoho  *
    702  1.2  christos  * FUNCTION:    AslDisableException
    703  1.2  christos  *
    704  1.2  christos  * PARAMETERS:  MessageIdString     - ID to be disabled
    705  1.2  christos  *
    706  1.2  christos  * RETURN:      Status
    707  1.2  christos  *
    708  1.2  christos  * DESCRIPTION: Enter a message ID into the global disabled messages table
    709  1.2  christos  *
    710  1.2  christos  ******************************************************************************/
    711  1.2  christos 
    712  1.2  christos ACPI_STATUS
    713  1.2  christos AslDisableException (
    714  1.2  christos     char                    *MessageIdString)
    715  1.2  christos {
    716  1.2  christos     UINT32                  MessageId;
    717  1.2  christos 
    718  1.2  christos 
    719  1.2  christos     /* Convert argument to an integer and validate it */
    720  1.2  christos 
    721  1.2  christos     MessageId = (UINT32) strtoul (MessageIdString, NULL, 0);
    722  1.2  christos 
    723  1.2  christos     if ((MessageId < 2000) || (MessageId > 5999))
    724  1.2  christos     {
    725  1.2  christos         printf ("\"%s\" is not a valid warning/remark ID\n",
    726  1.2  christos             MessageIdString);
    727  1.2  christos         return (AE_BAD_PARAMETER);
    728  1.2  christos     }
    729  1.2  christos 
    730  1.2  christos     /* Insert value into the global disabled message array */
    731  1.2  christos 
    732  1.2  christos     if (Gbl_DisabledMessagesIndex >= ASL_MAX_DISABLED_MESSAGES)
    733  1.2  christos     {
    734  1.2  christos         printf ("Too many messages have been disabled (max %u)\n",
    735  1.2  christos             ASL_MAX_DISABLED_MESSAGES);
    736  1.2  christos         return (AE_LIMIT);
    737  1.2  christos     }
    738  1.2  christos 
    739  1.2  christos     Gbl_DisabledMessages[Gbl_DisabledMessagesIndex] = MessageId;
    740  1.2  christos     Gbl_DisabledMessagesIndex++;
    741  1.2  christos     return (AE_OK);
    742  1.2  christos }
    743  1.2  christos 
    744  1.2  christos 
    745  1.2  christos /*******************************************************************************
    746  1.2  christos  *
    747  1.2  christos  * FUNCTION:    AslIsExceptionDisabled
    748  1.2  christos  *
    749  1.2  christos  * PARAMETERS:  Level               - Seriousness (Warning/error, etc.)
    750  1.2  christos  *              MessageId           - Index into global message buffer
    751  1.2  christos  *
    752  1.2  christos  * RETURN:      TRUE if exception/message should be ignored
    753  1.2  christos  *
    754  1.2  christos  * DESCRIPTION: Check if the user has specified options such that this
    755  1.2  christos  *              exception should be ignored
    756  1.2  christos  *
    757  1.2  christos  ******************************************************************************/
    758  1.2  christos 
    759  1.2  christos BOOLEAN
    760  1.2  christos AslIsExceptionDisabled (
    761  1.2  christos     UINT8                   Level,
    762  1.3  christos     UINT16                  MessageId)
    763  1.2  christos {
    764  1.2  christos     UINT32                  EncodedMessageId;
    765  1.2  christos     UINT32                  i;
    766  1.2  christos 
    767  1.2  christos 
    768  1.2  christos     switch (Level)
    769  1.2  christos     {
    770  1.2  christos     case ASL_WARNING2:
    771  1.2  christos     case ASL_WARNING3:
    772  1.2  christos 
    773  1.2  christos         /* Check for global disable via -w1/-w2/-w3 options */
    774  1.2  christos 
    775  1.2  christos         if (Level > Gbl_WarningLevel)
    776  1.2  christos         {
    777  1.2  christos             return (TRUE);
    778  1.2  christos         }
    779  1.2  christos         /* Fall through */
    780  1.2  christos 
    781  1.2  christos     case ASL_WARNING:
    782  1.2  christos     case ASL_REMARK:
    783  1.2  christos         /*
    784  1.2  christos          * Ignore this warning/remark if it has been disabled by
    785  1.2  christos          * the user (-vw option)
    786  1.2  christos          */
    787  1.3  christos         EncodedMessageId = AeBuildFullExceptionCode (Level, MessageId);
    788  1.2  christos         for (i = 0; i < Gbl_DisabledMessagesIndex; i++)
    789  1.2  christos         {
    790  1.2  christos             /* Simple implementation via fixed array */
    791  1.2  christos 
    792  1.2  christos             if (EncodedMessageId == Gbl_DisabledMessages[i])
    793  1.2  christos             {
    794  1.2  christos                 return (TRUE);
    795  1.2  christos             }
    796  1.2  christos         }
    797  1.2  christos         break;
    798  1.2  christos 
    799  1.2  christos     default:
    800  1.2  christos         break;
    801  1.2  christos     }
    802  1.2  christos 
    803  1.2  christos     return (FALSE);
    804  1.2  christos }
    805  1.2  christos 
    806  1.2  christos 
    807  1.2  christos /*******************************************************************************
    808  1.2  christos  *
    809  1.1    jruoho  * FUNCTION:    AslError
    810  1.1    jruoho  *
    811  1.1    jruoho  * PARAMETERS:  Level               - Seriousness (Warning/error, etc.)
    812  1.1    jruoho  *              MessageId           - Index into global message buffer
    813  1.1    jruoho  *              Op                  - Parse node where error happened
    814  1.1    jruoho  *              ExtraMessage        - additional error message
    815  1.1    jruoho  *
    816  1.1    jruoho  * RETURN:      None
    817  1.1    jruoho  *
    818  1.1    jruoho  * DESCRIPTION: Main error reporting routine for the ASL compiler (all code
    819  1.1    jruoho  *              except the parser.)
    820  1.1    jruoho  *
    821  1.1    jruoho  ******************************************************************************/
    822  1.1    jruoho 
    823  1.1    jruoho void
    824  1.1    jruoho AslError (
    825  1.1    jruoho     UINT8                   Level,
    826  1.3  christos     UINT16                  MessageId,
    827  1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
    828  1.1    jruoho     char                    *ExtraMessage)
    829  1.1    jruoho {
    830  1.1    jruoho 
    831  1.2  christos     /* Check if user wants to ignore this exception */
    832  1.2  christos 
    833  1.3  christos     if (Gbl_AllExceptionsDisabled ||
    834  1.3  christos         AslIsExceptionDisabled (Level, MessageId))
    835  1.1    jruoho     {
    836  1.2  christos         return;
    837  1.1    jruoho     }
    838  1.1    jruoho 
    839  1.1    jruoho     if (Op)
    840  1.1    jruoho     {
    841  1.1    jruoho         AslCommonError (Level, MessageId, Op->Asl.LineNumber,
    842  1.2  christos             Op->Asl.LogicalLineNumber,
    843  1.2  christos             Op->Asl.LogicalByteOffset,
    844  1.2  christos             Op->Asl.Column,
    845  1.2  christos             Op->Asl.Filename, ExtraMessage);
    846  1.1    jruoho     }
    847  1.1    jruoho     else
    848  1.1    jruoho     {
    849  1.1    jruoho         AslCommonError (Level, MessageId, 0,
    850  1.2  christos             0, 0, 0, NULL, ExtraMessage);
    851  1.1    jruoho     }
    852  1.1    jruoho }
    853  1.1    jruoho 
    854  1.1    jruoho 
    855  1.1    jruoho /*******************************************************************************
    856  1.1    jruoho  *
    857  1.1    jruoho  * FUNCTION:    AslCoreSubsystemError
    858  1.1    jruoho  *
    859  1.1    jruoho  * PARAMETERS:  Op                  - Parse node where error happened
    860  1.3  christos  *              Status              - The ACPICA Exception
    861  1.1    jruoho  *              ExtraMessage        - additional error message
    862  1.1    jruoho  *              Abort               - TRUE -> Abort compilation
    863  1.1    jruoho  *
    864  1.1    jruoho  * RETURN:      None
    865  1.1    jruoho  *
    866  1.3  christos  * DESCRIPTION: Error reporting routine for exceptions returned by the ACPICA
    867  1.3  christos  *              core subsystem.
    868  1.1    jruoho  *
    869  1.1    jruoho  ******************************************************************************/
    870  1.1    jruoho 
    871  1.1    jruoho void
    872  1.1    jruoho AslCoreSubsystemError (
    873  1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
    874  1.1    jruoho     ACPI_STATUS             Status,
    875  1.1    jruoho     char                    *ExtraMessage,
    876  1.1    jruoho     BOOLEAN                 Abort)
    877  1.1    jruoho {
    878  1.1    jruoho 
    879  1.2  christos     snprintf (MsgBuffer, sizeof(MsgBuffer), "%s %s", AcpiFormatException (Status), ExtraMessage);
    880  1.1    jruoho 
    881  1.1    jruoho     if (Op)
    882  1.1    jruoho     {
    883  1.1    jruoho         AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, Op->Asl.LineNumber,
    884  1.1    jruoho                         Op->Asl.LogicalLineNumber,
    885  1.1    jruoho                         Op->Asl.LogicalByteOffset,
    886  1.1    jruoho                         Op->Asl.Column,
    887  1.1    jruoho                         Op->Asl.Filename, MsgBuffer);
    888  1.1    jruoho     }
    889  1.1    jruoho     else
    890  1.1    jruoho     {
    891  1.1    jruoho         AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, 0,
    892  1.1    jruoho                         0, 0, 0, NULL, MsgBuffer);
    893  1.1    jruoho     }
    894  1.1    jruoho 
    895  1.1    jruoho     if (Abort)
    896  1.1    jruoho     {
    897  1.1    jruoho         AslAbort ();
    898  1.1    jruoho     }
    899  1.1    jruoho }
    900  1.1    jruoho 
    901  1.1    jruoho 
    902  1.1    jruoho /*******************************************************************************
    903  1.1    jruoho  *
    904  1.1    jruoho  * FUNCTION:    AslCompilererror
    905  1.1    jruoho  *
    906  1.1    jruoho  * PARAMETERS:  CompilerMessage         - Error message from the parser
    907  1.1    jruoho  *
    908  1.1    jruoho  * RETURN:      Status (0 for now)
    909  1.1    jruoho  *
    910  1.1    jruoho  * DESCRIPTION: Report an error situation discovered in a production
    911  1.1    jruoho  *              NOTE: don't change the name of this function, it is called
    912  1.1    jruoho  *              from the auto-generated parser.
    913  1.1    jruoho  *
    914  1.1    jruoho  ******************************************************************************/
    915  1.1    jruoho 
    916  1.1    jruoho int
    917  1.1    jruoho AslCompilererror (
    918  1.2  christos     const char              *CompilerMessage)
    919  1.1    jruoho {
    920  1.1    jruoho 
    921  1.1    jruoho     AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, Gbl_CurrentLineNumber,
    922  1.2  christos         Gbl_LogicalLineNumber, Gbl_CurrentLineOffset,
    923  1.2  christos         Gbl_CurrentColumn, Gbl_Files[ASL_FILE_INPUT].Filename,
    924  1.2  christos         ACPI_CAST_PTR (char, CompilerMessage));
    925  1.1    jruoho 
    926  1.2  christos     return (0);
    927  1.1    jruoho }
    928