dbobject.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /*******************************************************************************
  3. *
  4. * Module Name: dbobject - ACPI object decode and display
  5. *
  6. ******************************************************************************/
  7. #include <acpi/acpi.h>
  8. #include "accommon.h"
  9. #include "acnamesp.h"
  10. #include "acdebug.h"
  11. #define _COMPONENT ACPI_CA_DEBUGGER
  12. ACPI_MODULE_NAME("dbobject")
  13. /* Local prototypes */
  14. static void acpi_db_decode_node(struct acpi_namespace_node *node);
  15. /*******************************************************************************
  16. *
  17. * FUNCTION: acpi_db_dump_method_info
  18. *
  19. * PARAMETERS: status - Method execution status
  20. * walk_state - Current state of the parse tree walk
  21. *
  22. * RETURN: None
  23. *
  24. * DESCRIPTION: Called when a method has been aborted because of an error.
  25. * Dumps the method execution stack, and the method locals/args,
  26. * and disassembles the AML opcode that failed.
  27. *
  28. ******************************************************************************/
  29. void
  30. acpi_db_dump_method_info(acpi_status status, struct acpi_walk_state *walk_state)
  31. {
  32. struct acpi_thread_state *thread;
  33. struct acpi_namespace_node *node;
  34. node = walk_state->method_node;
  35. /* There are no locals or arguments for the module-level code case */
  36. if (node == acpi_gbl_root_node) {
  37. return;
  38. }
  39. /* Ignore control codes, they are not errors */
  40. if (ACPI_CNTL_EXCEPTION(status)) {
  41. return;
  42. }
  43. /* We may be executing a deferred opcode */
  44. if (walk_state->deferred_node) {
  45. acpi_os_printf("Executing subtree for Buffer/Package/Region\n");
  46. return;
  47. }
  48. /*
  49. * If there is no Thread, we are not actually executing a method.
  50. * This can happen when the iASL compiler calls the interpreter
  51. * to perform constant folding.
  52. */
  53. thread = walk_state->thread;
  54. if (!thread) {
  55. return;
  56. }
  57. /* Display the method locals and arguments */
  58. acpi_os_printf("\n");
  59. acpi_db_decode_locals(walk_state);
  60. acpi_os_printf("\n");
  61. acpi_db_decode_arguments(walk_state);
  62. acpi_os_printf("\n");
  63. }
  64. /*******************************************************************************
  65. *
  66. * FUNCTION: acpi_db_decode_internal_object
  67. *
  68. * PARAMETERS: obj_desc - Object to be displayed
  69. *
  70. * RETURN: None
  71. *
  72. * DESCRIPTION: Short display of an internal object. Numbers/Strings/Buffers.
  73. *
  74. ******************************************************************************/
  75. void acpi_db_decode_internal_object(union acpi_operand_object *obj_desc)
  76. {
  77. u32 i;
  78. if (!obj_desc) {
  79. acpi_os_printf(" Uninitialized");
  80. return;
  81. }
  82. if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) != ACPI_DESC_TYPE_OPERAND) {
  83. acpi_os_printf(" %p [%s]", obj_desc,
  84. acpi_ut_get_descriptor_name(obj_desc));
  85. return;
  86. }
  87. acpi_os_printf(" %s", acpi_ut_get_object_type_name(obj_desc));
  88. switch (obj_desc->common.type) {
  89. case ACPI_TYPE_INTEGER:
  90. acpi_os_printf(" %8.8X%8.8X",
  91. ACPI_FORMAT_UINT64(obj_desc->integer.value));
  92. break;
  93. case ACPI_TYPE_STRING:
  94. acpi_os_printf("(%u) \"%.60s",
  95. obj_desc->string.length,
  96. obj_desc->string.pointer);
  97. if (obj_desc->string.length > 60) {
  98. acpi_os_printf("...");
  99. } else {
  100. acpi_os_printf("\"");
  101. }
  102. break;
  103. case ACPI_TYPE_BUFFER:
  104. acpi_os_printf("(%u)", obj_desc->buffer.length);
  105. for (i = 0; (i < 8) && (i < obj_desc->buffer.length); i++) {
  106. acpi_os_printf(" %2.2X", obj_desc->buffer.pointer[i]);
  107. }
  108. break;
  109. default:
  110. acpi_os_printf(" %p", obj_desc);
  111. break;
  112. }
  113. }
  114. /*******************************************************************************
  115. *
  116. * FUNCTION: acpi_db_decode_node
  117. *
  118. * PARAMETERS: node - Object to be displayed
  119. *
  120. * RETURN: None
  121. *
  122. * DESCRIPTION: Short display of a namespace node
  123. *
  124. ******************************************************************************/
  125. static void acpi_db_decode_node(struct acpi_namespace_node *node)
  126. {
  127. acpi_os_printf("<Node> Name %4.4s",
  128. acpi_ut_get_node_name(node));
  129. if (node->flags & ANOBJ_METHOD_ARG) {
  130. acpi_os_printf(" [Method Arg]");
  131. }
  132. if (node->flags & ANOBJ_METHOD_LOCAL) {
  133. acpi_os_printf(" [Method Local]");
  134. }
  135. switch (node->type) {
  136. /* These types have no attached object */
  137. case ACPI_TYPE_DEVICE:
  138. acpi_os_printf(" Device");
  139. break;
  140. case ACPI_TYPE_THERMAL:
  141. acpi_os_printf(" Thermal Zone");
  142. break;
  143. default:
  144. acpi_db_decode_internal_object(acpi_ns_get_attached_object
  145. (node));
  146. break;
  147. }
  148. }
  149. /*******************************************************************************
  150. *
  151. * FUNCTION: acpi_db_display_internal_object
  152. *
  153. * PARAMETERS: obj_desc - Object to be displayed
  154. * walk_state - Current walk state
  155. *
  156. * RETURN: None
  157. *
  158. * DESCRIPTION: Short display of an internal object
  159. *
  160. ******************************************************************************/
  161. void
  162. acpi_db_display_internal_object(union acpi_operand_object *obj_desc,
  163. struct acpi_walk_state *walk_state)
  164. {
  165. u8 type;
  166. acpi_os_printf("%p ", obj_desc);
  167. if (!obj_desc) {
  168. acpi_os_printf("<Null Object>\n");
  169. return;
  170. }
  171. /* Decode the object type */
  172. switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) {
  173. case ACPI_DESC_TYPE_PARSER:
  174. acpi_os_printf("<Parser> ");
  175. break;
  176. case ACPI_DESC_TYPE_NAMED:
  177. acpi_db_decode_node((struct acpi_namespace_node *)obj_desc);
  178. break;
  179. case ACPI_DESC_TYPE_OPERAND:
  180. type = obj_desc->common.type;
  181. if (type > ACPI_TYPE_LOCAL_MAX) {
  182. acpi_os_printf(" Type %X [Invalid Type]", (u32)type);
  183. return;
  184. }
  185. /* Decode the ACPI object type */
  186. switch (obj_desc->common.type) {
  187. case ACPI_TYPE_LOCAL_REFERENCE:
  188. acpi_os_printf("[%s] ",
  189. acpi_ut_get_reference_name(obj_desc));
  190. /* Decode the reference */
  191. switch (obj_desc->reference.class) {
  192. case ACPI_REFCLASS_LOCAL:
  193. acpi_os_printf("%X ",
  194. obj_desc->reference.value);
  195. if (walk_state) {
  196. obj_desc = walk_state->local_variables
  197. [obj_desc->reference.value].object;
  198. acpi_os_printf("%p", obj_desc);
  199. acpi_db_decode_internal_object
  200. (obj_desc);
  201. }
  202. break;
  203. case ACPI_REFCLASS_ARG:
  204. acpi_os_printf("%X ",
  205. obj_desc->reference.value);
  206. if (walk_state) {
  207. obj_desc = walk_state->arguments
  208. [obj_desc->reference.value].object;
  209. acpi_os_printf("%p", obj_desc);
  210. acpi_db_decode_internal_object
  211. (obj_desc);
  212. }
  213. break;
  214. case ACPI_REFCLASS_INDEX:
  215. switch (obj_desc->reference.target_type) {
  216. case ACPI_TYPE_BUFFER_FIELD:
  217. acpi_os_printf("%p",
  218. obj_desc->reference.
  219. object);
  220. acpi_db_decode_internal_object
  221. (obj_desc->reference.object);
  222. break;
  223. case ACPI_TYPE_PACKAGE:
  224. acpi_os_printf("%p",
  225. obj_desc->reference.
  226. where);
  227. if (!obj_desc->reference.where) {
  228. acpi_os_printf
  229. (" Uninitialized WHERE pointer");
  230. } else {
  231. acpi_db_decode_internal_object(*
  232. (obj_desc->
  233. reference.
  234. where));
  235. }
  236. break;
  237. default:
  238. acpi_os_printf
  239. ("Unknown index target type");
  240. break;
  241. }
  242. break;
  243. case ACPI_REFCLASS_REFOF:
  244. if (!obj_desc->reference.object) {
  245. acpi_os_printf
  246. ("Uninitialized reference subobject pointer");
  247. break;
  248. }
  249. /* Reference can be to a Node or an Operand object */
  250. switch (ACPI_GET_DESCRIPTOR_TYPE
  251. (obj_desc->reference.object)) {
  252. case ACPI_DESC_TYPE_NAMED:
  253. acpi_db_decode_node(obj_desc->reference.
  254. object);
  255. break;
  256. case ACPI_DESC_TYPE_OPERAND:
  257. acpi_db_decode_internal_object
  258. (obj_desc->reference.object);
  259. break;
  260. default:
  261. break;
  262. }
  263. break;
  264. case ACPI_REFCLASS_NAME:
  265. acpi_db_decode_node(obj_desc->reference.node);
  266. break;
  267. case ACPI_REFCLASS_DEBUG:
  268. case ACPI_REFCLASS_TABLE:
  269. acpi_os_printf("\n");
  270. break;
  271. default: /* Unknown reference class */
  272. acpi_os_printf("%2.2X\n",
  273. obj_desc->reference.class);
  274. break;
  275. }
  276. break;
  277. default:
  278. acpi_os_printf("<Obj> ");
  279. acpi_db_decode_internal_object(obj_desc);
  280. break;
  281. }
  282. break;
  283. default:
  284. acpi_os_printf("<Not a valid ACPI Object Descriptor> [%s]",
  285. acpi_ut_get_descriptor_name(obj_desc));
  286. break;
  287. }
  288. acpi_os_printf("\n");
  289. }
  290. /*******************************************************************************
  291. *
  292. * FUNCTION: acpi_db_decode_locals
  293. *
  294. * PARAMETERS: walk_state - State for current method
  295. *
  296. * RETURN: None
  297. *
  298. * DESCRIPTION: Display all locals for the currently running control method
  299. *
  300. ******************************************************************************/
  301. void acpi_db_decode_locals(struct acpi_walk_state *walk_state)
  302. {
  303. u32 i;
  304. union acpi_operand_object *obj_desc;
  305. struct acpi_namespace_node *node;
  306. u8 display_locals = FALSE;
  307. node = walk_state->method_node;
  308. /* There are no locals for the module-level code case */
  309. if (node == acpi_gbl_root_node) {
  310. return;
  311. }
  312. if (!node) {
  313. acpi_os_printf
  314. ("No method node (Executing subtree for buffer or opregion)\n");
  315. return;
  316. }
  317. if (node->type != ACPI_TYPE_METHOD) {
  318. acpi_os_printf("Executing subtree for Buffer/Package/Region\n");
  319. return;
  320. }
  321. /* Are any locals actually set? */
  322. for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++) {
  323. obj_desc = walk_state->local_variables[i].object;
  324. if (obj_desc) {
  325. display_locals = TRUE;
  326. break;
  327. }
  328. }
  329. /* If any are set, only display the ones that are set */
  330. if (display_locals) {
  331. acpi_os_printf
  332. ("\nInitialized Local Variables for Method [%4.4s]:\n",
  333. acpi_ut_get_node_name(node));
  334. for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++) {
  335. obj_desc = walk_state->local_variables[i].object;
  336. if (obj_desc) {
  337. acpi_os_printf(" Local%X: ", i);
  338. acpi_db_display_internal_object(obj_desc,
  339. walk_state);
  340. }
  341. }
  342. } else {
  343. acpi_os_printf
  344. ("No Local Variables are initialized for Method [%4.4s]\n",
  345. acpi_ut_get_node_name(node));
  346. }
  347. }
  348. /*******************************************************************************
  349. *
  350. * FUNCTION: acpi_db_decode_arguments
  351. *
  352. * PARAMETERS: walk_state - State for current method
  353. *
  354. * RETURN: None
  355. *
  356. * DESCRIPTION: Display all arguments for the currently running control method
  357. *
  358. ******************************************************************************/
  359. void acpi_db_decode_arguments(struct acpi_walk_state *walk_state)
  360. {
  361. u32 i;
  362. union acpi_operand_object *obj_desc;
  363. struct acpi_namespace_node *node;
  364. u8 display_args = FALSE;
  365. node = walk_state->method_node;
  366. /* There are no arguments for the module-level code case */
  367. if (node == acpi_gbl_root_node) {
  368. return;
  369. }
  370. if (!node) {
  371. acpi_os_printf
  372. ("No method node (Executing subtree for buffer or opregion)\n");
  373. return;
  374. }
  375. if (node->type != ACPI_TYPE_METHOD) {
  376. acpi_os_printf("Executing subtree for Buffer/Package/Region\n");
  377. return;
  378. }
  379. /* Are any arguments actually set? */
  380. for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++) {
  381. obj_desc = walk_state->arguments[i].object;
  382. if (obj_desc) {
  383. display_args = TRUE;
  384. break;
  385. }
  386. }
  387. /* If any are set, only display the ones that are set */
  388. if (display_args) {
  389. acpi_os_printf("Initialized Arguments for Method [%4.4s]: "
  390. "(%X arguments defined for method invocation)\n",
  391. acpi_ut_get_node_name(node),
  392. node->object->method.param_count);
  393. for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++) {
  394. obj_desc = walk_state->arguments[i].object;
  395. if (obj_desc) {
  396. acpi_os_printf(" Arg%u: ", i);
  397. acpi_db_display_internal_object(obj_desc,
  398. walk_state);
  399. }
  400. }
  401. } else {
  402. acpi_os_printf
  403. ("No Arguments are initialized for method [%4.4s]\n",
  404. acpi_ut_get_node_name(node));
  405. }
  406. }