dbxface.c 14 KB

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