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