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;
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 AcpiOsReleaseMutex (AcpiGbl_DbCommandComplete);
107 Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandReady,
109 if (ACPI_FAILURE (Status))
116 /* Single threaded, we must get a command line ourselves */
118 /* Force output to console until a command is entered */
120 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
122 /* Different prompt if method is executing */
124 if (!AcpiGbl_MethodExecuting)
126 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
130 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
133 /* Get the user input line */
135 Status = AcpiOsGetLine (AcpiGbl_DbLineBuf,
136 ACPI_DB_LINE_BUFFER_SIZE, NULL);
137 if (ACPI_FAILURE (Status))
139 ACPI_EXCEPTION ((AE_INFO, Status,
140 "While parsing command line"));
145 Status = AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, WalkState, Op);
148 /* AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); */
154 /*******************************************************************************
156 * FUNCTION: AcpiDbSignalBreakPoint
158 * PARAMETERS: WalkState - Current walk
162 * DESCRIPTION: Called for AML_BREAK_POINT_OP
164 ******************************************************************************/
167 AcpiDbSignalBreakPoint (
168 ACPI_WALK_STATE *WalkState)
171 #ifndef ACPI_APPLICATION
172 if (AcpiGbl_DbThreadId != AcpiOsGetThreadId ())
179 * Set the single-step flag. This will cause the debugger (if present)
180 * to break to the console within the AML debugger at the start of the
181 * next AML instruction.
183 AcpiGbl_CmSingleStep = TRUE;
184 AcpiOsPrintf ("**break** Executed AML BreakPoint opcode\n");
188 /*******************************************************************************
190 * FUNCTION: AcpiDbSingleStep
192 * PARAMETERS: WalkState - Current walk
193 * Op - Current executing op (from aml interpreter)
194 * OpcodeClass - Class of the current AML Opcode
198 * DESCRIPTION: Called just before execution of an AML opcode.
200 ******************************************************************************/
204 ACPI_WALK_STATE *WalkState,
205 ACPI_PARSE_OBJECT *Op,
208 ACPI_PARSE_OBJECT *Next;
209 ACPI_STATUS Status = AE_OK;
210 UINT32 OriginalDebugLevel;
211 ACPI_PARSE_OBJECT *DisplayOp;
212 ACPI_PARSE_OBJECT *ParentOp;
216 ACPI_FUNCTION_ENTRY ();
219 #ifndef ACPI_APPLICATION
220 if (AcpiGbl_DbThreadId != AcpiOsGetThreadId ())
226 /* Check the abort flag */
228 if (AcpiGbl_AbortMethod)
230 AcpiGbl_AbortMethod = FALSE;
231 return (AE_ABORT_METHOD);
234 AmlOffset = (UINT32) ACPI_PTR_DIFF (Op->Common.Aml,
235 WalkState->ParserState.AmlStart);
237 /* Check for single-step breakpoint */
239 if (WalkState->MethodBreakpoint &&
240 (WalkState->MethodBreakpoint <= AmlOffset))
242 /* Check if the breakpoint has been reached or passed */
243 /* Hit the breakpoint, resume single step, reset breakpoint */
245 AcpiOsPrintf ("***Break*** at AML offset %X\n", AmlOffset);
246 AcpiGbl_CmSingleStep = TRUE;
247 AcpiGbl_StepToNextCall = FALSE;
248 WalkState->MethodBreakpoint = 0;
251 /* Check for user breakpoint (Must be on exact Aml offset) */
253 else if (WalkState->UserBreakpoint &&
254 (WalkState->UserBreakpoint == AmlOffset))
256 AcpiOsPrintf ("***UserBreakpoint*** at AML offset %X\n",
258 AcpiGbl_CmSingleStep = TRUE;
259 AcpiGbl_StepToNextCall = FALSE;
260 WalkState->MethodBreakpoint = 0;
264 * Check if this is an opcode that we are interested in --
265 * namely, opcodes that have arguments
267 if (Op->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
274 case AML_CLASS_UNKNOWN:
275 case AML_CLASS_ARGUMENT: /* constants, literals, etc. do nothing */
281 /* All other opcodes -- continue */
286 * Under certain debug conditions, display this opcode and its operands
288 if ((AcpiGbl_DbOutputToFile) ||
289 (AcpiGbl_CmSingleStep) ||
290 (AcpiDbgLevel & ACPI_LV_PARSE))
292 if ((AcpiGbl_DbOutputToFile) ||
293 (AcpiDbgLevel & ACPI_LV_PARSE))
295 AcpiOsPrintf ("\n[AmlDebug] Next AML Opcode to execute:\n");
299 * Display this op (and only this op - zero out the NEXT field
300 * temporarily, and disable parser trace output for the duration of
301 * the display because we don't want the extraneous debug output)
303 OriginalDebugLevel = AcpiDbgLevel;
304 AcpiDbgLevel &= ~(ACPI_LV_PARSE | ACPI_LV_FUNCTIONS);
305 Next = Op->Common.Next;
306 Op->Common.Next = NULL;
310 ParentOp = Op->Common.Parent;
313 if ((WalkState->ControlState) &&
314 (WalkState->ControlState->Common.State ==
315 ACPI_CONTROL_PREDICATE_EXECUTING))
318 * We are executing the predicate of an IF or WHILE statement
319 * Search upwards for the containing IF or WHILE so that the
320 * entire predicate can be displayed.
324 if ((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
325 (ParentOp->Common.AmlOpcode == AML_WHILE_OP))
327 DisplayOp = ParentOp;
330 ParentOp = ParentOp->Common.Parent;
337 if ((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
338 (ParentOp->Common.AmlOpcode == AML_ELSE_OP) ||
339 (ParentOp->Common.AmlOpcode == AML_SCOPE_OP) ||
340 (ParentOp->Common.AmlOpcode == AML_METHOD_OP) ||
341 (ParentOp->Common.AmlOpcode == AML_WHILE_OP))
345 DisplayOp = ParentOp;
346 ParentOp = ParentOp->Common.Parent;
351 /* Now we can display it */
353 #ifdef ACPI_DISASSEMBLER
354 AcpiDmDisassemble (WalkState, DisplayOp, ACPI_UINT32_MAX);
357 if ((Op->Common.AmlOpcode == AML_IF_OP) ||
358 (Op->Common.AmlOpcode == AML_WHILE_OP))
360 if (WalkState->ControlState->Common.Value)
362 AcpiOsPrintf ("Predicate = [True], IF block was executed\n");
366 AcpiOsPrintf ("Predicate = [False], Skipping IF block\n");
369 else if (Op->Common.AmlOpcode == AML_ELSE_OP)
371 AcpiOsPrintf ("Predicate = [False], ELSE block was executed\n");
374 /* Restore everything */
376 Op->Common.Next = Next;
378 if ((AcpiGbl_DbOutputToFile) ||
379 (AcpiDbgLevel & ACPI_LV_PARSE))
383 AcpiDbgLevel = OriginalDebugLevel;
386 /* If we are not single stepping, just continue executing the method */
388 if (!AcpiGbl_CmSingleStep)
394 * If we are executing a step-to-call command,
395 * Check if this is a method call.
397 if (AcpiGbl_StepToNextCall)
399 if (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP)
401 /* Not a method call, just keep executing */
406 /* Found a method call, stop executing */
408 AcpiGbl_StepToNextCall = FALSE;
412 * If the next opcode is a method call, we will "step over" it
415 if (Op->Common.AmlOpcode == AML_INT_METHODCALL_OP)
417 /* Force no more single stepping while executing called method */
419 AcpiGbl_CmSingleStep = FALSE;
422 * Set the breakpoint on/before the call, it will stop execution
423 * as soon as we return
425 WalkState->MethodBreakpoint = 1; /* Must be non-zero! */
429 Status = AcpiDbStartCommand (WalkState, Op);
431 /* User commands complete, continue execution of the interrupted method */
437 /*******************************************************************************
439 * FUNCTION: AcpiInitializeDebugger
445 * DESCRIPTION: Init and start debugger
447 ******************************************************************************/
450 AcpiInitializeDebugger (
456 ACPI_FUNCTION_TRACE (AcpiInitializeDebugger);
461 AcpiGbl_DbBuffer = NULL;
462 AcpiGbl_DbFilename = NULL;
463 AcpiGbl_DbOutputToFile = FALSE;
465 AcpiGbl_DbDebugLevel = ACPI_LV_VERBOSITY2;
466 AcpiGbl_DbConsoleDebugLevel = ACPI_NORMAL_DEFAULT | ACPI_LV_TABLES;
467 AcpiGbl_DbOutputFlags = ACPI_DB_CONSOLE_OUTPUT;
469 AcpiGbl_DbOpt_NoIniMethods = FALSE;
471 AcpiGbl_DbBuffer = AcpiOsAllocate (ACPI_DEBUG_BUFFER_SIZE);
472 if (!AcpiGbl_DbBuffer)
474 return_ACPI_STATUS (AE_NO_MEMORY);
476 memset (AcpiGbl_DbBuffer, 0, ACPI_DEBUG_BUFFER_SIZE);
478 /* Initial scope is the root */
480 AcpiGbl_DbScopeBuf [0] = AML_ROOT_PREFIX;
481 AcpiGbl_DbScopeBuf [1] = 0;
482 AcpiGbl_DbScopeNode = AcpiGbl_RootNode;
484 /* Initialize user commands loop */
486 AcpiGbl_DbTerminateLoop = FALSE;
489 * If configured for multi-thread support, the debug executor runs in
490 * a separate thread so that the front end can be in another address
491 * space, environment, or even another machine.
493 if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
495 /* These were created with one unit, grab it */
497 Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandComplete,
499 if (ACPI_FAILURE (Status))
501 AcpiOsPrintf ("Could not get debugger mutex\n");
502 return_ACPI_STATUS (Status);
505 Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandReady,
507 if (ACPI_FAILURE (Status))
509 AcpiOsPrintf ("Could not get debugger mutex\n");
510 return_ACPI_STATUS (Status);
513 /* Create the debug execution thread to execute commands */
515 AcpiGbl_DbThreadsTerminated = FALSE;
516 Status = AcpiOsExecute (OSL_DEBUGGER_MAIN_THREAD,
517 AcpiDbExecuteThread, NULL);
518 if (ACPI_FAILURE (Status))
520 ACPI_EXCEPTION ((AE_INFO, Status,
521 "Could not start debugger thread"));
522 AcpiGbl_DbThreadsTerminated = TRUE;
523 return_ACPI_STATUS (Status);
528 AcpiGbl_DbThreadId = AcpiOsGetThreadId ();
531 return_ACPI_STATUS (AE_OK);
534 ACPI_EXPORT_SYMBOL (AcpiInitializeDebugger)
537 /*******************************************************************************
539 * FUNCTION: AcpiTerminateDebugger
545 * DESCRIPTION: Stop debugger
547 ******************************************************************************/
550 AcpiTerminateDebugger (
554 /* Terminate the AML Debugger */
556 AcpiGbl_DbTerminateLoop = TRUE;
558 if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
560 AcpiOsReleaseMutex (AcpiGbl_DbCommandReady);
562 /* Wait the AML Debugger threads */
564 while (!AcpiGbl_DbThreadsTerminated)
570 if (AcpiGbl_DbBuffer)
572 AcpiOsFree (AcpiGbl_DbBuffer);
573 AcpiGbl_DbBuffer = NULL;
576 /* Ensure that debug output is now disabled */
578 AcpiGbl_DbOutputFlags = ACPI_DB_DISABLE_OUTPUT;
581 ACPI_EXPORT_SYMBOL (AcpiTerminateDebugger)
584 /*******************************************************************************
586 * FUNCTION: AcpiSetDebuggerThreadId
588 * PARAMETERS: ThreadId - Debugger thread ID
592 * DESCRIPTION: Set debugger thread ID
594 ******************************************************************************/
597 AcpiSetDebuggerThreadId (
598 ACPI_THREAD_ID ThreadId)
600 AcpiGbl_DbThreadId = ThreadId;
603 ACPI_EXPORT_SYMBOL (AcpiSetDebuggerThreadId)
605 #endif /* ACPI_DEBUGGER */