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 #include <contrib/dev/acpica/include/acdisasm.h>
53 #define _COMPONENT ACPI_CA_DEBUGGER
54 ACPI_MODULE_NAME ("dbxface")
57 /* Local prototypes */
61 ACPI_WALK_STATE *WalkState,
62 ACPI_PARSE_OBJECT *Op);
64 #ifdef ACPI_OBSOLETE_FUNCTIONS
67 ACPI_WALK_STATE *WalkState);
71 /*******************************************************************************
73 * FUNCTION: AcpiDbStartCommand
75 * PARAMETERS: WalkState - Current walk
76 * Op - Current executing Op, from AML interpreter
80 * DESCRIPTION: Enter debugger command loop
82 ******************************************************************************/
86 ACPI_WALK_STATE *WalkState,
87 ACPI_PARSE_OBJECT *Op)
92 /* TBD: [Investigate] are there namespace locking issues here? */
94 /* AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); */
96 /* Go into the command loop and await next user command */
99 AcpiGbl_MethodExecuting = TRUE;
100 Status = AE_CTRL_TRUE;
101 while (Status == AE_CTRL_TRUE)
103 if (AcpiGbl_DebuggerConfiguration == DEBUGGER_MULTI_THREADED)
105 /* Handshake with the front-end that gets user command lines */
107 Status = AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
108 if (ACPI_FAILURE (Status))
112 Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_READY);
113 if (ACPI_FAILURE (Status))
120 /* Single threaded, we must get a command line ourselves */
122 /* Force output to console until a command is entered */
124 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
126 /* Different prompt if method is executing */
128 if (!AcpiGbl_MethodExecuting)
130 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
134 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
137 /* Get the user input line */
139 Status = AcpiOsGetLine (AcpiGbl_DbLineBuf,
140 ACPI_DB_LINE_BUFFER_SIZE, NULL);
141 if (ACPI_FAILURE (Status))
143 ACPI_EXCEPTION ((AE_INFO, Status, "While parsing command line"));
148 Status = AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, WalkState, Op);
151 /* AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); */
157 /*******************************************************************************
159 * FUNCTION: AcpiDbSingleStep
161 * PARAMETERS: WalkState - Current walk
162 * Op - Current executing op (from aml interpreter)
163 * OpcodeClass - Class of the current AML Opcode
167 * DESCRIPTION: Called just before execution of an AML opcode.
169 ******************************************************************************/
173 ACPI_WALK_STATE *WalkState,
174 ACPI_PARSE_OBJECT *Op,
177 ACPI_PARSE_OBJECT *Next;
178 ACPI_STATUS Status = AE_OK;
179 UINT32 OriginalDebugLevel;
180 ACPI_PARSE_OBJECT *DisplayOp;
181 ACPI_PARSE_OBJECT *ParentOp;
184 ACPI_FUNCTION_ENTRY ();
187 /* Check the abort flag */
189 if (AcpiGbl_AbortMethod)
191 AcpiGbl_AbortMethod = FALSE;
192 return (AE_ABORT_METHOD);
195 /* Check for single-step breakpoint */
197 if (WalkState->MethodBreakpoint &&
198 (WalkState->MethodBreakpoint <= Op->Common.AmlOffset))
200 /* Check if the breakpoint has been reached or passed */
201 /* Hit the breakpoint, resume single step, reset breakpoint */
203 AcpiOsPrintf ("***Break*** at AML offset %X\n", Op->Common.AmlOffset);
204 AcpiGbl_CmSingleStep = TRUE;
205 AcpiGbl_StepToNextCall = FALSE;
206 WalkState->MethodBreakpoint = 0;
209 /* Check for user breakpoint (Must be on exact Aml offset) */
211 else if (WalkState->UserBreakpoint &&
212 (WalkState->UserBreakpoint == Op->Common.AmlOffset))
214 AcpiOsPrintf ("***UserBreakpoint*** at AML offset %X\n",
215 Op->Common.AmlOffset);
216 AcpiGbl_CmSingleStep = TRUE;
217 AcpiGbl_StepToNextCall = FALSE;
218 WalkState->MethodBreakpoint = 0;
222 * Check if this is an opcode that we are interested in --
223 * namely, opcodes that have arguments
225 if (Op->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
232 case AML_CLASS_UNKNOWN:
233 case AML_CLASS_ARGUMENT: /* constants, literals, etc. do nothing */
239 /* All other opcodes -- continue */
244 * Under certain debug conditions, display this opcode and its operands
246 if ((AcpiGbl_DbOutputToFile) ||
247 (AcpiGbl_CmSingleStep) ||
248 (AcpiDbgLevel & ACPI_LV_PARSE))
250 if ((AcpiGbl_DbOutputToFile) ||
251 (AcpiDbgLevel & ACPI_LV_PARSE))
253 AcpiOsPrintf ("\n[AmlDebug] Next AML Opcode to execute:\n");
257 * Display this op (and only this op - zero out the NEXT field
258 * temporarily, and disable parser trace output for the duration of
259 * the display because we don't want the extraneous debug output)
261 OriginalDebugLevel = AcpiDbgLevel;
262 AcpiDbgLevel &= ~(ACPI_LV_PARSE | ACPI_LV_FUNCTIONS);
263 Next = Op->Common.Next;
264 Op->Common.Next = NULL;
268 ParentOp = Op->Common.Parent;
271 if ((WalkState->ControlState) &&
272 (WalkState->ControlState->Common.State ==
273 ACPI_CONTROL_PREDICATE_EXECUTING))
276 * We are executing the predicate of an IF or WHILE statement
277 * Search upwards for the containing IF or WHILE so that the
278 * entire predicate can be displayed.
282 if ((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
283 (ParentOp->Common.AmlOpcode == AML_WHILE_OP))
285 DisplayOp = ParentOp;
288 ParentOp = ParentOp->Common.Parent;
295 if ((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
296 (ParentOp->Common.AmlOpcode == AML_ELSE_OP) ||
297 (ParentOp->Common.AmlOpcode == AML_SCOPE_OP) ||
298 (ParentOp->Common.AmlOpcode == AML_METHOD_OP) ||
299 (ParentOp->Common.AmlOpcode == AML_WHILE_OP))
303 DisplayOp = ParentOp;
304 ParentOp = ParentOp->Common.Parent;
309 /* Now we can display it */
311 #ifdef ACPI_DISASSEMBLER
312 AcpiDmDisassemble (WalkState, DisplayOp, ACPI_UINT32_MAX);
315 if ((Op->Common.AmlOpcode == AML_IF_OP) ||
316 (Op->Common.AmlOpcode == AML_WHILE_OP))
318 if (WalkState->ControlState->Common.Value)
320 AcpiOsPrintf ("Predicate = [True], IF block was executed\n");
324 AcpiOsPrintf ("Predicate = [False], Skipping IF block\n");
327 else if (Op->Common.AmlOpcode == AML_ELSE_OP)
329 AcpiOsPrintf ("Predicate = [False], ELSE block was executed\n");
332 /* Restore everything */
334 Op->Common.Next = Next;
336 if ((AcpiGbl_DbOutputToFile) ||
337 (AcpiDbgLevel & ACPI_LV_PARSE))
341 AcpiDbgLevel = OriginalDebugLevel;
344 /* If we are not single stepping, just continue executing the method */
346 if (!AcpiGbl_CmSingleStep)
352 * If we are executing a step-to-call command,
353 * Check if this is a method call.
355 if (AcpiGbl_StepToNextCall)
357 if (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP)
359 /* Not a method call, just keep executing */
364 /* Found a method call, stop executing */
366 AcpiGbl_StepToNextCall = FALSE;
370 * If the next opcode is a method call, we will "step over" it
373 if (Op->Common.AmlOpcode == AML_INT_METHODCALL_OP)
375 /* Force no more single stepping while executing called method */
377 AcpiGbl_CmSingleStep = FALSE;
380 * Set the breakpoint on/before the call, it will stop execution
381 * as soon as we return
383 WalkState->MethodBreakpoint = 1; /* Must be non-zero! */
387 Status = AcpiDbStartCommand (WalkState, Op);
389 /* User commands complete, continue execution of the interrupted method */
395 /*******************************************************************************
397 * FUNCTION: AcpiDbInitialize
403 * DESCRIPTION: Init and start debugger
405 ******************************************************************************/
414 ACPI_FUNCTION_TRACE (DbInitialize);
419 AcpiGbl_DbBuffer = NULL;
420 AcpiGbl_DbFilename = NULL;
421 AcpiGbl_DbOutputToFile = FALSE;
423 AcpiGbl_DbDebugLevel = ACPI_LV_VERBOSITY2;
424 AcpiGbl_DbConsoleDebugLevel = ACPI_NORMAL_DEFAULT | ACPI_LV_TABLES;
425 AcpiGbl_DbOutputFlags = ACPI_DB_CONSOLE_OUTPUT;
427 AcpiGbl_DbOpt_Disasm = FALSE;
428 #ifdef ACPI_DISASSEMBLER
429 AcpiGbl_DbOpt_Verbose = TRUE;
431 AcpiGbl_DbOpt_NoIniMethods = FALSE;
433 AcpiGbl_DbBuffer = AcpiOsAllocate (ACPI_DEBUG_BUFFER_SIZE);
434 if (!AcpiGbl_DbBuffer)
436 return_ACPI_STATUS (AE_NO_MEMORY);
438 ACPI_MEMSET (AcpiGbl_DbBuffer, 0, ACPI_DEBUG_BUFFER_SIZE);
440 /* Initial scope is the root */
442 AcpiGbl_DbScopeBuf [0] = AML_ROOT_PREFIX;
443 AcpiGbl_DbScopeBuf [1] = 0;
444 AcpiGbl_DbScopeNode = AcpiGbl_RootNode;
447 * If configured for multi-thread support, the debug executor runs in
448 * a separate thread so that the front end can be in another address
449 * space, environment, or even another machine.
451 if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
453 /* These were created with one unit, grab it */
455 Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
456 if (ACPI_FAILURE (Status))
458 AcpiOsPrintf ("Could not get debugger mutex\n");
459 return_ACPI_STATUS (Status);
462 Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_READY);
463 if (ACPI_FAILURE (Status))
465 AcpiOsPrintf ("Could not get debugger mutex\n");
466 return_ACPI_STATUS (Status);
469 /* Create the debug execution thread to execute commands */
471 Status = AcpiOsExecute (OSL_DEBUGGER_THREAD, AcpiDbExecuteThread, NULL);
472 if (ACPI_FAILURE (Status))
474 ACPI_EXCEPTION ((AE_INFO, Status, "Could not start debugger thread"));
475 return_ACPI_STATUS (Status);
479 #ifdef ACPI_DISASSEMBLER
480 if (!AcpiGbl_DbOpt_Verbose)
482 AcpiGbl_DbOpt_Disasm = TRUE;
486 return_ACPI_STATUS (AE_OK);
490 /*******************************************************************************
492 * FUNCTION: AcpiDbTerminate
498 * DESCRIPTION: Stop debugger
500 ******************************************************************************/
507 if (AcpiGbl_DbBuffer)
509 AcpiOsFree (AcpiGbl_DbBuffer);
510 AcpiGbl_DbBuffer = NULL;
513 /* Ensure that debug output is now disabled */
515 AcpiGbl_DbOutputFlags = ACPI_DB_DISABLE_OUTPUT;
519 #ifdef ACPI_OBSOLETE_FUNCTIONS
520 /*******************************************************************************
522 * FUNCTION: AcpiDbMethodEnd
524 * PARAMETERS: WalkState - Current walk
528 * DESCRIPTION: Called at method termination
530 ******************************************************************************/
534 ACPI_WALK_STATE *WalkState)
537 if (!AcpiGbl_CmSingleStep)
542 AcpiOsPrintf ("<Method Terminating>\n");
544 AcpiDbStartCommand (WalkState, NULL);
548 #endif /* ACPI_DEBUGGER */