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 #ifndef ACPI_APPLICATION
168 if (acpi_gbl_db_thread_id
!= acpi_os_get_thread_id()) {
173 /* Check the abort flag */
175 if (acpi_gbl_abort_method
) {
176 acpi_gbl_abort_method
= FALSE
;
177 return (AE_ABORT_METHOD
);
180 aml_offset
= (u32
)ACPI_PTR_DIFF(op
->common
.aml
,
181 walk_state
->parser_state
.aml_start
);
183 /* Check for single-step breakpoint */
185 if (walk_state
->method_breakpoint
&&
186 (walk_state
->method_breakpoint
<= aml_offset
)) {
188 /* Check if the breakpoint has been reached or passed */
189 /* Hit the breakpoint, resume single step, reset breakpoint */
191 acpi_os_printf("***Break*** at AML offset %X\n", aml_offset
);
192 acpi_gbl_cm_single_step
= TRUE
;
193 acpi_gbl_step_to_next_call
= FALSE
;
194 walk_state
->method_breakpoint
= 0;
197 /* Check for user breakpoint (Must be on exact Aml offset) */
199 else if (walk_state
->user_breakpoint
&&
200 (walk_state
->user_breakpoint
== aml_offset
)) {
201 acpi_os_printf("***UserBreakpoint*** at AML offset %X\n",
203 acpi_gbl_cm_single_step
= TRUE
;
204 acpi_gbl_step_to_next_call
= FALSE
;
205 walk_state
->method_breakpoint
= 0;
209 * Check if this is an opcode that we are interested in --
210 * namely, opcodes that have arguments
212 if (op
->common
.aml_opcode
== AML_INT_NAMEDFIELD_OP
) {
216 switch (opcode_class
) {
217 case AML_CLASS_UNKNOWN
:
218 case AML_CLASS_ARGUMENT
: /* constants, literals, etc. do nothing */
224 /* All other opcodes -- continue */
229 * Under certain debug conditions, display this opcode and its operands
231 if ((acpi_gbl_db_output_to_file
) ||
232 (acpi_gbl_cm_single_step
) || (acpi_dbg_level
& ACPI_LV_PARSE
)) {
233 if ((acpi_gbl_db_output_to_file
) ||
234 (acpi_dbg_level
& ACPI_LV_PARSE
)) {
236 ("\n[AmlDebug] Next AML Opcode to execute:\n");
240 * Display this op (and only this op - zero out the NEXT field
241 * temporarily, and disable parser trace output for the duration of
242 * the display because we don't want the extraneous debug output)
244 original_debug_level
= acpi_dbg_level
;
245 acpi_dbg_level
&= ~(ACPI_LV_PARSE
| ACPI_LV_FUNCTIONS
);
246 next
= op
->common
.next
;
247 op
->common
.next
= NULL
;
250 parent_op
= op
->common
.parent
;
252 if ((walk_state
->control_state
) &&
253 (walk_state
->control_state
->common
.state
==
254 ACPI_CONTROL_PREDICATE_EXECUTING
)) {
256 * We are executing the predicate of an IF or WHILE statement
257 * Search upwards for the containing IF or WHILE so that the
258 * entire predicate can be displayed.
261 if ((parent_op
->common
.aml_opcode
==
263 || (parent_op
->common
.aml_opcode
==
265 display_op
= parent_op
;
268 parent_op
= parent_op
->common
.parent
;
272 if ((parent_op
->common
.aml_opcode
==
274 || (parent_op
->common
.aml_opcode
==
276 || (parent_op
->common
.aml_opcode
==
278 || (parent_op
->common
.aml_opcode
==
280 || (parent_op
->common
.aml_opcode
==
284 display_op
= parent_op
;
285 parent_op
= parent_op
->common
.parent
;
290 /* Now we can display it */
292 #ifdef ACPI_DISASSEMBLER
293 acpi_dm_disassemble(walk_state
, display_op
, ACPI_UINT32_MAX
);
296 if ((op
->common
.aml_opcode
== AML_IF_OP
) ||
297 (op
->common
.aml_opcode
== AML_WHILE_OP
)) {
298 if (walk_state
->control_state
->common
.value
) {
300 ("Predicate = [True], IF block was executed\n");
303 ("Predicate = [False], Skipping IF block\n");
305 } else if (op
->common
.aml_opcode
== AML_ELSE_OP
) {
307 ("Predicate = [False], ELSE block was executed\n");
310 /* Restore everything */
312 op
->common
.next
= next
;
313 acpi_os_printf("\n");
314 if ((acpi_gbl_db_output_to_file
) ||
315 (acpi_dbg_level
& ACPI_LV_PARSE
)) {
316 acpi_os_printf("\n");
318 acpi_dbg_level
= original_debug_level
;
321 /* If we are not single stepping, just continue executing the method */
323 if (!acpi_gbl_cm_single_step
) {
328 * If we are executing a step-to-call command,
329 * Check if this is a method call.
331 if (acpi_gbl_step_to_next_call
) {
332 if (op
->common
.aml_opcode
!= AML_INT_METHODCALL_OP
) {
334 /* Not a method call, just keep executing */
339 /* Found a method call, stop executing */
341 acpi_gbl_step_to_next_call
= FALSE
;
345 * If the next opcode is a method call, we will "step over" it
348 if (op
->common
.aml_opcode
== AML_INT_METHODCALL_OP
) {
350 /* Force no more single stepping while executing called method */
352 acpi_gbl_cm_single_step
= FALSE
;
355 * Set the breakpoint on/before the call, it will stop execution
356 * as soon as we return
358 walk_state
->method_breakpoint
= 1; /* Must be non-zero! */
361 status
= acpi_db_start_command(walk_state
, op
);
363 /* User commands complete, continue execution of the interrupted method */
368 /*******************************************************************************
370 * FUNCTION: acpi_initialize_debugger
376 * DESCRIPTION: Init and start debugger
378 ******************************************************************************/
380 acpi_status
acpi_initialize_debugger(void)
384 ACPI_FUNCTION_TRACE(acpi_initialize_debugger
);
388 acpi_gbl_db_buffer
= NULL
;
389 acpi_gbl_db_filename
= NULL
;
390 acpi_gbl_db_output_to_file
= FALSE
;
392 acpi_gbl_db_debug_level
= ACPI_LV_VERBOSITY2
;
393 acpi_gbl_db_console_debug_level
= ACPI_NORMAL_DEFAULT
| ACPI_LV_TABLES
;
394 acpi_gbl_db_output_flags
= ACPI_DB_CONSOLE_OUTPUT
;
396 acpi_gbl_db_opt_no_ini_methods
= FALSE
;
398 acpi_gbl_db_buffer
= acpi_os_allocate(ACPI_DEBUG_BUFFER_SIZE
);
399 if (!acpi_gbl_db_buffer
) {
400 return_ACPI_STATUS(AE_NO_MEMORY
);
402 memset(acpi_gbl_db_buffer
, 0, ACPI_DEBUG_BUFFER_SIZE
);
404 /* Initial scope is the root */
406 acpi_gbl_db_scope_buf
[0] = AML_ROOT_PREFIX
;
407 acpi_gbl_db_scope_buf
[1] = 0;
408 acpi_gbl_db_scope_node
= acpi_gbl_root_node
;
410 /* Initialize user commands loop */
412 acpi_gbl_db_terminate_loop
= FALSE
;
415 * If configured for multi-thread support, the debug executor runs in
416 * a separate thread so that the front end can be in another address
417 * space, environment, or even another machine.
419 if (acpi_gbl_debugger_configuration
& DEBUGGER_MULTI_THREADED
) {
421 /* These were created with one unit, grab it */
423 status
= acpi_os_acquire_mutex(acpi_gbl_db_command_complete
,
425 if (ACPI_FAILURE(status
)) {
426 acpi_os_printf("Could not get debugger mutex\n");
427 return_ACPI_STATUS(status
);
430 status
= acpi_os_acquire_mutex(acpi_gbl_db_command_ready
,
432 if (ACPI_FAILURE(status
)) {
433 acpi_os_printf("Could not get debugger mutex\n");
434 return_ACPI_STATUS(status
);
437 /* Create the debug execution thread to execute commands */
439 acpi_gbl_db_threads_terminated
= FALSE
;
440 status
= acpi_os_execute(OSL_DEBUGGER_MAIN_THREAD
,
441 acpi_db_execute_thread
, NULL
);
442 if (ACPI_FAILURE(status
)) {
443 ACPI_EXCEPTION((AE_INFO
, status
,
444 "Could not start debugger thread"));
445 acpi_gbl_db_threads_terminated
= TRUE
;
446 return_ACPI_STATUS(status
);
449 acpi_gbl_db_thread_id
= acpi_os_get_thread_id();
452 return_ACPI_STATUS(AE_OK
);
455 ACPI_EXPORT_SYMBOL(acpi_initialize_debugger
)
457 /*******************************************************************************
459 * FUNCTION: acpi_terminate_debugger
465 * DESCRIPTION: Stop debugger
467 ******************************************************************************/
468 void acpi_terminate_debugger(void)
471 /* Terminate the AML Debugger */
473 acpi_gbl_db_terminate_loop
= TRUE
;
475 if (acpi_gbl_debugger_configuration
& DEBUGGER_MULTI_THREADED
) {
476 acpi_os_release_mutex(acpi_gbl_db_command_ready
);
478 /* Wait the AML Debugger threads */
480 while (!acpi_gbl_db_threads_terminated
) {
485 if (acpi_gbl_db_buffer
) {
486 acpi_os_free(acpi_gbl_db_buffer
);
487 acpi_gbl_db_buffer
= NULL
;
490 /* Ensure that debug output is now disabled */
492 acpi_gbl_db_output_flags
= ACPI_DB_DISABLE_OUTPUT
;
495 ACPI_EXPORT_SYMBOL(acpi_terminate_debugger
)
497 /*******************************************************************************
499 * FUNCTION: acpi_set_debugger_thread_id
501 * PARAMETERS: thread_id - Debugger thread ID
505 * DESCRIPTION: Set debugger thread ID
507 ******************************************************************************/
508 void acpi_set_debugger_thread_id(acpi_thread_id thread_id
)
510 acpi_gbl_db_thread_id
= thread_id
;
513 ACPI_EXPORT_SYMBOL(acpi_set_debugger_thread_id
)