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.
44 #include <contrib/dev/acpica/include/acpi.h>
45 #include <contrib/dev/acpica/include/accommon.h>
46 #include <contrib/dev/acpica/include/amlcode.h>
47 #include <contrib/dev/acpica/include/acdebug.h>
50 #define _COMPONENT ACPI_CA_DEBUGGER
51 ACPI_MODULE_NAME ("dbxface")
54 /* Local prototypes */
58 ACPI_WALK_STATE *WalkState,
59 ACPI_PARSE_OBJECT *Op);
61 #ifdef ACPI_OBSOLETE_FUNCTIONS
64 ACPI_WALK_STATE *WalkState);
68 /*******************************************************************************
70 * FUNCTION: AcpiDbStartCommand
72 * PARAMETERS: WalkState - Current walk
73 * Op - Current executing Op, from AML interpreter
77 * DESCRIPTION: Enter debugger command loop
79 ******************************************************************************/
83 ACPI_WALK_STATE *WalkState,
84 ACPI_PARSE_OBJECT *Op)
89 /* TBD: [Investigate] are there namespace locking issues here? */
91 /* AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); */
93 /* Go into the command loop and await next user command */
96 AcpiGbl_MethodExecuting = TRUE;
97 Status = AE_CTRL_TRUE;
98 while (Status == AE_CTRL_TRUE)
100 if (AcpiGbl_DebuggerConfiguration == DEBUGGER_MULTI_THREADED)
102 /* Handshake with the front-end that gets user command lines */
104 AcpiOsReleaseMutex (AcpiGbl_DbCommandComplete);
106 Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandReady,
108 if (ACPI_FAILURE (Status))
115 /* Single threaded, we must get a command line ourselves */
117 /* Force output to console until a command is entered */
119 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
121 /* Different prompt if method is executing */
123 if (!AcpiGbl_MethodExecuting)
125 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
129 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
132 /* Get the user input line */
134 Status = AcpiOsGetLine (AcpiGbl_DbLineBuf,
135 ACPI_DB_LINE_BUFFER_SIZE, NULL);
136 if (ACPI_FAILURE (Status))
138 ACPI_EXCEPTION ((AE_INFO, Status,
139 "While parsing command line"));
144 Status = AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, WalkState, Op);
147 /* AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); */
153 /*******************************************************************************
155 * FUNCTION: AcpiDbSignalBreakPoint
157 * PARAMETERS: WalkState - Current walk
161 * DESCRIPTION: Called for AML_BREAK_POINT_OP
163 ******************************************************************************/
166 AcpiDbSignalBreakPoint (
167 ACPI_WALK_STATE *WalkState)
170 #ifndef ACPI_APPLICATION
171 if (AcpiGbl_DbThreadId != AcpiOsGetThreadId ())
178 * Set the single-step flag. This will cause the debugger (if present)
179 * to break to the console within the AML debugger at the start of the
180 * next AML instruction.
182 AcpiGbl_CmSingleStep = TRUE;
183 AcpiOsPrintf ("**break** Executed AML BreakPoint opcode\n");
187 /*******************************************************************************
189 * FUNCTION: AcpiDbSingleStep
191 * PARAMETERS: WalkState - Current walk
192 * Op - Current executing op (from aml interpreter)
193 * OpcodeClass - Class of the current AML Opcode
197 * DESCRIPTION: Called just before execution of an AML opcode.
199 ******************************************************************************/
203 ACPI_WALK_STATE *WalkState,
204 ACPI_PARSE_OBJECT *Op,
207 ACPI_PARSE_OBJECT *Next;
208 ACPI_STATUS Status = AE_OK;
209 UINT32 OriginalDebugLevel;
210 ACPI_PARSE_OBJECT *DisplayOp;
211 ACPI_PARSE_OBJECT *ParentOp;
215 ACPI_FUNCTION_ENTRY ();
218 #ifndef ACPI_APPLICATION
219 if (AcpiGbl_DbThreadId != AcpiOsGetThreadId ())
225 /* Check the abort flag */
227 if (AcpiGbl_AbortMethod)
229 AcpiGbl_AbortMethod = FALSE;
230 return (AE_ABORT_METHOD);
233 AmlOffset = (UINT32) ACPI_PTR_DIFF (Op->Common.Aml,
234 WalkState->ParserState.AmlStart);
236 /* Check for single-step breakpoint */
238 if (WalkState->MethodBreakpoint &&
239 (WalkState->MethodBreakpoint <= AmlOffset))
241 /* Check if the breakpoint has been reached or passed */
242 /* Hit the breakpoint, resume single step, reset breakpoint */
244 AcpiOsPrintf ("***Break*** at AML offset %X\n", AmlOffset);
245 AcpiGbl_CmSingleStep = TRUE;
246 AcpiGbl_StepToNextCall = FALSE;
247 WalkState->MethodBreakpoint = 0;
250 /* Check for user breakpoint (Must be on exact Aml offset) */
252 else if (WalkState->UserBreakpoint &&
253 (WalkState->UserBreakpoint == AmlOffset))
255 AcpiOsPrintf ("***UserBreakpoint*** at AML offset %X\n",
257 AcpiGbl_CmSingleStep = TRUE;
258 AcpiGbl_StepToNextCall = FALSE;
259 WalkState->MethodBreakpoint = 0;
263 * Check if this is an opcode that we are interested in --
264 * namely, opcodes that have arguments
266 if (Op->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
273 case AML_CLASS_UNKNOWN:
274 case AML_CLASS_ARGUMENT: /* constants, literals, etc. do nothing */
280 /* All other opcodes -- continue */
285 * Under certain debug conditions, display this opcode and its operands
287 if ((AcpiGbl_DbOutputToFile) ||
288 (AcpiGbl_CmSingleStep) ||
289 (AcpiDbgLevel & ACPI_LV_PARSE))
291 if ((AcpiGbl_DbOutputToFile) ||
292 (AcpiDbgLevel & ACPI_LV_PARSE))
294 AcpiOsPrintf ("\n[AmlDebug] Next AML Opcode to execute:\n");
298 * Display this op (and only this op - zero out the NEXT field
299 * temporarily, and disable parser trace output for the duration of
300 * the display because we don't want the extraneous debug output)
302 OriginalDebugLevel = AcpiDbgLevel;
303 AcpiDbgLevel &= ~(ACPI_LV_PARSE | ACPI_LV_FUNCTIONS);
304 Next = Op->Common.Next;
305 Op->Common.Next = NULL;
309 ParentOp = Op->Common.Parent;
312 if ((WalkState->ControlState) &&
313 (WalkState->ControlState->Common.State ==
314 ACPI_CONTROL_PREDICATE_EXECUTING))
317 * We are executing the predicate of an IF or WHILE statement
318 * Search upwards for the containing IF or WHILE so that the
319 * entire predicate can be displayed.
323 if ((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
324 (ParentOp->Common.AmlOpcode == AML_WHILE_OP))
326 DisplayOp = ParentOp;
329 ParentOp = ParentOp->Common.Parent;
336 if ((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
337 (ParentOp->Common.AmlOpcode == AML_ELSE_OP) ||
338 (ParentOp->Common.AmlOpcode == AML_SCOPE_OP) ||
339 (ParentOp->Common.AmlOpcode == AML_METHOD_OP) ||
340 (ParentOp->Common.AmlOpcode == AML_WHILE_OP))
344 DisplayOp = ParentOp;
345 ParentOp = ParentOp->Common.Parent;
350 /* Now we can display it */
352 #ifdef ACPI_DISASSEMBLER
353 AcpiDmDisassemble (WalkState, DisplayOp, ACPI_UINT32_MAX);
356 if ((Op->Common.AmlOpcode == AML_IF_OP) ||
357 (Op->Common.AmlOpcode == AML_WHILE_OP))
359 if (WalkState->ControlState->Common.Value)
361 AcpiOsPrintf ("Predicate = [True], IF block was executed\n");
365 AcpiOsPrintf ("Predicate = [False], Skipping IF block\n");
368 else if (Op->Common.AmlOpcode == AML_ELSE_OP)
370 AcpiOsPrintf ("Predicate = [False], ELSE block was executed\n");
373 /* Restore everything */
375 Op->Common.Next = Next;
377 if ((AcpiGbl_DbOutputToFile) ||
378 (AcpiDbgLevel & ACPI_LV_PARSE))
382 AcpiDbgLevel = OriginalDebugLevel;
385 /* If we are not single stepping, just continue executing the method */
387 if (!AcpiGbl_CmSingleStep)
393 * If we are executing a step-to-call command,
394 * Check if this is a method call.
396 if (AcpiGbl_StepToNextCall)
398 if (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP)
400 /* Not a method call, just keep executing */
405 /* Found a method call, stop executing */
407 AcpiGbl_StepToNextCall = FALSE;
411 * If the next opcode is a method call, we will "step over" it
414 if (Op->Common.AmlOpcode == AML_INT_METHODCALL_OP)
416 /* Force no more single stepping while executing called method */
418 AcpiGbl_CmSingleStep = FALSE;
421 * Set the breakpoint on/before the call, it will stop execution
422 * as soon as we return
424 WalkState->MethodBreakpoint = 1; /* Must be non-zero! */
428 Status = AcpiDbStartCommand (WalkState, Op);
430 /* User commands complete, continue execution of the interrupted method */
436 /*******************************************************************************
438 * FUNCTION: AcpiInitializeDebugger
444 * DESCRIPTION: Init and start debugger
446 ******************************************************************************/
449 AcpiInitializeDebugger (
455 ACPI_FUNCTION_TRACE (AcpiInitializeDebugger);
460 AcpiGbl_DbBuffer = NULL;
461 AcpiGbl_DbFilename = NULL;
462 AcpiGbl_DbOutputToFile = FALSE;
464 AcpiGbl_DbDebugLevel = ACPI_LV_VERBOSITY2;
465 AcpiGbl_DbConsoleDebugLevel = ACPI_NORMAL_DEFAULT | ACPI_LV_TABLES;
466 AcpiGbl_DbOutputFlags = ACPI_DB_CONSOLE_OUTPUT;
468 AcpiGbl_DbOpt_NoIniMethods = FALSE;
470 AcpiGbl_DbBuffer = AcpiOsAllocate (ACPI_DEBUG_BUFFER_SIZE);
471 if (!AcpiGbl_DbBuffer)
473 return_ACPI_STATUS (AE_NO_MEMORY);
475 memset (AcpiGbl_DbBuffer, 0, ACPI_DEBUG_BUFFER_SIZE);
477 /* Initial scope is the root */
479 AcpiGbl_DbScopeBuf [0] = AML_ROOT_PREFIX;
480 AcpiGbl_DbScopeBuf [1] = 0;
481 AcpiGbl_DbScopeNode = AcpiGbl_RootNode;
483 /* Initialize user commands loop */
485 AcpiGbl_DbTerminateLoop = FALSE;
488 * If configured for multi-thread support, the debug executor runs in
489 * a separate thread so that the front end can be in another address
490 * space, environment, or even another machine.
492 if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
494 /* These were created with one unit, grab it */
496 Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandComplete,
498 if (ACPI_FAILURE (Status))
500 AcpiOsPrintf ("Could not get debugger mutex\n");
501 return_ACPI_STATUS (Status);
504 Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandReady,
506 if (ACPI_FAILURE (Status))
508 AcpiOsPrintf ("Could not get debugger mutex\n");
509 return_ACPI_STATUS (Status);
512 /* Create the debug execution thread to execute commands */
514 AcpiGbl_DbThreadsTerminated = FALSE;
515 Status = AcpiOsExecute (OSL_DEBUGGER_MAIN_THREAD,
516 AcpiDbExecuteThread, NULL);
517 if (ACPI_FAILURE (Status))
519 ACPI_EXCEPTION ((AE_INFO, Status,
520 "Could not start debugger thread"));
521 AcpiGbl_DbThreadsTerminated = TRUE;
522 return_ACPI_STATUS (Status);
527 AcpiGbl_DbThreadId = AcpiOsGetThreadId ();
530 return_ACPI_STATUS (AE_OK);
533 ACPI_EXPORT_SYMBOL (AcpiInitializeDebugger)
536 /*******************************************************************************
538 * FUNCTION: AcpiTerminateDebugger
544 * DESCRIPTION: Stop debugger
546 ******************************************************************************/
549 AcpiTerminateDebugger (
553 /* Terminate the AML Debugger */
555 AcpiGbl_DbTerminateLoop = TRUE;
557 if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
559 AcpiOsReleaseMutex (AcpiGbl_DbCommandReady);
561 /* Wait the AML Debugger threads */
563 while (!AcpiGbl_DbThreadsTerminated)
569 if (AcpiGbl_DbBuffer)
571 AcpiOsFree (AcpiGbl_DbBuffer);
572 AcpiGbl_DbBuffer = NULL;
575 /* Ensure that debug output is now disabled */
577 AcpiGbl_DbOutputFlags = ACPI_DB_DISABLE_OUTPUT;
580 ACPI_EXPORT_SYMBOL (AcpiTerminateDebugger)
583 /*******************************************************************************
585 * FUNCTION: AcpiSetDebuggerThreadId
587 * PARAMETERS: ThreadId - Debugger thread ID
591 * DESCRIPTION: Set debugger thread ID
593 ******************************************************************************/
596 AcpiSetDebuggerThreadId (
597 ACPI_THREAD_ID ThreadId)
599 AcpiGbl_DbThreadId = ThreadId;
602 ACPI_EXPORT_SYMBOL (AcpiSetDebuggerThreadId)