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.
53 #define _COMPONENT ACPI_CA_DEBUGGER
54 ACPI_MODULE_NAME ("dbxface")
57 /* Local prototypes */
61 ACPI_WALK_STATE *WalkState,
62 ACPI_PARSE_OBJECT *Op);
64 #ifdef ACPI_OBSOLETE_FUNCTIONS
67 ACPI_WALK_STATE *WalkState);
71 /*******************************************************************************
73 * FUNCTION: AcpiDbStartCommand
75 * PARAMETERS: WalkState - Current walk
76 * Op - Current executing Op, from AML interpreter
80 * DESCRIPTION: Enter debugger command loop
82 ******************************************************************************/
86 ACPI_WALK_STATE *WalkState,
87 ACPI_PARSE_OBJECT *Op)
92 /* TBD: [Investigate] are there namespace locking issues here? */
94 /* AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); */
96 /* Go into the command loop and await next user command */
99 AcpiGbl_MethodExecuting = TRUE;
100 Status = AE_CTRL_TRUE;
101 while (Status == AE_CTRL_TRUE)
103 if (AcpiGbl_DebuggerConfiguration == DEBUGGER_MULTI_THREADED)
105 /* Handshake with the front-end that gets user command lines */
107 Status = AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
108 if (ACPI_FAILURE (Status))
112 Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_READY);
113 if (ACPI_FAILURE (Status))
120 /* Single threaded, we must get a command line ourselves */
122 /* Force output to console until a command is entered */
124 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
126 /* Different prompt if method is executing */
128 if (!AcpiGbl_MethodExecuting)
130 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
134 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
137 /* Get the user input line */
139 Status = AcpiOsGetLine (AcpiGbl_DbLineBuf,
140 ACPI_DB_LINE_BUFFER_SIZE, NULL);
141 if (ACPI_FAILURE (Status))
143 ACPI_EXCEPTION ((AE_INFO, Status, "While parsing command line"));
148 Status = AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, WalkState, Op);
151 /* AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); */
157 /*******************************************************************************
159 * FUNCTION: AcpiDbSingleStep
161 * PARAMETERS: WalkState - Current walk
162 * Op - Current executing op (from aml interpreter)
163 * OpcodeClass - Class of the current AML Opcode
167 * DESCRIPTION: Called just before execution of an AML opcode.
169 ******************************************************************************/
173 ACPI_WALK_STATE *WalkState,
174 ACPI_PARSE_OBJECT *Op,
177 ACPI_PARSE_OBJECT *Next;
178 ACPI_STATUS Status = AE_OK;
179 UINT32 OriginalDebugLevel;
180 ACPI_PARSE_OBJECT *DisplayOp;
181 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 /* Check for single-step breakpoint */
197 if (WalkState->MethodBreakpoint &&
198 (WalkState->MethodBreakpoint <= Op->Common.AmlOffset))
200 /* Check if the breakpoint has been reached or passed */
201 /* Hit the breakpoint, resume single step, reset breakpoint */
203 AcpiOsPrintf ("***Break*** at AML offset %X\n", Op->Common.AmlOffset);
204 AcpiGbl_CmSingleStep = TRUE;
205 AcpiGbl_StepToNextCall = FALSE;
206 WalkState->MethodBreakpoint = 0;
209 /* Check for user breakpoint (Must be on exact Aml offset) */
211 else if (WalkState->UserBreakpoint &&
212 (WalkState->UserBreakpoint == Op->Common.AmlOffset))
214 AcpiOsPrintf ("***UserBreakpoint*** at AML offset %X\n",
215 Op->Common.AmlOffset);
216 AcpiGbl_CmSingleStep = TRUE;
217 AcpiGbl_StepToNextCall = FALSE;
218 WalkState->MethodBreakpoint = 0;
222 * Check if this is an opcode that we are interested in --
223 * namely, opcodes that have arguments
225 if (Op->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
232 case AML_CLASS_UNKNOWN:
233 case AML_CLASS_ARGUMENT: /* constants, literals, etc. do nothing */
239 /* All other opcodes -- continue */
244 * Under certain debug conditions, display this opcode and its operands
246 if ((AcpiGbl_DbOutputToFile) ||
247 (AcpiGbl_CmSingleStep) ||
248 (AcpiDbgLevel & ACPI_LV_PARSE))
250 if ((AcpiGbl_DbOutputToFile) ||
251 (AcpiDbgLevel & ACPI_LV_PARSE))
253 AcpiOsPrintf ("\n[AmlDebug] Next AML Opcode to execute:\n");
257 * Display this op (and only this op - zero out the NEXT field
258 * temporarily, and disable parser trace output for the duration of
259 * the display because we don't want the extraneous debug output)
261 OriginalDebugLevel = AcpiDbgLevel;
262 AcpiDbgLevel &= ~(ACPI_LV_PARSE | ACPI_LV_FUNCTIONS);
263 Next = Op->Common.Next;
264 Op->Common.Next = NULL;
268 ParentOp = Op->Common.Parent;
271 if ((WalkState->ControlState) &&
272 (WalkState->ControlState->Common.State ==
273 ACPI_CONTROL_PREDICATE_EXECUTING))
276 * We are executing the predicate of an IF or WHILE statement
277 * Search upwards for the containing IF or WHILE so that the
278 * entire predicate can be displayed.
282 if ((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
283 (ParentOp->Common.AmlOpcode == AML_WHILE_OP))
285 DisplayOp = ParentOp;
288 ParentOp = ParentOp->Common.Parent;
295 if ((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
296 (ParentOp->Common.AmlOpcode == AML_ELSE_OP) ||
297 (ParentOp->Common.AmlOpcode == AML_SCOPE_OP) ||
298 (ParentOp->Common.AmlOpcode == AML_METHOD_OP) ||
299 (ParentOp->Common.AmlOpcode == AML_WHILE_OP))
303 DisplayOp = ParentOp;
304 ParentOp = ParentOp->Common.Parent;
309 /* Now we can display it */
311 AcpiDmDisassemble (WalkState, DisplayOp, ACPI_UINT32_MAX);
313 if ((Op->Common.AmlOpcode == AML_IF_OP) ||
314 (Op->Common.AmlOpcode == AML_WHILE_OP))
316 if (WalkState->ControlState->Common.Value)
318 AcpiOsPrintf ("Predicate = [True], IF block was executed\n");
322 AcpiOsPrintf ("Predicate = [False], Skipping IF block\n");
325 else if (Op->Common.AmlOpcode == AML_ELSE_OP)
327 AcpiOsPrintf ("Predicate = [False], ELSE block was executed\n");
330 /* Restore everything */
332 Op->Common.Next = Next;
334 if ((AcpiGbl_DbOutputToFile) ||
335 (AcpiDbgLevel & ACPI_LV_PARSE))
339 AcpiDbgLevel = OriginalDebugLevel;
342 /* If we are not single stepping, just continue executing the method */
344 if (!AcpiGbl_CmSingleStep)
350 * If we are executing a step-to-call command,
351 * Check if this is a method call.
353 if (AcpiGbl_StepToNextCall)
355 if (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP)
357 /* Not a method call, just keep executing */
362 /* Found a method call, stop executing */
364 AcpiGbl_StepToNextCall = FALSE;
368 * If the next opcode is a method call, we will "step over" it
371 if (Op->Common.AmlOpcode == AML_INT_METHODCALL_OP)
373 /* Force no more single stepping while executing called method */
375 AcpiGbl_CmSingleStep = FALSE;
378 * Set the breakpoint on/before the call, it will stop execution
379 * as soon as we return
381 WalkState->MethodBreakpoint = 1; /* Must be non-zero! */
385 Status = AcpiDbStartCommand (WalkState, Op);
387 /* User commands complete, continue execution of the interrupted method */
393 /*******************************************************************************
395 * FUNCTION: AcpiDbInitialize
401 * DESCRIPTION: Init and start debugger
403 ******************************************************************************/
412 ACPI_FUNCTION_TRACE (DbInitialize);
417 AcpiGbl_DbBuffer = NULL;
418 AcpiGbl_DbFilename = NULL;
419 AcpiGbl_DbOutputToFile = FALSE;
421 AcpiGbl_DbDebugLevel = ACPI_LV_VERBOSITY2;
422 AcpiGbl_DbConsoleDebugLevel = ACPI_NORMAL_DEFAULT | ACPI_LV_TABLES;
423 AcpiGbl_DbOutputFlags = ACPI_DB_CONSOLE_OUTPUT;
425 AcpiGbl_DbOpt_tables = FALSE;
426 AcpiGbl_DbOpt_disasm = FALSE;
427 AcpiGbl_DbOpt_stats = FALSE;
428 AcpiGbl_DbOpt_verbose = TRUE;
429 AcpiGbl_DbOpt_ini_methods = TRUE;
431 AcpiGbl_DbBuffer = AcpiOsAllocate (ACPI_DEBUG_BUFFER_SIZE);
432 if (!AcpiGbl_DbBuffer)
434 return_ACPI_STATUS (AE_NO_MEMORY);
436 ACPI_MEMSET (AcpiGbl_DbBuffer, 0, ACPI_DEBUG_BUFFER_SIZE);
438 /* Initial scope is the root */
440 AcpiGbl_DbScopeBuf [0] = AML_ROOT_PREFIX;
441 AcpiGbl_DbScopeBuf [1] = 0;
442 AcpiGbl_DbScopeNode = AcpiGbl_RootNode;
445 * If configured for multi-thread support, the debug executor runs in
446 * a separate thread so that the front end can be in another address
447 * space, environment, or even another machine.
449 if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
451 /* These were created with one unit, grab it */
453 Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
454 if (ACPI_FAILURE (Status))
456 AcpiOsPrintf ("Could not get debugger mutex\n");
457 return_ACPI_STATUS (Status);
460 Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_READY);
461 if (ACPI_FAILURE (Status))
463 AcpiOsPrintf ("Could not get debugger mutex\n");
464 return_ACPI_STATUS (Status);
467 /* Create the debug execution thread to execute commands */
469 Status = AcpiOsExecute (OSL_DEBUGGER_THREAD, AcpiDbExecuteThread, NULL);
470 if (ACPI_FAILURE (Status))
472 ACPI_EXCEPTION ((AE_INFO, Status, "Could not start debugger thread"));
473 return_ACPI_STATUS (Status);
477 if (!AcpiGbl_DbOpt_verbose)
479 AcpiGbl_DbOpt_disasm = TRUE;
480 AcpiGbl_DbOpt_stats = FALSE;
483 return_ACPI_STATUS (AE_OK);
487 /*******************************************************************************
489 * FUNCTION: AcpiDbTerminate
495 * DESCRIPTION: Stop debugger
497 ******************************************************************************/
504 if (AcpiGbl_DbBuffer)
506 AcpiOsFree (AcpiGbl_DbBuffer);
507 AcpiGbl_DbBuffer = NULL;
510 /* Ensure that debug output is now disabled */
512 AcpiGbl_DbOutputFlags = ACPI_DB_DISABLE_OUTPUT;
516 #ifdef ACPI_OBSOLETE_FUNCTIONS
517 /*******************************************************************************
519 * FUNCTION: AcpiDbMethodEnd
521 * PARAMETERS: WalkState - Current walk
525 * DESCRIPTION: Called at method termination
527 ******************************************************************************/
531 ACPI_WALK_STATE *WalkState)
534 if (!AcpiGbl_CmSingleStep)
539 AcpiOsPrintf ("<Method Terminating>\n");
541 AcpiDbStartCommand (WalkState, NULL);
545 #endif /* ACPI_DEBUGGER */