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 <acpi/acpi.h>
49 #define _COMPONENT ACPI_CA_DEBUGGER
50 ACPI_MODULE_NAME("dbxface")
52 /* Local prototypes */
54 acpi_db_start_command(struct acpi_walk_state *walk_state,
55 union acpi_parse_object *op);
57 #ifdef ACPI_OBSOLETE_FUNCTIONS
58 void acpi_db_method_end(struct acpi_walk_state *walk_state);
61 /*******************************************************************************
63 * FUNCTION: acpi_db_start_command
65 * PARAMETERS: walk_state - Current walk
66 * op - Current executing Op, from AML interpreter
70 * DESCRIPTION: Enter debugger command loop
72 ******************************************************************************/
75 acpi_db_start_command(struct acpi_walk_state *walk_state,
76 union acpi_parse_object *op)
80 /* TBD: [Investigate] are there namespace locking issues here? */
82 /* acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); */
84 /* Go into the command loop and await next user command */
86 acpi_gbl_method_executing = TRUE;
87 status = AE_CTRL_TRUE;
88 while (status == AE_CTRL_TRUE) {
89 if (acpi_gbl_debugger_configuration == DEBUGGER_MULTI_THREADED) {
91 /* Handshake with the front-end that gets user command lines */
93 acpi_os_release_mutex(acpi_gbl_db_command_complete);
96 acpi_os_acquire_mutex(acpi_gbl_db_command_ready,
98 if (ACPI_FAILURE(status)) {
102 /* Single threaded, we must get a command line ourselves */
104 /* Force output to console until a command is entered */
106 acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
108 /* Different prompt if method is executing */
110 if (!acpi_gbl_method_executing) {
111 acpi_os_printf("%1c ",
112 ACPI_DEBUGGER_COMMAND_PROMPT);
114 acpi_os_printf("%1c ",
115 ACPI_DEBUGGER_EXECUTE_PROMPT);
118 /* Get the user input line */
120 status = acpi_os_get_line(acpi_gbl_db_line_buf,
121 ACPI_DB_LINE_BUFFER_SIZE,
123 if (ACPI_FAILURE(status)) {
124 ACPI_EXCEPTION((AE_INFO, status,
125 "While parsing command line"));
131 acpi_db_command_dispatch(acpi_gbl_db_line_buf, walk_state,
135 /* acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE); */
140 /*******************************************************************************
142 * FUNCTION: acpi_db_single_step
144 * PARAMETERS: walk_state - Current walk
145 * op - Current executing op (from aml interpreter)
146 * opcode_class - Class of the current AML Opcode
150 * DESCRIPTION: Called just before execution of an AML opcode.
152 ******************************************************************************/
155 acpi_db_single_step(struct acpi_walk_state * walk_state,
156 union acpi_parse_object * op, u32 opcode_class)
158 union acpi_parse_object *next;
159 acpi_status status = AE_OK;
160 u32 original_debug_level;
161 union acpi_parse_object *display_op;
162 union acpi_parse_object *parent_op;
165 ACPI_FUNCTION_ENTRY();
167 /* Check the abort flag */
169 if (acpi_gbl_abort_method) {
170 acpi_gbl_abort_method = FALSE;
171 return (AE_ABORT_METHOD);
174 aml_offset = (u32)ACPI_PTR_DIFF(op->common.aml,
175 walk_state->parser_state.aml_start);
177 /* Check for single-step breakpoint */
179 if (walk_state->method_breakpoint &&
180 (walk_state->method_breakpoint <= aml_offset)) {
182 /* Check if the breakpoint has been reached or passed */
183 /* Hit the breakpoint, resume single step, reset breakpoint */
185 acpi_os_printf("***Break*** at AML offset %X\n", aml_offset);
186 acpi_gbl_cm_single_step = TRUE;
187 acpi_gbl_step_to_next_call = FALSE;
188 walk_state->method_breakpoint = 0;
191 /* Check for user breakpoint (Must be on exact Aml offset) */
193 else if (walk_state->user_breakpoint &&
194 (walk_state->user_breakpoint == aml_offset)) {
195 acpi_os_printf("***UserBreakpoint*** at AML offset %X\n",
197 acpi_gbl_cm_single_step = TRUE;
198 acpi_gbl_step_to_next_call = FALSE;
199 walk_state->method_breakpoint = 0;
203 * Check if this is an opcode that we are interested in --
204 * namely, opcodes that have arguments
206 if (op->common.aml_opcode == AML_INT_NAMEDFIELD_OP) {
210 switch (opcode_class) {
211 case AML_CLASS_UNKNOWN:
212 case AML_CLASS_ARGUMENT: /* constants, literals, etc. do nothing */
218 /* All other opcodes -- continue */
223 * Under certain debug conditions, display this opcode and its operands
225 if ((acpi_gbl_db_output_to_file) ||
226 (acpi_gbl_cm_single_step) || (acpi_dbg_level & ACPI_LV_PARSE)) {
227 if ((acpi_gbl_db_output_to_file) ||
228 (acpi_dbg_level & ACPI_LV_PARSE)) {
230 ("\n[AmlDebug] Next AML Opcode to execute:\n");
234 * Display this op (and only this op - zero out the NEXT field
235 * temporarily, and disable parser trace output for the duration of
236 * the display because we don't want the extraneous debug output)
238 original_debug_level = acpi_dbg_level;
239 acpi_dbg_level &= ~(ACPI_LV_PARSE | ACPI_LV_FUNCTIONS);
240 next = op->common.next;
241 op->common.next = NULL;
244 parent_op = op->common.parent;
246 if ((walk_state->control_state) &&
247 (walk_state->control_state->common.state ==
248 ACPI_CONTROL_PREDICATE_EXECUTING)) {
250 * We are executing the predicate of an IF or WHILE statement
251 * Search upwards for the containing IF or WHILE so that the
252 * entire predicate can be displayed.
255 if ((parent_op->common.aml_opcode ==
257 || (parent_op->common.aml_opcode ==
259 display_op = parent_op;
262 parent_op = parent_op->common.parent;
266 if ((parent_op->common.aml_opcode ==
268 || (parent_op->common.aml_opcode ==
270 || (parent_op->common.aml_opcode ==
272 || (parent_op->common.aml_opcode ==
274 || (parent_op->common.aml_opcode ==
278 display_op = parent_op;
279 parent_op = parent_op->common.parent;
284 /* Now we can display it */
286 #ifdef ACPI_DISASSEMBLER
287 acpi_dm_disassemble(walk_state, display_op, ACPI_UINT32_MAX);
290 if ((op->common.aml_opcode == AML_IF_OP) ||
291 (op->common.aml_opcode == AML_WHILE_OP)) {
292 if (walk_state->control_state->common.value) {
294 ("Predicate = [True], IF block was executed\n");
297 ("Predicate = [False], Skipping IF block\n");
299 } else if (op->common.aml_opcode == AML_ELSE_OP) {
301 ("Predicate = [False], ELSE block was executed\n");
304 /* Restore everything */
306 op->common.next = next;
307 acpi_os_printf("\n");
308 if ((acpi_gbl_db_output_to_file) ||
309 (acpi_dbg_level & ACPI_LV_PARSE)) {
310 acpi_os_printf("\n");
312 acpi_dbg_level = original_debug_level;
315 /* If we are not single stepping, just continue executing the method */
317 if (!acpi_gbl_cm_single_step) {
322 * If we are executing a step-to-call command,
323 * Check if this is a method call.
325 if (acpi_gbl_step_to_next_call) {
326 if (op->common.aml_opcode != AML_INT_METHODCALL_OP) {
328 /* Not a method call, just keep executing */
333 /* Found a method call, stop executing */
335 acpi_gbl_step_to_next_call = FALSE;
339 * If the next opcode is a method call, we will "step over" it
342 if (op->common.aml_opcode == AML_INT_METHODCALL_OP) {
344 /* Force no more single stepping while executing called method */
346 acpi_gbl_cm_single_step = FALSE;
349 * Set the breakpoint on/before the call, it will stop execution
350 * as soon as we return
352 walk_state->method_breakpoint = 1; /* Must be non-zero! */
355 status = acpi_db_start_command(walk_state, op);
357 /* User commands complete, continue execution of the interrupted method */
362 /*******************************************************************************
364 * FUNCTION: acpi_initialize_debugger
370 * DESCRIPTION: Init and start debugger
372 ******************************************************************************/
374 acpi_status acpi_initialize_debugger(void)
378 ACPI_FUNCTION_TRACE(acpi_initialize_debugger);
382 acpi_gbl_db_buffer = NULL;
383 acpi_gbl_db_filename = NULL;
384 acpi_gbl_db_output_to_file = FALSE;
386 acpi_gbl_db_debug_level = ACPI_LV_VERBOSITY2;
387 acpi_gbl_db_console_debug_level = ACPI_NORMAL_DEFAULT | ACPI_LV_TABLES;
388 acpi_gbl_db_output_flags = ACPI_DB_CONSOLE_OUTPUT;
390 acpi_gbl_db_opt_no_ini_methods = FALSE;
392 acpi_gbl_db_buffer = acpi_os_allocate(ACPI_DEBUG_BUFFER_SIZE);
393 if (!acpi_gbl_db_buffer) {
394 return_ACPI_STATUS(AE_NO_MEMORY);
396 memset(acpi_gbl_db_buffer, 0, ACPI_DEBUG_BUFFER_SIZE);
398 /* Initial scope is the root */
400 acpi_gbl_db_scope_buf[0] = AML_ROOT_PREFIX;
401 acpi_gbl_db_scope_buf[1] = 0;
402 acpi_gbl_db_scope_node = acpi_gbl_root_node;
404 /* Initialize user commands loop */
406 acpi_gbl_db_terminate_loop = FALSE;
409 * If configured for multi-thread support, the debug executor runs in
410 * a separate thread so that the front end can be in another address
411 * space, environment, or even another machine.
413 if (acpi_gbl_debugger_configuration & DEBUGGER_MULTI_THREADED) {
415 /* These were created with one unit, grab it */
417 status = acpi_os_acquire_mutex(acpi_gbl_db_command_complete,
419 if (ACPI_FAILURE(status)) {
420 acpi_os_printf("Could not get debugger mutex\n");
421 return_ACPI_STATUS(status);
424 status = acpi_os_acquire_mutex(acpi_gbl_db_command_ready,
426 if (ACPI_FAILURE(status)) {
427 acpi_os_printf("Could not get debugger mutex\n");
428 return_ACPI_STATUS(status);
431 /* Create the debug execution thread to execute commands */
433 acpi_gbl_db_threads_terminated = FALSE;
434 status = acpi_os_execute(OSL_DEBUGGER_THREAD,
435 acpi_db_execute_thread, NULL);
436 if (ACPI_FAILURE(status)) {
437 ACPI_EXCEPTION((AE_INFO, status,
438 "Could not start debugger thread"));
439 acpi_gbl_db_threads_terminated = TRUE;
440 return_ACPI_STATUS(status);
444 return_ACPI_STATUS(AE_OK);
447 ACPI_EXPORT_SYMBOL(acpi_initialize_debugger)
449 /*******************************************************************************
451 * FUNCTION: acpi_terminate_debugger
457 * DESCRIPTION: Stop debugger
459 ******************************************************************************/
460 void acpi_terminate_debugger(void)
463 /* Terminate the AML Debugger */
465 acpi_gbl_db_terminate_loop = TRUE;
467 if (acpi_gbl_debugger_configuration & DEBUGGER_MULTI_THREADED) {
468 acpi_os_release_mutex(acpi_gbl_db_command_ready);
470 /* Wait the AML Debugger threads */
472 while (!acpi_gbl_db_threads_terminated) {
477 if (acpi_gbl_db_buffer) {
478 acpi_os_free(acpi_gbl_db_buffer);
479 acpi_gbl_db_buffer = NULL;
482 /* Ensure that debug output is now disabled */
484 acpi_gbl_db_output_flags = ACPI_DB_DISABLE_OUTPUT;
487 ACPI_EXPORT_SYMBOL(acpi_terminate_debugger)