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