asldebug.c revision 1.1.1.2.4.1 1 /******************************************************************************
2 *
3 * Module Name: asldebug -- Debug output support
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2017, 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 "aslcompiler.h"
45 #include "aslcompiler.y.h"
46
47
48 #define _COMPONENT ACPI_COMPILER
49 ACPI_MODULE_NAME ("asldebug")
50
51
52 /* Local prototypes */
53
54 static void
55 UtDumpParseOpName (
56 ACPI_PARSE_OBJECT *Op,
57 UINT32 Level,
58 UINT32 DataLength);
59
60
61 /*******************************************************************************
62 *
63 * FUNCTION: CvDbgPrint
64 *
65 * PARAMETERS: Type - Type of output
66 * Fmt - Printf format string
67 * ... - variable printf list
68 *
69 * RETURN: None
70 *
71 * DESCRIPTION: Print statement for debug messages within the converter.
72 *
73 ******************************************************************************/
74
75 void
76 CvDbgPrint (
77 char *Fmt,
78 ...)
79 {
80 va_list Args;
81
82
83 if (!Gbl_CaptureComments || !AcpiGbl_DebugAslConversion)
84 {
85 return;
86 }
87
88 va_start (Args, Fmt);
89 (void) vfprintf (AcpiGbl_ConvDebugFile, Fmt, Args);
90 va_end (Args);
91 return;
92 }
93
94
95 /*******************************************************************************
96 *
97 * FUNCTION: UtDumpIntegerOp
98 *
99 * PARAMETERS: Op - Current parse op
100 * Level - Current output indentation level
101 * IntegerLength - Output length of the integer (2/4/8/16)
102 *
103 * RETURN: None
104 *
105 * DESCRIPTION: Emit formatted debug output for "integer" ops.
106 * Note: IntegerLength must be one of 2,4,8,16.
107 *
108 ******************************************************************************/
109
110 void
111 UtDumpIntegerOp (
112 ACPI_PARSE_OBJECT *Op,
113 UINT32 Level,
114 UINT32 IntegerLength)
115 {
116
117 /* Emit the ParseOp name, leaving room for the integer */
118
119 UtDumpParseOpName (Op, Level, IntegerLength);
120
121 /* Emit the integer based upon length */
122
123 switch (IntegerLength)
124 {
125 case 2: /* Byte */
126 case 4: /* Word */
127 case 8: /* Dword */
128
129 DbgPrint (ASL_TREE_OUTPUT,
130 "%*.*X", IntegerLength, IntegerLength, Op->Asl.Value.Integer);
131 break;
132
133 case 16: /* Qword and Integer */
134
135 DbgPrint (ASL_TREE_OUTPUT,
136 "%8.8X%8.8X", ACPI_FORMAT_UINT64 (Op->Asl.Value.Integer));
137 break;
138
139 default:
140 break;
141 }
142 }
143
144
145 /*******************************************************************************
146 *
147 * FUNCTION: UtDumpStringOp
148 *
149 * PARAMETERS: Op - Current parse op
150 * Level - Current output indentation level
151 *
152 * RETURN: None
153 *
154 * DESCRIPTION: Emit formatted debug output for String/Pathname ops.
155 *
156 ******************************************************************************/
157
158 void
159 UtDumpStringOp (
160 ACPI_PARSE_OBJECT *Op,
161 UINT32 Level)
162 {
163 char *String;
164
165
166 String = Op->Asl.Value.String;
167
168 if (Op->Asl.ParseOpcode != PARSEOP_STRING_LITERAL)
169 {
170 /*
171 * For the "path" ops NAMEPATH, NAMESEG, METHODCALL -- if the
172 * ExternalName is valid, it takes precedence. In these cases the
173 * Value.String is the raw "internal" name from the AML code, which
174 * we don't want to use, because it contains non-ascii characters.
175 */
176 if (Op->Asl.ExternalName)
177 {
178 String = Op->Asl.ExternalName;
179 }
180 }
181
182 if (!String)
183 {
184 DbgPrint (ASL_TREE_OUTPUT,
185 " ERROR: Could not find a valid String/Path pointer\n");
186 return;
187 }
188
189 /* Emit the ParseOp name, leaving room for the string */
190
191 UtDumpParseOpName (Op, Level, strlen (String));
192 DbgPrint (ASL_TREE_OUTPUT, "%s", String);
193 }
194
195
196 /*******************************************************************************
197 *
198 * FUNCTION: UtDumpBasicOp
199 *
200 * PARAMETERS: Op - Current parse op
201 * Level - Current output indentation level
202 *
203 * RETURN: None
204 *
205 * DESCRIPTION: Generic formatted debug output for "basic" ops that have no
206 * associated strings or integer values.
207 *
208 ******************************************************************************/
209
210 void
211 UtDumpBasicOp (
212 ACPI_PARSE_OBJECT *Op,
213 UINT32 Level)
214 {
215
216 /* Just print out the ParseOp name, there is no extra data */
217
218 UtDumpParseOpName (Op, Level, 0);
219 }
220
221
222 /*******************************************************************************
223 *
224 * FUNCTION: UtDumpParseOpName
225 *
226 * PARAMETERS: Op - Current parse op
227 * Level - Current output indentation level
228 * DataLength - Length of data to appear after the name
229 *
230 * RETURN: None
231 *
232 * DESCRIPTION: Indent and emit the ascii ParseOp name for the op
233 *
234 ******************************************************************************/
235
236 static void
237 UtDumpParseOpName (
238 ACPI_PARSE_OBJECT *Op,
239 UINT32 Level,
240 UINT32 DataLength)
241 {
242 char *ParseOpName;
243 UINT32 IndentLength;
244 UINT32 NameLength;
245 UINT32 LineLength;
246 UINT32 PaddingLength;
247
248
249 /* Emit the LineNumber/IndentLevel prefix on each output line */
250
251 DbgPrint (ASL_TREE_OUTPUT,
252 "%5.5d [%2d]", Op->Asl.LogicalLineNumber, Level);
253
254 ParseOpName = UtGetOpName (Op->Asl.ParseOpcode);
255
256 /* Calculate various lengths for output alignment */
257
258 IndentLength = Level * DEBUG_SPACES_PER_INDENT;
259 NameLength = strlen (ParseOpName);
260 LineLength = IndentLength + 1 + NameLength + 1 + DataLength;
261 PaddingLength = (DEBUG_MAX_LINE_LENGTH + 1) - LineLength;
262
263 /* Parse tree indentation is based upon the nesting/indent level */
264
265 if (Level)
266 {
267 DbgPrint (ASL_TREE_OUTPUT, "%*s", IndentLength, " ");
268 }
269
270 /* Emit the actual name here */
271
272 DbgPrint (ASL_TREE_OUTPUT, " %s", ParseOpName);
273
274 /* Emit extra padding blanks for alignment of later data items */
275
276 if (LineLength > DEBUG_MAX_LINE_LENGTH)
277 {
278 /* Split a long line immediately after the ParseOpName string */
279
280 DbgPrint (ASL_TREE_OUTPUT, "\n%*s",
281 (DEBUG_FULL_LINE_LENGTH - DataLength), " ");
282 }
283 else
284 {
285 DbgPrint (ASL_TREE_OUTPUT, "%*s", PaddingLength, " ");
286 }
287 }
288