dbobject.c 11 KB

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