1 |
227 |
jeremybenn |
/* Print in infix form a struct expression.
|
2 |
|
|
|
3 |
|
|
Copyright (C) 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
|
4 |
|
|
1998, 1999, 2000, 2003, 2007, 2008, 2009, 2010
|
5 |
|
|
Free Software Foundation, Inc.
|
6 |
|
|
|
7 |
|
|
This file is part of GDB.
|
8 |
|
|
|
9 |
|
|
This program is free software; you can redistribute it and/or modify
|
10 |
|
|
it under the terms of the GNU General Public License as published by
|
11 |
|
|
the Free Software Foundation; either version 3 of the License, or
|
12 |
|
|
(at your option) any later version.
|
13 |
|
|
|
14 |
|
|
This program is distributed in the hope that it will be useful,
|
15 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
|
|
GNU General Public License for more details.
|
18 |
|
|
|
19 |
|
|
You should have received a copy of the GNU General Public License
|
20 |
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
21 |
|
|
|
22 |
|
|
#include "defs.h"
|
23 |
|
|
#include "symtab.h"
|
24 |
|
|
#include "gdbtypes.h"
|
25 |
|
|
#include "expression.h"
|
26 |
|
|
#include "value.h"
|
27 |
|
|
#include "language.h"
|
28 |
|
|
#include "parser-defs.h"
|
29 |
|
|
#include "user-regs.h" /* For user_reg_map_regnum_to_name. */
|
30 |
|
|
#include "target.h"
|
31 |
|
|
#include "gdb_string.h"
|
32 |
|
|
#include "block.h"
|
33 |
|
|
#include "objfiles.h"
|
34 |
|
|
#include "gdb_assert.h"
|
35 |
|
|
#include "valprint.h"
|
36 |
|
|
|
37 |
|
|
#ifdef HAVE_CTYPE_H
|
38 |
|
|
#include <ctype.h>
|
39 |
|
|
#endif
|
40 |
|
|
|
41 |
|
|
void
|
42 |
|
|
print_expression (struct expression *exp, struct ui_file *stream)
|
43 |
|
|
{
|
44 |
|
|
int pc = 0;
|
45 |
|
|
print_subexp (exp, &pc, stream, PREC_NULL);
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
/* Print the subexpression of EXP that starts in position POS, on STREAM.
|
49 |
|
|
PREC is the precedence of the surrounding operator;
|
50 |
|
|
if the precedence of the main operator of this subexpression is less,
|
51 |
|
|
parentheses are needed here. */
|
52 |
|
|
|
53 |
|
|
void
|
54 |
|
|
print_subexp (struct expression *exp, int *pos,
|
55 |
|
|
struct ui_file *stream, enum precedence prec)
|
56 |
|
|
{
|
57 |
|
|
exp->language_defn->la_exp_desc->print_subexp (exp, pos, stream, prec);
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
/* Standard implementation of print_subexp for use in language_defn
|
61 |
|
|
vectors. */
|
62 |
|
|
void
|
63 |
|
|
print_subexp_standard (struct expression *exp, int *pos,
|
64 |
|
|
struct ui_file *stream, enum precedence prec)
|
65 |
|
|
{
|
66 |
|
|
unsigned tem;
|
67 |
|
|
const struct op_print *op_print_tab;
|
68 |
|
|
int pc;
|
69 |
|
|
unsigned nargs;
|
70 |
|
|
char *op_str;
|
71 |
|
|
int assign_modify = 0;
|
72 |
|
|
enum exp_opcode opcode;
|
73 |
|
|
enum precedence myprec = PREC_NULL;
|
74 |
|
|
/* Set to 1 for a right-associative operator. */
|
75 |
|
|
int assoc = 0;
|
76 |
|
|
struct value *val;
|
77 |
|
|
char *tempstr = NULL;
|
78 |
|
|
|
79 |
|
|
op_print_tab = exp->language_defn->la_op_print_tab;
|
80 |
|
|
pc = (*pos)++;
|
81 |
|
|
opcode = exp->elts[pc].opcode;
|
82 |
|
|
switch (opcode)
|
83 |
|
|
{
|
84 |
|
|
/* Common ops */
|
85 |
|
|
|
86 |
|
|
case OP_SCOPE:
|
87 |
|
|
myprec = PREC_PREFIX;
|
88 |
|
|
assoc = 0;
|
89 |
|
|
fputs_filtered (type_name_no_tag (exp->elts[pc + 1].type), stream);
|
90 |
|
|
fputs_filtered ("::", stream);
|
91 |
|
|
nargs = longest_to_int (exp->elts[pc + 2].longconst);
|
92 |
|
|
(*pos) += 4 + BYTES_TO_EXP_ELEM (nargs + 1);
|
93 |
|
|
fputs_filtered (&exp->elts[pc + 3].string, stream);
|
94 |
|
|
return;
|
95 |
|
|
|
96 |
|
|
case OP_LONG:
|
97 |
|
|
{
|
98 |
|
|
struct value_print_options opts;
|
99 |
|
|
get_raw_print_options (&opts);
|
100 |
|
|
(*pos) += 3;
|
101 |
|
|
value_print (value_from_longest (exp->elts[pc + 1].type,
|
102 |
|
|
exp->elts[pc + 2].longconst),
|
103 |
|
|
stream, &opts);
|
104 |
|
|
}
|
105 |
|
|
return;
|
106 |
|
|
|
107 |
|
|
case OP_DOUBLE:
|
108 |
|
|
{
|
109 |
|
|
struct value_print_options opts;
|
110 |
|
|
get_raw_print_options (&opts);
|
111 |
|
|
(*pos) += 3;
|
112 |
|
|
value_print (value_from_double (exp->elts[pc + 1].type,
|
113 |
|
|
exp->elts[pc + 2].doubleconst),
|
114 |
|
|
stream, &opts);
|
115 |
|
|
}
|
116 |
|
|
return;
|
117 |
|
|
|
118 |
|
|
case OP_VAR_VALUE:
|
119 |
|
|
{
|
120 |
|
|
struct block *b;
|
121 |
|
|
(*pos) += 3;
|
122 |
|
|
b = exp->elts[pc + 1].block;
|
123 |
|
|
if (b != NULL
|
124 |
|
|
&& BLOCK_FUNCTION (b) != NULL
|
125 |
|
|
&& SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b)) != NULL)
|
126 |
|
|
{
|
127 |
|
|
fputs_filtered (SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b)), stream);
|
128 |
|
|
fputs_filtered ("::", stream);
|
129 |
|
|
}
|
130 |
|
|
fputs_filtered (SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol), stream);
|
131 |
|
|
}
|
132 |
|
|
return;
|
133 |
|
|
|
134 |
|
|
case OP_LAST:
|
135 |
|
|
(*pos) += 2;
|
136 |
|
|
fprintf_filtered (stream, "$%d",
|
137 |
|
|
longest_to_int (exp->elts[pc + 1].longconst));
|
138 |
|
|
return;
|
139 |
|
|
|
140 |
|
|
case OP_REGISTER:
|
141 |
|
|
{
|
142 |
|
|
const char *name = &exp->elts[pc + 2].string;
|
143 |
|
|
(*pos) += 3 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1);
|
144 |
|
|
fprintf_filtered (stream, "$%s", name);
|
145 |
|
|
return;
|
146 |
|
|
}
|
147 |
|
|
|
148 |
|
|
case OP_BOOL:
|
149 |
|
|
(*pos) += 2;
|
150 |
|
|
fprintf_filtered (stream, "%s",
|
151 |
|
|
longest_to_int (exp->elts[pc + 1].longconst)
|
152 |
|
|
? "TRUE" : "FALSE");
|
153 |
|
|
return;
|
154 |
|
|
|
155 |
|
|
case OP_INTERNALVAR:
|
156 |
|
|
(*pos) += 2;
|
157 |
|
|
fprintf_filtered (stream, "$%s",
|
158 |
|
|
internalvar_name (exp->elts[pc + 1].internalvar));
|
159 |
|
|
return;
|
160 |
|
|
|
161 |
|
|
case OP_FUNCALL:
|
162 |
|
|
(*pos) += 2;
|
163 |
|
|
nargs = longest_to_int (exp->elts[pc + 1].longconst);
|
164 |
|
|
print_subexp (exp, pos, stream, PREC_SUFFIX);
|
165 |
|
|
fputs_filtered (" (", stream);
|
166 |
|
|
for (tem = 0; tem < nargs; tem++)
|
167 |
|
|
{
|
168 |
|
|
if (tem != 0)
|
169 |
|
|
fputs_filtered (", ", stream);
|
170 |
|
|
print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
|
171 |
|
|
}
|
172 |
|
|
fputs_filtered (")", stream);
|
173 |
|
|
return;
|
174 |
|
|
|
175 |
|
|
case OP_NAME:
|
176 |
|
|
nargs = longest_to_int (exp->elts[pc + 1].longconst);
|
177 |
|
|
(*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1);
|
178 |
|
|
fputs_filtered (&exp->elts[pc + 2].string, stream);
|
179 |
|
|
return;
|
180 |
|
|
|
181 |
|
|
case OP_STRING:
|
182 |
|
|
{
|
183 |
|
|
struct value_print_options opts;
|
184 |
|
|
nargs = longest_to_int (exp->elts[pc + 1].longconst);
|
185 |
|
|
(*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1);
|
186 |
|
|
/* LA_PRINT_STRING will print using the current repeat count threshold.
|
187 |
|
|
If necessary, we can temporarily set it to zero, or pass it as an
|
188 |
|
|
additional parameter to LA_PRINT_STRING. -fnf */
|
189 |
|
|
get_user_print_options (&opts);
|
190 |
|
|
LA_PRINT_STRING (stream, builtin_type (exp->gdbarch)->builtin_char,
|
191 |
|
|
&exp->elts[pc + 2].string, nargs, NULL, 0, &opts);
|
192 |
|
|
}
|
193 |
|
|
return;
|
194 |
|
|
|
195 |
|
|
case OP_BITSTRING:
|
196 |
|
|
nargs = longest_to_int (exp->elts[pc + 1].longconst);
|
197 |
|
|
(*pos)
|
198 |
|
|
+= 3 + BYTES_TO_EXP_ELEM ((nargs + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT);
|
199 |
|
|
fprintf_unfiltered (stream, "B'<unimplemented>'");
|
200 |
|
|
return;
|
201 |
|
|
|
202 |
|
|
case OP_OBJC_NSSTRING: /* Objective-C Foundation Class NSString constant. */
|
203 |
|
|
{
|
204 |
|
|
struct value_print_options opts;
|
205 |
|
|
nargs = longest_to_int (exp->elts[pc + 1].longconst);
|
206 |
|
|
(*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1);
|
207 |
|
|
fputs_filtered ("@\"", stream);
|
208 |
|
|
get_user_print_options (&opts);
|
209 |
|
|
LA_PRINT_STRING (stream, builtin_type (exp->gdbarch)->builtin_char,
|
210 |
|
|
&exp->elts[pc + 2].string, nargs, NULL, 0, &opts);
|
211 |
|
|
fputs_filtered ("\"", stream);
|
212 |
|
|
}
|
213 |
|
|
return;
|
214 |
|
|
|
215 |
|
|
case OP_OBJC_MSGCALL:
|
216 |
|
|
{ /* Objective C message (method) call. */
|
217 |
|
|
char *selector;
|
218 |
|
|
(*pos) += 3;
|
219 |
|
|
nargs = longest_to_int (exp->elts[pc + 2].longconst);
|
220 |
|
|
fprintf_unfiltered (stream, "[");
|
221 |
|
|
print_subexp (exp, pos, stream, PREC_SUFFIX);
|
222 |
|
|
if (0 == target_read_string (exp->elts[pc + 1].longconst,
|
223 |
|
|
&selector, 1024, NULL))
|
224 |
|
|
{
|
225 |
|
|
error (_("bad selector"));
|
226 |
|
|
return;
|
227 |
|
|
}
|
228 |
|
|
if (nargs)
|
229 |
|
|
{
|
230 |
|
|
char *s, *nextS;
|
231 |
|
|
s = alloca (strlen (selector) + 1);
|
232 |
|
|
strcpy (s, selector);
|
233 |
|
|
for (tem = 0; tem < nargs; tem++)
|
234 |
|
|
{
|
235 |
|
|
nextS = strchr (s, ':');
|
236 |
|
|
gdb_assert (nextS); /* Make sure we found ':'. */
|
237 |
|
|
*nextS = '\0';
|
238 |
|
|
fprintf_unfiltered (stream, " %s: ", s);
|
239 |
|
|
s = nextS + 1;
|
240 |
|
|
print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
|
241 |
|
|
}
|
242 |
|
|
}
|
243 |
|
|
else
|
244 |
|
|
{
|
245 |
|
|
fprintf_unfiltered (stream, " %s", selector);
|
246 |
|
|
}
|
247 |
|
|
fprintf_unfiltered (stream, "]");
|
248 |
|
|
/* "selector" was malloc'd by target_read_string. Free it. */
|
249 |
|
|
xfree (selector);
|
250 |
|
|
return;
|
251 |
|
|
}
|
252 |
|
|
|
253 |
|
|
case OP_ARRAY:
|
254 |
|
|
(*pos) += 3;
|
255 |
|
|
nargs = longest_to_int (exp->elts[pc + 2].longconst);
|
256 |
|
|
nargs -= longest_to_int (exp->elts[pc + 1].longconst);
|
257 |
|
|
nargs++;
|
258 |
|
|
tem = 0;
|
259 |
|
|
if (exp->elts[pc + 4].opcode == OP_LONG
|
260 |
|
|
&& exp->elts[pc + 5].type
|
261 |
|
|
== builtin_type (exp->gdbarch)->builtin_char
|
262 |
|
|
&& exp->language_defn->la_language == language_c)
|
263 |
|
|
{
|
264 |
|
|
/* Attempt to print C character arrays using string syntax.
|
265 |
|
|
Walk through the args, picking up one character from each
|
266 |
|
|
of the OP_LONG expression elements. If any array element
|
267 |
|
|
does not match our expection of what we should find for
|
268 |
|
|
a simple string, revert back to array printing. Note that
|
269 |
|
|
the last expression element is an explicit null terminator
|
270 |
|
|
byte, which doesn't get printed. */
|
271 |
|
|
tempstr = alloca (nargs);
|
272 |
|
|
pc += 4;
|
273 |
|
|
while (tem < nargs)
|
274 |
|
|
{
|
275 |
|
|
if (exp->elts[pc].opcode != OP_LONG
|
276 |
|
|
|| exp->elts[pc + 1].type
|
277 |
|
|
!= builtin_type (exp->gdbarch)->builtin_char)
|
278 |
|
|
{
|
279 |
|
|
/* Not a simple array of char, use regular array printing. */
|
280 |
|
|
tem = 0;
|
281 |
|
|
break;
|
282 |
|
|
}
|
283 |
|
|
else
|
284 |
|
|
{
|
285 |
|
|
tempstr[tem++] =
|
286 |
|
|
longest_to_int (exp->elts[pc + 2].longconst);
|
287 |
|
|
pc += 4;
|
288 |
|
|
}
|
289 |
|
|
}
|
290 |
|
|
}
|
291 |
|
|
if (tem > 0)
|
292 |
|
|
{
|
293 |
|
|
struct value_print_options opts;
|
294 |
|
|
get_user_print_options (&opts);
|
295 |
|
|
LA_PRINT_STRING (stream, builtin_type (exp->gdbarch)->builtin_char,
|
296 |
|
|
tempstr, nargs - 1, NULL, 0, &opts);
|
297 |
|
|
(*pos) = pc;
|
298 |
|
|
}
|
299 |
|
|
else
|
300 |
|
|
{
|
301 |
|
|
fputs_filtered (" {", stream);
|
302 |
|
|
for (tem = 0; tem < nargs; tem++)
|
303 |
|
|
{
|
304 |
|
|
if (tem != 0)
|
305 |
|
|
{
|
306 |
|
|
fputs_filtered (", ", stream);
|
307 |
|
|
}
|
308 |
|
|
print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
|
309 |
|
|
}
|
310 |
|
|
fputs_filtered ("}", stream);
|
311 |
|
|
}
|
312 |
|
|
return;
|
313 |
|
|
|
314 |
|
|
case OP_LABELED:
|
315 |
|
|
tem = longest_to_int (exp->elts[pc + 1].longconst);
|
316 |
|
|
(*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
|
317 |
|
|
/* Gcc support both these syntaxes. Unsure which is preferred. */
|
318 |
|
|
#if 1
|
319 |
|
|
fputs_filtered (&exp->elts[pc + 2].string, stream);
|
320 |
|
|
fputs_filtered (": ", stream);
|
321 |
|
|
#else
|
322 |
|
|
fputs_filtered (".", stream);
|
323 |
|
|
fputs_filtered (&exp->elts[pc + 2].string, stream);
|
324 |
|
|
fputs_filtered ("=", stream);
|
325 |
|
|
#endif
|
326 |
|
|
print_subexp (exp, pos, stream, PREC_SUFFIX);
|
327 |
|
|
return;
|
328 |
|
|
|
329 |
|
|
case TERNOP_COND:
|
330 |
|
|
if ((int) prec > (int) PREC_COMMA)
|
331 |
|
|
fputs_filtered ("(", stream);
|
332 |
|
|
/* Print the subexpressions, forcing parentheses
|
333 |
|
|
around any binary operations within them.
|
334 |
|
|
This is more parentheses than are strictly necessary,
|
335 |
|
|
but it looks clearer. */
|
336 |
|
|
print_subexp (exp, pos, stream, PREC_HYPER);
|
337 |
|
|
fputs_filtered (" ? ", stream);
|
338 |
|
|
print_subexp (exp, pos, stream, PREC_HYPER);
|
339 |
|
|
fputs_filtered (" : ", stream);
|
340 |
|
|
print_subexp (exp, pos, stream, PREC_HYPER);
|
341 |
|
|
if ((int) prec > (int) PREC_COMMA)
|
342 |
|
|
fputs_filtered (")", stream);
|
343 |
|
|
return;
|
344 |
|
|
|
345 |
|
|
case TERNOP_SLICE:
|
346 |
|
|
case TERNOP_SLICE_COUNT:
|
347 |
|
|
print_subexp (exp, pos, stream, PREC_SUFFIX);
|
348 |
|
|
fputs_filtered ("(", stream);
|
349 |
|
|
print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
|
350 |
|
|
fputs_filtered (opcode == TERNOP_SLICE ? " : " : " UP ", stream);
|
351 |
|
|
print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
|
352 |
|
|
fputs_filtered (")", stream);
|
353 |
|
|
return;
|
354 |
|
|
|
355 |
|
|
case STRUCTOP_STRUCT:
|
356 |
|
|
tem = longest_to_int (exp->elts[pc + 1].longconst);
|
357 |
|
|
(*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
|
358 |
|
|
print_subexp (exp, pos, stream, PREC_SUFFIX);
|
359 |
|
|
fputs_filtered (".", stream);
|
360 |
|
|
fputs_filtered (&exp->elts[pc + 2].string, stream);
|
361 |
|
|
return;
|
362 |
|
|
|
363 |
|
|
/* Will not occur for Modula-2 */
|
364 |
|
|
case STRUCTOP_PTR:
|
365 |
|
|
tem = longest_to_int (exp->elts[pc + 1].longconst);
|
366 |
|
|
(*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
|
367 |
|
|
print_subexp (exp, pos, stream, PREC_SUFFIX);
|
368 |
|
|
fputs_filtered ("->", stream);
|
369 |
|
|
fputs_filtered (&exp->elts[pc + 2].string, stream);
|
370 |
|
|
return;
|
371 |
|
|
|
372 |
|
|
case STRUCTOP_MEMBER:
|
373 |
|
|
print_subexp (exp, pos, stream, PREC_SUFFIX);
|
374 |
|
|
fputs_filtered (".*", stream);
|
375 |
|
|
print_subexp (exp, pos, stream, PREC_SUFFIX);
|
376 |
|
|
return;
|
377 |
|
|
|
378 |
|
|
case STRUCTOP_MPTR:
|
379 |
|
|
print_subexp (exp, pos, stream, PREC_SUFFIX);
|
380 |
|
|
fputs_filtered ("->*", stream);
|
381 |
|
|
print_subexp (exp, pos, stream, PREC_SUFFIX);
|
382 |
|
|
return;
|
383 |
|
|
|
384 |
|
|
case BINOP_SUBSCRIPT:
|
385 |
|
|
print_subexp (exp, pos, stream, PREC_SUFFIX);
|
386 |
|
|
fputs_filtered ("[", stream);
|
387 |
|
|
print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
|
388 |
|
|
fputs_filtered ("]", stream);
|
389 |
|
|
return;
|
390 |
|
|
|
391 |
|
|
case UNOP_POSTINCREMENT:
|
392 |
|
|
print_subexp (exp, pos, stream, PREC_SUFFIX);
|
393 |
|
|
fputs_filtered ("++", stream);
|
394 |
|
|
return;
|
395 |
|
|
|
396 |
|
|
case UNOP_POSTDECREMENT:
|
397 |
|
|
print_subexp (exp, pos, stream, PREC_SUFFIX);
|
398 |
|
|
fputs_filtered ("--", stream);
|
399 |
|
|
return;
|
400 |
|
|
|
401 |
|
|
case UNOP_CAST:
|
402 |
|
|
(*pos) += 2;
|
403 |
|
|
if ((int) prec > (int) PREC_PREFIX)
|
404 |
|
|
fputs_filtered ("(", stream);
|
405 |
|
|
fputs_filtered ("(", stream);
|
406 |
|
|
type_print (exp->elts[pc + 1].type, "", stream, 0);
|
407 |
|
|
fputs_filtered (") ", stream);
|
408 |
|
|
print_subexp (exp, pos, stream, PREC_PREFIX);
|
409 |
|
|
if ((int) prec > (int) PREC_PREFIX)
|
410 |
|
|
fputs_filtered (")", stream);
|
411 |
|
|
return;
|
412 |
|
|
|
413 |
|
|
case UNOP_DYNAMIC_CAST:
|
414 |
|
|
case UNOP_REINTERPRET_CAST:
|
415 |
|
|
fputs_filtered (opcode == UNOP_DYNAMIC_CAST ? "dynamic_cast"
|
416 |
|
|
: "reinterpret_cast", stream);
|
417 |
|
|
fputs_filtered ("<", stream);
|
418 |
|
|
(*pos) += 2;
|
419 |
|
|
type_print (exp->elts[pc + 1].type, "", stream, 0);
|
420 |
|
|
fputs_filtered ("> (", stream);
|
421 |
|
|
print_subexp (exp, pos, stream, PREC_PREFIX);
|
422 |
|
|
fputs_filtered (")", stream);
|
423 |
|
|
return;
|
424 |
|
|
|
425 |
|
|
case UNOP_MEMVAL:
|
426 |
|
|
(*pos) += 2;
|
427 |
|
|
if ((int) prec > (int) PREC_PREFIX)
|
428 |
|
|
fputs_filtered ("(", stream);
|
429 |
|
|
if (TYPE_CODE (exp->elts[pc + 1].type) == TYPE_CODE_FUNC
|
430 |
|
|
&& exp->elts[pc + 3].opcode == OP_LONG)
|
431 |
|
|
{
|
432 |
|
|
struct value_print_options opts;
|
433 |
|
|
|
434 |
|
|
/* We have a minimal symbol fn, probably. It's encoded
|
435 |
|
|
as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address).
|
436 |
|
|
Swallow the OP_LONG (including both its opcodes); ignore
|
437 |
|
|
its type; print the value in the type of the MEMVAL. */
|
438 |
|
|
(*pos) += 4;
|
439 |
|
|
val = value_at_lazy (exp->elts[pc + 1].type,
|
440 |
|
|
(CORE_ADDR) exp->elts[pc + 5].longconst);
|
441 |
|
|
get_raw_print_options (&opts);
|
442 |
|
|
value_print (val, stream, &opts);
|
443 |
|
|
}
|
444 |
|
|
else
|
445 |
|
|
{
|
446 |
|
|
fputs_filtered ("{", stream);
|
447 |
|
|
type_print (exp->elts[pc + 1].type, "", stream, 0);
|
448 |
|
|
fputs_filtered ("} ", stream);
|
449 |
|
|
print_subexp (exp, pos, stream, PREC_PREFIX);
|
450 |
|
|
}
|
451 |
|
|
if ((int) prec > (int) PREC_PREFIX)
|
452 |
|
|
fputs_filtered (")", stream);
|
453 |
|
|
return;
|
454 |
|
|
|
455 |
|
|
case UNOP_MEMVAL_TLS:
|
456 |
|
|
(*pos) += 3;
|
457 |
|
|
if ((int) prec > (int) PREC_PREFIX)
|
458 |
|
|
fputs_filtered ("(", stream);
|
459 |
|
|
fputs_filtered ("{", stream);
|
460 |
|
|
type_print (exp->elts[pc + 2].type, "", stream, 0);
|
461 |
|
|
fputs_filtered ("} ", stream);
|
462 |
|
|
print_subexp (exp, pos, stream, PREC_PREFIX);
|
463 |
|
|
if ((int) prec > (int) PREC_PREFIX)
|
464 |
|
|
fputs_filtered (")", stream);
|
465 |
|
|
return;
|
466 |
|
|
|
467 |
|
|
case BINOP_ASSIGN_MODIFY:
|
468 |
|
|
opcode = exp->elts[pc + 1].opcode;
|
469 |
|
|
(*pos) += 2;
|
470 |
|
|
myprec = PREC_ASSIGN;
|
471 |
|
|
assoc = 1;
|
472 |
|
|
assign_modify = 1;
|
473 |
|
|
op_str = "???";
|
474 |
|
|
for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++)
|
475 |
|
|
if (op_print_tab[tem].opcode == opcode)
|
476 |
|
|
{
|
477 |
|
|
op_str = op_print_tab[tem].string;
|
478 |
|
|
break;
|
479 |
|
|
}
|
480 |
|
|
if (op_print_tab[tem].opcode != opcode)
|
481 |
|
|
/* Not found; don't try to keep going because we don't know how
|
482 |
|
|
to interpret further elements. */
|
483 |
|
|
error (_("Invalid expression"));
|
484 |
|
|
break;
|
485 |
|
|
|
486 |
|
|
/* C++ ops */
|
487 |
|
|
|
488 |
|
|
case OP_THIS:
|
489 |
|
|
++(*pos);
|
490 |
|
|
fputs_filtered ("this", stream);
|
491 |
|
|
return;
|
492 |
|
|
|
493 |
|
|
/* Objective-C ops */
|
494 |
|
|
|
495 |
|
|
case OP_OBJC_SELF:
|
496 |
|
|
++(*pos);
|
497 |
|
|
fputs_filtered ("self", stream); /* The ObjC equivalent of "this". */
|
498 |
|
|
return;
|
499 |
|
|
|
500 |
|
|
/* Modula-2 ops */
|
501 |
|
|
|
502 |
|
|
case MULTI_SUBSCRIPT:
|
503 |
|
|
(*pos) += 2;
|
504 |
|
|
nargs = longest_to_int (exp->elts[pc + 1].longconst);
|
505 |
|
|
print_subexp (exp, pos, stream, PREC_SUFFIX);
|
506 |
|
|
fprintf_unfiltered (stream, " [");
|
507 |
|
|
for (tem = 0; tem < nargs; tem++)
|
508 |
|
|
{
|
509 |
|
|
if (tem != 0)
|
510 |
|
|
fprintf_unfiltered (stream, ", ");
|
511 |
|
|
print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
|
512 |
|
|
}
|
513 |
|
|
fprintf_unfiltered (stream, "]");
|
514 |
|
|
return;
|
515 |
|
|
|
516 |
|
|
case BINOP_VAL:
|
517 |
|
|
(*pos) += 2;
|
518 |
|
|
fprintf_unfiltered (stream, "VAL(");
|
519 |
|
|
type_print (exp->elts[pc + 1].type, "", stream, 0);
|
520 |
|
|
fprintf_unfiltered (stream, ",");
|
521 |
|
|
print_subexp (exp, pos, stream, PREC_PREFIX);
|
522 |
|
|
fprintf_unfiltered (stream, ")");
|
523 |
|
|
return;
|
524 |
|
|
|
525 |
|
|
case BINOP_INCL:
|
526 |
|
|
case BINOP_EXCL:
|
527 |
|
|
error (_("print_subexp: Not implemented."));
|
528 |
|
|
|
529 |
|
|
/* Default ops */
|
530 |
|
|
|
531 |
|
|
default:
|
532 |
|
|
op_str = "???";
|
533 |
|
|
for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++)
|
534 |
|
|
if (op_print_tab[tem].opcode == opcode)
|
535 |
|
|
{
|
536 |
|
|
op_str = op_print_tab[tem].string;
|
537 |
|
|
myprec = op_print_tab[tem].precedence;
|
538 |
|
|
assoc = op_print_tab[tem].right_assoc;
|
539 |
|
|
break;
|
540 |
|
|
}
|
541 |
|
|
if (op_print_tab[tem].opcode != opcode)
|
542 |
|
|
/* Not found; don't try to keep going because we don't know how
|
543 |
|
|
to interpret further elements. For example, this happens
|
544 |
|
|
if opcode is OP_TYPE. */
|
545 |
|
|
error (_("Invalid expression"));
|
546 |
|
|
}
|
547 |
|
|
|
548 |
|
|
/* Note that PREC_BUILTIN will always emit parentheses. */
|
549 |
|
|
if ((int) myprec < (int) prec)
|
550 |
|
|
fputs_filtered ("(", stream);
|
551 |
|
|
if ((int) opcode > (int) BINOP_END)
|
552 |
|
|
{
|
553 |
|
|
if (assoc)
|
554 |
|
|
{
|
555 |
|
|
/* Unary postfix operator. */
|
556 |
|
|
print_subexp (exp, pos, stream, PREC_SUFFIX);
|
557 |
|
|
fputs_filtered (op_str, stream);
|
558 |
|
|
}
|
559 |
|
|
else
|
560 |
|
|
{
|
561 |
|
|
/* Unary prefix operator. */
|
562 |
|
|
fputs_filtered (op_str, stream);
|
563 |
|
|
if (myprec == PREC_BUILTIN_FUNCTION)
|
564 |
|
|
fputs_filtered ("(", stream);
|
565 |
|
|
print_subexp (exp, pos, stream, PREC_PREFIX);
|
566 |
|
|
if (myprec == PREC_BUILTIN_FUNCTION)
|
567 |
|
|
fputs_filtered (")", stream);
|
568 |
|
|
}
|
569 |
|
|
}
|
570 |
|
|
else
|
571 |
|
|
{
|
572 |
|
|
/* Binary operator. */
|
573 |
|
|
/* Print left operand.
|
574 |
|
|
If operator is right-associative,
|
575 |
|
|
increment precedence for this operand. */
|
576 |
|
|
print_subexp (exp, pos, stream,
|
577 |
|
|
(enum precedence) ((int) myprec + assoc));
|
578 |
|
|
/* Print the operator itself. */
|
579 |
|
|
if (assign_modify)
|
580 |
|
|
fprintf_filtered (stream, " %s= ", op_str);
|
581 |
|
|
else if (op_str[0] == ',')
|
582 |
|
|
fprintf_filtered (stream, "%s ", op_str);
|
583 |
|
|
else
|
584 |
|
|
fprintf_filtered (stream, " %s ", op_str);
|
585 |
|
|
/* Print right operand.
|
586 |
|
|
If operator is left-associative,
|
587 |
|
|
increment precedence for this operand. */
|
588 |
|
|
print_subexp (exp, pos, stream,
|
589 |
|
|
(enum precedence) ((int) myprec + !assoc));
|
590 |
|
|
}
|
591 |
|
|
|
592 |
|
|
if ((int) myprec < (int) prec)
|
593 |
|
|
fputs_filtered (")", stream);
|
594 |
|
|
}
|
595 |
|
|
|
596 |
|
|
/* Return the operator corresponding to opcode OP as
|
597 |
|
|
a string. NULL indicates that the opcode was not found in the
|
598 |
|
|
current language table. */
|
599 |
|
|
char *
|
600 |
|
|
op_string (enum exp_opcode op)
|
601 |
|
|
{
|
602 |
|
|
int tem;
|
603 |
|
|
const struct op_print *op_print_tab;
|
604 |
|
|
|
605 |
|
|
op_print_tab = current_language->la_op_print_tab;
|
606 |
|
|
for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++)
|
607 |
|
|
if (op_print_tab[tem].opcode == op)
|
608 |
|
|
return op_print_tab[tem].string;
|
609 |
|
|
return NULL;
|
610 |
|
|
}
|
611 |
|
|
|
612 |
|
|
/* Support for dumping the raw data from expressions in a human readable
|
613 |
|
|
form. */
|
614 |
|
|
|
615 |
|
|
static char *op_name (struct expression *, enum exp_opcode);
|
616 |
|
|
static int dump_subexp_body (struct expression *exp, struct ui_file *, int);
|
617 |
|
|
|
618 |
|
|
/* Name for OPCODE, when it appears in expression EXP. */
|
619 |
|
|
|
620 |
|
|
static char *
|
621 |
|
|
op_name (struct expression *exp, enum exp_opcode opcode)
|
622 |
|
|
{
|
623 |
|
|
return exp->language_defn->la_exp_desc->op_name (opcode);
|
624 |
|
|
}
|
625 |
|
|
|
626 |
|
|
/* Default name for the standard operator OPCODE (i.e., one defined in
|
627 |
|
|
the definition of enum exp_opcode). */
|
628 |
|
|
|
629 |
|
|
char *
|
630 |
|
|
op_name_standard (enum exp_opcode opcode)
|
631 |
|
|
{
|
632 |
|
|
switch (opcode)
|
633 |
|
|
{
|
634 |
|
|
default:
|
635 |
|
|
{
|
636 |
|
|
static char buf[30];
|
637 |
|
|
|
638 |
|
|
sprintf (buf, "<unknown %d>", opcode);
|
639 |
|
|
return buf;
|
640 |
|
|
}
|
641 |
|
|
case OP_NULL:
|
642 |
|
|
return "OP_NULL";
|
643 |
|
|
case BINOP_ADD:
|
644 |
|
|
return "BINOP_ADD";
|
645 |
|
|
case BINOP_SUB:
|
646 |
|
|
return "BINOP_SUB";
|
647 |
|
|
case BINOP_MUL:
|
648 |
|
|
return "BINOP_MUL";
|
649 |
|
|
case BINOP_DIV:
|
650 |
|
|
return "BINOP_DIV";
|
651 |
|
|
case BINOP_REM:
|
652 |
|
|
return "BINOP_REM";
|
653 |
|
|
case BINOP_MOD:
|
654 |
|
|
return "BINOP_MOD";
|
655 |
|
|
case BINOP_LSH:
|
656 |
|
|
return "BINOP_LSH";
|
657 |
|
|
case BINOP_RSH:
|
658 |
|
|
return "BINOP_RSH";
|
659 |
|
|
case BINOP_LOGICAL_AND:
|
660 |
|
|
return "BINOP_LOGICAL_AND";
|
661 |
|
|
case BINOP_LOGICAL_OR:
|
662 |
|
|
return "BINOP_LOGICAL_OR";
|
663 |
|
|
case BINOP_BITWISE_AND:
|
664 |
|
|
return "BINOP_BITWISE_AND";
|
665 |
|
|
case BINOP_BITWISE_IOR:
|
666 |
|
|
return "BINOP_BITWISE_IOR";
|
667 |
|
|
case BINOP_BITWISE_XOR:
|
668 |
|
|
return "BINOP_BITWISE_XOR";
|
669 |
|
|
case BINOP_EQUAL:
|
670 |
|
|
return "BINOP_EQUAL";
|
671 |
|
|
case BINOP_NOTEQUAL:
|
672 |
|
|
return "BINOP_NOTEQUAL";
|
673 |
|
|
case BINOP_LESS:
|
674 |
|
|
return "BINOP_LESS";
|
675 |
|
|
case BINOP_GTR:
|
676 |
|
|
return "BINOP_GTR";
|
677 |
|
|
case BINOP_LEQ:
|
678 |
|
|
return "BINOP_LEQ";
|
679 |
|
|
case BINOP_GEQ:
|
680 |
|
|
return "BINOP_GEQ";
|
681 |
|
|
case BINOP_REPEAT:
|
682 |
|
|
return "BINOP_REPEAT";
|
683 |
|
|
case BINOP_ASSIGN:
|
684 |
|
|
return "BINOP_ASSIGN";
|
685 |
|
|
case BINOP_COMMA:
|
686 |
|
|
return "BINOP_COMMA";
|
687 |
|
|
case BINOP_SUBSCRIPT:
|
688 |
|
|
return "BINOP_SUBSCRIPT";
|
689 |
|
|
case MULTI_SUBSCRIPT:
|
690 |
|
|
return "MULTI_SUBSCRIPT";
|
691 |
|
|
case BINOP_EXP:
|
692 |
|
|
return "BINOP_EXP";
|
693 |
|
|
case BINOP_MIN:
|
694 |
|
|
return "BINOP_MIN";
|
695 |
|
|
case BINOP_MAX:
|
696 |
|
|
return "BINOP_MAX";
|
697 |
|
|
case STRUCTOP_MEMBER:
|
698 |
|
|
return "STRUCTOP_MEMBER";
|
699 |
|
|
case STRUCTOP_MPTR:
|
700 |
|
|
return "STRUCTOP_MPTR";
|
701 |
|
|
case BINOP_INTDIV:
|
702 |
|
|
return "BINOP_INTDIV";
|
703 |
|
|
case BINOP_ASSIGN_MODIFY:
|
704 |
|
|
return "BINOP_ASSIGN_MODIFY";
|
705 |
|
|
case BINOP_VAL:
|
706 |
|
|
return "BINOP_VAL";
|
707 |
|
|
case BINOP_INCL:
|
708 |
|
|
return "BINOP_INCL";
|
709 |
|
|
case BINOP_EXCL:
|
710 |
|
|
return "BINOP_EXCL";
|
711 |
|
|
case BINOP_CONCAT:
|
712 |
|
|
return "BINOP_CONCAT";
|
713 |
|
|
case BINOP_RANGE:
|
714 |
|
|
return "BINOP_RANGE";
|
715 |
|
|
case BINOP_END:
|
716 |
|
|
return "BINOP_END";
|
717 |
|
|
case TERNOP_COND:
|
718 |
|
|
return "TERNOP_COND";
|
719 |
|
|
case TERNOP_SLICE:
|
720 |
|
|
return "TERNOP_SLICE";
|
721 |
|
|
case TERNOP_SLICE_COUNT:
|
722 |
|
|
return "TERNOP_SLICE_COUNT";
|
723 |
|
|
case OP_LONG:
|
724 |
|
|
return "OP_LONG";
|
725 |
|
|
case OP_DOUBLE:
|
726 |
|
|
return "OP_DOUBLE";
|
727 |
|
|
case OP_VAR_VALUE:
|
728 |
|
|
return "OP_VAR_VALUE";
|
729 |
|
|
case OP_LAST:
|
730 |
|
|
return "OP_LAST";
|
731 |
|
|
case OP_REGISTER:
|
732 |
|
|
return "OP_REGISTER";
|
733 |
|
|
case OP_INTERNALVAR:
|
734 |
|
|
return "OP_INTERNALVAR";
|
735 |
|
|
case OP_FUNCALL:
|
736 |
|
|
return "OP_FUNCALL";
|
737 |
|
|
case OP_STRING:
|
738 |
|
|
return "OP_STRING";
|
739 |
|
|
case OP_BITSTRING:
|
740 |
|
|
return "OP_BITSTRING";
|
741 |
|
|
case OP_ARRAY:
|
742 |
|
|
return "OP_ARRAY";
|
743 |
|
|
case UNOP_CAST:
|
744 |
|
|
return "UNOP_CAST";
|
745 |
|
|
case UNOP_DYNAMIC_CAST:
|
746 |
|
|
return "UNOP_DYNAMIC_CAST";
|
747 |
|
|
case UNOP_REINTERPRET_CAST:
|
748 |
|
|
return "UNOP_REINTERPRET_CAST";
|
749 |
|
|
case UNOP_MEMVAL:
|
750 |
|
|
return "UNOP_MEMVAL";
|
751 |
|
|
case UNOP_MEMVAL_TLS:
|
752 |
|
|
return "UNOP_MEMVAL_TLS";
|
753 |
|
|
case UNOP_NEG:
|
754 |
|
|
return "UNOP_NEG";
|
755 |
|
|
case UNOP_LOGICAL_NOT:
|
756 |
|
|
return "UNOP_LOGICAL_NOT";
|
757 |
|
|
case UNOP_COMPLEMENT:
|
758 |
|
|
return "UNOP_COMPLEMENT";
|
759 |
|
|
case UNOP_IND:
|
760 |
|
|
return "UNOP_IND";
|
761 |
|
|
case UNOP_ADDR:
|
762 |
|
|
return "UNOP_ADDR";
|
763 |
|
|
case UNOP_PREINCREMENT:
|
764 |
|
|
return "UNOP_PREINCREMENT";
|
765 |
|
|
case UNOP_POSTINCREMENT:
|
766 |
|
|
return "UNOP_POSTINCREMENT";
|
767 |
|
|
case UNOP_PREDECREMENT:
|
768 |
|
|
return "UNOP_PREDECREMENT";
|
769 |
|
|
case UNOP_POSTDECREMENT:
|
770 |
|
|
return "UNOP_POSTDECREMENT";
|
771 |
|
|
case UNOP_SIZEOF:
|
772 |
|
|
return "UNOP_SIZEOF";
|
773 |
|
|
case UNOP_LOWER:
|
774 |
|
|
return "UNOP_LOWER";
|
775 |
|
|
case UNOP_UPPER:
|
776 |
|
|
return "UNOP_UPPER";
|
777 |
|
|
case UNOP_LENGTH:
|
778 |
|
|
return "UNOP_LENGTH";
|
779 |
|
|
case UNOP_PLUS:
|
780 |
|
|
return "UNOP_PLUS";
|
781 |
|
|
case UNOP_CAP:
|
782 |
|
|
return "UNOP_CAP";
|
783 |
|
|
case UNOP_CHR:
|
784 |
|
|
return "UNOP_CHR";
|
785 |
|
|
case UNOP_ORD:
|
786 |
|
|
return "UNOP_ORD";
|
787 |
|
|
case UNOP_ABS:
|
788 |
|
|
return "UNOP_ABS";
|
789 |
|
|
case UNOP_FLOAT:
|
790 |
|
|
return "UNOP_FLOAT";
|
791 |
|
|
case UNOP_HIGH:
|
792 |
|
|
return "UNOP_HIGH";
|
793 |
|
|
case UNOP_MAX:
|
794 |
|
|
return "UNOP_MAX";
|
795 |
|
|
case UNOP_MIN:
|
796 |
|
|
return "UNOP_MIN";
|
797 |
|
|
case UNOP_ODD:
|
798 |
|
|
return "UNOP_ODD";
|
799 |
|
|
case UNOP_TRUNC:
|
800 |
|
|
return "UNOP_TRUNC";
|
801 |
|
|
case OP_BOOL:
|
802 |
|
|
return "OP_BOOL";
|
803 |
|
|
case OP_M2_STRING:
|
804 |
|
|
return "OP_M2_STRING";
|
805 |
|
|
case STRUCTOP_STRUCT:
|
806 |
|
|
return "STRUCTOP_STRUCT";
|
807 |
|
|
case STRUCTOP_PTR:
|
808 |
|
|
return "STRUCTOP_PTR";
|
809 |
|
|
case OP_THIS:
|
810 |
|
|
return "OP_THIS";
|
811 |
|
|
case OP_OBJC_SELF:
|
812 |
|
|
return "OP_OBJC_SELF";
|
813 |
|
|
case OP_SCOPE:
|
814 |
|
|
return "OP_SCOPE";
|
815 |
|
|
case OP_TYPE:
|
816 |
|
|
return "OP_TYPE";
|
817 |
|
|
case OP_LABELED:
|
818 |
|
|
return "OP_LABELED";
|
819 |
|
|
}
|
820 |
|
|
}
|
821 |
|
|
|
822 |
|
|
/* Print a raw dump of expression EXP to STREAM.
|
823 |
|
|
NOTE, if non-NULL, is printed as extra explanatory text. */
|
824 |
|
|
|
825 |
|
|
void
|
826 |
|
|
dump_raw_expression (struct expression *exp, struct ui_file *stream,
|
827 |
|
|
char *note)
|
828 |
|
|
{
|
829 |
|
|
int elt;
|
830 |
|
|
char *opcode_name;
|
831 |
|
|
char *eltscan;
|
832 |
|
|
int eltsize;
|
833 |
|
|
|
834 |
|
|
fprintf_filtered (stream, "Dump of expression @ ");
|
835 |
|
|
gdb_print_host_address (exp, stream);
|
836 |
|
|
if (note)
|
837 |
|
|
fprintf_filtered (stream, ", %s:", note);
|
838 |
|
|
fprintf_filtered (stream, "\n\tLanguage %s, %d elements, %ld bytes each.\n",
|
839 |
|
|
exp->language_defn->la_name, exp->nelts,
|
840 |
|
|
(long) sizeof (union exp_element));
|
841 |
|
|
fprintf_filtered (stream, "\t%5s %20s %16s %s\n", "Index", "Opcode",
|
842 |
|
|
"Hex Value", "String Value");
|
843 |
|
|
for (elt = 0; elt < exp->nelts; elt++)
|
844 |
|
|
{
|
845 |
|
|
fprintf_filtered (stream, "\t%5d ", elt);
|
846 |
|
|
opcode_name = op_name (exp, exp->elts[elt].opcode);
|
847 |
|
|
|
848 |
|
|
fprintf_filtered (stream, "%20s ", opcode_name);
|
849 |
|
|
print_longest (stream, 'd', 0, exp->elts[elt].longconst);
|
850 |
|
|
fprintf_filtered (stream, " ");
|
851 |
|
|
|
852 |
|
|
for (eltscan = (char *) &exp->elts[elt],
|
853 |
|
|
eltsize = sizeof (union exp_element);
|
854 |
|
|
eltsize-- > 0;
|
855 |
|
|
eltscan++)
|
856 |
|
|
{
|
857 |
|
|
fprintf_filtered (stream, "%c",
|
858 |
|
|
isprint (*eltscan) ? (*eltscan & 0xFF) : '.');
|
859 |
|
|
}
|
860 |
|
|
fprintf_filtered (stream, "\n");
|
861 |
|
|
}
|
862 |
|
|
}
|
863 |
|
|
|
864 |
|
|
/* Dump the subexpression of prefix expression EXP whose operator is at
|
865 |
|
|
position ELT onto STREAM. Returns the position of the next
|
866 |
|
|
subexpression in EXP. */
|
867 |
|
|
|
868 |
|
|
int
|
869 |
|
|
dump_subexp (struct expression *exp, struct ui_file *stream, int elt)
|
870 |
|
|
{
|
871 |
|
|
static int indent = 0;
|
872 |
|
|
int i;
|
873 |
|
|
|
874 |
|
|
fprintf_filtered (stream, "\n");
|
875 |
|
|
fprintf_filtered (stream, "\t%5d ", elt);
|
876 |
|
|
|
877 |
|
|
for (i = 1; i <= indent; i++)
|
878 |
|
|
fprintf_filtered (stream, " ");
|
879 |
|
|
indent += 2;
|
880 |
|
|
|
881 |
|
|
fprintf_filtered (stream, "%-20s ", op_name (exp, exp->elts[elt].opcode));
|
882 |
|
|
|
883 |
|
|
elt = dump_subexp_body (exp, stream, elt);
|
884 |
|
|
|
885 |
|
|
indent -= 2;
|
886 |
|
|
|
887 |
|
|
return elt;
|
888 |
|
|
}
|
889 |
|
|
|
890 |
|
|
/* Dump the operands of prefix expression EXP whose opcode is at
|
891 |
|
|
position ELT onto STREAM. Returns the position of the next
|
892 |
|
|
subexpression in EXP. */
|
893 |
|
|
|
894 |
|
|
static int
|
895 |
|
|
dump_subexp_body (struct expression *exp, struct ui_file *stream, int elt)
|
896 |
|
|
{
|
897 |
|
|
return exp->language_defn->la_exp_desc->dump_subexp_body (exp, stream, elt);
|
898 |
|
|
}
|
899 |
|
|
|
900 |
|
|
/* Default value for subexp_body in exp_descriptor vector. */
|
901 |
|
|
|
902 |
|
|
int
|
903 |
|
|
dump_subexp_body_standard (struct expression *exp,
|
904 |
|
|
struct ui_file *stream, int elt)
|
905 |
|
|
{
|
906 |
|
|
int opcode = exp->elts[elt++].opcode;
|
907 |
|
|
|
908 |
|
|
switch (opcode)
|
909 |
|
|
{
|
910 |
|
|
case TERNOP_COND:
|
911 |
|
|
case TERNOP_SLICE:
|
912 |
|
|
case TERNOP_SLICE_COUNT:
|
913 |
|
|
elt = dump_subexp (exp, stream, elt);
|
914 |
|
|
case BINOP_ADD:
|
915 |
|
|
case BINOP_SUB:
|
916 |
|
|
case BINOP_MUL:
|
917 |
|
|
case BINOP_DIV:
|
918 |
|
|
case BINOP_REM:
|
919 |
|
|
case BINOP_MOD:
|
920 |
|
|
case BINOP_LSH:
|
921 |
|
|
case BINOP_RSH:
|
922 |
|
|
case BINOP_LOGICAL_AND:
|
923 |
|
|
case BINOP_LOGICAL_OR:
|
924 |
|
|
case BINOP_BITWISE_AND:
|
925 |
|
|
case BINOP_BITWISE_IOR:
|
926 |
|
|
case BINOP_BITWISE_XOR:
|
927 |
|
|
case BINOP_EQUAL:
|
928 |
|
|
case BINOP_NOTEQUAL:
|
929 |
|
|
case BINOP_LESS:
|
930 |
|
|
case BINOP_GTR:
|
931 |
|
|
case BINOP_LEQ:
|
932 |
|
|
case BINOP_GEQ:
|
933 |
|
|
case BINOP_REPEAT:
|
934 |
|
|
case BINOP_ASSIGN:
|
935 |
|
|
case BINOP_COMMA:
|
936 |
|
|
case BINOP_SUBSCRIPT:
|
937 |
|
|
case BINOP_EXP:
|
938 |
|
|
case BINOP_MIN:
|
939 |
|
|
case BINOP_MAX:
|
940 |
|
|
case BINOP_INTDIV:
|
941 |
|
|
case BINOP_ASSIGN_MODIFY:
|
942 |
|
|
case BINOP_VAL:
|
943 |
|
|
case BINOP_INCL:
|
944 |
|
|
case BINOP_EXCL:
|
945 |
|
|
case BINOP_CONCAT:
|
946 |
|
|
case BINOP_IN:
|
947 |
|
|
case BINOP_RANGE:
|
948 |
|
|
case BINOP_END:
|
949 |
|
|
case STRUCTOP_MEMBER:
|
950 |
|
|
case STRUCTOP_MPTR:
|
951 |
|
|
elt = dump_subexp (exp, stream, elt);
|
952 |
|
|
case UNOP_NEG:
|
953 |
|
|
case UNOP_LOGICAL_NOT:
|
954 |
|
|
case UNOP_COMPLEMENT:
|
955 |
|
|
case UNOP_IND:
|
956 |
|
|
case UNOP_ADDR:
|
957 |
|
|
case UNOP_PREINCREMENT:
|
958 |
|
|
case UNOP_POSTINCREMENT:
|
959 |
|
|
case UNOP_PREDECREMENT:
|
960 |
|
|
case UNOP_POSTDECREMENT:
|
961 |
|
|
case UNOP_SIZEOF:
|
962 |
|
|
case UNOP_PLUS:
|
963 |
|
|
case UNOP_CAP:
|
964 |
|
|
case UNOP_CHR:
|
965 |
|
|
case UNOP_ORD:
|
966 |
|
|
case UNOP_ABS:
|
967 |
|
|
case UNOP_FLOAT:
|
968 |
|
|
case UNOP_HIGH:
|
969 |
|
|
case UNOP_MAX:
|
970 |
|
|
case UNOP_MIN:
|
971 |
|
|
case UNOP_ODD:
|
972 |
|
|
case UNOP_TRUNC:
|
973 |
|
|
case UNOP_LOWER:
|
974 |
|
|
case UNOP_UPPER:
|
975 |
|
|
case UNOP_LENGTH:
|
976 |
|
|
case UNOP_CARD:
|
977 |
|
|
case UNOP_CHMAX:
|
978 |
|
|
case UNOP_CHMIN:
|
979 |
|
|
elt = dump_subexp (exp, stream, elt);
|
980 |
|
|
break;
|
981 |
|
|
case OP_LONG:
|
982 |
|
|
fprintf_filtered (stream, "Type @");
|
983 |
|
|
gdb_print_host_address (exp->elts[elt].type, stream);
|
984 |
|
|
fprintf_filtered (stream, " (");
|
985 |
|
|
type_print (exp->elts[elt].type, NULL, stream, 0);
|
986 |
|
|
fprintf_filtered (stream, "), value %ld (0x%lx)",
|
987 |
|
|
(long) exp->elts[elt + 1].longconst,
|
988 |
|
|
(long) exp->elts[elt + 1].longconst);
|
989 |
|
|
elt += 3;
|
990 |
|
|
break;
|
991 |
|
|
case OP_DOUBLE:
|
992 |
|
|
fprintf_filtered (stream, "Type @");
|
993 |
|
|
gdb_print_host_address (exp->elts[elt].type, stream);
|
994 |
|
|
fprintf_filtered (stream, " (");
|
995 |
|
|
type_print (exp->elts[elt].type, NULL, stream, 0);
|
996 |
|
|
fprintf_filtered (stream, "), value %g",
|
997 |
|
|
(double) exp->elts[elt + 1].doubleconst);
|
998 |
|
|
elt += 3;
|
999 |
|
|
break;
|
1000 |
|
|
case OP_VAR_VALUE:
|
1001 |
|
|
fprintf_filtered (stream, "Block @");
|
1002 |
|
|
gdb_print_host_address (exp->elts[elt].block, stream);
|
1003 |
|
|
fprintf_filtered (stream, ", symbol @");
|
1004 |
|
|
gdb_print_host_address (exp->elts[elt + 1].symbol, stream);
|
1005 |
|
|
fprintf_filtered (stream, " (%s)",
|
1006 |
|
|
SYMBOL_PRINT_NAME (exp->elts[elt + 1].symbol));
|
1007 |
|
|
elt += 3;
|
1008 |
|
|
break;
|
1009 |
|
|
case OP_LAST:
|
1010 |
|
|
fprintf_filtered (stream, "History element %ld",
|
1011 |
|
|
(long) exp->elts[elt].longconst);
|
1012 |
|
|
elt += 2;
|
1013 |
|
|
break;
|
1014 |
|
|
case OP_REGISTER:
|
1015 |
|
|
fprintf_filtered (stream, "Register $%s", &exp->elts[elt + 1].string);
|
1016 |
|
|
elt += 3 + BYTES_TO_EXP_ELEM (exp->elts[elt].longconst + 1);
|
1017 |
|
|
break;
|
1018 |
|
|
case OP_INTERNALVAR:
|
1019 |
|
|
fprintf_filtered (stream, "Internal var @");
|
1020 |
|
|
gdb_print_host_address (exp->elts[elt].internalvar, stream);
|
1021 |
|
|
fprintf_filtered (stream, " (%s)",
|
1022 |
|
|
internalvar_name (exp->elts[elt].internalvar));
|
1023 |
|
|
elt += 2;
|
1024 |
|
|
break;
|
1025 |
|
|
case OP_FUNCALL:
|
1026 |
|
|
{
|
1027 |
|
|
int i, nargs;
|
1028 |
|
|
|
1029 |
|
|
nargs = longest_to_int (exp->elts[elt].longconst);
|
1030 |
|
|
|
1031 |
|
|
fprintf_filtered (stream, "Number of args: %d", nargs);
|
1032 |
|
|
elt += 2;
|
1033 |
|
|
|
1034 |
|
|
for (i = 1; i <= nargs + 1; i++)
|
1035 |
|
|
elt = dump_subexp (exp, stream, elt);
|
1036 |
|
|
}
|
1037 |
|
|
break;
|
1038 |
|
|
case OP_ARRAY:
|
1039 |
|
|
{
|
1040 |
|
|
int lower, upper;
|
1041 |
|
|
int i;
|
1042 |
|
|
|
1043 |
|
|
lower = longest_to_int (exp->elts[elt].longconst);
|
1044 |
|
|
upper = longest_to_int (exp->elts[elt + 1].longconst);
|
1045 |
|
|
|
1046 |
|
|
fprintf_filtered (stream, "Bounds [%d:%d]", lower, upper);
|
1047 |
|
|
elt += 3;
|
1048 |
|
|
|
1049 |
|
|
for (i = 1; i <= upper - lower + 1; i++)
|
1050 |
|
|
elt = dump_subexp (exp, stream, elt);
|
1051 |
|
|
}
|
1052 |
|
|
break;
|
1053 |
|
|
case UNOP_MEMVAL:
|
1054 |
|
|
case UNOP_CAST:
|
1055 |
|
|
case UNOP_DYNAMIC_CAST:
|
1056 |
|
|
case UNOP_REINTERPRET_CAST:
|
1057 |
|
|
fprintf_filtered (stream, "Type @");
|
1058 |
|
|
gdb_print_host_address (exp->elts[elt].type, stream);
|
1059 |
|
|
fprintf_filtered (stream, " (");
|
1060 |
|
|
type_print (exp->elts[elt].type, NULL, stream, 0);
|
1061 |
|
|
fprintf_filtered (stream, ")");
|
1062 |
|
|
elt = dump_subexp (exp, stream, elt + 2);
|
1063 |
|
|
break;
|
1064 |
|
|
case UNOP_MEMVAL_TLS:
|
1065 |
|
|
fprintf_filtered (stream, "TLS type @");
|
1066 |
|
|
gdb_print_host_address (exp->elts[elt + 1].type, stream);
|
1067 |
|
|
fprintf_filtered (stream, " (__thread /* \"%s\" */ ",
|
1068 |
|
|
(exp->elts[elt].objfile == NULL ? "(null)"
|
1069 |
|
|
: exp->elts[elt].objfile->name));
|
1070 |
|
|
type_print (exp->elts[elt + 1].type, NULL, stream, 0);
|
1071 |
|
|
fprintf_filtered (stream, ")");
|
1072 |
|
|
elt = dump_subexp (exp, stream, elt + 3);
|
1073 |
|
|
break;
|
1074 |
|
|
case OP_TYPE:
|
1075 |
|
|
fprintf_filtered (stream, "Type @");
|
1076 |
|
|
gdb_print_host_address (exp->elts[elt].type, stream);
|
1077 |
|
|
fprintf_filtered (stream, " (");
|
1078 |
|
|
type_print (exp->elts[elt].type, NULL, stream, 0);
|
1079 |
|
|
fprintf_filtered (stream, ")");
|
1080 |
|
|
elt += 2;
|
1081 |
|
|
break;
|
1082 |
|
|
case STRUCTOP_STRUCT:
|
1083 |
|
|
case STRUCTOP_PTR:
|
1084 |
|
|
{
|
1085 |
|
|
char *elem_name;
|
1086 |
|
|
int len;
|
1087 |
|
|
|
1088 |
|
|
len = longest_to_int (exp->elts[elt].longconst);
|
1089 |
|
|
elem_name = &exp->elts[elt + 1].string;
|
1090 |
|
|
|
1091 |
|
|
fprintf_filtered (stream, "Element name: `%.*s'", len, elem_name);
|
1092 |
|
|
elt = dump_subexp (exp, stream, elt + 3 + BYTES_TO_EXP_ELEM (len + 1));
|
1093 |
|
|
}
|
1094 |
|
|
break;
|
1095 |
|
|
case OP_SCOPE:
|
1096 |
|
|
{
|
1097 |
|
|
char *elem_name;
|
1098 |
|
|
int len;
|
1099 |
|
|
|
1100 |
|
|
fprintf_filtered (stream, "Type @");
|
1101 |
|
|
gdb_print_host_address (exp->elts[elt].type, stream);
|
1102 |
|
|
fprintf_filtered (stream, " (");
|
1103 |
|
|
type_print (exp->elts[elt].type, NULL, stream, 0);
|
1104 |
|
|
fprintf_filtered (stream, ") ");
|
1105 |
|
|
|
1106 |
|
|
len = longest_to_int (exp->elts[elt + 1].longconst);
|
1107 |
|
|
elem_name = &exp->elts[elt + 2].string;
|
1108 |
|
|
|
1109 |
|
|
fprintf_filtered (stream, "Field name: `%.*s'", len, elem_name);
|
1110 |
|
|
elt += 4 + BYTES_TO_EXP_ELEM (len + 1);
|
1111 |
|
|
}
|
1112 |
|
|
break;
|
1113 |
|
|
default:
|
1114 |
|
|
case OP_NULL:
|
1115 |
|
|
case MULTI_SUBSCRIPT:
|
1116 |
|
|
case OP_F77_UNDETERMINED_ARGLIST:
|
1117 |
|
|
case OP_COMPLEX:
|
1118 |
|
|
case OP_STRING:
|
1119 |
|
|
case OP_BITSTRING:
|
1120 |
|
|
case OP_BOOL:
|
1121 |
|
|
case OP_M2_STRING:
|
1122 |
|
|
case OP_THIS:
|
1123 |
|
|
case OP_LABELED:
|
1124 |
|
|
case OP_NAME:
|
1125 |
|
|
fprintf_filtered (stream, "Unknown format");
|
1126 |
|
|
}
|
1127 |
|
|
|
1128 |
|
|
return elt;
|
1129 |
|
|
}
|
1130 |
|
|
|
1131 |
|
|
void
|
1132 |
|
|
dump_prefix_expression (struct expression *exp, struct ui_file *stream)
|
1133 |
|
|
{
|
1134 |
|
|
int elt;
|
1135 |
|
|
|
1136 |
|
|
fprintf_filtered (stream, "Dump of expression @ ");
|
1137 |
|
|
gdb_print_host_address (exp, stream);
|
1138 |
|
|
fputs_filtered (", after conversion to prefix form:\nExpression: `", stream);
|
1139 |
|
|
if (exp->elts[0].opcode != OP_TYPE)
|
1140 |
|
|
print_expression (exp, stream);
|
1141 |
|
|
else
|
1142 |
|
|
fputs_filtered ("Type printing not yet supported....", stream);
|
1143 |
|
|
fprintf_filtered (stream, "'\n\tLanguage %s, %d elements, %ld bytes each.\n",
|
1144 |
|
|
exp->language_defn->la_name, exp->nelts,
|
1145 |
|
|
(long) sizeof (union exp_element));
|
1146 |
|
|
fputs_filtered ("\n", stream);
|
1147 |
|
|
|
1148 |
|
|
for (elt = 0; elt < exp->nelts;)
|
1149 |
|
|
elt = dump_subexp (exp, stream, elt);
|
1150 |
|
|
fputs_filtered ("\n", stream);
|
1151 |
|
|
}
|