1 /*******************************************************************************
3 * Module Name: dbxface - AML Debugger external interfaces
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2016, 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
;
89 while (status
== AE_CTRL_TRUE
) {
91 /* Notify the completion of the command */
93 status
= acpi_os_notify_command_complete();
94 if (ACPI_FAILURE(status
)) {
98 /* Wait the readiness of the command */
100 status
= acpi_os_wait_command_ready();
101 if (ACPI_FAILURE(status
)) {
106 acpi_db_command_dispatch(acpi_gbl_db_line_buf
, walk_state
,
110 /* acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE); */
113 if (ACPI_FAILURE(status
) && status
!= AE_CTRL_TERMINATE
) {
114 ACPI_EXCEPTION((AE_INFO
, status
,
115 "While parsing/handling command line"));
120 /*******************************************************************************
122 * FUNCTION: acpi_db_signal_break_point
124 * PARAMETERS: walk_state - Current walk
128 * DESCRIPTION: Called for AML_BREAK_POINT_OP
130 ******************************************************************************/
132 void acpi_db_signal_break_point(struct acpi_walk_state
*walk_state
)
135 #ifndef ACPI_APPLICATION
136 if (acpi_gbl_db_thread_id
!= acpi_os_get_thread_id()) {
142 * Set the single-step flag. This will cause the debugger (if present)
143 * to break to the console within the AML debugger at the start of the
144 * next AML instruction.
146 acpi_gbl_cm_single_step
= TRUE
;
147 acpi_os_printf("**break** Executed AML BreakPoint opcode\n");
150 /*******************************************************************************
152 * FUNCTION: acpi_db_single_step
154 * PARAMETERS: walk_state - Current walk
155 * op - Current executing op (from aml interpreter)
156 * opcode_class - Class of the current AML Opcode
160 * DESCRIPTION: Called just before execution of an AML opcode.
162 ******************************************************************************/
165 acpi_db_single_step(struct acpi_walk_state
*walk_state
,
166 union acpi_parse_object
*op
, u32 opcode_class
)
168 union acpi_parse_object
*next
;
169 acpi_status status
= AE_OK
;
170 u32 original_debug_level
;
171 union acpi_parse_object
*display_op
;
172 union acpi_parse_object
*parent_op
;
175 ACPI_FUNCTION_ENTRY();
177 #ifndef ACPI_APPLICATION
178 if (acpi_gbl_db_thread_id
!= acpi_os_get_thread_id()) {
183 /* Check the abort flag */
185 if (acpi_gbl_abort_method
) {
186 acpi_gbl_abort_method
= FALSE
;
187 return (AE_ABORT_METHOD
);
190 aml_offset
= (u32
)ACPI_PTR_DIFF(op
->common
.aml
,
191 walk_state
->parser_state
.aml_start
);
193 /* Check for single-step breakpoint */
195 if (walk_state
->method_breakpoint
&&
196 (walk_state
->method_breakpoint
<= aml_offset
)) {
198 /* Check if the breakpoint has been reached or passed */
199 /* Hit the breakpoint, resume single step, reset breakpoint */
201 acpi_os_printf("***Break*** at AML offset %X\n", aml_offset
);
202 acpi_gbl_cm_single_step
= TRUE
;
203 acpi_gbl_step_to_next_call
= FALSE
;
204 walk_state
->method_breakpoint
= 0;
207 /* Check for user breakpoint (Must be on exact Aml offset) */
209 else if (walk_state
->user_breakpoint
&&
210 (walk_state
->user_breakpoint
== aml_offset
)) {
211 acpi_os_printf("***UserBreakpoint*** at AML offset %X\n",
213 acpi_gbl_cm_single_step
= TRUE
;
214 acpi_gbl_step_to_next_call
= FALSE
;
215 walk_state
->method_breakpoint
= 0;
219 * Check if this is an opcode that we are interested in --
220 * namely, opcodes that have arguments
222 if (op
->common
.aml_opcode
== AML_INT_NAMEDFIELD_OP
) {
226 switch (opcode_class
) {
227 case AML_CLASS_UNKNOWN
:
228 case AML_CLASS_ARGUMENT
: /* constants, literals, etc. do nothing */
234 /* All other opcodes -- continue */
239 * Under certain debug conditions, display this opcode and its operands
241 if ((acpi_gbl_db_output_to_file
) ||
242 (acpi_gbl_cm_single_step
) || (acpi_dbg_level
& ACPI_LV_PARSE
)) {
243 if ((acpi_gbl_db_output_to_file
) ||
244 (acpi_dbg_level
& ACPI_LV_PARSE
)) {
246 ("\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 original_debug_level
= acpi_dbg_level
;
255 acpi_dbg_level
&= ~(ACPI_LV_PARSE
| ACPI_LV_FUNCTIONS
);
256 next
= op
->common
.next
;
257 op
->common
.next
= NULL
;
260 parent_op
= op
->common
.parent
;
262 if ((walk_state
->control_state
) &&
263 (walk_state
->control_state
->common
.state
==
264 ACPI_CONTROL_PREDICATE_EXECUTING
)) {
266 * We are executing the predicate of an IF or WHILE statement
267 * Search upwards for the containing IF or WHILE so that the
268 * entire predicate can be displayed.
271 if ((parent_op
->common
.aml_opcode
==
273 || (parent_op
->common
.aml_opcode
==
275 display_op
= parent_op
;
278 parent_op
= parent_op
->common
.parent
;
282 if ((parent_op
->common
.aml_opcode
==
284 || (parent_op
->common
.aml_opcode
==
286 || (parent_op
->common
.aml_opcode
==
288 || (parent_op
->common
.aml_opcode
==
290 || (parent_op
->common
.aml_opcode
==
294 display_op
= parent_op
;
295 parent_op
= parent_op
->common
.parent
;
300 /* Now we can display it */
302 #ifdef ACPI_DISASSEMBLER
303 acpi_dm_disassemble(walk_state
, display_op
, ACPI_UINT32_MAX
);
306 if ((op
->common
.aml_opcode
== AML_IF_OP
) ||
307 (op
->common
.aml_opcode
== AML_WHILE_OP
)) {
308 if (walk_state
->control_state
->common
.value
) {
310 ("Predicate = [True], IF block was executed\n");
313 ("Predicate = [False], Skipping IF block\n");
315 } else if (op
->common
.aml_opcode
== AML_ELSE_OP
) {
317 ("Predicate = [False], ELSE block was executed\n");
320 /* Restore everything */
322 op
->common
.next
= next
;
323 acpi_os_printf("\n");
324 if ((acpi_gbl_db_output_to_file
) ||
325 (acpi_dbg_level
& ACPI_LV_PARSE
)) {
326 acpi_os_printf("\n");
328 acpi_dbg_level
= original_debug_level
;
331 /* If we are not single stepping, just continue executing the method */
333 if (!acpi_gbl_cm_single_step
) {
338 * If we are executing a step-to-call command,
339 * Check if this is a method call.
341 if (acpi_gbl_step_to_next_call
) {
342 if (op
->common
.aml_opcode
!= AML_INT_METHODCALL_OP
) {
344 /* Not a method call, just keep executing */
349 /* Found a method call, stop executing */
351 acpi_gbl_step_to_next_call
= FALSE
;
355 * If the next opcode is a method call, we will "step over" it
358 if (op
->common
.aml_opcode
== AML_INT_METHODCALL_OP
) {
360 /* Force no more single stepping while executing called method */
362 acpi_gbl_cm_single_step
= FALSE
;
365 * Set the breakpoint on/before the call, it will stop execution
366 * as soon as we return
368 walk_state
->method_breakpoint
= 1; /* Must be non-zero! */
371 status
= acpi_db_start_command(walk_state
, op
);
373 /* User commands complete, continue execution of the interrupted method */
378 /*******************************************************************************
380 * FUNCTION: acpi_initialize_debugger
386 * DESCRIPTION: Init and start debugger
388 ******************************************************************************/
390 acpi_status
acpi_initialize_debugger(void)
394 ACPI_FUNCTION_TRACE(acpi_initialize_debugger
);
398 acpi_gbl_db_buffer
= NULL
;
399 acpi_gbl_db_filename
= NULL
;
400 acpi_gbl_db_output_to_file
= FALSE
;
402 acpi_gbl_db_debug_level
= ACPI_LV_VERBOSITY2
;
403 acpi_gbl_db_console_debug_level
= ACPI_NORMAL_DEFAULT
| ACPI_LV_TABLES
;
404 acpi_gbl_db_output_flags
= ACPI_DB_CONSOLE_OUTPUT
;
406 acpi_gbl_db_opt_no_ini_methods
= FALSE
;
408 acpi_gbl_db_buffer
= acpi_os_allocate(ACPI_DEBUG_BUFFER_SIZE
);
409 if (!acpi_gbl_db_buffer
) {
410 return_ACPI_STATUS(AE_NO_MEMORY
);
412 memset(acpi_gbl_db_buffer
, 0, ACPI_DEBUG_BUFFER_SIZE
);
414 /* Initial scope is the root */
416 acpi_gbl_db_scope_buf
[0] = AML_ROOT_PREFIX
;
417 acpi_gbl_db_scope_buf
[1] = 0;
418 acpi_gbl_db_scope_node
= acpi_gbl_root_node
;
420 /* Initialize user commands loop */
422 acpi_gbl_db_terminate_loop
= FALSE
;
425 * If configured for multi-thread support, the debug executor runs in
426 * a separate thread so that the front end can be in another address
427 * space, environment, or even another machine.
429 if (acpi_gbl_debugger_configuration
& DEBUGGER_MULTI_THREADED
) {
431 /* These were created with one unit, grab it */
433 status
= acpi_os_initialize_command_signals();
434 if (ACPI_FAILURE(status
)) {
435 acpi_os_printf("Could not get debugger mutex\n");
436 return_ACPI_STATUS(status
);
439 /* Create the debug execution thread to execute commands */
441 acpi_gbl_db_threads_terminated
= FALSE
;
442 status
= acpi_os_execute(OSL_DEBUGGER_MAIN_THREAD
,
443 acpi_db_execute_thread
, NULL
);
444 if (ACPI_FAILURE(status
)) {
445 ACPI_EXCEPTION((AE_INFO
, status
,
446 "Could not start debugger thread"));
447 acpi_gbl_db_threads_terminated
= TRUE
;
448 return_ACPI_STATUS(status
);
451 acpi_gbl_db_thread_id
= acpi_os_get_thread_id();
454 return_ACPI_STATUS(AE_OK
);
457 ACPI_EXPORT_SYMBOL(acpi_initialize_debugger
)
459 /*******************************************************************************
461 * FUNCTION: acpi_terminate_debugger
467 * DESCRIPTION: Stop debugger
469 ******************************************************************************/
470 void acpi_terminate_debugger(void)
473 /* Terminate the AML Debugger */
475 acpi_gbl_db_terminate_loop
= TRUE
;
477 if (acpi_gbl_debugger_configuration
& DEBUGGER_MULTI_THREADED
) {
479 /* Wait the AML Debugger threads */
481 while (!acpi_gbl_db_threads_terminated
) {
485 acpi_os_terminate_command_signals();
488 if (acpi_gbl_db_buffer
) {
489 acpi_os_free(acpi_gbl_db_buffer
);
490 acpi_gbl_db_buffer
= NULL
;
493 /* Ensure that debug output is now disabled */
495 acpi_gbl_db_output_flags
= ACPI_DB_DISABLE_OUTPUT
;
498 ACPI_EXPORT_SYMBOL(acpi_terminate_debugger
)
500 /*******************************************************************************
502 * FUNCTION: acpi_set_debugger_thread_id
504 * PARAMETERS: thread_id - Debugger thread ID
508 * DESCRIPTION: Set debugger thread ID
510 ******************************************************************************/
511 void acpi_set_debugger_thread_id(acpi_thread_id thread_id
)
513 acpi_gbl_db_thread_id
= thread_id
;
516 ACPI_EXPORT_SYMBOL(acpi_set_debugger_thread_id
)