Home | History | Annotate | Line # | Download | only in debugger
dbxface.c revision 1.1.1.2
      1 /*******************************************************************************
      2  *
      3  * Module Name: dbxface - AML Debugger external interfaces
      4  *
      5  ******************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2011, Intel Corp.
      9  * All rights reserved.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions, and the following disclaimer,
     16  *    without modification.
     17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  *    including a substantially similar Disclaimer requirement for further
     21  *    binary redistribution.
     22  * 3. Neither the names of the above-listed copyright holders nor the names
     23  *    of any contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * Alternatively, this software may be distributed under the terms of the
     27  * GNU General Public License ("GPL") version 2 as published by the Free
     28  * Software Foundation.
     29  *
     30  * NO WARRANTY
     31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  * POSSIBILITY OF SUCH DAMAGES.
     42  */
     43 
     44 
     45 #include "acpi.h"
     46 #include "accommon.h"
     47 #include "amlcode.h"
     48 #include "acdebug.h"
     49 #include "acdisasm.h"
     50 
     51 
     52 #ifdef ACPI_DEBUGGER
     53 
     54 #define _COMPONENT          ACPI_CA_DEBUGGER
     55         ACPI_MODULE_NAME    ("dbxface")
     56 
     57 
     58 /* Local prototypes */
     59 
     60 static ACPI_STATUS
     61 AcpiDbStartCommand (
     62     ACPI_WALK_STATE         *WalkState,
     63     ACPI_PARSE_OBJECT       *Op);
     64 
     65 #ifdef ACPI_OBSOLETE_FUNCTIONS
     66 void
     67 AcpiDbMethodEnd (
     68     ACPI_WALK_STATE         *WalkState);
     69 #endif
     70 
     71 
     72 /*******************************************************************************
     73  *
     74  * FUNCTION:    AcpiDbStartCommand
     75  *
     76  * PARAMETERS:  WalkState       - Current walk
     77  *              Op              - Current executing Op, from AML interpreter
     78  *
     79  * RETURN:      Status
     80  *
     81  * DESCRIPTION: Enter debugger command loop
     82  *
     83  ******************************************************************************/
     84 
     85 static ACPI_STATUS
     86 AcpiDbStartCommand (
     87     ACPI_WALK_STATE         *WalkState,
     88     ACPI_PARSE_OBJECT       *Op)
     89 {
     90     ACPI_STATUS             Status;
     91 
     92 
     93     /* TBD: [Investigate] are there namespace locking issues here? */
     94 
     95     /* AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); */
     96 
     97     /* Go into the command loop and await next user command */
     98 
     99 
    100     AcpiGbl_MethodExecuting = TRUE;
    101     Status = AE_CTRL_TRUE;
    102     while (Status == AE_CTRL_TRUE)
    103     {
    104         if (AcpiGbl_DebuggerConfiguration == DEBUGGER_MULTI_THREADED)
    105         {
    106             /* Handshake with the front-end that gets user command lines */
    107 
    108             Status = AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
    109             if (ACPI_FAILURE (Status))
    110             {
    111                 return (Status);
    112             }
    113             Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_READY);
    114             if (ACPI_FAILURE (Status))
    115             {
    116                 return (Status);
    117             }
    118         }
    119         else
    120         {
    121             /* Single threaded, we must get a command line ourselves */
    122 
    123             /* Force output to console until a command is entered */
    124 
    125             AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
    126 
    127             /* Different prompt if method is executing */
    128 
    129             if (!AcpiGbl_MethodExecuting)
    130             {
    131                 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
    132             }
    133             else
    134             {
    135                 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
    136             }
    137 
    138             /* Get the user input line */
    139 
    140             (void) AcpiOsGetLine (AcpiGbl_DbLineBuf);
    141         }
    142 
    143         Status = AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, WalkState, Op);
    144     }
    145 
    146     /* AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); */
    147 
    148     return (Status);
    149 }
    150 
    151 
    152 /*******************************************************************************
    153  *
    154  * FUNCTION:    AcpiDbSingleStep
    155  *
    156  * PARAMETERS:  WalkState       - Current walk
    157  *              Op              - Current executing op (from aml interpreter)
    158  *              OpcodeClass     - Class of the current AML Opcode
    159  *
    160  * RETURN:      Status
    161  *
    162  * DESCRIPTION: Called just before execution of an AML opcode.
    163  *
    164  ******************************************************************************/
    165 
    166 ACPI_STATUS
    167 AcpiDbSingleStep (
    168     ACPI_WALK_STATE         *WalkState,
    169     ACPI_PARSE_OBJECT       *Op,
    170     UINT32                  OpcodeClass)
    171 {
    172     ACPI_PARSE_OBJECT       *Next;
    173     ACPI_STATUS             Status = AE_OK;
    174     UINT32                  OriginalDebugLevel;
    175     ACPI_PARSE_OBJECT       *DisplayOp;
    176     ACPI_PARSE_OBJECT       *ParentOp;
    177 
    178 
    179     ACPI_FUNCTION_ENTRY ();
    180 
    181 
    182     /* Check the abort flag */
    183 
    184     if (AcpiGbl_AbortMethod)
    185     {
    186         AcpiGbl_AbortMethod = FALSE;
    187         return (AE_ABORT_METHOD);
    188     }
    189 
    190     /* Check for single-step breakpoint */
    191 
    192     if (WalkState->MethodBreakpoint &&
    193        (WalkState->MethodBreakpoint <= Op->Common.AmlOffset))
    194     {
    195         /* Check if the breakpoint has been reached or passed */
    196         /* Hit the breakpoint, resume single step, reset breakpoint */
    197 
    198         AcpiOsPrintf ("***Break*** at AML offset %X\n", Op->Common.AmlOffset);
    199         AcpiGbl_CmSingleStep = TRUE;
    200         AcpiGbl_StepToNextCall = FALSE;
    201         WalkState->MethodBreakpoint = 0;
    202     }
    203 
    204     /* Check for user breakpoint (Must be on exact Aml offset) */
    205 
    206     else if (WalkState->UserBreakpoint &&
    207             (WalkState->UserBreakpoint == Op->Common.AmlOffset))
    208     {
    209         AcpiOsPrintf ("***UserBreakpoint*** at AML offset %X\n",
    210             Op->Common.AmlOffset);
    211         AcpiGbl_CmSingleStep = TRUE;
    212         AcpiGbl_StepToNextCall = FALSE;
    213         WalkState->MethodBreakpoint = 0;
    214     }
    215 
    216     /*
    217      * Check if this is an opcode that we are interested in --
    218      * namely, opcodes that have arguments
    219      */
    220     if (Op->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
    221     {
    222         return (AE_OK);
    223     }
    224 
    225     switch (OpcodeClass)
    226     {
    227     case AML_CLASS_UNKNOWN:
    228     case AML_CLASS_ARGUMENT:    /* constants, literals, etc.  do nothing */
    229         return (AE_OK);
    230 
    231     default:
    232         /* All other opcodes -- continue */
    233         break;
    234     }
    235 
    236     /*
    237      * Under certain debug conditions, display this opcode and its operands
    238      */
    239     if ((AcpiGbl_DbOutputToFile)            ||
    240         (AcpiGbl_CmSingleStep)              ||
    241         (AcpiDbgLevel & ACPI_LV_PARSE))
    242     {
    243         if ((AcpiGbl_DbOutputToFile)        ||
    244             (AcpiDbgLevel & ACPI_LV_PARSE))
    245         {
    246             AcpiOsPrintf ("\n[AmlDebug] Next AML Opcode to execute:\n");
    247         }
    248 
    249         /*
    250          * Display this op (and only this op - zero out the NEXT field
    251          * temporarily, and disable parser trace output for the duration of
    252          * the display because we don't want the extraneous debug output)
    253          */
    254         OriginalDebugLevel = AcpiDbgLevel;
    255         AcpiDbgLevel &= ~(ACPI_LV_PARSE | ACPI_LV_FUNCTIONS);
    256         Next = Op->Common.Next;
    257         Op->Common.Next = NULL;
    258 
    259 
    260         DisplayOp = Op;
    261         ParentOp = Op->Common.Parent;
    262         if (ParentOp)
    263         {
    264             if ((WalkState->ControlState) &&
    265                 (WalkState->ControlState->Common.State ==
    266                     ACPI_CONTROL_PREDICATE_EXECUTING))
    267             {
    268                 /*
    269                  * We are executing the predicate of an IF or WHILE statement
    270                  * Search upwards for the containing IF or WHILE so that the
    271                  * entire predicate can be displayed.
    272                  */
    273                 while (ParentOp)
    274                 {
    275                     if ((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
    276                         (ParentOp->Common.AmlOpcode == AML_WHILE_OP))
    277                     {
    278                         DisplayOp = ParentOp;
    279                         break;
    280                     }
    281                     ParentOp = ParentOp->Common.Parent;
    282                 }
    283             }
    284             else
    285             {
    286                 while (ParentOp)
    287                 {
    288                     if ((ParentOp->Common.AmlOpcode == AML_IF_OP)     ||
    289                         (ParentOp->Common.AmlOpcode == AML_ELSE_OP)   ||
    290                         (ParentOp->Common.AmlOpcode == AML_SCOPE_OP)  ||
    291                         (ParentOp->Common.AmlOpcode == AML_METHOD_OP) ||
    292                         (ParentOp->Common.AmlOpcode == AML_WHILE_OP))
    293                     {
    294                         break;
    295                     }
    296                     DisplayOp = ParentOp;
    297                     ParentOp = ParentOp->Common.Parent;
    298                 }
    299             }
    300         }
    301 
    302         /* Now we can display it */
    303 
    304         AcpiDmDisassemble (WalkState, DisplayOp, ACPI_UINT32_MAX);
    305 
    306         if ((Op->Common.AmlOpcode == AML_IF_OP) ||
    307             (Op->Common.AmlOpcode == AML_WHILE_OP))
    308         {
    309             if (WalkState->ControlState->Common.Value)
    310             {
    311                 AcpiOsPrintf ("Predicate = [True], IF block was executed\n");
    312             }
    313             else
    314             {
    315                 AcpiOsPrintf ("Predicate = [False], Skipping IF block\n");
    316             }
    317         }
    318         else if (Op->Common.AmlOpcode == AML_ELSE_OP)
    319         {
    320             AcpiOsPrintf ("Predicate = [False], ELSE block was executed\n");
    321         }
    322 
    323         /* Restore everything */
    324 
    325         Op->Common.Next = Next;
    326         AcpiOsPrintf ("\n");
    327         if ((AcpiGbl_DbOutputToFile)        ||
    328             (AcpiDbgLevel & ACPI_LV_PARSE))
    329         {
    330             AcpiOsPrintf ("\n");
    331         }
    332         AcpiDbgLevel = OriginalDebugLevel;
    333     }
    334 
    335     /* If we are not single stepping, just continue executing the method */
    336 
    337     if (!AcpiGbl_CmSingleStep)
    338     {
    339         return (AE_OK);
    340     }
    341 
    342     /*
    343      * If we are executing a step-to-call command,
    344      * Check if this is a method call.
    345      */
    346     if (AcpiGbl_StepToNextCall)
    347     {
    348         if (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP)
    349         {
    350             /* Not a method call, just keep executing */
    351 
    352             return (AE_OK);
    353         }
    354 
    355         /* Found a method call, stop executing */
    356 
    357         AcpiGbl_StepToNextCall = FALSE;
    358     }
    359 
    360     /*
    361      * If the next opcode is a method call, we will "step over" it
    362      * by default.
    363      */
    364     if (Op->Common.AmlOpcode == AML_INT_METHODCALL_OP)
    365     {
    366         /* Force no more single stepping while executing called method */
    367 
    368         AcpiGbl_CmSingleStep = FALSE;
    369 
    370         /*
    371          * Set the breakpoint on/before the call, it will stop execution
    372          * as soon as we return
    373          */
    374         WalkState->MethodBreakpoint = 1;  /* Must be non-zero! */
    375     }
    376 
    377 
    378     Status = AcpiDbStartCommand (WalkState, Op);
    379 
    380     /* User commands complete, continue execution of the interrupted method */
    381 
    382     return (Status);
    383 }
    384 
    385 
    386 /*******************************************************************************
    387  *
    388  * FUNCTION:    AcpiDbInitialize
    389  *
    390  * PARAMETERS:  None
    391  *
    392  * RETURN:      Status
    393  *
    394  * DESCRIPTION: Init and start debugger
    395  *
    396  ******************************************************************************/
    397 
    398 ACPI_STATUS
    399 AcpiDbInitialize (
    400     void)
    401 {
    402     ACPI_STATUS             Status;
    403 
    404 
    405     /* Init globals */
    406 
    407     AcpiGbl_DbBuffer            = NULL;
    408     AcpiGbl_DbFilename          = NULL;
    409     AcpiGbl_DbOutputToFile      = FALSE;
    410 
    411     AcpiGbl_DbDebugLevel        = ACPI_LV_VERBOSITY2;
    412     AcpiGbl_DbConsoleDebugLevel = ACPI_NORMAL_DEFAULT | ACPI_LV_TABLES;
    413     AcpiGbl_DbOutputFlags       = ACPI_DB_CONSOLE_OUTPUT;
    414 
    415     AcpiGbl_DbOpt_tables        = FALSE;
    416     AcpiGbl_DbOpt_disasm        = FALSE;
    417     AcpiGbl_DbOpt_stats         = FALSE;
    418     AcpiGbl_DbOpt_verbose       = TRUE;
    419     AcpiGbl_DbOpt_ini_methods   = TRUE;
    420 
    421     AcpiGbl_DbBuffer = AcpiOsAllocate (ACPI_DEBUG_BUFFER_SIZE);
    422     if (!AcpiGbl_DbBuffer)
    423     {
    424         return (AE_NO_MEMORY);
    425     }
    426     ACPI_MEMSET (AcpiGbl_DbBuffer, 0, ACPI_DEBUG_BUFFER_SIZE);
    427 
    428     /* Initial scope is the root */
    429 
    430     AcpiGbl_DbScopeBuf [0] = '\\';
    431     AcpiGbl_DbScopeBuf [1] =  0;
    432     AcpiGbl_DbScopeNode = AcpiGbl_RootNode;
    433 
    434     /*
    435      * If configured for multi-thread support, the debug executor runs in
    436      * a separate thread so that the front end can be in another address
    437      * space, environment, or even another machine.
    438      */
    439     if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
    440     {
    441         /* These were created with one unit, grab it */
    442 
    443         Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
    444         if (ACPI_FAILURE (Status))
    445         {
    446             AcpiOsPrintf ("Could not get debugger mutex\n");
    447             return (Status);
    448         }
    449 
    450         Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_READY);
    451         if (ACPI_FAILURE (Status))
    452         {
    453             AcpiOsPrintf ("Could not get debugger mutex\n");
    454             return (Status);
    455         }
    456 
    457         /* Create the debug execution thread to execute commands */
    458 
    459         Status = AcpiOsExecute (OSL_DEBUGGER_THREAD, AcpiDbExecuteThread, NULL);
    460         if (ACPI_FAILURE (Status))
    461         {
    462             AcpiOsPrintf ("Could not start debugger thread\n");
    463             return (Status);
    464         }
    465     }
    466 
    467     if (!AcpiGbl_DbOpt_verbose)
    468     {
    469         AcpiGbl_DbOpt_disasm = TRUE;
    470         AcpiGbl_DbOpt_stats = FALSE;
    471     }
    472 
    473     return (AE_OK);
    474 }
    475 
    476 
    477 /*******************************************************************************
    478  *
    479  * FUNCTION:    AcpiDbTerminate
    480  *
    481  * PARAMETERS:  None
    482  *
    483  * RETURN:      None
    484  *
    485  * DESCRIPTION: Stop debugger
    486  *
    487  ******************************************************************************/
    488 
    489 void
    490 AcpiDbTerminate (
    491     void)
    492 {
    493 
    494     if (AcpiGbl_DbBuffer)
    495     {
    496         AcpiOsFree (AcpiGbl_DbBuffer);
    497     }
    498 }
    499 
    500 
    501 #ifdef ACPI_OBSOLETE_FUNCTIONS
    502 /*******************************************************************************
    503  *
    504  * FUNCTION:    AcpiDbMethodEnd
    505  *
    506  * PARAMETERS:  WalkState       - Current walk
    507  *
    508  * RETURN:      Status
    509  *
    510  * DESCRIPTION: Called at method termination
    511  *
    512  ******************************************************************************/
    513 
    514 void
    515 AcpiDbMethodEnd (
    516     ACPI_WALK_STATE         *WalkState)
    517 {
    518 
    519     if (!AcpiGbl_CmSingleStep)
    520     {
    521         return;
    522     }
    523 
    524     AcpiOsPrintf ("<Method Terminating>\n");
    525 
    526     AcpiDbStartCommand (WalkState, NULL);
    527 }
    528 #endif
    529 
    530 #endif /* ACPI_DEBUGGER */
    531