extrace.c 10 KB

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