1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /*******************************************************************************
4 * Module Name: dbxface - AML Debugger external interfaces
6 ******************************************************************************/
15 #define _COMPONENT ACPI_CA_DEBUGGER
16 ACPI_MODULE_NAME("dbxface")
18 /* Local prototypes */
20 acpi_db_start_command(struct acpi_walk_state
*walk_state
,
21 union acpi_parse_object
*op
);
23 #ifdef ACPI_OBSOLETE_FUNCTIONS
24 void acpi_db_method_end(struct acpi_walk_state
*walk_state
);
27 #ifdef ACPI_DISASSEMBLER
28 static union acpi_parse_object
*acpi_db_get_display_op(struct acpi_walk_state
30 union acpi_parse_object
34 /*******************************************************************************
36 * FUNCTION: acpi_db_start_command
38 * PARAMETERS: walk_state - Current walk
39 * op - Current executing Op, from AML interpreter
43 * DESCRIPTION: Enter debugger command loop
45 ******************************************************************************/
48 acpi_db_start_command(struct acpi_walk_state
*walk_state
,
49 union acpi_parse_object
*op
)
53 /* TBD: [Investigate] are there namespace locking issues here? */
55 /* acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); */
57 /* Go into the command loop and await next user command */
59 acpi_gbl_method_executing
= TRUE
;
60 status
= AE_CTRL_TRUE
;
62 while (status
== AE_CTRL_TRUE
) {
64 /* Notify the completion of the command */
66 status
= acpi_os_notify_command_complete();
67 if (ACPI_FAILURE(status
)) {
71 /* Wait the readiness of the command */
73 status
= acpi_os_wait_command_ready();
74 if (ACPI_FAILURE(status
)) {
79 acpi_db_command_dispatch(acpi_gbl_db_line_buf
, walk_state
,
83 /* acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE); */
86 if (ACPI_FAILURE(status
) && status
!= AE_CTRL_TERMINATE
) {
87 ACPI_EXCEPTION((AE_INFO
, status
,
88 "While parsing/handling command line"));
93 /*******************************************************************************
95 * FUNCTION: acpi_db_signal_break_point
97 * PARAMETERS: walk_state - Current walk
101 * DESCRIPTION: Called for AML_BREAKPOINT_OP
103 ******************************************************************************/
105 void acpi_db_signal_break_point(struct acpi_walk_state
*walk_state
)
108 #ifndef ACPI_APPLICATION
109 if (acpi_gbl_db_thread_id
!= acpi_os_get_thread_id()) {
115 * Set the single-step flag. This will cause the debugger (if present)
116 * to break to the console within the AML debugger at the start of the
117 * next AML instruction.
119 acpi_gbl_cm_single_step
= TRUE
;
120 acpi_os_printf("**break** Executed AML BreakPoint opcode\n");
123 #ifdef ACPI_DISASSEMBLER
124 /*******************************************************************************
126 * FUNCTION: acpi_db_get_display_op
128 * PARAMETERS: walk_state - Current walk
129 * op - Current executing op (from aml interpreter)
131 * RETURN: Opcode to display
133 * DESCRIPTION: Find the opcode to display during single stepping
135 ******************************************************************************/
137 static union acpi_parse_object
*acpi_db_get_display_op(struct acpi_walk_state
139 union acpi_parse_object
142 union acpi_parse_object
*display_op
;
143 union acpi_parse_object
*parent_op
;
146 parent_op
= op
->common
.parent
;
148 if ((walk_state
->control_state
) &&
149 (walk_state
->control_state
->common
.state
==
150 ACPI_CONTROL_PREDICATE_EXECUTING
)) {
152 * We are executing the predicate of an IF or WHILE statement
153 * Search upwards for the containing IF or WHILE so that the
154 * entire predicate can be displayed.
157 if ((parent_op
->common
.aml_opcode
== AML_IF_OP
)
158 || (parent_op
->common
.aml_opcode
==
160 display_op
= parent_op
;
163 parent_op
= parent_op
->common
.parent
;
167 if ((parent_op
->common
.aml_opcode
== AML_IF_OP
)
168 || (parent_op
->common
.aml_opcode
==
170 || (parent_op
->common
.aml_opcode
==
172 || (parent_op
->common
.aml_opcode
==
174 || (parent_op
->common
.aml_opcode
==
178 display_op
= parent_op
;
179 parent_op
= parent_op
->common
.parent
;
187 /*******************************************************************************
189 * FUNCTION: acpi_db_single_step
191 * PARAMETERS: walk_state - Current walk
192 * op - Current executing op (from aml interpreter)
193 * opcode_class - Class of the current AML Opcode
197 * DESCRIPTION: Called just before execution of an AML opcode.
199 ******************************************************************************/
202 acpi_db_single_step(struct acpi_walk_state
*walk_state
,
203 union acpi_parse_object
*op
, u32 opcode_class
)
205 union acpi_parse_object
*next
;
206 acpi_status status
= AE_OK
;
207 u32 original_debug_level
;
210 ACPI_FUNCTION_ENTRY();
212 #ifndef ACPI_APPLICATION
213 if (acpi_gbl_db_thread_id
!= acpi_os_get_thread_id()) {
218 /* Check the abort flag */
220 if (acpi_gbl_abort_method
) {
221 acpi_gbl_abort_method
= FALSE
;
222 return (AE_ABORT_METHOD
);
225 aml_offset
= (u32
)ACPI_PTR_DIFF(op
->common
.aml
,
226 walk_state
->parser_state
.aml_start
);
228 /* Check for single-step breakpoint */
230 if (walk_state
->method_breakpoint
&&
231 (walk_state
->method_breakpoint
<= aml_offset
)) {
233 /* Check if the breakpoint has been reached or passed */
234 /* Hit the breakpoint, resume single step, reset breakpoint */
236 acpi_os_printf("***Break*** at AML offset %X\n", aml_offset
);
237 acpi_gbl_cm_single_step
= TRUE
;
238 acpi_gbl_step_to_next_call
= FALSE
;
239 walk_state
->method_breakpoint
= 0;
242 /* Check for user breakpoint (Must be on exact Aml offset) */
244 else if (walk_state
->user_breakpoint
&&
245 (walk_state
->user_breakpoint
== aml_offset
)) {
246 acpi_os_printf("***UserBreakpoint*** at AML offset %X\n",
248 acpi_gbl_cm_single_step
= TRUE
;
249 acpi_gbl_step_to_next_call
= FALSE
;
250 walk_state
->method_breakpoint
= 0;
254 * Check if this is an opcode that we are interested in --
255 * namely, opcodes that have arguments
257 if (op
->common
.aml_opcode
== AML_INT_NAMEDFIELD_OP
) {
261 switch (opcode_class
) {
262 case AML_CLASS_UNKNOWN
:
263 case AML_CLASS_ARGUMENT
: /* constants, literals, etc. do nothing */
269 /* All other opcodes -- continue */
274 * Under certain debug conditions, display this opcode and its operands
276 if ((acpi_gbl_db_output_to_file
) ||
277 (acpi_gbl_cm_single_step
) || (acpi_dbg_level
& ACPI_LV_PARSE
)) {
278 if ((acpi_gbl_db_output_to_file
) ||
279 (acpi_dbg_level
& ACPI_LV_PARSE
)) {
281 ("\nAML Debug: Next AML Opcode to execute:\n");
285 * Display this op (and only this op - zero out the NEXT field
286 * temporarily, and disable parser trace output for the duration of
287 * the display because we don't want the extraneous debug output)
289 original_debug_level
= acpi_dbg_level
;
290 acpi_dbg_level
&= ~(ACPI_LV_PARSE
| ACPI_LV_FUNCTIONS
);
291 next
= op
->common
.next
;
292 op
->common
.next
= NULL
;
294 /* Now we can disassemble and display it */
296 #ifdef ACPI_DISASSEMBLER
297 acpi_dm_disassemble(walk_state
,
298 acpi_db_get_display_op(walk_state
, op
),
302 * The AML Disassembler is not configured - at least we can
303 * display the opcode value and name
305 acpi_os_printf("AML Opcode: %4.4X %s\n", op
->common
.aml_opcode
,
306 acpi_ps_get_opcode_name(op
->common
.aml_opcode
));
309 if ((op
->common
.aml_opcode
== AML_IF_OP
) ||
310 (op
->common
.aml_opcode
== AML_WHILE_OP
)) {
311 if (walk_state
->control_state
->common
.value
) {
313 ("Predicate = [True], IF block was executed\n");
316 ("Predicate = [False], Skipping IF block\n");
318 } else if (op
->common
.aml_opcode
== AML_ELSE_OP
) {
320 ("Predicate = [False], ELSE block was executed\n");
323 /* Restore everything */
325 op
->common
.next
= next
;
326 acpi_os_printf("\n");
327 if ((acpi_gbl_db_output_to_file
) ||
328 (acpi_dbg_level
& ACPI_LV_PARSE
)) {
329 acpi_os_printf("\n");
331 acpi_dbg_level
= original_debug_level
;
334 /* If we are not single stepping, just continue executing the method */
336 if (!acpi_gbl_cm_single_step
) {
341 * If we are executing a step-to-call command,
342 * Check if this is a method call.
344 if (acpi_gbl_step_to_next_call
) {
345 if (op
->common
.aml_opcode
!= AML_INT_METHODCALL_OP
) {
347 /* Not a method call, just keep executing */
352 /* Found a method call, stop executing */
354 acpi_gbl_step_to_next_call
= FALSE
;
358 * If the next opcode is a method call, we will "step over" it
361 if (op
->common
.aml_opcode
== AML_INT_METHODCALL_OP
) {
363 /* Force no more single stepping while executing called method */
365 acpi_gbl_cm_single_step
= FALSE
;
368 * Set the breakpoint on/before the call, it will stop execution
369 * as soon as we return
371 walk_state
->method_breakpoint
= 1; /* Must be non-zero! */
374 acpi_ex_exit_interpreter();
375 status
= acpi_db_start_command(walk_state
, op
);
376 acpi_ex_enter_interpreter();
378 /* User commands complete, continue execution of the interrupted method */
383 /*******************************************************************************
385 * FUNCTION: acpi_initialize_debugger
391 * DESCRIPTION: Init and start debugger
393 ******************************************************************************/
395 acpi_status
acpi_initialize_debugger(void)
399 ACPI_FUNCTION_TRACE(acpi_initialize_debugger
);
403 acpi_gbl_db_buffer
= NULL
;
404 acpi_gbl_db_filename
= NULL
;
405 acpi_gbl_db_output_to_file
= FALSE
;
407 acpi_gbl_db_debug_level
= ACPI_LV_VERBOSITY2
;
408 acpi_gbl_db_console_debug_level
= ACPI_NORMAL_DEFAULT
| ACPI_LV_TABLES
;
409 acpi_gbl_db_output_flags
= ACPI_DB_CONSOLE_OUTPUT
;
411 acpi_gbl_db_opt_no_ini_methods
= FALSE
;
413 acpi_gbl_db_buffer
= acpi_os_allocate(ACPI_DEBUG_BUFFER_SIZE
);
414 if (!acpi_gbl_db_buffer
) {
415 return_ACPI_STATUS(AE_NO_MEMORY
);
417 memset(acpi_gbl_db_buffer
, 0, ACPI_DEBUG_BUFFER_SIZE
);
419 /* Initial scope is the root */
421 acpi_gbl_db_scope_buf
[0] = AML_ROOT_PREFIX
;
422 acpi_gbl_db_scope_buf
[1] = 0;
423 acpi_gbl_db_scope_node
= acpi_gbl_root_node
;
425 /* Initialize user commands loop */
427 acpi_gbl_db_terminate_loop
= FALSE
;
430 * If configured for multi-thread support, the debug executor runs in
431 * a separate thread so that the front end can be in another address
432 * space, environment, or even another machine.
434 if (acpi_gbl_debugger_configuration
& DEBUGGER_MULTI_THREADED
) {
436 /* These were created with one unit, grab it */
438 status
= acpi_os_initialize_debugger();
439 if (ACPI_FAILURE(status
)) {
440 acpi_os_printf("Could not get debugger mutex\n");
441 return_ACPI_STATUS(status
);
444 /* Create the debug execution thread to execute commands */
446 acpi_gbl_db_threads_terminated
= FALSE
;
447 status
= acpi_os_execute(OSL_DEBUGGER_MAIN_THREAD
,
448 acpi_db_execute_thread
, NULL
);
449 if (ACPI_FAILURE(status
)) {
450 ACPI_EXCEPTION((AE_INFO
, status
,
451 "Could not start debugger thread"));
452 acpi_gbl_db_threads_terminated
= TRUE
;
453 return_ACPI_STATUS(status
);
456 acpi_gbl_db_thread_id
= acpi_os_get_thread_id();
459 return_ACPI_STATUS(AE_OK
);
462 ACPI_EXPORT_SYMBOL(acpi_initialize_debugger
)
464 /*******************************************************************************
466 * FUNCTION: acpi_terminate_debugger
472 * DESCRIPTION: Stop debugger
474 ******************************************************************************/
475 void acpi_terminate_debugger(void)
478 /* Terminate the AML Debugger */
480 acpi_gbl_db_terminate_loop
= TRUE
;
482 if (acpi_gbl_debugger_configuration
& DEBUGGER_MULTI_THREADED
) {
484 /* Wait the AML Debugger threads */
486 while (!acpi_gbl_db_threads_terminated
) {
490 acpi_os_terminate_debugger();
493 if (acpi_gbl_db_buffer
) {
494 acpi_os_free(acpi_gbl_db_buffer
);
495 acpi_gbl_db_buffer
= NULL
;
498 /* Ensure that debug output is now disabled */
500 acpi_gbl_db_output_flags
= ACPI_DB_DISABLE_OUTPUT
;
503 ACPI_EXPORT_SYMBOL(acpi_terminate_debugger
)
505 /*******************************************************************************
507 * FUNCTION: acpi_set_debugger_thread_id
509 * PARAMETERS: thread_id - Debugger thread ID
513 * DESCRIPTION: Set debugger thread ID
515 ******************************************************************************/
516 void acpi_set_debugger_thread_id(acpi_thread_id thread_id
)
518 acpi_gbl_db_thread_id
= thread_id
;
521 ACPI_EXPORT_SYMBOL(acpi_set_debugger_thread_id
)