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.
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>
48 #ifdef ACPI_DISASSEMBLER
49 #include <contrib/dev/acpica/include/acdisasm.h>
55 #define _COMPONENT ACPI_CA_DEBUGGER
56 ACPI_MODULE_NAME ("dbxface")
59 /* Local prototypes */
63 ACPI_WALK_STATE *WalkState,
64 ACPI_PARSE_OBJECT *Op);
66 #ifdef ACPI_OBSOLETE_FUNCTIONS
69 ACPI_WALK_STATE *WalkState);
73 /*******************************************************************************
75 * FUNCTION: AcpiDbStartCommand
77 * PARAMETERS: WalkState - Current walk
78 * Op - Current executing Op, from AML interpreter
82 * DESCRIPTION: Enter debugger command loop
84 ******************************************************************************/
88 ACPI_WALK_STATE *WalkState,
89 ACPI_PARSE_OBJECT *Op)
94 /* TBD: [Investigate] are there namespace locking issues here? */
96 /* AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); */
98 /* Go into the command loop and await next user command */
101 AcpiGbl_MethodExecuting = TRUE;
102 Status = AE_CTRL_TRUE;
103 while (Status == AE_CTRL_TRUE)
105 if (AcpiGbl_DebuggerConfiguration == DEBUGGER_MULTI_THREADED)
107 /* Handshake with the front-end that gets user command lines */
109 Status = AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
110 if (ACPI_FAILURE (Status))
114 Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_READY);
115 if (ACPI_FAILURE (Status))
122 /* Single threaded, we must get a command line ourselves */
124 /* Force output to console until a command is entered */
126 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
128 /* Different prompt if method is executing */
130 if (!AcpiGbl_MethodExecuting)
132 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
136 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
139 /* Get the user input line */
141 Status = AcpiOsGetLine (AcpiGbl_DbLineBuf,
142 ACPI_DB_LINE_BUFFER_SIZE, NULL);
143 if (ACPI_FAILURE (Status))
145 ACPI_EXCEPTION ((AE_INFO, Status, "While parsing command line"));
150 Status = AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, WalkState, Op);
153 /* AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); */
159 /*******************************************************************************
161 * FUNCTION: AcpiDbSingleStep
163 * PARAMETERS: WalkState - Current walk
164 * Op - Current executing op (from aml interpreter)
165 * OpcodeClass - Class of the current AML Opcode
169 * DESCRIPTION: Called just before execution of an AML opcode.
171 ******************************************************************************/
175 ACPI_WALK_STATE *WalkState,
176 ACPI_PARSE_OBJECT *Op,
179 ACPI_PARSE_OBJECT *Next;
180 ACPI_STATUS Status = AE_OK;
181 UINT32 OriginalDebugLevel;
182 ACPI_PARSE_OBJECT *DisplayOp;
183 ACPI_PARSE_OBJECT *ParentOp;
187 ACPI_FUNCTION_ENTRY ();
190 /* Check the abort flag */
192 if (AcpiGbl_AbortMethod)
194 AcpiGbl_AbortMethod = FALSE;
195 return (AE_ABORT_METHOD);
198 AmlOffset = (UINT32) ACPI_PTR_DIFF (Op->Common.Aml,
199 WalkState->ParserState.AmlStart);
201 /* Check for single-step breakpoint */
203 if (WalkState->MethodBreakpoint &&
204 (WalkState->MethodBreakpoint <= AmlOffset))
206 /* Check if the breakpoint has been reached or passed */
207 /* Hit the breakpoint, resume single step, reset breakpoint */
209 AcpiOsPrintf ("***Break*** at AML offset %X\n", AmlOffset);
210 AcpiGbl_CmSingleStep = TRUE;
211 AcpiGbl_StepToNextCall = FALSE;
212 WalkState->MethodBreakpoint = 0;
215 /* Check for user breakpoint (Must be on exact Aml offset) */
217 else if (WalkState->UserBreakpoint &&
218 (WalkState->UserBreakpoint == AmlOffset))
220 AcpiOsPrintf ("***UserBreakpoint*** at AML offset %X\n",
222 AcpiGbl_CmSingleStep = TRUE;
223 AcpiGbl_StepToNextCall = FALSE;
224 WalkState->MethodBreakpoint = 0;
228 * Check if this is an opcode that we are interested in --
229 * namely, opcodes that have arguments
231 if (Op->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
238 case AML_CLASS_UNKNOWN:
239 case AML_CLASS_ARGUMENT: /* constants, literals, etc. do nothing */
245 /* All other opcodes -- continue */
250 * Under certain debug conditions, display this opcode and its operands
252 if ((AcpiGbl_DbOutputToFile) ||
253 (AcpiGbl_CmSingleStep) ||
254 (AcpiDbgLevel & ACPI_LV_PARSE))
256 if ((AcpiGbl_DbOutputToFile) ||
257 (AcpiDbgLevel & ACPI_LV_PARSE))
259 AcpiOsPrintf ("\n[AmlDebug] Next AML Opcode to execute:\n");
263 * Display this op (and only this op - zero out the NEXT field
264 * temporarily, and disable parser trace output for the duration of
265 * the display because we don't want the extraneous debug output)
267 OriginalDebugLevel = AcpiDbgLevel;
268 AcpiDbgLevel &= ~(ACPI_LV_PARSE | ACPI_LV_FUNCTIONS);
269 Next = Op->Common.Next;
270 Op->Common.Next = NULL;
274 ParentOp = Op->Common.Parent;
277 if ((WalkState->ControlState) &&
278 (WalkState->ControlState->Common.State ==
279 ACPI_CONTROL_PREDICATE_EXECUTING))
282 * We are executing the predicate of an IF or WHILE statement
283 * Search upwards for the containing IF or WHILE so that the
284 * entire predicate can be displayed.
288 if ((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
289 (ParentOp->Common.AmlOpcode == AML_WHILE_OP))
291 DisplayOp = ParentOp;
294 ParentOp = ParentOp->Common.Parent;
301 if ((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
302 (ParentOp->Common.AmlOpcode == AML_ELSE_OP) ||
303 (ParentOp->Common.AmlOpcode == AML_SCOPE_OP) ||
304 (ParentOp->Common.AmlOpcode == AML_METHOD_OP) ||
305 (ParentOp->Common.AmlOpcode == AML_WHILE_OP))
309 DisplayOp = ParentOp;
310 ParentOp = ParentOp->Common.Parent;
315 /* Now we can display it */
317 #ifdef ACPI_DISASSEMBLER
318 AcpiDmDisassemble (WalkState, DisplayOp, ACPI_UINT32_MAX);
321 if ((Op->Common.AmlOpcode == AML_IF_OP) ||
322 (Op->Common.AmlOpcode == AML_WHILE_OP))
324 if (WalkState->ControlState->Common.Value)
326 AcpiOsPrintf ("Predicate = [True], IF block was executed\n");
330 AcpiOsPrintf ("Predicate = [False], Skipping IF block\n");
333 else if (Op->Common.AmlOpcode == AML_ELSE_OP)
335 AcpiOsPrintf ("Predicate = [False], ELSE block was executed\n");
338 /* Restore everything */
340 Op->Common.Next = Next;
342 if ((AcpiGbl_DbOutputToFile) ||
343 (AcpiDbgLevel & ACPI_LV_PARSE))
347 AcpiDbgLevel = OriginalDebugLevel;
350 /* If we are not single stepping, just continue executing the method */
352 if (!AcpiGbl_CmSingleStep)
358 * If we are executing a step-to-call command,
359 * Check if this is a method call.
361 if (AcpiGbl_StepToNextCall)
363 if (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP)
365 /* Not a method call, just keep executing */
370 /* Found a method call, stop executing */
372 AcpiGbl_StepToNextCall = FALSE;
376 * If the next opcode is a method call, we will "step over" it
379 if (Op->Common.AmlOpcode == AML_INT_METHODCALL_OP)
381 /* Force no more single stepping while executing called method */
383 AcpiGbl_CmSingleStep = FALSE;
386 * Set the breakpoint on/before the call, it will stop execution
387 * as soon as we return
389 WalkState->MethodBreakpoint = 1; /* Must be non-zero! */
393 Status = AcpiDbStartCommand (WalkState, Op);
395 /* User commands complete, continue execution of the interrupted method */
401 /*******************************************************************************
403 * FUNCTION: AcpiDbInitialize
409 * DESCRIPTION: Init and start debugger
411 ******************************************************************************/
420 ACPI_FUNCTION_TRACE (DbInitialize);
425 AcpiGbl_DbBuffer = NULL;
426 AcpiGbl_DbFilename = NULL;
427 AcpiGbl_DbOutputToFile = FALSE;
429 AcpiGbl_DbDebugLevel = ACPI_LV_VERBOSITY2;
430 AcpiGbl_DbConsoleDebugLevel = ACPI_NORMAL_DEFAULT | ACPI_LV_TABLES;
431 AcpiGbl_DbOutputFlags = ACPI_DB_CONSOLE_OUTPUT;
433 AcpiGbl_DbOpt_Disasm = FALSE;
435 AcpiGbl_DbOpt_Verbose = TRUE;
437 AcpiGbl_DbOpt_NoIniMethods = FALSE;
439 AcpiGbl_DbBuffer = AcpiOsAllocate (ACPI_DEBUG_BUFFER_SIZE);
440 if (!AcpiGbl_DbBuffer)
442 return_ACPI_STATUS (AE_NO_MEMORY);
444 memset (AcpiGbl_DbBuffer, 0, ACPI_DEBUG_BUFFER_SIZE);
446 /* Initial scope is the root */
448 AcpiGbl_DbScopeBuf [0] = AML_ROOT_PREFIX;
449 AcpiGbl_DbScopeBuf [1] = 0;
450 AcpiGbl_DbScopeNode = AcpiGbl_RootNode;
453 * If configured for multi-thread support, the debug executor runs in
454 * a separate thread so that the front end can be in another address
455 * space, environment, or even another machine.
457 if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
459 /* These were created with one unit, grab it */
461 Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
462 if (ACPI_FAILURE (Status))
464 AcpiOsPrintf ("Could not get debugger mutex\n");
465 return_ACPI_STATUS (Status);
468 Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_READY);
469 if (ACPI_FAILURE (Status))
471 AcpiOsPrintf ("Could not get debugger mutex\n");
472 return_ACPI_STATUS (Status);
475 /* Create the debug execution thread to execute commands */
477 Status = AcpiOsExecute (OSL_DEBUGGER_THREAD, AcpiDbExecuteThread, NULL);
478 if (ACPI_FAILURE (Status))
480 ACPI_EXCEPTION ((AE_INFO, Status, "Could not start debugger thread"));
481 return_ACPI_STATUS (Status);
486 if (!AcpiGbl_DbOpt_Verbose)
488 AcpiGbl_DbOpt_Disasm = TRUE;
492 return_ACPI_STATUS (AE_OK);
496 /*******************************************************************************
498 * FUNCTION: AcpiDbTerminate
504 * DESCRIPTION: Stop debugger
506 ******************************************************************************/
513 if (AcpiGbl_DbBuffer)
515 AcpiOsFree (AcpiGbl_DbBuffer);
516 AcpiGbl_DbBuffer = NULL;
519 /* Ensure that debug output is now disabled */
521 AcpiGbl_DbOutputFlags = ACPI_DB_DISABLE_OUTPUT;
525 #ifdef ACPI_OBSOLETE_FUNCTIONS
526 /*******************************************************************************
528 * FUNCTION: AcpiDbMethodEnd
530 * PARAMETERS: WalkState - Current walk
534 * DESCRIPTION: Called at method termination
536 ******************************************************************************/
540 ACPI_WALK_STATE *WalkState)
543 if (!AcpiGbl_CmSingleStep)
548 AcpiOsPrintf ("<Method Terminating>\n");
550 AcpiDbStartCommand (WalkState, NULL);
554 #endif /* ACPI_DEBUGGER */