Home | History | Annotate | Line # | Download | only in debugger
dbmethod.c revision 1.6
      1  1.1    jruoho /*******************************************************************************
      2  1.1    jruoho  *
      3  1.1    jruoho  * Module Name: dbmethod - Debug commands for control methods
      4  1.1    jruoho  *
      5  1.1    jruoho  ******************************************************************************/
      6  1.1    jruoho 
      7  1.1    jruoho /*
      8  1.6  christos  * Copyright (C) 2000 - 2016, Intel Corp.
      9  1.1    jruoho  * All rights reserved.
     10  1.1    jruoho  *
     11  1.1    jruoho  * Redistribution and use in source and binary forms, with or without
     12  1.1    jruoho  * modification, are permitted provided that the following conditions
     13  1.1    jruoho  * are met:
     14  1.1    jruoho  * 1. Redistributions of source code must retain the above copyright
     15  1.1    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16  1.1    jruoho  *    without modification.
     17  1.1    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.1    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.1    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.1    jruoho  *    including a substantially similar Disclaimer requirement for further
     21  1.1    jruoho  *    binary redistribution.
     22  1.1    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.1    jruoho  *    of any contributors may be used to endorse or promote products derived
     24  1.1    jruoho  *    from this software without specific prior written permission.
     25  1.1    jruoho  *
     26  1.1    jruoho  * Alternatively, this software may be distributed under the terms of the
     27  1.1    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.1    jruoho  * Software Foundation.
     29  1.1    jruoho  *
     30  1.1    jruoho  * NO WARRANTY
     31  1.1    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.1    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.1    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.1    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.1    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.1    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.1    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.1    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.1    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.1    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42  1.1    jruoho  */
     43  1.1    jruoho 
     44  1.1    jruoho #include "acpi.h"
     45  1.1    jruoho #include "accommon.h"
     46  1.1    jruoho #include "acdispat.h"
     47  1.1    jruoho #include "acnamesp.h"
     48  1.1    jruoho #include "acdebug.h"
     49  1.1    jruoho #include "acparser.h"
     50  1.2  christos #include "acpredef.h"
     51  1.1    jruoho 
     52  1.1    jruoho 
     53  1.1    jruoho #define _COMPONENT          ACPI_CA_DEBUGGER
     54  1.1    jruoho         ACPI_MODULE_NAME    ("dbmethod")
     55  1.1    jruoho 
     56  1.1    jruoho 
     57  1.1    jruoho /*******************************************************************************
     58  1.1    jruoho  *
     59  1.1    jruoho  * FUNCTION:    AcpiDbSetMethodBreakpoint
     60  1.1    jruoho  *
     61  1.1    jruoho  * PARAMETERS:  Location            - AML offset of breakpoint
     62  1.1    jruoho  *              WalkState           - Current walk info
     63  1.1    jruoho  *              Op                  - Current Op (from parse walk)
     64  1.1    jruoho  *
     65  1.1    jruoho  * RETURN:      None
     66  1.1    jruoho  *
     67  1.1    jruoho  * DESCRIPTION: Set a breakpoint in a control method at the specified
     68  1.1    jruoho  *              AML offset
     69  1.1    jruoho  *
     70  1.1    jruoho  ******************************************************************************/
     71  1.1    jruoho 
     72  1.1    jruoho void
     73  1.1    jruoho AcpiDbSetMethodBreakpoint (
     74  1.1    jruoho     char                    *Location,
     75  1.1    jruoho     ACPI_WALK_STATE         *WalkState,
     76  1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
     77  1.1    jruoho {
     78  1.1    jruoho     UINT32                  Address;
     79  1.5  christos     UINT32                  AmlOffset;
     80  1.1    jruoho 
     81  1.1    jruoho 
     82  1.1    jruoho     if (!Op)
     83  1.1    jruoho     {
     84  1.1    jruoho         AcpiOsPrintf ("There is no method currently executing\n");
     85  1.1    jruoho         return;
     86  1.1    jruoho     }
     87  1.1    jruoho 
     88  1.1    jruoho     /* Get and verify the breakpoint address */
     89  1.1    jruoho 
     90  1.5  christos     Address = strtoul (Location, NULL, 16);
     91  1.5  christos     AmlOffset = (UINT32) ACPI_PTR_DIFF (Op->Common.Aml,
     92  1.6  christos         WalkState->ParserState.AmlStart);
     93  1.5  christos     if (Address <= AmlOffset)
     94  1.1    jruoho     {
     95  1.1    jruoho         AcpiOsPrintf ("Breakpoint %X is beyond current address %X\n",
     96  1.5  christos             Address, AmlOffset);
     97  1.1    jruoho     }
     98  1.1    jruoho 
     99  1.1    jruoho     /* Save breakpoint in current walk */
    100  1.1    jruoho 
    101  1.1    jruoho     WalkState->UserBreakpoint = Address;
    102  1.1    jruoho     AcpiOsPrintf ("Breakpoint set at AML offset %X\n", Address);
    103  1.1    jruoho }
    104  1.1    jruoho 
    105  1.1    jruoho 
    106  1.1    jruoho /*******************************************************************************
    107  1.1    jruoho  *
    108  1.1    jruoho  * FUNCTION:    AcpiDbSetMethodCallBreakpoint
    109  1.1    jruoho  *
    110  1.1    jruoho  * PARAMETERS:  Op                  - Current Op (from parse walk)
    111  1.1    jruoho  *
    112  1.1    jruoho  * RETURN:      None
    113  1.1    jruoho  *
    114  1.1    jruoho  * DESCRIPTION: Set a breakpoint in a control method at the specified
    115  1.1    jruoho  *              AML offset
    116  1.1    jruoho  *
    117  1.1    jruoho  ******************************************************************************/
    118  1.1    jruoho 
    119  1.1    jruoho void
    120  1.1    jruoho AcpiDbSetMethodCallBreakpoint (
    121  1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
    122  1.1    jruoho {
    123  1.1    jruoho 
    124  1.1    jruoho 
    125  1.1    jruoho     if (!Op)
    126  1.1    jruoho     {
    127  1.1    jruoho         AcpiOsPrintf ("There is no method currently executing\n");
    128  1.1    jruoho         return;
    129  1.1    jruoho     }
    130  1.1    jruoho 
    131  1.1    jruoho     AcpiGbl_StepToNextCall = TRUE;
    132  1.1    jruoho }
    133  1.1    jruoho 
    134  1.1    jruoho 
    135  1.1    jruoho /*******************************************************************************
    136  1.1    jruoho  *
    137  1.1    jruoho  * FUNCTION:    AcpiDbSetMethodData
    138  1.1    jruoho  *
    139  1.1    jruoho  * PARAMETERS:  TypeArg         - L for local, A for argument
    140  1.1    jruoho  *              IndexArg        - which one
    141  1.1    jruoho  *              ValueArg        - Value to set.
    142  1.1    jruoho  *
    143  1.1    jruoho  * RETURN:      None
    144  1.1    jruoho  *
    145  1.1    jruoho  * DESCRIPTION: Set a local or argument for the running control method.
    146  1.1    jruoho  *              NOTE: only object supported is Number.
    147  1.1    jruoho  *
    148  1.1    jruoho  ******************************************************************************/
    149  1.1    jruoho 
    150  1.1    jruoho void
    151  1.1    jruoho AcpiDbSetMethodData (
    152  1.1    jruoho     char                    *TypeArg,
    153  1.1    jruoho     char                    *IndexArg,
    154  1.1    jruoho     char                    *ValueArg)
    155  1.1    jruoho {
    156  1.1    jruoho     char                    Type;
    157  1.1    jruoho     UINT32                  Index;
    158  1.1    jruoho     UINT32                  Value;
    159  1.1    jruoho     ACPI_WALK_STATE         *WalkState;
    160  1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    161  1.1    jruoho     ACPI_STATUS             Status;
    162  1.1    jruoho     ACPI_NAMESPACE_NODE     *Node;
    163  1.1    jruoho 
    164  1.1    jruoho 
    165  1.1    jruoho     /* Validate TypeArg */
    166  1.1    jruoho 
    167  1.1    jruoho     AcpiUtStrupr (TypeArg);
    168  1.1    jruoho     Type = TypeArg[0];
    169  1.1    jruoho     if ((Type != 'L') &&
    170  1.1    jruoho         (Type != 'A') &&
    171  1.1    jruoho         (Type != 'N'))
    172  1.1    jruoho     {
    173  1.1    jruoho         AcpiOsPrintf ("Invalid SET operand: %s\n", TypeArg);
    174  1.1    jruoho         return;
    175  1.1    jruoho     }
    176  1.1    jruoho 
    177  1.5  christos     Value = strtoul (ValueArg, NULL, 16);
    178  1.1    jruoho 
    179  1.1    jruoho     if (Type == 'N')
    180  1.1    jruoho     {
    181  1.1    jruoho         Node = AcpiDbConvertToNode (IndexArg);
    182  1.3  christos         if (!Node)
    183  1.3  christos         {
    184  1.3  christos             return;
    185  1.3  christos         }
    186  1.3  christos 
    187  1.1    jruoho         if (Node->Type != ACPI_TYPE_INTEGER)
    188  1.1    jruoho         {
    189  1.1    jruoho             AcpiOsPrintf ("Can only set Integer nodes\n");
    190  1.1    jruoho             return;
    191  1.1    jruoho         }
    192  1.1    jruoho         ObjDesc = Node->Object;
    193  1.1    jruoho         ObjDesc->Integer.Value = Value;
    194  1.1    jruoho         return;
    195  1.1    jruoho     }
    196  1.1    jruoho 
    197  1.1    jruoho     /* Get the index and value */
    198  1.1    jruoho 
    199  1.5  christos     Index = strtoul (IndexArg, NULL, 16);
    200  1.1    jruoho 
    201  1.1    jruoho     WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
    202  1.1    jruoho     if (!WalkState)
    203  1.1    jruoho     {
    204  1.1    jruoho         AcpiOsPrintf ("There is no method currently executing\n");
    205  1.1    jruoho         return;
    206  1.1    jruoho     }
    207  1.1    jruoho 
    208  1.1    jruoho     /* Create and initialize the new object */
    209  1.1    jruoho 
    210  1.1    jruoho     ObjDesc = AcpiUtCreateIntegerObject ((UINT64) Value);
    211  1.1    jruoho     if (!ObjDesc)
    212  1.1    jruoho     {
    213  1.1    jruoho         AcpiOsPrintf ("Could not create an internal object\n");
    214  1.1    jruoho         return;
    215  1.1    jruoho     }
    216  1.1    jruoho 
    217  1.1    jruoho     /* Store the new object into the target */
    218  1.1    jruoho 
    219  1.1    jruoho     switch (Type)
    220  1.1    jruoho     {
    221  1.1    jruoho     case 'A':
    222  1.1    jruoho 
    223  1.1    jruoho         /* Set a method argument */
    224  1.1    jruoho 
    225  1.1    jruoho         if (Index > ACPI_METHOD_MAX_ARG)
    226  1.1    jruoho         {
    227  1.6  christos             AcpiOsPrintf ("Arg%u - Invalid argument name\n",
    228  1.6  christos                 Index);
    229  1.1    jruoho             goto Cleanup;
    230  1.1    jruoho         }
    231  1.1    jruoho 
    232  1.6  christos         Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_ARG,
    233  1.6  christos             Index, ObjDesc, WalkState);
    234  1.1    jruoho         if (ACPI_FAILURE (Status))
    235  1.1    jruoho         {
    236  1.1    jruoho             goto Cleanup;
    237  1.1    jruoho         }
    238  1.1    jruoho 
    239  1.1    jruoho         ObjDesc = WalkState->Arguments[Index].Object;
    240  1.1    jruoho 
    241  1.1    jruoho         AcpiOsPrintf ("Arg%u: ", Index);
    242  1.5  christos         AcpiDbDisplayInternalObject (ObjDesc, WalkState);
    243  1.1    jruoho         break;
    244  1.1    jruoho 
    245  1.1    jruoho     case 'L':
    246  1.1    jruoho 
    247  1.1    jruoho         /* Set a method local */
    248  1.1    jruoho 
    249  1.1    jruoho         if (Index > ACPI_METHOD_MAX_LOCAL)
    250  1.1    jruoho         {
    251  1.6  christos             AcpiOsPrintf ("Local%u - Invalid local variable name\n",
    252  1.6  christos                 Index);
    253  1.1    jruoho             goto Cleanup;
    254  1.1    jruoho         }
    255  1.1    jruoho 
    256  1.6  christos         Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_LOCAL,
    257  1.6  christos             Index, ObjDesc, WalkState);
    258  1.1    jruoho         if (ACPI_FAILURE (Status))
    259  1.1    jruoho         {
    260  1.1    jruoho             goto Cleanup;
    261  1.1    jruoho         }
    262  1.1    jruoho 
    263  1.1    jruoho         ObjDesc = WalkState->LocalVariables[Index].Object;
    264  1.1    jruoho 
    265  1.1    jruoho         AcpiOsPrintf ("Local%u: ", Index);
    266  1.5  christos         AcpiDbDisplayInternalObject (ObjDesc, WalkState);
    267  1.1    jruoho         break;
    268  1.1    jruoho 
    269  1.1    jruoho     default:
    270  1.2  christos 
    271  1.1    jruoho         break;
    272  1.1    jruoho     }
    273  1.1    jruoho 
    274  1.1    jruoho Cleanup:
    275  1.1    jruoho     AcpiUtRemoveReference (ObjDesc);
    276  1.1    jruoho }
    277  1.1    jruoho 
    278  1.1    jruoho 
    279  1.1    jruoho /*******************************************************************************
    280  1.1    jruoho  *
    281  1.1    jruoho  * FUNCTION:    AcpiDbDisassembleAml
    282  1.1    jruoho  *
    283  1.1    jruoho  * PARAMETERS:  Statements          - Number of statements to disassemble
    284  1.1    jruoho  *              Op                  - Current Op (from parse walk)
    285  1.1    jruoho  *
    286  1.1    jruoho  * RETURN:      None
    287  1.1    jruoho  *
    288  1.1    jruoho  * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
    289  1.1    jruoho  *              of statements specified.
    290  1.1    jruoho  *
    291  1.1    jruoho  ******************************************************************************/
    292  1.1    jruoho 
    293  1.1    jruoho void
    294  1.1    jruoho AcpiDbDisassembleAml (
    295  1.1    jruoho     char                    *Statements,
    296  1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
    297  1.1    jruoho {
    298  1.1    jruoho     UINT32                  NumStatements = 8;
    299  1.1    jruoho 
    300  1.1    jruoho 
    301  1.1    jruoho     if (!Op)
    302  1.1    jruoho     {
    303  1.1    jruoho         AcpiOsPrintf ("There is no method currently executing\n");
    304  1.1    jruoho         return;
    305  1.1    jruoho     }
    306  1.1    jruoho 
    307  1.1    jruoho     if (Statements)
    308  1.1    jruoho     {
    309  1.5  christos         NumStatements = strtoul (Statements, NULL, 0);
    310  1.1    jruoho     }
    311  1.1    jruoho 
    312  1.5  christos #ifdef ACPI_DISASSEMBLER
    313  1.1    jruoho     AcpiDmDisassemble (NULL, Op, NumStatements);
    314  1.5  christos #endif
    315  1.1    jruoho }
    316  1.1    jruoho 
    317  1.1    jruoho 
    318  1.1    jruoho /*******************************************************************************
    319  1.1    jruoho  *
    320  1.1    jruoho  * FUNCTION:    AcpiDbDisassembleMethod
    321  1.1    jruoho  *
    322  1.1    jruoho  * PARAMETERS:  Name            - Name of control method
    323  1.1    jruoho  *
    324  1.1    jruoho  * RETURN:      None
    325  1.1    jruoho  *
    326  1.1    jruoho  * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
    327  1.1    jruoho  *              of statements specified.
    328  1.1    jruoho  *
    329  1.1    jruoho  ******************************************************************************/
    330  1.1    jruoho 
    331  1.1    jruoho ACPI_STATUS
    332  1.1    jruoho AcpiDbDisassembleMethod (
    333  1.1    jruoho     char                    *Name)
    334  1.1    jruoho {
    335  1.1    jruoho     ACPI_STATUS             Status;
    336  1.1    jruoho     ACPI_PARSE_OBJECT       *Op;
    337  1.1    jruoho     ACPI_WALK_STATE         *WalkState;
    338  1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    339  1.1    jruoho     ACPI_NAMESPACE_NODE     *Method;
    340  1.1    jruoho 
    341  1.1    jruoho 
    342  1.1    jruoho     Method = AcpiDbConvertToNode (Name);
    343  1.1    jruoho     if (!Method)
    344  1.1    jruoho     {
    345  1.1    jruoho         return (AE_BAD_PARAMETER);
    346  1.1    jruoho     }
    347  1.1    jruoho 
    348  1.2  christos     if (Method->Type != ACPI_TYPE_METHOD)
    349  1.2  christos     {
    350  1.2  christos         ACPI_ERROR ((AE_INFO, "%s (%s): Object must be a control method",
    351  1.2  christos             Name, AcpiUtGetTypeName (Method->Type)));
    352  1.2  christos         return (AE_BAD_PARAMETER);
    353  1.2  christos     }
    354  1.2  christos 
    355  1.1    jruoho     ObjDesc = Method->Object;
    356  1.1    jruoho 
    357  1.5  christos     Op = AcpiPsCreateScopeOp (ObjDesc->Method.AmlStart);
    358  1.1    jruoho     if (!Op)
    359  1.1    jruoho     {
    360  1.1    jruoho         return (AE_NO_MEMORY);
    361  1.1    jruoho     }
    362  1.1    jruoho 
    363  1.1    jruoho     /* Create and initialize a new walk state */
    364  1.1    jruoho 
    365  1.1    jruoho     WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
    366  1.1    jruoho     if (!WalkState)
    367  1.1    jruoho     {
    368  1.1    jruoho         return (AE_NO_MEMORY);
    369  1.1    jruoho     }
    370  1.1    jruoho 
    371  1.1    jruoho     Status = AcpiDsInitAmlWalk (WalkState, Op, NULL,
    372  1.2  christos         ObjDesc->Method.AmlStart,
    373  1.2  christos         ObjDesc->Method.AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
    374  1.2  christos     if (ACPI_FAILURE (Status))
    375  1.2  christos     {
    376  1.2  christos         return (Status);
    377  1.2  christos     }
    378  1.2  christos 
    379  1.2  christos     Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId);
    380  1.2  christos     WalkState->OwnerId = ObjDesc->Method.OwnerId;
    381  1.2  christos 
    382  1.2  christos     /* Push start scope on scope stack and make it current */
    383  1.2  christos 
    384  1.2  christos     Status = AcpiDsScopeStackPush (Method,
    385  1.2  christos         Method->Type, WalkState);
    386  1.1    jruoho     if (ACPI_FAILURE (Status))
    387  1.1    jruoho     {
    388  1.1    jruoho         return (Status);
    389  1.1    jruoho     }
    390  1.1    jruoho 
    391  1.2  christos     /* Parse the entire method AML including deferred operators */
    392  1.1    jruoho 
    393  1.1    jruoho     WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
    394  1.1    jruoho     WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
    395  1.2  christos 
    396  1.1    jruoho     Status = AcpiPsParseAml (WalkState);
    397  1.5  christos 
    398  1.6  christos #ifdef ACPI_DISASSEMBLER
    399  1.2  christos     (void) AcpiDmParseDeferredOps (Op);
    400  1.2  christos 
    401  1.2  christos     /* Now we can disassemble the method */
    402  1.1    jruoho 
    403  1.6  christos     AcpiGbl_DmOpt_Verbose = FALSE;
    404  1.1    jruoho     AcpiDmDisassemble (NULL, Op, 0);
    405  1.6  christos     AcpiGbl_DmOpt_Verbose = TRUE;
    406  1.5  christos #endif
    407  1.2  christos 
    408  1.1    jruoho     AcpiPsDeleteParseTree (Op);
    409  1.2  christos 
    410  1.2  christos     /* Method cleanup */
    411  1.2  christos 
    412  1.2  christos     AcpiNsDeleteNamespaceSubtree (Method);
    413  1.2  christos     AcpiNsDeleteNamespaceByOwner (ObjDesc->Method.OwnerId);
    414  1.2  christos     AcpiUtReleaseOwnerId (&ObjDesc->Method.OwnerId);
    415  1.1    jruoho     return (AE_OK);
    416  1.1    jruoho }
    417