extrace.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. acpi_status status;
  173. char *pathname = NULL;
  174. u8 enabled = FALSE;
  175. ACPI_FUNCTION_NAME(ex_start_trace_method);
  176. if (method_node) {
  177. pathname = acpi_ns_get_normalized_pathname(method_node, TRUE);
  178. }
  179. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  180. if (ACPI_FAILURE(status)) {
  181. goto exit;
  182. }
  183. enabled = acpi_ex_interpreter_trace_enabled(pathname);
  184. if (enabled && !acpi_gbl_trace_method_object) {
  185. acpi_gbl_trace_method_object = obj_desc;
  186. acpi_gbl_original_dbg_level = acpi_dbg_level;
  187. acpi_gbl_original_dbg_layer = acpi_dbg_layer;
  188. acpi_dbg_level = ACPI_TRACE_LEVEL_ALL;
  189. acpi_dbg_layer = ACPI_TRACE_LAYER_ALL;
  190. if (acpi_gbl_trace_dbg_level) {
  191. acpi_dbg_level = acpi_gbl_trace_dbg_level;
  192. }
  193. if (acpi_gbl_trace_dbg_layer) {
  194. acpi_dbg_layer = acpi_gbl_trace_dbg_layer;
  195. }
  196. }
  197. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  198. exit:
  199. if (enabled) {
  200. ACPI_TRACE_POINT(ACPI_TRACE_AML_METHOD, TRUE,
  201. obj_desc ? obj_desc->method.aml_start : NULL,
  202. pathname);
  203. }
  204. if (pathname) {
  205. ACPI_FREE(pathname);
  206. }
  207. }
  208. /*******************************************************************************
  209. *
  210. * FUNCTION: acpi_ex_stop_trace_method
  211. *
  212. * PARAMETERS: method_node - Node of the method
  213. * obj_desc - The method object
  214. * walk_state - current state, NULL if not yet executing
  215. * a method.
  216. *
  217. * RETURN: None
  218. *
  219. * DESCRIPTION: Stop control method execution trace
  220. *
  221. ******************************************************************************/
  222. void
  223. acpi_ex_stop_trace_method(struct acpi_namespace_node *method_node,
  224. union acpi_operand_object *obj_desc,
  225. struct acpi_walk_state *walk_state)
  226. {
  227. acpi_status status;
  228. char *pathname = NULL;
  229. u8 enabled;
  230. ACPI_FUNCTION_NAME(ex_stop_trace_method);
  231. if (method_node) {
  232. pathname = acpi_ns_get_normalized_pathname(method_node, TRUE);
  233. }
  234. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  235. if (ACPI_FAILURE(status)) {
  236. goto exit_path;
  237. }
  238. enabled = acpi_ex_interpreter_trace_enabled(NULL);
  239. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  240. if (enabled) {
  241. ACPI_TRACE_POINT(ACPI_TRACE_AML_METHOD, FALSE,
  242. obj_desc ? obj_desc->method.aml_start : NULL,
  243. pathname);
  244. }
  245. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  246. if (ACPI_FAILURE(status)) {
  247. goto exit_path;
  248. }
  249. /* Check whether the tracer should be stopped */
  250. if (acpi_gbl_trace_method_object == obj_desc) {
  251. /* Disable further tracing if type is one-shot */
  252. if (acpi_gbl_trace_flags & ACPI_TRACE_ONESHOT) {
  253. acpi_gbl_trace_method_name = NULL;
  254. }
  255. acpi_dbg_level = acpi_gbl_original_dbg_level;
  256. acpi_dbg_layer = acpi_gbl_original_dbg_layer;
  257. acpi_gbl_trace_method_object = NULL;
  258. }
  259. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  260. exit_path:
  261. if (pathname) {
  262. ACPI_FREE(pathname);
  263. }
  264. }
  265. /*******************************************************************************
  266. *
  267. * FUNCTION: acpi_ex_start_trace_opcode
  268. *
  269. * PARAMETERS: op - The parser opcode object
  270. * walk_state - current state, NULL if not yet executing
  271. * a method.
  272. *
  273. * RETURN: None
  274. *
  275. * DESCRIPTION: Start opcode execution trace
  276. *
  277. ******************************************************************************/
  278. void
  279. acpi_ex_start_trace_opcode(union acpi_parse_object *op,
  280. struct acpi_walk_state *walk_state)
  281. {
  282. ACPI_FUNCTION_NAME(ex_start_trace_opcode);
  283. if (acpi_ex_interpreter_trace_enabled(NULL) &&
  284. (acpi_gbl_trace_flags & ACPI_TRACE_OPCODE)) {
  285. ACPI_TRACE_POINT(ACPI_TRACE_AML_OPCODE, TRUE,
  286. op->common.aml, op->common.aml_op_name);
  287. }
  288. }
  289. /*******************************************************************************
  290. *
  291. * FUNCTION: acpi_ex_stop_trace_opcode
  292. *
  293. * PARAMETERS: op - The parser opcode object
  294. * walk_state - current state, NULL if not yet executing
  295. * a method.
  296. *
  297. * RETURN: None
  298. *
  299. * DESCRIPTION: Stop opcode execution trace
  300. *
  301. ******************************************************************************/
  302. void
  303. acpi_ex_stop_trace_opcode(union acpi_parse_object *op,
  304. struct acpi_walk_state *walk_state)
  305. {
  306. ACPI_FUNCTION_NAME(ex_stop_trace_opcode);
  307. if (acpi_ex_interpreter_trace_enabled(NULL) &&
  308. (acpi_gbl_trace_flags & ACPI_TRACE_OPCODE)) {
  309. ACPI_TRACE_POINT(ACPI_TRACE_AML_OPCODE, FALSE,
  310. op->common.aml, op->common.aml_op_name);
  311. }
  312. }