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