dbxface.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. /*******************************************************************************
  2. *
  3. * Module Name: dbxface - AML Debugger external interfaces
  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 "amlcode.h"
  45. #include "acdebug.h"
  46. #define _COMPONENT ACPI_CA_DEBUGGER
  47. ACPI_MODULE_NAME("dbxface")
  48. /* Local prototypes */
  49. static acpi_status
  50. acpi_db_start_command(struct acpi_walk_state *walk_state,
  51. union acpi_parse_object *op);
  52. #ifdef ACPI_OBSOLETE_FUNCTIONS
  53. void acpi_db_method_end(struct acpi_walk_state *walk_state);
  54. #endif
  55. /*******************************************************************************
  56. *
  57. * FUNCTION: acpi_db_start_command
  58. *
  59. * PARAMETERS: walk_state - Current walk
  60. * op - Current executing Op, from AML interpreter
  61. *
  62. * RETURN: Status
  63. *
  64. * DESCRIPTION: Enter debugger command loop
  65. *
  66. ******************************************************************************/
  67. static acpi_status
  68. acpi_db_start_command(struct acpi_walk_state *walk_state,
  69. union acpi_parse_object *op)
  70. {
  71. acpi_status status;
  72. /* TBD: [Investigate] are there namespace locking issues here? */
  73. /* acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); */
  74. /* Go into the command loop and await next user command */
  75. acpi_gbl_method_executing = TRUE;
  76. status = AE_CTRL_TRUE;
  77. while (status == AE_CTRL_TRUE) {
  78. /* Notify the completion of the command */
  79. status = acpi_os_notify_command_complete();
  80. if (ACPI_FAILURE(status)) {
  81. goto error_exit;
  82. }
  83. /* Wait the readiness of the command */
  84. status = acpi_os_wait_command_ready();
  85. if (ACPI_FAILURE(status)) {
  86. goto error_exit;
  87. }
  88. status =
  89. acpi_db_command_dispatch(acpi_gbl_db_line_buf, walk_state,
  90. op);
  91. }
  92. /* acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE); */
  93. error_exit:
  94. if (ACPI_FAILURE(status) && status != AE_CTRL_TERMINATE) {
  95. ACPI_EXCEPTION((AE_INFO, status,
  96. "While parsing/handling command line"));
  97. }
  98. return (status);
  99. }
  100. /*******************************************************************************
  101. *
  102. * FUNCTION: acpi_db_signal_break_point
  103. *
  104. * PARAMETERS: walk_state - Current walk
  105. *
  106. * RETURN: Status
  107. *
  108. * DESCRIPTION: Called for AML_BREAK_POINT_OP
  109. *
  110. ******************************************************************************/
  111. void acpi_db_signal_break_point(struct acpi_walk_state *walk_state)
  112. {
  113. #ifndef ACPI_APPLICATION
  114. if (acpi_gbl_db_thread_id != acpi_os_get_thread_id()) {
  115. return;
  116. }
  117. #endif
  118. /*
  119. * Set the single-step flag. This will cause the debugger (if present)
  120. * to break to the console within the AML debugger at the start of the
  121. * next AML instruction.
  122. */
  123. acpi_gbl_cm_single_step = TRUE;
  124. acpi_os_printf("**break** Executed AML BreakPoint opcode\n");
  125. }
  126. /*******************************************************************************
  127. *
  128. * FUNCTION: acpi_db_single_step
  129. *
  130. * PARAMETERS: walk_state - Current walk
  131. * op - Current executing op (from aml interpreter)
  132. * opcode_class - Class of the current AML Opcode
  133. *
  134. * RETURN: Status
  135. *
  136. * DESCRIPTION: Called just before execution of an AML opcode.
  137. *
  138. ******************************************************************************/
  139. acpi_status
  140. acpi_db_single_step(struct acpi_walk_state *walk_state,
  141. union acpi_parse_object *op, u32 opcode_class)
  142. {
  143. union acpi_parse_object *next;
  144. acpi_status status = AE_OK;
  145. u32 original_debug_level;
  146. union acpi_parse_object *display_op;
  147. union acpi_parse_object *parent_op;
  148. u32 aml_offset;
  149. ACPI_FUNCTION_ENTRY();
  150. #ifndef ACPI_APPLICATION
  151. if (acpi_gbl_db_thread_id != acpi_os_get_thread_id()) {
  152. return (AE_OK);
  153. }
  154. #endif
  155. /* Check the abort flag */
  156. if (acpi_gbl_abort_method) {
  157. acpi_gbl_abort_method = FALSE;
  158. return (AE_ABORT_METHOD);
  159. }
  160. aml_offset = (u32)ACPI_PTR_DIFF(op->common.aml,
  161. walk_state->parser_state.aml_start);
  162. /* Check for single-step breakpoint */
  163. if (walk_state->method_breakpoint &&
  164. (walk_state->method_breakpoint <= aml_offset)) {
  165. /* Check if the breakpoint has been reached or passed */
  166. /* Hit the breakpoint, resume single step, reset breakpoint */
  167. acpi_os_printf("***Break*** at AML offset %X\n", aml_offset);
  168. acpi_gbl_cm_single_step = TRUE;
  169. acpi_gbl_step_to_next_call = FALSE;
  170. walk_state->method_breakpoint = 0;
  171. }
  172. /* Check for user breakpoint (Must be on exact Aml offset) */
  173. else if (walk_state->user_breakpoint &&
  174. (walk_state->user_breakpoint == aml_offset)) {
  175. acpi_os_printf("***UserBreakpoint*** at AML offset %X\n",
  176. aml_offset);
  177. acpi_gbl_cm_single_step = TRUE;
  178. acpi_gbl_step_to_next_call = FALSE;
  179. walk_state->method_breakpoint = 0;
  180. }
  181. /*
  182. * Check if this is an opcode that we are interested in --
  183. * namely, opcodes that have arguments
  184. */
  185. if (op->common.aml_opcode == AML_INT_NAMEDFIELD_OP) {
  186. return (AE_OK);
  187. }
  188. switch (opcode_class) {
  189. case AML_CLASS_UNKNOWN:
  190. case AML_CLASS_ARGUMENT: /* constants, literals, etc. do nothing */
  191. return (AE_OK);
  192. default:
  193. /* All other opcodes -- continue */
  194. break;
  195. }
  196. /*
  197. * Under certain debug conditions, display this opcode and its operands
  198. */
  199. if ((acpi_gbl_db_output_to_file) ||
  200. (acpi_gbl_cm_single_step) || (acpi_dbg_level & ACPI_LV_PARSE)) {
  201. if ((acpi_gbl_db_output_to_file) ||
  202. (acpi_dbg_level & ACPI_LV_PARSE)) {
  203. acpi_os_printf
  204. ("\n[AmlDebug] Next AML Opcode to execute:\n");
  205. }
  206. /*
  207. * Display this op (and only this op - zero out the NEXT field
  208. * temporarily, and disable parser trace output for the duration of
  209. * the display because we don't want the extraneous debug output)
  210. */
  211. original_debug_level = acpi_dbg_level;
  212. acpi_dbg_level &= ~(ACPI_LV_PARSE | ACPI_LV_FUNCTIONS);
  213. next = op->common.next;
  214. op->common.next = NULL;
  215. display_op = op;
  216. parent_op = op->common.parent;
  217. if (parent_op) {
  218. if ((walk_state->control_state) &&
  219. (walk_state->control_state->common.state ==
  220. ACPI_CONTROL_PREDICATE_EXECUTING)) {
  221. /*
  222. * We are executing the predicate of an IF or WHILE statement
  223. * Search upwards for the containing IF or WHILE so that the
  224. * entire predicate can be displayed.
  225. */
  226. while (parent_op) {
  227. if ((parent_op->common.aml_opcode ==
  228. AML_IF_OP)
  229. || (parent_op->common.aml_opcode ==
  230. AML_WHILE_OP)) {
  231. display_op = parent_op;
  232. break;
  233. }
  234. parent_op = parent_op->common.parent;
  235. }
  236. } else {
  237. while (parent_op) {
  238. if ((parent_op->common.aml_opcode ==
  239. AML_IF_OP)
  240. || (parent_op->common.aml_opcode ==
  241. AML_ELSE_OP)
  242. || (parent_op->common.aml_opcode ==
  243. AML_SCOPE_OP)
  244. || (parent_op->common.aml_opcode ==
  245. AML_METHOD_OP)
  246. || (parent_op->common.aml_opcode ==
  247. AML_WHILE_OP)) {
  248. break;
  249. }
  250. display_op = parent_op;
  251. parent_op = parent_op->common.parent;
  252. }
  253. }
  254. }
  255. /* Now we can display it */
  256. #ifdef ACPI_DISASSEMBLER
  257. acpi_dm_disassemble(walk_state, display_op, ACPI_UINT32_MAX);
  258. #endif
  259. if ((op->common.aml_opcode == AML_IF_OP) ||
  260. (op->common.aml_opcode == AML_WHILE_OP)) {
  261. if (walk_state->control_state->common.value) {
  262. acpi_os_printf
  263. ("Predicate = [True], IF block was executed\n");
  264. } else {
  265. acpi_os_printf
  266. ("Predicate = [False], Skipping IF block\n");
  267. }
  268. } else if (op->common.aml_opcode == AML_ELSE_OP) {
  269. acpi_os_printf
  270. ("Predicate = [False], ELSE block was executed\n");
  271. }
  272. /* Restore everything */
  273. op->common.next = next;
  274. acpi_os_printf("\n");
  275. if ((acpi_gbl_db_output_to_file) ||
  276. (acpi_dbg_level & ACPI_LV_PARSE)) {
  277. acpi_os_printf("\n");
  278. }
  279. acpi_dbg_level = original_debug_level;
  280. }
  281. /* If we are not single stepping, just continue executing the method */
  282. if (!acpi_gbl_cm_single_step) {
  283. return (AE_OK);
  284. }
  285. /*
  286. * If we are executing a step-to-call command,
  287. * Check if this is a method call.
  288. */
  289. if (acpi_gbl_step_to_next_call) {
  290. if (op->common.aml_opcode != AML_INT_METHODCALL_OP) {
  291. /* Not a method call, just keep executing */
  292. return (AE_OK);
  293. }
  294. /* Found a method call, stop executing */
  295. acpi_gbl_step_to_next_call = FALSE;
  296. }
  297. /*
  298. * If the next opcode is a method call, we will "step over" it
  299. * by default.
  300. */
  301. if (op->common.aml_opcode == AML_INT_METHODCALL_OP) {
  302. /* Force no more single stepping while executing called method */
  303. acpi_gbl_cm_single_step = FALSE;
  304. /*
  305. * Set the breakpoint on/before the call, it will stop execution
  306. * as soon as we return
  307. */
  308. walk_state->method_breakpoint = 1; /* Must be non-zero! */
  309. }
  310. status = acpi_db_start_command(walk_state, op);
  311. /* User commands complete, continue execution of the interrupted method */
  312. return (status);
  313. }
  314. /*******************************************************************************
  315. *
  316. * FUNCTION: acpi_initialize_debugger
  317. *
  318. * PARAMETERS: None
  319. *
  320. * RETURN: Status
  321. *
  322. * DESCRIPTION: Init and start debugger
  323. *
  324. ******************************************************************************/
  325. acpi_status acpi_initialize_debugger(void)
  326. {
  327. acpi_status status;
  328. ACPI_FUNCTION_TRACE(acpi_initialize_debugger);
  329. /* Init globals */
  330. acpi_gbl_db_buffer = NULL;
  331. acpi_gbl_db_filename = NULL;
  332. acpi_gbl_db_output_to_file = FALSE;
  333. acpi_gbl_db_debug_level = ACPI_LV_VERBOSITY2;
  334. acpi_gbl_db_console_debug_level = ACPI_NORMAL_DEFAULT | ACPI_LV_TABLES;
  335. acpi_gbl_db_output_flags = ACPI_DB_CONSOLE_OUTPUT;
  336. acpi_gbl_db_opt_no_ini_methods = FALSE;
  337. acpi_gbl_db_buffer = acpi_os_allocate(ACPI_DEBUG_BUFFER_SIZE);
  338. if (!acpi_gbl_db_buffer) {
  339. return_ACPI_STATUS(AE_NO_MEMORY);
  340. }
  341. memset(acpi_gbl_db_buffer, 0, ACPI_DEBUG_BUFFER_SIZE);
  342. /* Initial scope is the root */
  343. acpi_gbl_db_scope_buf[0] = AML_ROOT_PREFIX;
  344. acpi_gbl_db_scope_buf[1] = 0;
  345. acpi_gbl_db_scope_node = acpi_gbl_root_node;
  346. /* Initialize user commands loop */
  347. acpi_gbl_db_terminate_loop = FALSE;
  348. /*
  349. * If configured for multi-thread support, the debug executor runs in
  350. * a separate thread so that the front end can be in another address
  351. * space, environment, or even another machine.
  352. */
  353. if (acpi_gbl_debugger_configuration & DEBUGGER_MULTI_THREADED) {
  354. /* These were created with one unit, grab it */
  355. status = acpi_os_initialize_command_signals();
  356. if (ACPI_FAILURE(status)) {
  357. acpi_os_printf("Could not get debugger mutex\n");
  358. return_ACPI_STATUS(status);
  359. }
  360. /* Create the debug execution thread to execute commands */
  361. acpi_gbl_db_threads_terminated = FALSE;
  362. status = acpi_os_execute(OSL_DEBUGGER_MAIN_THREAD,
  363. acpi_db_execute_thread, NULL);
  364. if (ACPI_FAILURE(status)) {
  365. ACPI_EXCEPTION((AE_INFO, status,
  366. "Could not start debugger thread"));
  367. acpi_gbl_db_threads_terminated = TRUE;
  368. return_ACPI_STATUS(status);
  369. }
  370. } else {
  371. acpi_gbl_db_thread_id = acpi_os_get_thread_id();
  372. }
  373. return_ACPI_STATUS(AE_OK);
  374. }
  375. ACPI_EXPORT_SYMBOL(acpi_initialize_debugger)
  376. /*******************************************************************************
  377. *
  378. * FUNCTION: acpi_terminate_debugger
  379. *
  380. * PARAMETERS: None
  381. *
  382. * RETURN: None
  383. *
  384. * DESCRIPTION: Stop debugger
  385. *
  386. ******************************************************************************/
  387. void acpi_terminate_debugger(void)
  388. {
  389. /* Terminate the AML Debugger */
  390. acpi_gbl_db_terminate_loop = TRUE;
  391. if (acpi_gbl_debugger_configuration & DEBUGGER_MULTI_THREADED) {
  392. /* Wait the AML Debugger threads */
  393. while (!acpi_gbl_db_threads_terminated) {
  394. acpi_os_sleep(100);
  395. }
  396. acpi_os_terminate_command_signals();
  397. }
  398. if (acpi_gbl_db_buffer) {
  399. acpi_os_free(acpi_gbl_db_buffer);
  400. acpi_gbl_db_buffer = NULL;
  401. }
  402. /* Ensure that debug output is now disabled */
  403. acpi_gbl_db_output_flags = ACPI_DB_DISABLE_OUTPUT;
  404. }
  405. ACPI_EXPORT_SYMBOL(acpi_terminate_debugger)
  406. /*******************************************************************************
  407. *
  408. * FUNCTION: acpi_set_debugger_thread_id
  409. *
  410. * PARAMETERS: thread_id - Debugger thread ID
  411. *
  412. * RETURN: None
  413. *
  414. * DESCRIPTION: Set debugger thread ID
  415. *
  416. ******************************************************************************/
  417. void acpi_set_debugger_thread_id(acpi_thread_id thread_id)
  418. {
  419. acpi_gbl_db_thread_id = thread_id;
  420. }
  421. ACPI_EXPORT_SYMBOL(acpi_set_debugger_thread_id)