dsdebug.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /******************************************************************************
  2. *
  3. * Module Name: dsdebug - Parser/Interpreter interface - debugging
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2016, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include "accommon.h"
  44. #include "acdispat.h"
  45. #include "acnamesp.h"
  46. #ifdef ACPI_DISASSEMBLER
  47. #include "acdisasm.h"
  48. #endif
  49. #include "acinterp.h"
  50. #define _COMPONENT ACPI_DISPATCHER
  51. ACPI_MODULE_NAME("dsdebug")
  52. #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
  53. /* Local prototypes */
  54. static void
  55. acpi_ds_print_node_pathname(struct acpi_namespace_node *node,
  56. const char *message);
  57. /*******************************************************************************
  58. *
  59. * FUNCTION: acpi_ds_print_node_pathname
  60. *
  61. * PARAMETERS: node - Object
  62. * message - Prefix message
  63. *
  64. * DESCRIPTION: Print an object's full namespace pathname
  65. * Manages allocation/freeing of a pathname buffer
  66. *
  67. ******************************************************************************/
  68. static void
  69. acpi_ds_print_node_pathname(struct acpi_namespace_node *node,
  70. const char *message)
  71. {
  72. struct acpi_buffer buffer;
  73. acpi_status status;
  74. ACPI_FUNCTION_TRACE(ds_print_node_pathname);
  75. if (!node) {
  76. ACPI_DEBUG_PRINT_RAW((ACPI_DB_DISPATCH, "[NULL NAME]"));
  77. return_VOID;
  78. }
  79. /* Convert handle to full pathname and print it (with supplied message) */
  80. buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
  81. status = acpi_ns_handle_to_pathname(node, &buffer, TRUE);
  82. if (ACPI_SUCCESS(status)) {
  83. if (message) {
  84. ACPI_DEBUG_PRINT_RAW((ACPI_DB_DISPATCH, "%s ",
  85. message));
  86. }
  87. ACPI_DEBUG_PRINT_RAW((ACPI_DB_DISPATCH, "[%s] (Node %p)",
  88. (char *)buffer.pointer, node));
  89. ACPI_FREE(buffer.pointer);
  90. }
  91. return_VOID;
  92. }
  93. /*******************************************************************************
  94. *
  95. * FUNCTION: acpi_ds_dump_method_stack
  96. *
  97. * PARAMETERS: status - Method execution status
  98. * walk_state - Current state of the parse tree walk
  99. * op - Executing parse op
  100. *
  101. * RETURN: None
  102. *
  103. * DESCRIPTION: Called when a method has been aborted because of an error.
  104. * Dumps the method execution stack.
  105. *
  106. ******************************************************************************/
  107. void
  108. acpi_ds_dump_method_stack(acpi_status status,
  109. struct acpi_walk_state *walk_state,
  110. union acpi_parse_object *op)
  111. {
  112. union acpi_parse_object *next;
  113. struct acpi_thread_state *thread;
  114. struct acpi_walk_state *next_walk_state;
  115. struct acpi_namespace_node *previous_method = NULL;
  116. union acpi_operand_object *method_desc;
  117. ACPI_FUNCTION_TRACE(ds_dump_method_stack);
  118. /* Ignore control codes, they are not errors */
  119. if ((status & AE_CODE_MASK) == AE_CODE_CONTROL) {
  120. return_VOID;
  121. }
  122. /* We may be executing a deferred opcode */
  123. if (walk_state->deferred_node) {
  124. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  125. "Executing subtree for Buffer/Package/Region\n"));
  126. return_VOID;
  127. }
  128. /*
  129. * If there is no Thread, we are not actually executing a method.
  130. * This can happen when the iASL compiler calls the interpreter
  131. * to perform constant folding.
  132. */
  133. thread = walk_state->thread;
  134. if (!thread) {
  135. return_VOID;
  136. }
  137. /* Display exception and method name */
  138. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  139. "\n**** Exception %s during execution of method ",
  140. acpi_format_exception(status)));
  141. acpi_ds_print_node_pathname(walk_state->method_node, NULL);
  142. /* Display stack of executing methods */
  143. ACPI_DEBUG_PRINT_RAW((ACPI_DB_DISPATCH,
  144. "\n\nMethod Execution Stack:\n"));
  145. next_walk_state = thread->walk_state_list;
  146. /* Walk list of linked walk states */
  147. while (next_walk_state) {
  148. method_desc = next_walk_state->method_desc;
  149. if (method_desc) {
  150. acpi_ex_stop_trace_method((struct acpi_namespace_node *)
  151. method_desc->method.node,
  152. method_desc, walk_state);
  153. }
  154. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  155. " Method [%4.4s] executing: ",
  156. acpi_ut_get_node_name(next_walk_state->
  157. method_node)));
  158. /* First method is the currently executing method */
  159. if (next_walk_state == walk_state) {
  160. if (op) {
  161. /* Display currently executing ASL statement */
  162. next = op->common.next;
  163. op->common.next = NULL;
  164. #ifdef ACPI_DISASSEMBLER
  165. acpi_dm_disassemble(next_walk_state, op,
  166. ACPI_UINT32_MAX);
  167. #endif
  168. op->common.next = next;
  169. }
  170. } else {
  171. /*
  172. * This method has called another method
  173. * NOTE: the method call parse subtree is already deleted at
  174. * this point, so we cannot disassemble the method invocation.
  175. */
  176. ACPI_DEBUG_PRINT_RAW((ACPI_DB_DISPATCH,
  177. "Call to method "));
  178. acpi_ds_print_node_pathname(previous_method, NULL);
  179. }
  180. previous_method = next_walk_state->method_node;
  181. next_walk_state = next_walk_state->next;
  182. ACPI_DEBUG_PRINT_RAW((ACPI_DB_DISPATCH, "\n"));
  183. }
  184. return_VOID;
  185. }
  186. #else
  187. void
  188. acpi_ds_dump_method_stack(acpi_status status,
  189. struct acpi_walk_state *walk_state,
  190. union acpi_parse_object *op)
  191. {
  192. return;
  193. }
  194. #endif