dbxface.c 14 KB

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