1 /*******************************************************************************
3 * Module Name: dbxface - AML Debugger external interfaces
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.
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;
100 while (Status == AE_CTRL_TRUE)
102 /* Notify the completion of the command */
104 Status = AcpiOsNotifyCommandComplete ();
105 if (ACPI_FAILURE (Status))
110 /* Wait the readiness of the command */
112 Status = AcpiOsWaitCommandReady ();
113 if (ACPI_FAILURE (Status))
118 Status = AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, WalkState, Op);
121 /* AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); */
124 if (ACPI_FAILURE (Status) && Status != AE_CTRL_TERMINATE)
126 ACPI_EXCEPTION ((AE_INFO, Status,
127 "While parsing/handling command line"));
133 /*******************************************************************************
135 * FUNCTION: AcpiDbSignalBreakPoint
137 * PARAMETERS: WalkState - Current walk
141 * DESCRIPTION: Called for AML_BREAK_POINT_OP
143 ******************************************************************************/
146 AcpiDbSignalBreakPoint (
147 ACPI_WALK_STATE *WalkState)
150 #ifndef ACPI_APPLICATION
151 if (AcpiGbl_DbThreadId != AcpiOsGetThreadId ())
158 * Set the single-step flag. This will cause the debugger (if present)
159 * to break to the console within the AML debugger at the start of the
160 * next AML instruction.
162 AcpiGbl_CmSingleStep = TRUE;
163 AcpiOsPrintf ("**break** Executed AML BreakPoint opcode\n");
167 /*******************************************************************************
169 * FUNCTION: AcpiDbSingleStep
171 * PARAMETERS: WalkState - Current walk
172 * Op - Current executing op (from aml interpreter)
173 * OpcodeClass - Class of the current AML Opcode
177 * DESCRIPTION: Called just before execution of an AML opcode.
179 ******************************************************************************/
183 ACPI_WALK_STATE *WalkState,
184 ACPI_PARSE_OBJECT *Op,
187 ACPI_PARSE_OBJECT *Next;
188 ACPI_STATUS Status = AE_OK;
189 UINT32 OriginalDebugLevel;
190 ACPI_PARSE_OBJECT *DisplayOp;
191 ACPI_PARSE_OBJECT *ParentOp;
195 ACPI_FUNCTION_ENTRY ();
198 #ifndef ACPI_APPLICATION
199 if (AcpiGbl_DbThreadId != AcpiOsGetThreadId ())
205 /* Check the abort flag */
207 if (AcpiGbl_AbortMethod)
209 AcpiGbl_AbortMethod = FALSE;
210 return (AE_ABORT_METHOD);
213 AmlOffset = (UINT32) ACPI_PTR_DIFF (Op->Common.Aml,
214 WalkState->ParserState.AmlStart);
216 /* Check for single-step breakpoint */
218 if (WalkState->MethodBreakpoint &&
219 (WalkState->MethodBreakpoint <= AmlOffset))
221 /* Check if the breakpoint has been reached or passed */
222 /* Hit the breakpoint, resume single step, reset breakpoint */
224 AcpiOsPrintf ("***Break*** at AML offset %X\n", AmlOffset);
225 AcpiGbl_CmSingleStep = TRUE;
226 AcpiGbl_StepToNextCall = FALSE;
227 WalkState->MethodBreakpoint = 0;
230 /* Check for user breakpoint (Must be on exact Aml offset) */
232 else if (WalkState->UserBreakpoint &&
233 (WalkState->UserBreakpoint == AmlOffset))
235 AcpiOsPrintf ("***UserBreakpoint*** at AML offset %X\n",
237 AcpiGbl_CmSingleStep = TRUE;
238 AcpiGbl_StepToNextCall = FALSE;
239 WalkState->MethodBreakpoint = 0;
243 * Check if this is an opcode that we are interested in --
244 * namely, opcodes that have arguments
246 if (Op->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
253 case AML_CLASS_UNKNOWN:
254 case AML_CLASS_ARGUMENT: /* constants, literals, etc. do nothing */
260 /* All other opcodes -- continue */
265 * Under certain debug conditions, display this opcode and its operands
267 if ((AcpiGbl_DbOutputToFile) ||
268 (AcpiGbl_CmSingleStep) ||
269 (AcpiDbgLevel & ACPI_LV_PARSE))
271 if ((AcpiGbl_DbOutputToFile) ||
272 (AcpiDbgLevel & ACPI_LV_PARSE))
274 AcpiOsPrintf ("\n[AmlDebug] Next AML Opcode to execute:\n");
278 * Display this op (and only this op - zero out the NEXT field
279 * temporarily, and disable parser trace output for the duration of
280 * the display because we don't want the extraneous debug output)
282 OriginalDebugLevel = AcpiDbgLevel;
283 AcpiDbgLevel &= ~(ACPI_LV_PARSE | ACPI_LV_FUNCTIONS);
284 Next = Op->Common.Next;
285 Op->Common.Next = NULL;
289 ParentOp = Op->Common.Parent;
292 if ((WalkState->ControlState) &&
293 (WalkState->ControlState->Common.State ==
294 ACPI_CONTROL_PREDICATE_EXECUTING))
297 * We are executing the predicate of an IF or WHILE statement
298 * Search upwards for the containing IF or WHILE so that the
299 * entire predicate can be displayed.
303 if ((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
304 (ParentOp->Common.AmlOpcode == AML_WHILE_OP))
306 DisplayOp = ParentOp;
309 ParentOp = ParentOp->Common.Parent;
316 if ((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
317 (ParentOp->Common.AmlOpcode == AML_ELSE_OP) ||
318 (ParentOp->Common.AmlOpcode == AML_SCOPE_OP) ||
319 (ParentOp->Common.AmlOpcode == AML_METHOD_OP) ||
320 (ParentOp->Common.AmlOpcode == AML_WHILE_OP))
324 DisplayOp = ParentOp;
325 ParentOp = ParentOp->Common.Parent;
330 /* Now we can display it */
332 #ifdef ACPI_DISASSEMBLER
333 AcpiDmDisassemble (WalkState, DisplayOp, ACPI_UINT32_MAX);
336 if ((Op->Common.AmlOpcode == AML_IF_OP) ||
337 (Op->Common.AmlOpcode == AML_WHILE_OP))
339 if (WalkState->ControlState->Common.Value)
341 AcpiOsPrintf ("Predicate = [True], IF block was executed\n");
345 AcpiOsPrintf ("Predicate = [False], Skipping IF block\n");
348 else if (Op->Common.AmlOpcode == AML_ELSE_OP)
350 AcpiOsPrintf ("Predicate = [False], ELSE block was executed\n");
353 /* Restore everything */
355 Op->Common.Next = Next;
357 if ((AcpiGbl_DbOutputToFile) ||
358 (AcpiDbgLevel & ACPI_LV_PARSE))
362 AcpiDbgLevel = OriginalDebugLevel;
365 /* If we are not single stepping, just continue executing the method */
367 if (!AcpiGbl_CmSingleStep)
373 * If we are executing a step-to-call command,
374 * Check if this is a method call.
376 if (AcpiGbl_StepToNextCall)
378 if (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP)
380 /* Not a method call, just keep executing */
385 /* Found a method call, stop executing */
387 AcpiGbl_StepToNextCall = FALSE;
391 * If the next opcode is a method call, we will "step over" it
394 if (Op->Common.AmlOpcode == AML_INT_METHODCALL_OP)
396 /* Force no more single stepping while executing called method */
398 AcpiGbl_CmSingleStep = FALSE;
401 * Set the breakpoint on/before the call, it will stop execution
402 * as soon as we return
404 WalkState->MethodBreakpoint = 1; /* Must be non-zero! */
408 Status = AcpiDbStartCommand (WalkState, Op);
410 /* User commands complete, continue execution of the interrupted method */
416 /*******************************************************************************
418 * FUNCTION: AcpiInitializeDebugger
424 * DESCRIPTION: Init and start debugger
426 ******************************************************************************/
429 AcpiInitializeDebugger (
435 ACPI_FUNCTION_TRACE (AcpiInitializeDebugger);
440 AcpiGbl_DbBuffer = NULL;
441 AcpiGbl_DbFilename = NULL;
442 AcpiGbl_DbOutputToFile = FALSE;
444 AcpiGbl_DbDebugLevel = ACPI_LV_VERBOSITY2;
445 AcpiGbl_DbConsoleDebugLevel = ACPI_NORMAL_DEFAULT | ACPI_LV_TABLES;
446 AcpiGbl_DbOutputFlags = ACPI_DB_CONSOLE_OUTPUT;
448 AcpiGbl_DbOpt_NoIniMethods = FALSE;
450 AcpiGbl_DbBuffer = AcpiOsAllocate (ACPI_DEBUG_BUFFER_SIZE);
451 if (!AcpiGbl_DbBuffer)
453 return_ACPI_STATUS (AE_NO_MEMORY);
455 memset (AcpiGbl_DbBuffer, 0, ACPI_DEBUG_BUFFER_SIZE);
457 /* Initial scope is the root */
459 AcpiGbl_DbScopeBuf [0] = AML_ROOT_PREFIX;
460 AcpiGbl_DbScopeBuf [1] = 0;
461 AcpiGbl_DbScopeNode = AcpiGbl_RootNode;
463 /* Initialize user commands loop */
465 AcpiGbl_DbTerminateLoop = FALSE;
468 * If configured for multi-thread support, the debug executor runs in
469 * a separate thread so that the front end can be in another address
470 * space, environment, or even another machine.
472 if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
474 /* These were created with one unit, grab it */
476 Status = AcpiOsInitializeDebugger ();
477 if (ACPI_FAILURE (Status))
479 AcpiOsPrintf ("Could not get debugger mutex\n");
480 return_ACPI_STATUS (Status);
483 /* Create the debug execution thread to execute commands */
485 AcpiGbl_DbThreadsTerminated = FALSE;
486 Status = AcpiOsExecute (OSL_DEBUGGER_MAIN_THREAD,
487 AcpiDbExecuteThread, NULL);
488 if (ACPI_FAILURE (Status))
490 ACPI_EXCEPTION ((AE_INFO, Status,
491 "Could not start debugger thread"));
492 AcpiGbl_DbThreadsTerminated = TRUE;
493 return_ACPI_STATUS (Status);
498 AcpiGbl_DbThreadId = AcpiOsGetThreadId ();
501 return_ACPI_STATUS (AE_OK);
504 ACPI_EXPORT_SYMBOL (AcpiInitializeDebugger)
507 /*******************************************************************************
509 * FUNCTION: AcpiTerminateDebugger
515 * DESCRIPTION: Stop debugger
517 ******************************************************************************/
520 AcpiTerminateDebugger (
524 /* Terminate the AML Debugger */
526 AcpiGbl_DbTerminateLoop = TRUE;
528 if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
530 /* Wait the AML Debugger threads */
532 while (!AcpiGbl_DbThreadsTerminated)
537 AcpiOsTerminateDebugger ();
540 if (AcpiGbl_DbBuffer)
542 AcpiOsFree (AcpiGbl_DbBuffer);
543 AcpiGbl_DbBuffer = NULL;
546 /* Ensure that debug output is now disabled */
548 AcpiGbl_DbOutputFlags = ACPI_DB_DISABLE_OUTPUT;
551 ACPI_EXPORT_SYMBOL (AcpiTerminateDebugger)
554 /*******************************************************************************
556 * FUNCTION: AcpiSetDebuggerThreadId
558 * PARAMETERS: ThreadId - Debugger thread ID
562 * DESCRIPTION: Set debugger thread ID
564 ******************************************************************************/
567 AcpiSetDebuggerThreadId (
568 ACPI_THREAD_ID ThreadId)
570 AcpiGbl_DbThreadId = ThreadId;
573 ACPI_EXPORT_SYMBOL (AcpiSetDebuggerThreadId)
575 #endif /* ACPI_DEBUGGER */