ACPICA: Dispatcher: Add trace support for interpreter
[firefly-linux-kernel-4.4.55.git] / drivers / acpi / acpica / dsdebug.c
1 /******************************************************************************
2  *
3  * Module Name: dsdebug - Parser/Interpreter interface - debugging
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2015, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions, and the following disclaimer,
16  *    without modification.
17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18  *    substantially similar to the "NO WARRANTY" disclaimer below
19  *    ("Disclaimer") and any redistribution must be conditioned upon
20  *    including a substantially similar Disclaimer requirement for further
21  *    binary redistribution.
22  * 3. Neither the names of the above-listed copyright holders nor the names
23  *    of any contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * Alternatively, this software may be distributed under the terms of the
27  * GNU General Public License ("GPL") version 2 as published by the Free
28  * Software Foundation.
29  *
30  * NO WARRANTY
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41  * POSSIBILITY OF SUCH DAMAGES.
42  */
43
44 #include <acpi/acpi.h>
45 #include "accommon.h"
46 #include "acdispat.h"
47 #include "acnamesp.h"
48 #ifdef ACPI_DISASSEMBLER
49 #include "acdisasm.h"
50 #endif
51
52 #define _COMPONENT          ACPI_DISPATCHER
53 ACPI_MODULE_NAME("dsdebug")
54
55 #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
56 /* Local prototypes */
57 static void
58 acpi_ds_print_node_pathname(struct acpi_namespace_node *node,
59                             const char *message);
60
61 /*******************************************************************************
62  *
63  * FUNCTION:    acpi_ds_print_node_pathname
64  *
65  * PARAMETERS:  node            - Object
66  *              message         - Prefix message
67  *
68  * DESCRIPTION: Print an object's full namespace pathname
69  *              Manages allocation/freeing of a pathname buffer
70  *
71  ******************************************************************************/
72
73 static void
74 acpi_ds_print_node_pathname(struct acpi_namespace_node *node,
75                             const char *message)
76 {
77         struct acpi_buffer buffer;
78         acpi_status status;
79
80         ACPI_FUNCTION_TRACE(ds_print_node_pathname);
81
82         if (!node) {
83                 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DISPATCH, "[NULL NAME]"));
84                 return_VOID;
85         }
86
87         /* Convert handle to full pathname and print it (with supplied message) */
88
89         buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
90
91         status = acpi_ns_handle_to_pathname(node, &buffer, FALSE);
92         if (ACPI_SUCCESS(status)) {
93                 if (message) {
94                         ACPI_DEBUG_PRINT_RAW((ACPI_DB_DISPATCH, "%s ",
95                                               message));
96                 }
97
98                 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DISPATCH, "[%s] (Node %p)",
99                                       (char *)buffer.pointer, node));
100                 ACPI_FREE(buffer.pointer);
101         }
102
103         return_VOID;
104 }
105
106 /*******************************************************************************
107  *
108  * FUNCTION:    acpi_ds_dump_method_stack
109  *
110  * PARAMETERS:  status          - Method execution status
111  *              walk_state      - Current state of the parse tree walk
112  *              op              - Executing parse op
113  *
114  * RETURN:      None
115  *
116  * DESCRIPTION: Called when a method has been aborted because of an error.
117  *              Dumps the method execution stack.
118  *
119  ******************************************************************************/
120
121 void
122 acpi_ds_dump_method_stack(acpi_status status,
123                           struct acpi_walk_state *walk_state,
124                           union acpi_parse_object *op)
125 {
126         union acpi_parse_object *next;
127         struct acpi_thread_state *thread;
128         struct acpi_walk_state *next_walk_state;
129         struct acpi_namespace_node *previous_method = NULL;
130         union acpi_operand_object *method_desc;
131         char *pathname = NULL;
132
133         ACPI_FUNCTION_TRACE(ds_dump_method_stack);
134
135         /* Ignore control codes, they are not errors */
136
137         if ((status & AE_CODE_MASK) == AE_CODE_CONTROL) {
138                 return_VOID;
139         }
140
141         /* We may be executing a deferred opcode */
142
143         if (walk_state->deferred_node) {
144                 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
145                                   "Executing subtree for Buffer/Package/Region\n"));
146                 return_VOID;
147         }
148
149         /*
150          * If there is no Thread, we are not actually executing a method.
151          * This can happen when the iASL compiler calls the interpreter
152          * to perform constant folding.
153          */
154         thread = walk_state->thread;
155         if (!thread) {
156                 return_VOID;
157         }
158
159         /* Display exception and method name */
160
161         ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
162                           "\n**** Exception %s during execution of method ",
163                           acpi_format_exception(status)));
164         acpi_ds_print_node_pathname(walk_state->method_node, NULL);
165
166         /* Display stack of executing methods */
167
168         ACPI_DEBUG_PRINT_RAW((ACPI_DB_DISPATCH,
169                               "\n\nMethod Execution Stack:\n"));
170         next_walk_state = thread->walk_state_list;
171
172         /* Walk list of linked walk states */
173
174         while (next_walk_state) {
175                 method_desc = next_walk_state->method_desc;
176                 if (method_desc && method_desc->method.node) {
177                         pathname = acpi_ns_get_normalized_pathname((struct
178                                                                     acpi_namespace_node
179                                                                     *)
180                                                                    method_desc->
181                                                                    method.node,
182                                                                    TRUE);
183                 }
184                 if (pathname) {
185                         ACPI_DEBUG_PRINT((ACPI_DB_TRACE_POINT,
186                                           "End method [0x%p:%s] execution.\n",
187                                           method_desc->method.aml_start,
188                                           pathname));
189                         ACPI_FREE(pathname);
190                         pathname = NULL;
191                 } else {
192                         ACPI_DEBUG_PRINT((ACPI_DB_TRACE_POINT,
193                                           "End method [0x%p] execution.\n",
194                                           method_desc->method.aml_start));
195                 }
196
197                 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
198                                   "    Method [%4.4s] executing: ",
199                                   acpi_ut_get_node_name(next_walk_state->
200                                                         method_node)));
201
202                 /* First method is the currently executing method */
203
204                 if (next_walk_state == walk_state) {
205                         if (op) {
206
207                                 /* Display currently executing ASL statement */
208
209                                 next = op->common.next;
210                                 op->common.next = NULL;
211
212 #ifdef ACPI_DISASSEMBLER
213                                 acpi_dm_disassemble(next_walk_state, op,
214                                                     ACPI_UINT32_MAX);
215 #endif
216                                 op->common.next = next;
217                         }
218                 } else {
219                         /*
220                          * This method has called another method
221                          * NOTE: the method call parse subtree is already deleted at this
222                          * point, so we cannot disassemble the method invocation.
223                          */
224                         ACPI_DEBUG_PRINT_RAW((ACPI_DB_DISPATCH,
225                                               "Call to method "));
226                         acpi_ds_print_node_pathname(previous_method, NULL);
227                 }
228
229                 previous_method = next_walk_state->method_node;
230                 next_walk_state = next_walk_state->next;
231                 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DISPATCH, "\n"));
232         }
233
234         return_VOID;
235 }
236
237 #else
238 void
239 acpi_ds_dump_method_stack(acpi_status status,
240                           struct acpi_walk_state *walk_state,
241                           union acpi_parse_object *op)
242 {
243         return;
244 }
245
246 #endif