dsdebug.c 5.3 KB

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