1 /*******************************************************************************
3 * Module Name: dbxface - AML Debugger external interfaces
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2017, 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.
52 #define _COMPONENT ACPI_CA_DEBUGGER
53 ACPI_MODULE_NAME ("dbxface")
56 /* Local prototypes */
60 ACPI_WALK_STATE *WalkState,
61 ACPI_PARSE_OBJECT *Op);
63 #ifdef ACPI_OBSOLETE_FUNCTIONS
66 ACPI_WALK_STATE *WalkState);
70 /*******************************************************************************
72 * FUNCTION: AcpiDbStartCommand
74 * PARAMETERS: WalkState - Current walk
75 * Op - Current executing Op, from AML interpreter
79 * DESCRIPTION: Enter debugger command loop
81 ******************************************************************************/
85 ACPI_WALK_STATE *WalkState,
86 ACPI_PARSE_OBJECT *Op)
91 /* TBD: [Investigate] are there namespace locking issues here? */
93 /* AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); */
95 /* Go into the command loop and await next user command */
98 AcpiGbl_MethodExecuting = TRUE;
99 Status = AE_CTRL_TRUE;
101 while (Status == AE_CTRL_TRUE)
103 /* Notify the completion of the command */
105 Status = AcpiOsNotifyCommandComplete ();
106 if (ACPI_FAILURE (Status))
111 /* Wait the readiness of the command */
113 Status = AcpiOsWaitCommandReady ();
114 if (ACPI_FAILURE (Status))
119 Status = AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, WalkState, Op);
122 /* AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); */
125 if (ACPI_FAILURE (Status) && Status != AE_CTRL_TERMINATE)
127 ACPI_EXCEPTION ((AE_INFO, Status,
128 "While parsing/handling command line"));
134 /*******************************************************************************
136 * FUNCTION: AcpiDbSignalBreakPoint
138 * PARAMETERS: WalkState - Current walk
142 * DESCRIPTION: Called for AML_BREAKPOINT_OP
144 ******************************************************************************/
147 AcpiDbSignalBreakPoint (
148 ACPI_WALK_STATE *WalkState)
151 #ifndef ACPI_APPLICATION
152 if (AcpiGbl_DbThreadId != AcpiOsGetThreadId ())
159 * Set the single-step flag. This will cause the debugger (if present)
160 * to break to the console within the AML debugger at the start of the
161 * next AML instruction.
163 AcpiGbl_CmSingleStep = TRUE;
164 AcpiOsPrintf ("**break** Executed AML BreakPoint opcode\n");
168 /*******************************************************************************
170 * FUNCTION: AcpiDbSingleStep
172 * PARAMETERS: WalkState - Current walk
173 * Op - Current executing op (from aml interpreter)
174 * OpcodeClass - Class of the current AML Opcode
178 * DESCRIPTION: Called just before execution of an AML opcode.
180 ******************************************************************************/
184 ACPI_WALK_STATE *WalkState,
185 ACPI_PARSE_OBJECT *Op,
188 ACPI_PARSE_OBJECT *Next;
189 ACPI_STATUS Status = AE_OK;
190 UINT32 OriginalDebugLevel;
191 ACPI_PARSE_OBJECT *DisplayOp;
192 ACPI_PARSE_OBJECT *ParentOp;
196 ACPI_FUNCTION_ENTRY ();
199 #ifndef ACPI_APPLICATION
200 if (AcpiGbl_DbThreadId != AcpiOsGetThreadId ())
206 /* Check the abort flag */
208 if (AcpiGbl_AbortMethod)
210 AcpiGbl_AbortMethod = FALSE;
211 return (AE_ABORT_METHOD);
214 AmlOffset = (UINT32) ACPI_PTR_DIFF (Op->Common.Aml,
215 WalkState->ParserState.AmlStart);
217 /* Check for single-step breakpoint */
219 if (WalkState->MethodBreakpoint &&
220 (WalkState->MethodBreakpoint <= AmlOffset))
222 /* Check if the breakpoint has been reached or passed */
223 /* Hit the breakpoint, resume single step, reset breakpoint */
225 AcpiOsPrintf ("***Break*** at AML offset %X\n", AmlOffset);
226 AcpiGbl_CmSingleStep = TRUE;
227 AcpiGbl_StepToNextCall = FALSE;
228 WalkState->MethodBreakpoint = 0;
231 /* Check for user breakpoint (Must be on exact Aml offset) */
233 else if (WalkState->UserBreakpoint &&
234 (WalkState->UserBreakpoint == AmlOffset))
236 AcpiOsPrintf ("***UserBreakpoint*** at AML offset %X\n",
238 AcpiGbl_CmSingleStep = TRUE;
239 AcpiGbl_StepToNextCall = FALSE;
240 WalkState->MethodBreakpoint = 0;
244 * Check if this is an opcode that we are interested in --
245 * namely, opcodes that have arguments
247 if (Op->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
254 case AML_CLASS_UNKNOWN:
255 case AML_CLASS_ARGUMENT: /* constants, literals, etc. do nothing */
261 /* All other opcodes -- continue */
266 * Under certain debug conditions, display this opcode and its operands
268 if ((AcpiGbl_DbOutputToFile) ||
269 (AcpiGbl_CmSingleStep) ||
270 (AcpiDbgLevel & ACPI_LV_PARSE))
272 if ((AcpiGbl_DbOutputToFile) ||
273 (AcpiDbgLevel & ACPI_LV_PARSE))
275 AcpiOsPrintf ("\n[AmlDebug] Next AML Opcode to execute:\n");
279 * Display this op (and only this op - zero out the NEXT field
280 * temporarily, and disable parser trace output for the duration of
281 * the display because we don't want the extraneous debug output)
283 OriginalDebugLevel = AcpiDbgLevel;
284 AcpiDbgLevel &= ~(ACPI_LV_PARSE | ACPI_LV_FUNCTIONS);
285 Next = Op->Common.Next;
286 Op->Common.Next = NULL;
290 ParentOp = Op->Common.Parent;
293 if ((WalkState->ControlState) &&
294 (WalkState->ControlState->Common.State ==
295 ACPI_CONTROL_PREDICATE_EXECUTING))
298 * We are executing the predicate of an IF or WHILE statement
299 * Search upwards for the containing IF or WHILE so that the
300 * entire predicate can be displayed.
304 if ((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
305 (ParentOp->Common.AmlOpcode == AML_WHILE_OP))
307 DisplayOp = ParentOp;
310 ParentOp = ParentOp->Common.Parent;
317 if ((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
318 (ParentOp->Common.AmlOpcode == AML_ELSE_OP) ||
319 (ParentOp->Common.AmlOpcode == AML_SCOPE_OP) ||
320 (ParentOp->Common.AmlOpcode == AML_METHOD_OP) ||
321 (ParentOp->Common.AmlOpcode == AML_WHILE_OP))
325 DisplayOp = ParentOp;
326 ParentOp = ParentOp->Common.Parent;
331 /* Now we can display it */
333 #ifdef ACPI_DISASSEMBLER
334 AcpiDmDisassemble (WalkState, DisplayOp, ACPI_UINT32_MAX);
337 if ((Op->Common.AmlOpcode == AML_IF_OP) ||
338 (Op->Common.AmlOpcode == AML_WHILE_OP))
340 if (WalkState->ControlState->Common.Value)
342 AcpiOsPrintf ("Predicate = [True], IF block was executed\n");
346 AcpiOsPrintf ("Predicate = [False], Skipping IF block\n");
349 else if (Op->Common.AmlOpcode == AML_ELSE_OP)
351 AcpiOsPrintf ("Predicate = [False], ELSE block was executed\n");
354 /* Restore everything */
356 Op->Common.Next = Next;
358 if ((AcpiGbl_DbOutputToFile) ||
359 (AcpiDbgLevel & ACPI_LV_PARSE))
363 AcpiDbgLevel = OriginalDebugLevel;
366 /* If we are not single stepping, just continue executing the method */
368 if (!AcpiGbl_CmSingleStep)
374 * If we are executing a step-to-call command,
375 * Check if this is a method call.
377 if (AcpiGbl_StepToNextCall)
379 if (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP)
381 /* Not a method call, just keep executing */
386 /* Found a method call, stop executing */
388 AcpiGbl_StepToNextCall = FALSE;
392 * If the next opcode is a method call, we will "step over" it
395 if (Op->Common.AmlOpcode == AML_INT_METHODCALL_OP)
397 /* Force no more single stepping while executing called method */
399 AcpiGbl_CmSingleStep = FALSE;
402 * Set the breakpoint on/before the call, it will stop execution
403 * as soon as we return
405 WalkState->MethodBreakpoint = 1; /* Must be non-zero! */
409 AcpiExExitInterpreter ();
410 Status = AcpiDbStartCommand (WalkState, Op);
411 AcpiExEnterInterpreter ();
413 /* User commands complete, continue execution of the interrupted method */
419 /*******************************************************************************
421 * FUNCTION: AcpiInitializeDebugger
427 * DESCRIPTION: Init and start debugger
429 ******************************************************************************/
432 AcpiInitializeDebugger (
438 ACPI_FUNCTION_TRACE (AcpiInitializeDebugger);
443 AcpiGbl_DbBuffer = NULL;
444 AcpiGbl_DbFilename = NULL;
445 AcpiGbl_DbOutputToFile = FALSE;
447 AcpiGbl_DbDebugLevel = ACPI_LV_VERBOSITY2;
448 AcpiGbl_DbConsoleDebugLevel = ACPI_NORMAL_DEFAULT | ACPI_LV_TABLES;
449 AcpiGbl_DbOutputFlags = ACPI_DB_CONSOLE_OUTPUT;
451 AcpiGbl_DbOpt_NoIniMethods = FALSE;
453 AcpiGbl_DbBuffer = AcpiOsAllocate (ACPI_DEBUG_BUFFER_SIZE);
454 if (!AcpiGbl_DbBuffer)
456 return_ACPI_STATUS (AE_NO_MEMORY);
458 memset (AcpiGbl_DbBuffer, 0, ACPI_DEBUG_BUFFER_SIZE);
460 /* Initial scope is the root */
462 AcpiGbl_DbScopeBuf [0] = AML_ROOT_PREFIX;
463 AcpiGbl_DbScopeBuf [1] = 0;
464 AcpiGbl_DbScopeNode = AcpiGbl_RootNode;
466 /* Initialize user commands loop */
468 AcpiGbl_DbTerminateLoop = FALSE;
471 * If configured for multi-thread support, the debug executor runs in
472 * a separate thread so that the front end can be in another address
473 * space, environment, or even another machine.
475 if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
477 /* These were created with one unit, grab it */
479 Status = AcpiOsInitializeDebugger ();
480 if (ACPI_FAILURE (Status))
482 AcpiOsPrintf ("Could not get debugger mutex\n");
483 return_ACPI_STATUS (Status);
486 /* Create the debug execution thread to execute commands */
488 AcpiGbl_DbThreadsTerminated = FALSE;
489 Status = AcpiOsExecute (OSL_DEBUGGER_MAIN_THREAD,
490 AcpiDbExecuteThread, NULL);
491 if (ACPI_FAILURE (Status))
493 ACPI_EXCEPTION ((AE_INFO, Status,
494 "Could not start debugger thread"));
495 AcpiGbl_DbThreadsTerminated = TRUE;
496 return_ACPI_STATUS (Status);
501 AcpiGbl_DbThreadId = AcpiOsGetThreadId ();
504 return_ACPI_STATUS (AE_OK);
507 ACPI_EXPORT_SYMBOL (AcpiInitializeDebugger)
510 /*******************************************************************************
512 * FUNCTION: AcpiTerminateDebugger
518 * DESCRIPTION: Stop debugger
520 ******************************************************************************/
523 AcpiTerminateDebugger (
527 /* Terminate the AML Debugger */
529 AcpiGbl_DbTerminateLoop = TRUE;
531 if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
533 /* Wait the AML Debugger threads */
535 while (!AcpiGbl_DbThreadsTerminated)
540 AcpiOsTerminateDebugger ();
543 if (AcpiGbl_DbBuffer)
545 AcpiOsFree (AcpiGbl_DbBuffer);
546 AcpiGbl_DbBuffer = NULL;
549 /* Ensure that debug output is now disabled */
551 AcpiGbl_DbOutputFlags = ACPI_DB_DISABLE_OUTPUT;
554 ACPI_EXPORT_SYMBOL (AcpiTerminateDebugger)
557 /*******************************************************************************
559 * FUNCTION: AcpiSetDebuggerThreadId
561 * PARAMETERS: ThreadId - Debugger thread ID
565 * DESCRIPTION: Set debugger thread ID
567 ******************************************************************************/
570 AcpiSetDebuggerThreadId (
571 ACPI_THREAD_ID ThreadId)
573 AcpiGbl_DbThreadId = ThreadId;
576 ACPI_EXPORT_SYMBOL (AcpiSetDebuggerThreadId)
578 #endif /* ACPI_DEBUGGER */