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.
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: AcpiDbSingleStep
158 * PARAMETERS: WalkState - Current walk
159 * Op - Current executing op (from aml interpreter)
160 * OpcodeClass - Class of the current AML Opcode
164 * DESCRIPTION: Called just before execution of an AML opcode.
166 ******************************************************************************/
170 ACPI_WALK_STATE *WalkState,
171 ACPI_PARSE_OBJECT *Op,
174 ACPI_PARSE_OBJECT *Next;
175 ACPI_STATUS Status = AE_OK;
176 UINT32 OriginalDebugLevel;
177 ACPI_PARSE_OBJECT *DisplayOp;
178 ACPI_PARSE_OBJECT *ParentOp;
182 ACPI_FUNCTION_ENTRY ();
185 /* Check the abort flag */
187 if (AcpiGbl_AbortMethod)
189 AcpiGbl_AbortMethod = FALSE;
190 return (AE_ABORT_METHOD);
193 AmlOffset = (UINT32) ACPI_PTR_DIFF (Op->Common.Aml,
194 WalkState->ParserState.AmlStart);
196 /* Check for single-step breakpoint */
198 if (WalkState->MethodBreakpoint &&
199 (WalkState->MethodBreakpoint <= AmlOffset))
201 /* Check if the breakpoint has been reached or passed */
202 /* Hit the breakpoint, resume single step, reset breakpoint */
204 AcpiOsPrintf ("***Break*** at AML offset %X\n", AmlOffset);
205 AcpiGbl_CmSingleStep = TRUE;
206 AcpiGbl_StepToNextCall = FALSE;
207 WalkState->MethodBreakpoint = 0;
210 /* Check for user breakpoint (Must be on exact Aml offset) */
212 else if (WalkState->UserBreakpoint &&
213 (WalkState->UserBreakpoint == AmlOffset))
215 AcpiOsPrintf ("***UserBreakpoint*** at AML offset %X\n",
217 AcpiGbl_CmSingleStep = TRUE;
218 AcpiGbl_StepToNextCall = FALSE;
219 WalkState->MethodBreakpoint = 0;
223 * Check if this is an opcode that we are interested in --
224 * namely, opcodes that have arguments
226 if (Op->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
233 case AML_CLASS_UNKNOWN:
234 case AML_CLASS_ARGUMENT: /* constants, literals, etc. do nothing */
240 /* All other opcodes -- continue */
245 * Under certain debug conditions, display this opcode and its operands
247 if ((AcpiGbl_DbOutputToFile) ||
248 (AcpiGbl_CmSingleStep) ||
249 (AcpiDbgLevel & ACPI_LV_PARSE))
251 if ((AcpiGbl_DbOutputToFile) ||
252 (AcpiDbgLevel & ACPI_LV_PARSE))
254 AcpiOsPrintf ("\n[AmlDebug] Next AML Opcode to execute:\n");
258 * Display this op (and only this op - zero out the NEXT field
259 * temporarily, and disable parser trace output for the duration of
260 * the display because we don't want the extraneous debug output)
262 OriginalDebugLevel = AcpiDbgLevel;
263 AcpiDbgLevel &= ~(ACPI_LV_PARSE | ACPI_LV_FUNCTIONS);
264 Next = Op->Common.Next;
265 Op->Common.Next = NULL;
269 ParentOp = Op->Common.Parent;
272 if ((WalkState->ControlState) &&
273 (WalkState->ControlState->Common.State ==
274 ACPI_CONTROL_PREDICATE_EXECUTING))
277 * We are executing the predicate of an IF or WHILE statement
278 * Search upwards for the containing IF or WHILE so that the
279 * entire predicate can be displayed.
283 if ((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
284 (ParentOp->Common.AmlOpcode == AML_WHILE_OP))
286 DisplayOp = ParentOp;
289 ParentOp = ParentOp->Common.Parent;
296 if ((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
297 (ParentOp->Common.AmlOpcode == AML_ELSE_OP) ||
298 (ParentOp->Common.AmlOpcode == AML_SCOPE_OP) ||
299 (ParentOp->Common.AmlOpcode == AML_METHOD_OP) ||
300 (ParentOp->Common.AmlOpcode == AML_WHILE_OP))
304 DisplayOp = ParentOp;
305 ParentOp = ParentOp->Common.Parent;
310 /* Now we can display it */
312 #ifdef ACPI_DISASSEMBLER
313 AcpiDmDisassemble (WalkState, DisplayOp, ACPI_UINT32_MAX);
316 if ((Op->Common.AmlOpcode == AML_IF_OP) ||
317 (Op->Common.AmlOpcode == AML_WHILE_OP))
319 if (WalkState->ControlState->Common.Value)
321 AcpiOsPrintf ("Predicate = [True], IF block was executed\n");
325 AcpiOsPrintf ("Predicate = [False], Skipping IF block\n");
328 else if (Op->Common.AmlOpcode == AML_ELSE_OP)
330 AcpiOsPrintf ("Predicate = [False], ELSE block was executed\n");
333 /* Restore everything */
335 Op->Common.Next = Next;
337 if ((AcpiGbl_DbOutputToFile) ||
338 (AcpiDbgLevel & ACPI_LV_PARSE))
342 AcpiDbgLevel = OriginalDebugLevel;
345 /* If we are not single stepping, just continue executing the method */
347 if (!AcpiGbl_CmSingleStep)
353 * If we are executing a step-to-call command,
354 * Check if this is a method call.
356 if (AcpiGbl_StepToNextCall)
358 if (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP)
360 /* Not a method call, just keep executing */
365 /* Found a method call, stop executing */
367 AcpiGbl_StepToNextCall = FALSE;
371 * If the next opcode is a method call, we will "step over" it
374 if (Op->Common.AmlOpcode == AML_INT_METHODCALL_OP)
376 /* Force no more single stepping while executing called method */
378 AcpiGbl_CmSingleStep = FALSE;
381 * Set the breakpoint on/before the call, it will stop execution
382 * as soon as we return
384 WalkState->MethodBreakpoint = 1; /* Must be non-zero! */
388 Status = AcpiDbStartCommand (WalkState, Op);
390 /* User commands complete, continue execution of the interrupted method */
396 /*******************************************************************************
398 * FUNCTION: AcpiInitializeDebugger
404 * DESCRIPTION: Init and start debugger
406 ******************************************************************************/
409 AcpiInitializeDebugger (
415 ACPI_FUNCTION_TRACE (AcpiInitializeDebugger);
420 AcpiGbl_DbBuffer = NULL;
421 AcpiGbl_DbFilename = NULL;
422 AcpiGbl_DbOutputToFile = FALSE;
424 AcpiGbl_DbDebugLevel = ACPI_LV_VERBOSITY2;
425 AcpiGbl_DbConsoleDebugLevel = ACPI_NORMAL_DEFAULT | ACPI_LV_TABLES;
426 AcpiGbl_DbOutputFlags = ACPI_DB_CONSOLE_OUTPUT;
428 AcpiGbl_DbOpt_NoIniMethods = FALSE;
430 AcpiGbl_DbBuffer = AcpiOsAllocate (ACPI_DEBUG_BUFFER_SIZE);
431 if (!AcpiGbl_DbBuffer)
433 return_ACPI_STATUS (AE_NO_MEMORY);
435 memset (AcpiGbl_DbBuffer, 0, ACPI_DEBUG_BUFFER_SIZE);
437 /* Initial scope is the root */
439 AcpiGbl_DbScopeBuf [0] = AML_ROOT_PREFIX;
440 AcpiGbl_DbScopeBuf [1] = 0;
441 AcpiGbl_DbScopeNode = AcpiGbl_RootNode;
444 * If configured for multi-thread support, the debug executor runs in
445 * a separate thread so that the front end can be in another address
446 * space, environment, or even another machine.
448 if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
450 /* These were created with one unit, grab it */
452 Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandComplete,
454 if (ACPI_FAILURE (Status))
456 AcpiOsPrintf ("Could not get debugger mutex\n");
457 return_ACPI_STATUS (Status);
460 Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandReady,
462 if (ACPI_FAILURE (Status))
464 AcpiOsPrintf ("Could not get debugger mutex\n");
465 return_ACPI_STATUS (Status);
468 /* Create the debug execution thread to execute commands */
470 Status = AcpiOsExecute (OSL_DEBUGGER_THREAD,
471 AcpiDbExecuteThread, NULL);
472 if (ACPI_FAILURE (Status))
474 ACPI_EXCEPTION ((AE_INFO, Status,
475 "Could not start debugger thread"));
476 return_ACPI_STATUS (Status);
480 return_ACPI_STATUS (AE_OK);
483 ACPI_EXPORT_SYMBOL (AcpiInitializeDebugger)
486 /*******************************************************************************
488 * FUNCTION: AcpiTerminateDebugger
494 * DESCRIPTION: Stop debugger
496 ******************************************************************************/
499 AcpiTerminateDebugger (
503 if (AcpiGbl_DbBuffer)
505 AcpiOsFree (AcpiGbl_DbBuffer);
506 AcpiGbl_DbBuffer = NULL;
509 /* Ensure that debug output is now disabled */
511 AcpiGbl_DbOutputFlags = ACPI_DB_DISABLE_OUTPUT;
514 ACPI_EXPORT_SYMBOL (AcpiTerminateDebugger)
516 #endif /* ACPI_DEBUGGER */