1 /*******************************************************************************
3 * Module Name: dbxface - AML Debugger external interfaces
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2015, 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.
51 #define _COMPONENT ACPI_CA_DEBUGGER
52 ACPI_MODULE_NAME ("dbxface")
55 /* Local prototypes */
59 ACPI_WALK_STATE *WalkState,
60 ACPI_PARSE_OBJECT *Op);
62 #ifdef ACPI_OBSOLETE_FUNCTIONS
65 ACPI_WALK_STATE *WalkState);
69 /*******************************************************************************
71 * FUNCTION: AcpiDbStartCommand
73 * PARAMETERS: WalkState - Current walk
74 * Op - Current executing Op, from AML interpreter
78 * DESCRIPTION: Enter debugger command loop
80 ******************************************************************************/
84 ACPI_WALK_STATE *WalkState,
85 ACPI_PARSE_OBJECT *Op)
90 /* TBD: [Investigate] are there namespace locking issues here? */
92 /* AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); */
94 /* Go into the command loop and await next user command */
97 AcpiGbl_MethodExecuting = TRUE;
98 Status = AE_CTRL_TRUE;
99 while (Status == AE_CTRL_TRUE)
101 if (AcpiGbl_DebuggerConfiguration == DEBUGGER_MULTI_THREADED)
103 /* Handshake with the front-end that gets user command lines */
105 Status = AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
106 if (ACPI_FAILURE (Status))
110 Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_READY);
111 if (ACPI_FAILURE (Status))
118 /* Single threaded, we must get a command line ourselves */
120 /* Force output to console until a command is entered */
122 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
124 /* Different prompt if method is executing */
126 if (!AcpiGbl_MethodExecuting)
128 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
132 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
135 /* Get the user input line */
137 Status = AcpiOsGetLine (AcpiGbl_DbLineBuf,
138 ACPI_DB_LINE_BUFFER_SIZE, NULL);
139 if (ACPI_FAILURE (Status))
141 ACPI_EXCEPTION ((AE_INFO, Status,
142 "While parsing command line"));
147 Status = AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, WalkState, Op);
150 /* AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); */
156 /*******************************************************************************
158 * FUNCTION: AcpiDbSingleStep
160 * PARAMETERS: WalkState - Current walk
161 * Op - Current executing op (from aml interpreter)
162 * OpcodeClass - Class of the current AML Opcode
166 * DESCRIPTION: Called just before execution of an AML opcode.
168 ******************************************************************************/
172 ACPI_WALK_STATE *WalkState,
173 ACPI_PARSE_OBJECT *Op,
176 ACPI_PARSE_OBJECT *Next;
177 ACPI_STATUS Status = AE_OK;
178 UINT32 OriginalDebugLevel;
179 ACPI_PARSE_OBJECT *DisplayOp;
180 ACPI_PARSE_OBJECT *ParentOp;
184 ACPI_FUNCTION_ENTRY ();
187 /* Check the abort flag */
189 if (AcpiGbl_AbortMethod)
191 AcpiGbl_AbortMethod = FALSE;
192 return (AE_ABORT_METHOD);
195 AmlOffset = (UINT32) ACPI_PTR_DIFF (Op->Common.Aml,
196 WalkState->ParserState.AmlStart);
198 /* Check for single-step breakpoint */
200 if (WalkState->MethodBreakpoint &&
201 (WalkState->MethodBreakpoint <= AmlOffset))
203 /* Check if the breakpoint has been reached or passed */
204 /* Hit the breakpoint, resume single step, reset breakpoint */
206 AcpiOsPrintf ("***Break*** at AML offset %X\n", AmlOffset);
207 AcpiGbl_CmSingleStep = TRUE;
208 AcpiGbl_StepToNextCall = FALSE;
209 WalkState->MethodBreakpoint = 0;
212 /* Check for user breakpoint (Must be on exact Aml offset) */
214 else if (WalkState->UserBreakpoint &&
215 (WalkState->UserBreakpoint == AmlOffset))
217 AcpiOsPrintf ("***UserBreakpoint*** at AML offset %X\n",
219 AcpiGbl_CmSingleStep = TRUE;
220 AcpiGbl_StepToNextCall = FALSE;
221 WalkState->MethodBreakpoint = 0;
225 * Check if this is an opcode that we are interested in --
226 * namely, opcodes that have arguments
228 if (Op->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
235 case AML_CLASS_UNKNOWN:
236 case AML_CLASS_ARGUMENT: /* constants, literals, etc. do nothing */
242 /* All other opcodes -- continue */
247 * Under certain debug conditions, display this opcode and its operands
249 if ((AcpiGbl_DbOutputToFile) ||
250 (AcpiGbl_CmSingleStep) ||
251 (AcpiDbgLevel & ACPI_LV_PARSE))
253 if ((AcpiGbl_DbOutputToFile) ||
254 (AcpiDbgLevel & ACPI_LV_PARSE))
256 AcpiOsPrintf ("\n[AmlDebug] Next AML Opcode to execute:\n");
260 * Display this op (and only this op - zero out the NEXT field
261 * temporarily, and disable parser trace output for the duration of
262 * the display because we don't want the extraneous debug output)
264 OriginalDebugLevel = AcpiDbgLevel;
265 AcpiDbgLevel &= ~(ACPI_LV_PARSE | ACPI_LV_FUNCTIONS);
266 Next = Op->Common.Next;
267 Op->Common.Next = NULL;
271 ParentOp = Op->Common.Parent;
274 if ((WalkState->ControlState) &&
275 (WalkState->ControlState->Common.State ==
276 ACPI_CONTROL_PREDICATE_EXECUTING))
279 * We are executing the predicate of an IF or WHILE statement
280 * Search upwards for the containing IF or WHILE so that the
281 * entire predicate can be displayed.
285 if ((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
286 (ParentOp->Common.AmlOpcode == AML_WHILE_OP))
288 DisplayOp = ParentOp;
291 ParentOp = ParentOp->Common.Parent;
298 if ((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
299 (ParentOp->Common.AmlOpcode == AML_ELSE_OP) ||
300 (ParentOp->Common.AmlOpcode == AML_SCOPE_OP) ||
301 (ParentOp->Common.AmlOpcode == AML_METHOD_OP) ||
302 (ParentOp->Common.AmlOpcode == AML_WHILE_OP))
306 DisplayOp = ParentOp;
307 ParentOp = ParentOp->Common.Parent;
312 /* Now we can display it */
314 #ifdef ACPI_DISASSEMBLER
315 AcpiDmDisassemble (WalkState, DisplayOp, ACPI_UINT32_MAX);
318 if ((Op->Common.AmlOpcode == AML_IF_OP) ||
319 (Op->Common.AmlOpcode == AML_WHILE_OP))
321 if (WalkState->ControlState->Common.Value)
323 AcpiOsPrintf ("Predicate = [True], IF block was executed\n");
327 AcpiOsPrintf ("Predicate = [False], Skipping IF block\n");
330 else if (Op->Common.AmlOpcode == AML_ELSE_OP)
332 AcpiOsPrintf ("Predicate = [False], ELSE block was executed\n");
335 /* Restore everything */
337 Op->Common.Next = Next;
339 if ((AcpiGbl_DbOutputToFile) ||
340 (AcpiDbgLevel & ACPI_LV_PARSE))
344 AcpiDbgLevel = OriginalDebugLevel;
347 /* If we are not single stepping, just continue executing the method */
349 if (!AcpiGbl_CmSingleStep)
355 * If we are executing a step-to-call command,
356 * Check if this is a method call.
358 if (AcpiGbl_StepToNextCall)
360 if (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP)
362 /* Not a method call, just keep executing */
367 /* Found a method call, stop executing */
369 AcpiGbl_StepToNextCall = FALSE;
373 * If the next opcode is a method call, we will "step over" it
376 if (Op->Common.AmlOpcode == AML_INT_METHODCALL_OP)
378 /* Force no more single stepping while executing called method */
380 AcpiGbl_CmSingleStep = FALSE;
383 * Set the breakpoint on/before the call, it will stop execution
384 * as soon as we return
386 WalkState->MethodBreakpoint = 1; /* Must be non-zero! */
390 Status = AcpiDbStartCommand (WalkState, Op);
392 /* User commands complete, continue execution of the interrupted method */
398 /*******************************************************************************
400 * FUNCTION: AcpiInitializeDebugger
406 * DESCRIPTION: Init and start debugger
408 ******************************************************************************/
411 AcpiInitializeDebugger (
417 ACPI_FUNCTION_TRACE (AcpiInitializeDebugger);
422 AcpiGbl_DbBuffer = NULL;
423 AcpiGbl_DbFilename = NULL;
424 AcpiGbl_DbOutputToFile = FALSE;
426 AcpiGbl_DbDebugLevel = ACPI_LV_VERBOSITY2;
427 AcpiGbl_DbConsoleDebugLevel = ACPI_NORMAL_DEFAULT | ACPI_LV_TABLES;
428 AcpiGbl_DbOutputFlags = ACPI_DB_CONSOLE_OUTPUT;
430 AcpiGbl_DbOpt_NoIniMethods = FALSE;
432 AcpiGbl_DbBuffer = AcpiOsAllocate (ACPI_DEBUG_BUFFER_SIZE);
433 if (!AcpiGbl_DbBuffer)
435 return_ACPI_STATUS (AE_NO_MEMORY);
437 memset (AcpiGbl_DbBuffer, 0, ACPI_DEBUG_BUFFER_SIZE);
439 /* Initial scope is the root */
441 AcpiGbl_DbScopeBuf [0] = AML_ROOT_PREFIX;
442 AcpiGbl_DbScopeBuf [1] = 0;
443 AcpiGbl_DbScopeNode = AcpiGbl_RootNode;
446 * If configured for multi-thread support, the debug executor runs in
447 * a separate thread so that the front end can be in another address
448 * space, environment, or even another machine.
450 if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
452 /* These were created with one unit, grab it */
454 Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
455 if (ACPI_FAILURE (Status))
457 AcpiOsPrintf ("Could not get debugger mutex\n");
458 return_ACPI_STATUS (Status);
461 Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_READY);
462 if (ACPI_FAILURE (Status))
464 AcpiOsPrintf ("Could not get debugger mutex\n");
465 return_ACPI_STATUS (Status);
468 /* Create the debug execution thread to execute commands */
470 Status = AcpiOsExecute (OSL_DEBUGGER_THREAD,
471 AcpiDbExecuteThread, NULL);
472 if (ACPI_FAILURE (Status))
474 ACPI_EXCEPTION ((AE_INFO, Status,
475 "Could not start debugger thread"));
476 return_ACPI_STATUS (Status);
480 return_ACPI_STATUS (AE_OK);
483 ACPI_EXPORT_SYMBOL (AcpiInitializeDebugger)
486 /*******************************************************************************
488 * FUNCTION: AcpiTerminateDebugger
494 * DESCRIPTION: Stop debugger
496 ******************************************************************************/
499 AcpiTerminateDebugger (
503 if (AcpiGbl_DbBuffer)
505 AcpiOsFree (AcpiGbl_DbBuffer);
506 AcpiGbl_DbBuffer = NULL;
509 /* Ensure that debug output is now disabled */
511 AcpiGbl_DbOutputFlags = ACPI_DB_DISABLE_OUTPUT;
514 ACPI_EXPORT_SYMBOL (AcpiTerminateDebugger)
517 #ifdef ACPI_OBSOLETE_FUNCTIONS
518 /*******************************************************************************
520 * FUNCTION: AcpiDbMethodEnd
522 * PARAMETERS: WalkState - Current walk
526 * DESCRIPTION: Called at method termination
528 ******************************************************************************/
532 ACPI_WALK_STATE *WalkState)
535 if (!AcpiGbl_CmSingleStep)
540 AcpiOsPrintf ("<Method Terminating>\n");
542 AcpiDbStartCommand (WalkState, NULL);
546 #endif /* ACPI_DEBUGGER */