1 /*******************************************************************************
3 * Module Name: dbxface - AML Debugger external interfaces
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2011, 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.
45 #include <contrib/dev/acpica/include/acpi.h>
46 #include <contrib/dev/acpica/include/accommon.h>
47 #include <contrib/dev/acpica/include/amlcode.h>
48 #include <contrib/dev/acpica/include/acdebug.h>
49 #include <contrib/dev/acpica/include/acdisasm.h>
54 #define _COMPONENT ACPI_CA_DEBUGGER
55 ACPI_MODULE_NAME ("dbxface")
58 /* Local prototypes */
62 ACPI_WALK_STATE *WalkState,
63 ACPI_PARSE_OBJECT *Op);
65 #ifdef ACPI_OBSOLETE_FUNCTIONS
68 ACPI_WALK_STATE *WalkState);
72 /*******************************************************************************
74 * FUNCTION: AcpiDbStartCommand
76 * PARAMETERS: WalkState - Current walk
77 * Op - Current executing Op, from AML interpreter
81 * DESCRIPTION: Enter debugger command loop
83 ******************************************************************************/
87 ACPI_WALK_STATE *WalkState,
88 ACPI_PARSE_OBJECT *Op)
93 /* TBD: [Investigate] are there namespace locking issues here? */
95 /* AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); */
97 /* Go into the command loop and await next user command */
100 AcpiGbl_MethodExecuting = TRUE;
101 Status = AE_CTRL_TRUE;
102 while (Status == AE_CTRL_TRUE)
104 if (AcpiGbl_DebuggerConfiguration == DEBUGGER_MULTI_THREADED)
106 /* Handshake with the front-end that gets user command lines */
108 Status = AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
109 if (ACPI_FAILURE (Status))
113 Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_READY);
114 if (ACPI_FAILURE (Status))
121 /* Single threaded, we must get a command line ourselves */
123 /* Force output to console until a command is entered */
125 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
127 /* Different prompt if method is executing */
129 if (!AcpiGbl_MethodExecuting)
131 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
135 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
138 /* Get the user input line */
140 (void) AcpiOsGetLine (AcpiGbl_DbLineBuf);
143 Status = AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, WalkState, Op);
146 /* AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); */
152 /*******************************************************************************
154 * FUNCTION: AcpiDbSingleStep
156 * PARAMETERS: WalkState - Current walk
157 * Op - Current executing op (from aml interpreter)
158 * OpcodeClass - Class of the current AML Opcode
162 * DESCRIPTION: Called just before execution of an AML opcode.
164 ******************************************************************************/
168 ACPI_WALK_STATE *WalkState,
169 ACPI_PARSE_OBJECT *Op,
172 ACPI_PARSE_OBJECT *Next;
173 ACPI_STATUS Status = AE_OK;
174 UINT32 OriginalDebugLevel;
175 ACPI_PARSE_OBJECT *DisplayOp;
176 ACPI_PARSE_OBJECT *ParentOp;
179 ACPI_FUNCTION_ENTRY ();
182 /* Check the abort flag */
184 if (AcpiGbl_AbortMethod)
186 AcpiGbl_AbortMethod = FALSE;
187 return (AE_ABORT_METHOD);
190 /* Check for single-step breakpoint */
192 if (WalkState->MethodBreakpoint &&
193 (WalkState->MethodBreakpoint <= Op->Common.AmlOffset))
195 /* Check if the breakpoint has been reached or passed */
196 /* Hit the breakpoint, resume single step, reset breakpoint */
198 AcpiOsPrintf ("***Break*** at AML offset %X\n", Op->Common.AmlOffset);
199 AcpiGbl_CmSingleStep = TRUE;
200 AcpiGbl_StepToNextCall = FALSE;
201 WalkState->MethodBreakpoint = 0;
204 /* Check for user breakpoint (Must be on exact Aml offset) */
206 else if (WalkState->UserBreakpoint &&
207 (WalkState->UserBreakpoint == Op->Common.AmlOffset))
209 AcpiOsPrintf ("***UserBreakpoint*** at AML offset %X\n",
210 Op->Common.AmlOffset);
211 AcpiGbl_CmSingleStep = TRUE;
212 AcpiGbl_StepToNextCall = FALSE;
213 WalkState->MethodBreakpoint = 0;
217 * Check if this is an opcode that we are interested in --
218 * namely, opcodes that have arguments
220 if (Op->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
227 case AML_CLASS_UNKNOWN:
228 case AML_CLASS_ARGUMENT: /* constants, literals, etc. do nothing */
232 /* All other opcodes -- continue */
237 * Under certain debug conditions, display this opcode and its operands
239 if ((AcpiGbl_DbOutputToFile) ||
240 (AcpiGbl_CmSingleStep) ||
241 (AcpiDbgLevel & ACPI_LV_PARSE))
243 if ((AcpiGbl_DbOutputToFile) ||
244 (AcpiDbgLevel & ACPI_LV_PARSE))
246 AcpiOsPrintf ("\n[AmlDebug] Next AML Opcode to execute:\n");
250 * Display this op (and only this op - zero out the NEXT field
251 * temporarily, and disable parser trace output for the duration of
252 * the display because we don't want the extraneous debug output)
254 OriginalDebugLevel = AcpiDbgLevel;
255 AcpiDbgLevel &= ~(ACPI_LV_PARSE | ACPI_LV_FUNCTIONS);
256 Next = Op->Common.Next;
257 Op->Common.Next = NULL;
261 ParentOp = Op->Common.Parent;
264 if ((WalkState->ControlState) &&
265 (WalkState->ControlState->Common.State ==
266 ACPI_CONTROL_PREDICATE_EXECUTING))
269 * We are executing the predicate of an IF or WHILE statement
270 * Search upwards for the containing IF or WHILE so that the
271 * entire predicate can be displayed.
275 if ((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
276 (ParentOp->Common.AmlOpcode == AML_WHILE_OP))
278 DisplayOp = ParentOp;
281 ParentOp = ParentOp->Common.Parent;
288 if ((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
289 (ParentOp->Common.AmlOpcode == AML_ELSE_OP) ||
290 (ParentOp->Common.AmlOpcode == AML_SCOPE_OP) ||
291 (ParentOp->Common.AmlOpcode == AML_METHOD_OP) ||
292 (ParentOp->Common.AmlOpcode == AML_WHILE_OP))
296 DisplayOp = ParentOp;
297 ParentOp = ParentOp->Common.Parent;
302 /* Now we can display it */
304 #ifdef ACPI_DISASSEMBLER
305 AcpiDmDisassemble (WalkState, DisplayOp, ACPI_UINT32_MAX);
308 if ((Op->Common.AmlOpcode == AML_IF_OP) ||
309 (Op->Common.AmlOpcode == AML_WHILE_OP))
311 if (WalkState->ControlState->Common.Value)
313 AcpiOsPrintf ("Predicate = [True], IF block was executed\n");
317 AcpiOsPrintf ("Predicate = [False], Skipping IF block\n");
320 else if (Op->Common.AmlOpcode == AML_ELSE_OP)
322 AcpiOsPrintf ("Predicate = [False], ELSE block was executed\n");
325 /* Restore everything */
327 Op->Common.Next = Next;
329 if ((AcpiGbl_DbOutputToFile) ||
330 (AcpiDbgLevel & ACPI_LV_PARSE))
334 AcpiDbgLevel = OriginalDebugLevel;
337 /* If we are not single stepping, just continue executing the method */
339 if (!AcpiGbl_CmSingleStep)
345 * If we are executing a step-to-call command,
346 * Check if this is a method call.
348 if (AcpiGbl_StepToNextCall)
350 if (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP)
352 /* Not a method call, just keep executing */
357 /* Found a method call, stop executing */
359 AcpiGbl_StepToNextCall = FALSE;
363 * If the next opcode is a method call, we will "step over" it
366 if (Op->Common.AmlOpcode == AML_INT_METHODCALL_OP)
368 /* Force no more single stepping while executing called method */
370 AcpiGbl_CmSingleStep = FALSE;
373 * Set the breakpoint on/before the call, it will stop execution
374 * as soon as we return
376 WalkState->MethodBreakpoint = 1; /* Must be non-zero! */
380 Status = AcpiDbStartCommand (WalkState, Op);
382 /* User commands complete, continue execution of the interrupted method */
388 /*******************************************************************************
390 * FUNCTION: AcpiDbInitialize
396 * DESCRIPTION: Init and start debugger
398 ******************************************************************************/
409 AcpiGbl_DbBuffer = NULL;
410 AcpiGbl_DbFilename = NULL;
411 AcpiGbl_DbOutputToFile = FALSE;
413 AcpiGbl_DbDebugLevel = ACPI_LV_VERBOSITY2;
414 AcpiGbl_DbConsoleDebugLevel = ACPI_NORMAL_DEFAULT | ACPI_LV_TABLES;
415 AcpiGbl_DbOutputFlags = ACPI_DB_CONSOLE_OUTPUT;
417 AcpiGbl_DbOpt_tables = FALSE;
418 AcpiGbl_DbOpt_stats = FALSE;
419 #ifdef ACPI_DISASSEMBLER
420 AcpiGbl_DbOpt_disasm = FALSE;
421 AcpiGbl_DbOpt_verbose = TRUE;
423 AcpiGbl_DbOpt_ini_methods = TRUE;
425 AcpiGbl_DbBuffer = AcpiOsAllocate (ACPI_DEBUG_BUFFER_SIZE);
426 if (!AcpiGbl_DbBuffer)
428 return (AE_NO_MEMORY);
430 ACPI_MEMSET (AcpiGbl_DbBuffer, 0, ACPI_DEBUG_BUFFER_SIZE);
432 /* Initial scope is the root */
434 AcpiGbl_DbScopeBuf [0] = '\\';
435 AcpiGbl_DbScopeBuf [1] = 0;
436 AcpiGbl_DbScopeNode = AcpiGbl_RootNode;
439 * If configured for multi-thread support, the debug executor runs in
440 * a separate thread so that the front end can be in another address
441 * space, environment, or even another machine.
443 if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
445 /* These were created with one unit, grab it */
447 Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
448 if (ACPI_FAILURE (Status))
450 AcpiOsPrintf ("Could not get debugger mutex\n");
454 Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_READY);
455 if (ACPI_FAILURE (Status))
457 AcpiOsPrintf ("Could not get debugger mutex\n");
461 /* Create the debug execution thread to execute commands */
463 Status = AcpiOsExecute (OSL_DEBUGGER_THREAD, AcpiDbExecuteThread, NULL);
464 if (ACPI_FAILURE (Status))
466 AcpiOsPrintf ("Could not start debugger thread\n");
471 #ifdef ACPI_DISASSEMBLER
472 if (!AcpiGbl_DbOpt_verbose)
474 AcpiGbl_DbOpt_disasm = TRUE;
475 AcpiGbl_DbOpt_stats = FALSE;
483 /*******************************************************************************
485 * FUNCTION: AcpiDbTerminate
491 * DESCRIPTION: Stop debugger
493 ******************************************************************************/
500 if (AcpiGbl_DbBuffer)
502 AcpiOsFree (AcpiGbl_DbBuffer);
507 #ifdef ACPI_OBSOLETE_FUNCTIONS
508 /*******************************************************************************
510 * FUNCTION: AcpiDbMethodEnd
512 * PARAMETERS: WalkState - Current walk
516 * DESCRIPTION: Called at method termination
518 ******************************************************************************/
522 ACPI_WALK_STATE *WalkState)
525 if (!AcpiGbl_CmSingleStep)
530 AcpiOsPrintf ("<Method Terminating>\n");
532 AcpiDbStartCommand (WalkState, NULL);
536 #endif /* ACPI_DEBUGGER */