1 /*******************************************************************************
3 * Module Name: dbmethod - Debug commands for control methods
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2016, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
55 #define _COMPONENT ACPI_CA_DEBUGGER
56 ACPI_MODULE_NAME ("dbmethod")
59 /*******************************************************************************
61 * FUNCTION: AcpiDbSetMethodBreakpoint
63 * PARAMETERS: Location - AML offset of breakpoint
64 * WalkState - Current walk info
65 * Op - Current Op (from parse walk)
69 * DESCRIPTION: Set a breakpoint in a control method at the specified
72 ******************************************************************************/
75 AcpiDbSetMethodBreakpoint (
77 ACPI_WALK_STATE *WalkState,
78 ACPI_PARSE_OBJECT *Op)
86 AcpiOsPrintf ("There is no method currently executing\n");
90 /* Get and verify the breakpoint address */
92 Address = strtoul (Location, NULL, 16);
93 AmlOffset = (UINT32) ACPI_PTR_DIFF (Op->Common.Aml,
94 WalkState->ParserState.AmlStart);
95 if (Address <= AmlOffset)
97 AcpiOsPrintf ("Breakpoint %X is beyond current address %X\n",
101 /* Save breakpoint in current walk */
103 WalkState->UserBreakpoint = Address;
104 AcpiOsPrintf ("Breakpoint set at AML offset %X\n", Address);
108 /*******************************************************************************
110 * FUNCTION: AcpiDbSetMethodCallBreakpoint
112 * PARAMETERS: Op - Current Op (from parse walk)
116 * DESCRIPTION: Set a breakpoint in a control method at the specified
119 ******************************************************************************/
122 AcpiDbSetMethodCallBreakpoint (
123 ACPI_PARSE_OBJECT *Op)
129 AcpiOsPrintf ("There is no method currently executing\n");
133 AcpiGbl_StepToNextCall = TRUE;
137 /*******************************************************************************
139 * FUNCTION: AcpiDbSetMethodData
141 * PARAMETERS: TypeArg - L for local, A for argument
142 * IndexArg - which one
143 * ValueArg - Value to set.
147 * DESCRIPTION: Set a local or argument for the running control method.
148 * NOTE: only object supported is Number.
150 ******************************************************************************/
153 AcpiDbSetMethodData (
161 ACPI_WALK_STATE *WalkState;
162 ACPI_OPERAND_OBJECT *ObjDesc;
164 ACPI_NAMESPACE_NODE *Node;
167 /* Validate TypeArg */
169 AcpiUtStrupr (TypeArg);
175 AcpiOsPrintf ("Invalid SET operand: %s\n", TypeArg);
179 Value = strtoul (ValueArg, NULL, 16);
183 Node = AcpiDbConvertToNode (IndexArg);
189 if (Node->Type != ACPI_TYPE_INTEGER)
191 AcpiOsPrintf ("Can only set Integer nodes\n");
194 ObjDesc = Node->Object;
195 ObjDesc->Integer.Value = Value;
199 /* Get the index and value */
201 Index = strtoul (IndexArg, NULL, 16);
203 WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
206 AcpiOsPrintf ("There is no method currently executing\n");
210 /* Create and initialize the new object */
212 ObjDesc = AcpiUtCreateIntegerObject ((UINT64) Value);
215 AcpiOsPrintf ("Could not create an internal object\n");
219 /* Store the new object into the target */
225 /* Set a method argument */
227 if (Index > ACPI_METHOD_MAX_ARG)
229 AcpiOsPrintf ("Arg%u - Invalid argument name\n",
234 Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_ARG,
235 Index, ObjDesc, WalkState);
236 if (ACPI_FAILURE (Status))
241 ObjDesc = WalkState->Arguments[Index].Object;
243 AcpiOsPrintf ("Arg%u: ", Index);
244 AcpiDbDisplayInternalObject (ObjDesc, WalkState);
249 /* Set a method local */
251 if (Index > ACPI_METHOD_MAX_LOCAL)
253 AcpiOsPrintf ("Local%u - Invalid local variable name\n",
258 Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_LOCAL,
259 Index, ObjDesc, WalkState);
260 if (ACPI_FAILURE (Status))
265 ObjDesc = WalkState->LocalVariables[Index].Object;
267 AcpiOsPrintf ("Local%u: ", Index);
268 AcpiDbDisplayInternalObject (ObjDesc, WalkState);
277 AcpiUtRemoveReference (ObjDesc);
281 /*******************************************************************************
283 * FUNCTION: AcpiDbDisassembleAml
285 * PARAMETERS: Statements - Number of statements to disassemble
286 * Op - Current Op (from parse walk)
290 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
291 * of statements specified.
293 ******************************************************************************/
296 AcpiDbDisassembleAml (
298 ACPI_PARSE_OBJECT *Op)
300 UINT32 NumStatements = 8;
305 AcpiOsPrintf ("There is no method currently executing\n");
311 NumStatements = strtoul (Statements, NULL, 0);
314 #ifdef ACPI_DISASSEMBLER
315 AcpiDmDisassemble (NULL, Op, NumStatements);
320 /*******************************************************************************
322 * FUNCTION: AcpiDbDisassembleMethod
324 * PARAMETERS: Name - Name of control method
328 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
329 * of statements specified.
331 ******************************************************************************/
334 AcpiDbDisassembleMethod (
338 ACPI_PARSE_OBJECT *Op;
339 ACPI_WALK_STATE *WalkState;
340 ACPI_OPERAND_OBJECT *ObjDesc;
341 ACPI_NAMESPACE_NODE *Method;
344 Method = AcpiDbConvertToNode (Name);
347 return (AE_BAD_PARAMETER);
350 if (Method->Type != ACPI_TYPE_METHOD)
352 ACPI_ERROR ((AE_INFO, "%s (%s): Object must be a control method",
353 Name, AcpiUtGetTypeName (Method->Type)));
354 return (AE_BAD_PARAMETER);
357 ObjDesc = Method->Object;
359 Op = AcpiPsCreateScopeOp (ObjDesc->Method.AmlStart);
362 return (AE_NO_MEMORY);
365 /* Create and initialize a new walk state */
367 WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
370 return (AE_NO_MEMORY);
373 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL,
374 ObjDesc->Method.AmlStart,
375 ObjDesc->Method.AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
376 if (ACPI_FAILURE (Status))
381 Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId);
382 WalkState->OwnerId = ObjDesc->Method.OwnerId;
384 /* Push start scope on scope stack and make it current */
386 Status = AcpiDsScopeStackPush (Method,
387 Method->Type, WalkState);
388 if (ACPI_FAILURE (Status))
393 /* Parse the entire method AML including deferred operators */
395 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
396 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
398 Status = AcpiPsParseAml (WalkState);
400 #ifdef ACPI_DISASSEMBLER
401 (void) AcpiDmParseDeferredOps (Op);
403 /* Now we can disassemble the method */
405 AcpiGbl_DmOpt_Verbose = FALSE;
406 AcpiDmDisassemble (NULL, Op, 0);
407 AcpiGbl_DmOpt_Verbose = TRUE;
410 AcpiPsDeleteParseTree (Op);
414 AcpiNsDeleteNamespaceSubtree (Method);
415 AcpiNsDeleteNamespaceByOwner (ObjDesc->Method.OwnerId);
416 AcpiUtReleaseOwnerId (&ObjDesc->Method.OwnerId);
420 #endif /* ACPI_DEBUGGER */