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.
48 #ifdef ACPI_DISASSEMBLER
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
;
434 AcpiGbl_DbOpt_Verbose
= TRUE
;
435 AcpiGbl_DbOpt_NoIniMethods
= FALSE
;
437 AcpiGbl_DbBuffer
= AcpiOsAllocate (ACPI_DEBUG_BUFFER_SIZE
);
438 if (!AcpiGbl_DbBuffer
)
440 return_ACPI_STATUS (AE_NO_MEMORY
);
442 memset (AcpiGbl_DbBuffer
, 0, ACPI_DEBUG_BUFFER_SIZE
);
444 /* Initial scope is the root */
446 AcpiGbl_DbScopeBuf
[0] = AML_ROOT_PREFIX
;
447 AcpiGbl_DbScopeBuf
[1] = 0;
448 AcpiGbl_DbScopeNode
= AcpiGbl_RootNode
;
451 * If configured for multi-thread support, the debug executor runs in
452 * a separate thread so that the front end can be in another address
453 * space, environment, or even another machine.
455 if (AcpiGbl_DebuggerConfiguration
& DEBUGGER_MULTI_THREADED
)
457 /* These were created with one unit, grab it */
459 Status
= AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_COMPLETE
);
460 if (ACPI_FAILURE (Status
))
462 AcpiOsPrintf ("Could not get debugger mutex\n");
463 return_ACPI_STATUS (Status
);
466 Status
= AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_READY
);
467 if (ACPI_FAILURE (Status
))
469 AcpiOsPrintf ("Could not get debugger mutex\n");
470 return_ACPI_STATUS (Status
);
473 /* Create the debug execution thread to execute commands */
475 Status
= AcpiOsExecute (OSL_DEBUGGER_THREAD
, AcpiDbExecuteThread
, NULL
);
476 if (ACPI_FAILURE (Status
))
478 ACPI_EXCEPTION ((AE_INFO
, Status
, "Could not start debugger thread"));
479 return_ACPI_STATUS (Status
);
483 if (!AcpiGbl_DbOpt_Verbose
)
485 AcpiGbl_DbOpt_Disasm
= TRUE
;
488 return_ACPI_STATUS (AE_OK
);
492 /*******************************************************************************
494 * FUNCTION: AcpiDbTerminate
500 * DESCRIPTION: Stop debugger
502 ******************************************************************************/
509 if (AcpiGbl_DbBuffer
)
511 AcpiOsFree (AcpiGbl_DbBuffer
);
512 AcpiGbl_DbBuffer
= NULL
;
515 /* Ensure that debug output is now disabled */
517 AcpiGbl_DbOutputFlags
= ACPI_DB_DISABLE_OUTPUT
;
521 #ifdef ACPI_OBSOLETE_FUNCTIONS
522 /*******************************************************************************
524 * FUNCTION: AcpiDbMethodEnd
526 * PARAMETERS: WalkState - Current walk
530 * DESCRIPTION: Called at method termination
532 ******************************************************************************/
536 ACPI_WALK_STATE
*WalkState
)
539 if (!AcpiGbl_CmSingleStep
)
544 AcpiOsPrintf ("<Method Terminating>\n");
546 AcpiDbStartCommand (WalkState
, NULL
);
550 #endif /* ACPI_DEBUGGER */