^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Module Name: dsdebug - Parser/Interpreter interface - debugging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2000 - 2020, Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <acpi/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "accommon.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "acdispat.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "acnamesp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #ifdef ACPI_DISASSEMBLER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "acdisasm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "acinterp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define _COMPONENT ACPI_DISPATCHER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) ACPI_MODULE_NAME("dsdebug")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) /* Local prototypes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) acpi_ds_print_node_pathname(struct acpi_namespace_node *node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) const char *message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * FUNCTION: acpi_ds_print_node_pathname
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * PARAMETERS: node - Object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * message - Prefix message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * DESCRIPTION: Print an object's full namespace pathname
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * Manages allocation/freeing of a pathname buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) acpi_ds_print_node_pathname(struct acpi_namespace_node *node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) const char *message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct acpi_buffer buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) ACPI_FUNCTION_TRACE(ds_print_node_pathname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) if (!node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) ACPI_DEBUG_PRINT_RAW((ACPI_DB_DISPATCH, "[NULL NAME]"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) return_VOID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) /* Convert handle to full pathname and print it (with supplied message) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) status = acpi_ns_handle_to_pathname(node, &buffer, TRUE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if (ACPI_SUCCESS(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) if (message) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) ACPI_DEBUG_PRINT_RAW((ACPI_DB_DISPATCH, "%s ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) message));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) ACPI_DEBUG_PRINT_RAW((ACPI_DB_DISPATCH, "[%s] (Node %p)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) (char *)buffer.pointer, node));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) ACPI_FREE(buffer.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) return_VOID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * FUNCTION: acpi_ds_dump_method_stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * PARAMETERS: status - Method execution status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * walk_state - Current state of the parse tree walk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * op - Executing parse op
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * RETURN: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * DESCRIPTION: Called when a method has been aborted because of an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * Dumps the method execution stack.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) acpi_ds_dump_method_stack(acpi_status status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct acpi_walk_state *walk_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) union acpi_parse_object *op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) union acpi_parse_object *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct acpi_thread_state *thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct acpi_walk_state *next_walk_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct acpi_namespace_node *previous_method = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) union acpi_operand_object *method_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) ACPI_FUNCTION_TRACE(ds_dump_method_stack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /* Ignore control codes, they are not errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) if ((status & AE_CODE_MASK) == AE_CODE_CONTROL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return_VOID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /* We may be executing a deferred opcode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (walk_state->deferred_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) "Executing subtree for Buffer/Package/Region\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) return_VOID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * If there is no Thread, we are not actually executing a method.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * This can happen when the iASL compiler calls the interpreter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * to perform constant folding.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) thread = walk_state->thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (!thread) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) return_VOID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /* Display exception and method name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) "\n**** Exception %s during execution of method ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) acpi_format_exception(status)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) acpi_ds_print_node_pathname(walk_state->method_node, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /* Display stack of executing methods */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) ACPI_DEBUG_PRINT_RAW((ACPI_DB_DISPATCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) "\n\nMethod Execution Stack:\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) next_walk_state = thread->walk_state_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) /* Walk list of linked walk states */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) while (next_walk_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) method_desc = next_walk_state->method_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (method_desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) acpi_ex_stop_trace_method((struct acpi_namespace_node *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) method_desc->method.node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) method_desc, walk_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) " Method [%4.4s] executing: ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) acpi_ut_get_node_name(next_walk_state->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) method_node)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /* First method is the currently executing method */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (next_walk_state == walk_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (op) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /* Display currently executing ASL statement */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) next = op->common.next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) op->common.next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) #ifdef ACPI_DISASSEMBLER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (walk_state->method_node !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) acpi_gbl_root_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) /* More verbose if not module-level code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) acpi_os_printf("Failed at ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) acpi_dm_disassemble(next_walk_state, op,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) ACPI_UINT32_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) op->common.next = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * This method has called another method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * NOTE: the method call parse subtree is already deleted at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * this point, so we cannot disassemble the method invocation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) ACPI_DEBUG_PRINT_RAW((ACPI_DB_DISPATCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) "Call to method "));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) acpi_ds_print_node_pathname(previous_method, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) previous_method = next_walk_state->method_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) next_walk_state = next_walk_state->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) ACPI_DEBUG_PRINT_RAW((ACPI_DB_DISPATCH, "\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return_VOID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) acpi_ds_dump_method_stack(acpi_status status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) struct acpi_walk_state *walk_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) union acpi_parse_object *op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) #endif