extrace.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /******************************************************************************
  3. *
  4. * Module Name: extrace - Support for interpreter execution tracing
  5. *
  6. * Copyright (C) 2000 - 2022, Intel Corp.
  7. *
  8. *****************************************************************************/
  9. #include <acpi/acpi.h>
  10. #include "accommon.h"
  11. #include "acnamesp.h"
  12. #include "acinterp.h"
  13. #define _COMPONENT ACPI_EXECUTER
  14. ACPI_MODULE_NAME("extrace")
  15. static union acpi_operand_object *acpi_gbl_trace_method_object = NULL;
  16. /* Local prototypes */
  17. #ifdef ACPI_DEBUG_OUTPUT
  18. static const char *acpi_ex_get_trace_event_name(acpi_trace_event_type type);
  19. #endif
  20. /*******************************************************************************
  21. *
  22. * FUNCTION: acpi_ex_interpreter_trace_enabled
  23. *
  24. * PARAMETERS: name - Whether method name should be matched,
  25. * this should be checked before starting
  26. * the tracer
  27. *
  28. * RETURN: TRUE if interpreter trace is enabled.
  29. *
  30. * DESCRIPTION: Check whether interpreter trace is enabled
  31. *
  32. ******************************************************************************/
  33. static u8 acpi_ex_interpreter_trace_enabled(char *name)
  34. {
  35. /* Check if tracing is enabled */
  36. if (!(acpi_gbl_trace_flags & ACPI_TRACE_ENABLED)) {
  37. return (FALSE);
  38. }
  39. /*
  40. * Check if tracing is filtered:
  41. *
  42. * 1. If the tracer is started, acpi_gbl_trace_method_object should have
  43. * been filled by the trace starter
  44. * 2. If the tracer is not started, acpi_gbl_trace_method_name should be
  45. * matched if it is specified
  46. * 3. If the tracer is oneshot style, acpi_gbl_trace_method_name should
  47. * not be cleared by the trace stopper during the first match
  48. */
  49. if (acpi_gbl_trace_method_object) {
  50. return (TRUE);
  51. }
  52. if (name &&
  53. (acpi_gbl_trace_method_name &&
  54. strcmp(acpi_gbl_trace_method_name, name))) {
  55. return (FALSE);
  56. }
  57. if ((acpi_gbl_trace_flags & ACPI_TRACE_ONESHOT) &&
  58. !acpi_gbl_trace_method_name) {
  59. return (FALSE);
  60. }
  61. return (TRUE);
  62. }
  63. /*******************************************************************************
  64. *
  65. * FUNCTION: acpi_ex_get_trace_event_name
  66. *
  67. * PARAMETERS: type - Trace event type
  68. *
  69. * RETURN: Trace event name.
  70. *
  71. * DESCRIPTION: Used to obtain the full trace event name.
  72. *
  73. ******************************************************************************/
  74. #ifdef ACPI_DEBUG_OUTPUT
  75. static const char *acpi_ex_get_trace_event_name(acpi_trace_event_type type)
  76. {
  77. switch (type) {
  78. case ACPI_TRACE_AML_METHOD:
  79. return "Method";
  80. case ACPI_TRACE_AML_OPCODE:
  81. return "Opcode";
  82. case ACPI_TRACE_AML_REGION:
  83. return "Region";
  84. default:
  85. return "";
  86. }
  87. }
  88. #endif
  89. /*******************************************************************************
  90. *
  91. * FUNCTION: acpi_ex_trace_point
  92. *
  93. * PARAMETERS: type - Trace event type
  94. * begin - TRUE if before execution
  95. * aml - Executed AML address
  96. * pathname - Object path
  97. *
  98. * RETURN: None
  99. *
  100. * DESCRIPTION: Internal interpreter execution trace.
  101. *
  102. ******************************************************************************/
  103. void
  104. acpi_ex_trace_point(acpi_trace_event_type type,
  105. u8 begin, u8 *aml, char *pathname)
  106. {
  107. ACPI_FUNCTION_NAME(ex_trace_point);
  108. if (pathname) {
  109. ACPI_DEBUG_PRINT((ACPI_DB_TRACE_POINT,
  110. "%s %s [0x%p:%s] execution.\n",
  111. acpi_ex_get_trace_event_name(type),
  112. begin ? "Begin" : "End", aml, pathname));
  113. } else {
  114. ACPI_DEBUG_PRINT((ACPI_DB_TRACE_POINT,
  115. "%s %s [0x%p] execution.\n",
  116. acpi_ex_get_trace_event_name(type),
  117. begin ? "Begin" : "End", aml));
  118. }
  119. }
  120. /*******************************************************************************
  121. *
  122. * FUNCTION: acpi_ex_start_trace_method
  123. *
  124. * PARAMETERS: method_node - Node of the method
  125. * obj_desc - The method object
  126. * walk_state - current state, NULL if not yet executing
  127. * a method.
  128. *
  129. * RETURN: None
  130. *
  131. * DESCRIPTION: Start control method execution trace
  132. *
  133. ******************************************************************************/
  134. void
  135. acpi_ex_start_trace_method(struct acpi_namespace_node *method_node,
  136. union acpi_operand_object *obj_desc,
  137. struct acpi_walk_state *walk_state)
  138. {
  139. char *pathname = NULL;
  140. u8 enabled = FALSE;
  141. ACPI_FUNCTION_NAME(ex_start_trace_method);
  142. if (method_node) {
  143. pathname = acpi_ns_get_normalized_pathname(method_node, TRUE);
  144. }
  145. enabled = acpi_ex_interpreter_trace_enabled(pathname);
  146. if (enabled && !acpi_gbl_trace_method_object) {
  147. acpi_gbl_trace_method_object = obj_desc;
  148. acpi_gbl_original_dbg_level = acpi_dbg_level;
  149. acpi_gbl_original_dbg_layer = acpi_dbg_layer;
  150. acpi_dbg_level = ACPI_TRACE_LEVEL_ALL;
  151. acpi_dbg_layer = ACPI_TRACE_LAYER_ALL;
  152. if (acpi_gbl_trace_dbg_level) {
  153. acpi_dbg_level = acpi_gbl_trace_dbg_level;
  154. }
  155. if (acpi_gbl_trace_dbg_layer) {
  156. acpi_dbg_layer = acpi_gbl_trace_dbg_layer;
  157. }
  158. }
  159. if (enabled) {
  160. ACPI_TRACE_POINT(ACPI_TRACE_AML_METHOD, TRUE,
  161. obj_desc ? obj_desc->method.aml_start : NULL,
  162. pathname);
  163. }
  164. if (pathname) {
  165. ACPI_FREE(pathname);
  166. }
  167. }
  168. /*******************************************************************************
  169. *
  170. * FUNCTION: acpi_ex_stop_trace_method
  171. *
  172. * PARAMETERS: method_node - Node of the method
  173. * obj_desc - The method object
  174. * walk_state - current state, NULL if not yet executing
  175. * a method.
  176. *
  177. * RETURN: None
  178. *
  179. * DESCRIPTION: Stop control method execution trace
  180. *
  181. ******************************************************************************/
  182. void
  183. acpi_ex_stop_trace_method(struct acpi_namespace_node *method_node,
  184. union acpi_operand_object *obj_desc,
  185. struct acpi_walk_state *walk_state)
  186. {
  187. char *pathname = NULL;
  188. u8 enabled;
  189. ACPI_FUNCTION_NAME(ex_stop_trace_method);
  190. if (method_node) {
  191. pathname = acpi_ns_get_normalized_pathname(method_node, TRUE);
  192. }
  193. enabled = acpi_ex_interpreter_trace_enabled(NULL);
  194. if (enabled) {
  195. ACPI_TRACE_POINT(ACPI_TRACE_AML_METHOD, FALSE,
  196. obj_desc ? obj_desc->method.aml_start : NULL,
  197. pathname);
  198. }
  199. /* Check whether the tracer should be stopped */
  200. if (acpi_gbl_trace_method_object == obj_desc) {
  201. /* Disable further tracing if type is one-shot */
  202. if (acpi_gbl_trace_flags & ACPI_TRACE_ONESHOT) {
  203. acpi_gbl_trace_method_name = NULL;
  204. }
  205. acpi_dbg_level = acpi_gbl_original_dbg_level;
  206. acpi_dbg_layer = acpi_gbl_original_dbg_layer;
  207. acpi_gbl_trace_method_object = NULL;
  208. }
  209. if (pathname) {
  210. ACPI_FREE(pathname);
  211. }
  212. }
  213. /*******************************************************************************
  214. *
  215. * FUNCTION: acpi_ex_start_trace_opcode
  216. *
  217. * PARAMETERS: op - The parser opcode object
  218. * walk_state - current state, NULL if not yet executing
  219. * a method.
  220. *
  221. * RETURN: None
  222. *
  223. * DESCRIPTION: Start opcode execution trace
  224. *
  225. ******************************************************************************/
  226. void
  227. acpi_ex_start_trace_opcode(union acpi_parse_object *op,
  228. struct acpi_walk_state *walk_state)
  229. {
  230. ACPI_FUNCTION_NAME(ex_start_trace_opcode);
  231. if (acpi_ex_interpreter_trace_enabled(NULL) &&
  232. (acpi_gbl_trace_flags & ACPI_TRACE_OPCODE)) {
  233. ACPI_TRACE_POINT(ACPI_TRACE_AML_OPCODE, TRUE,
  234. op->common.aml, op->common.aml_op_name);
  235. }
  236. }
  237. /*******************************************************************************
  238. *
  239. * FUNCTION: acpi_ex_stop_trace_opcode
  240. *
  241. * PARAMETERS: op - The parser opcode object
  242. * walk_state - current state, NULL if not yet executing
  243. * a method.
  244. *
  245. * RETURN: None
  246. *
  247. * DESCRIPTION: Stop opcode execution trace
  248. *
  249. ******************************************************************************/
  250. void
  251. acpi_ex_stop_trace_opcode(union acpi_parse_object *op,
  252. struct acpi_walk_state *walk_state)
  253. {
  254. ACPI_FUNCTION_NAME(ex_stop_trace_opcode);
  255. if (acpi_ex_interpreter_trace_enabled(NULL) &&
  256. (acpi_gbl_trace_flags & ACPI_TRACE_OPCODE)) {
  257. ACPI_TRACE_POINT(ACPI_TRACE_AML_OPCODE, FALSE,
  258. op->common.aml, op->common.aml_op_name);
  259. }
  260. }