extrace.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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 - 2025, 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 [%s] execution.\n",
  111. acpi_ex_get_trace_event_name(type),
  112. begin ? "Begin" : "End", 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_trace_args
  123. *
  124. * PARAMETERS: params - AML method arguments
  125. * count - numer of method arguments
  126. *
  127. * RETURN: None
  128. *
  129. * DESCRIPTION: Trace any arguments
  130. *
  131. ******************************************************************************/
  132. void
  133. acpi_ex_trace_args(union acpi_operand_object **params, u32 count)
  134. {
  135. u32 i;
  136. ACPI_FUNCTION_NAME(ex_trace_args);
  137. for (i = 0; i < count; i++) {
  138. union acpi_operand_object *obj_desc = params[i];
  139. if (!i) {
  140. ACPI_DEBUG_PRINT((ACPI_DB_TRACE_POINT, " "));
  141. }
  142. switch (obj_desc->common.type) {
  143. case ACPI_TYPE_INTEGER:
  144. ACPI_DEBUG_PRINT_RAW((ACPI_DB_TRACE_POINT, "%llx", obj_desc->integer.value));
  145. break;
  146. case ACPI_TYPE_STRING:
  147. if (!obj_desc->string.length) {
  148. ACPI_DEBUG_PRINT_RAW((ACPI_DB_TRACE_POINT, "NULL"));
  149. continue;
  150. }
  151. if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_TRACE_POINT, _COMPONENT))
  152. acpi_ut_print_string(obj_desc->string.pointer, ACPI_UINT8_MAX);
  153. break;
  154. default:
  155. ACPI_DEBUG_PRINT_RAW((ACPI_DB_TRACE_POINT, "Unknown"));
  156. break;
  157. }
  158. if (i+1 == count) {
  159. ACPI_DEBUG_PRINT_RAW((ACPI_DB_TRACE_POINT, "\n"));
  160. } else {
  161. ACPI_DEBUG_PRINT_RAW((ACPI_DB_TRACE_POINT, ", "));
  162. }
  163. }
  164. }
  165. /*******************************************************************************
  166. *
  167. * FUNCTION: acpi_ex_start_trace_method
  168. *
  169. * PARAMETERS: method_node - Node of the method
  170. * obj_desc - The method object
  171. * walk_state - current state, NULL if not yet executing
  172. * a method.
  173. *
  174. * RETURN: None
  175. *
  176. * DESCRIPTION: Start control method execution trace
  177. *
  178. ******************************************************************************/
  179. void
  180. acpi_ex_start_trace_method(struct acpi_namespace_node *method_node,
  181. union acpi_operand_object *obj_desc,
  182. struct acpi_walk_state *walk_state)
  183. {
  184. char *pathname = NULL;
  185. u8 enabled = FALSE;
  186. ACPI_FUNCTION_NAME(ex_start_trace_method);
  187. if (method_node) {
  188. pathname = acpi_ns_get_normalized_pathname(method_node, TRUE);
  189. }
  190. enabled = acpi_ex_interpreter_trace_enabled(pathname);
  191. if (enabled && !acpi_gbl_trace_method_object) {
  192. acpi_gbl_trace_method_object = obj_desc;
  193. acpi_gbl_original_dbg_level = acpi_dbg_level;
  194. acpi_gbl_original_dbg_layer = acpi_dbg_layer;
  195. acpi_dbg_level = ACPI_TRACE_LEVEL_ALL;
  196. acpi_dbg_layer = ACPI_TRACE_LAYER_ALL;
  197. if (acpi_gbl_trace_dbg_level) {
  198. acpi_dbg_level = acpi_gbl_trace_dbg_level;
  199. }
  200. if (acpi_gbl_trace_dbg_layer) {
  201. acpi_dbg_layer = acpi_gbl_trace_dbg_layer;
  202. }
  203. }
  204. if (enabled) {
  205. ACPI_TRACE_POINT(ACPI_TRACE_AML_METHOD, TRUE,
  206. obj_desc ? obj_desc->method.aml_start : NULL,
  207. pathname);
  208. }
  209. if (pathname) {
  210. ACPI_FREE(pathname);
  211. }
  212. }
  213. /*******************************************************************************
  214. *
  215. * FUNCTION: acpi_ex_stop_trace_method
  216. *
  217. * PARAMETERS: method_node - Node of the method
  218. * obj_desc - The method object
  219. * walk_state - current state, NULL if not yet executing
  220. * a method.
  221. *
  222. * RETURN: None
  223. *
  224. * DESCRIPTION: Stop control method execution trace
  225. *
  226. ******************************************************************************/
  227. void
  228. acpi_ex_stop_trace_method(struct acpi_namespace_node *method_node,
  229. union acpi_operand_object *obj_desc,
  230. struct acpi_walk_state *walk_state)
  231. {
  232. char *pathname = NULL;
  233. u8 enabled;
  234. ACPI_FUNCTION_NAME(ex_stop_trace_method);
  235. if (method_node) {
  236. pathname = acpi_ns_get_normalized_pathname(method_node, TRUE);
  237. }
  238. enabled = acpi_ex_interpreter_trace_enabled(NULL);
  239. if (enabled) {
  240. ACPI_TRACE_POINT(ACPI_TRACE_AML_METHOD, FALSE,
  241. obj_desc ? obj_desc->method.aml_start : NULL,
  242. pathname);
  243. }
  244. /* Check whether the tracer should be stopped */
  245. if (acpi_gbl_trace_method_object == obj_desc) {
  246. /* Disable further tracing if type is one-shot */
  247. if (acpi_gbl_trace_flags & ACPI_TRACE_ONESHOT) {
  248. acpi_gbl_trace_method_name = NULL;
  249. }
  250. acpi_dbg_level = acpi_gbl_original_dbg_level;
  251. acpi_dbg_layer = acpi_gbl_original_dbg_layer;
  252. acpi_gbl_trace_method_object = NULL;
  253. }
  254. if (pathname) {
  255. ACPI_FREE(pathname);
  256. }
  257. }
  258. /*******************************************************************************
  259. *
  260. * FUNCTION: acpi_ex_start_trace_opcode
  261. *
  262. * PARAMETERS: op - The parser opcode object
  263. * walk_state - current state, NULL if not yet executing
  264. * a method.
  265. *
  266. * RETURN: None
  267. *
  268. * DESCRIPTION: Start opcode execution trace
  269. *
  270. ******************************************************************************/
  271. void
  272. acpi_ex_start_trace_opcode(union acpi_parse_object *op,
  273. struct acpi_walk_state *walk_state)
  274. {
  275. ACPI_FUNCTION_NAME(ex_start_trace_opcode);
  276. if (acpi_ex_interpreter_trace_enabled(NULL) &&
  277. (acpi_gbl_trace_flags & ACPI_TRACE_OPCODE)) {
  278. ACPI_TRACE_POINT(ACPI_TRACE_AML_OPCODE, TRUE,
  279. op->common.aml, op->common.aml_op_name);
  280. }
  281. }
  282. /*******************************************************************************
  283. *
  284. * FUNCTION: acpi_ex_stop_trace_opcode
  285. *
  286. * PARAMETERS: op - The parser opcode object
  287. * walk_state - current state, NULL if not yet executing
  288. * a method.
  289. *
  290. * RETURN: None
  291. *
  292. * DESCRIPTION: Stop opcode execution trace
  293. *
  294. ******************************************************************************/
  295. void
  296. acpi_ex_stop_trace_opcode(union acpi_parse_object *op,
  297. struct acpi_walk_state *walk_state)
  298. {
  299. ACPI_FUNCTION_NAME(ex_stop_trace_opcode);
  300. if (acpi_ex_interpreter_trace_enabled(NULL) &&
  301. (acpi_gbl_trace_flags & ACPI_TRACE_OPCODE)) {
  302. ACPI_TRACE_POINT(ACPI_TRACE_AML_OPCODE, FALSE,
  303. op->common.aml, op->common.aml_op_name);
  304. }
  305. }