1 /* Print in infix form a struct expression.
3 Copyright (C) 1986-2019 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
22 /* Standard C includes. */
25 /* Local non-gdb includes. */
27 #include "expression.h"
31 #include "parser-defs.h"
34 #include "user-regs.h"
39 print_expression (struct expression
*exp
, struct ui_file
*stream
)
43 print_subexp (exp
, &pc
, stream
, PREC_NULL
);
46 /* Print the subexpression of EXP that starts in position POS, on STREAM.
47 PREC is the precedence of the surrounding operator;
48 if the precedence of the main operator of this subexpression is less,
49 parentheses are needed here. */
52 print_subexp (struct expression
*exp
, int *pos
,
53 struct ui_file
*stream
, enum precedence prec
)
55 exp
->language_defn
->la_exp_desc
->print_subexp (exp
, pos
, stream
, prec
);
58 /* Standard implementation of print_subexp for use in language_defn
61 print_subexp_standard (struct expression
*exp
, int *pos
,
62 struct ui_file
*stream
, enum precedence prec
)
65 const struct op_print
*op_print_tab
;
69 int assign_modify
= 0;
70 enum exp_opcode opcode
;
71 enum precedence myprec
= PREC_NULL
;
72 /* Set to 1 for a right-associative operator. */
77 op_print_tab
= exp
->language_defn
->la_op_print_tab
;
79 opcode
= exp
->elts
[pc
].opcode
;
86 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
92 fputs_filtered (TYPE_NAME (exp
->elts
[pc
+ 1].type
), stream
);
93 fputs_filtered ("::", stream
);
94 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
95 (*pos
) += 4 + BYTES_TO_EXP_ELEM (nargs
+ 1);
96 fputs_filtered (&exp
->elts
[pc
+ 3].string
, stream
);
101 struct value_print_options opts
;
103 get_no_prettyformat_print_options (&opts
);
105 value_print (value_from_longest (exp
->elts
[pc
+ 1].type
,
106 exp
->elts
[pc
+ 2].longconst
),
113 struct value_print_options opts
;
115 get_no_prettyformat_print_options (&opts
);
117 value_print (value_from_contents (exp
->elts
[pc
+ 1].type
,
118 exp
->elts
[pc
+ 2].floatconst
),
125 const struct block
*b
;
128 b
= exp
->elts
[pc
+ 1].block
;
130 && BLOCK_FUNCTION (b
) != NULL
131 && SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b
)) != NULL
)
133 fputs_filtered (SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b
)), stream
);
134 fputs_filtered ("::", stream
);
136 fputs_filtered (SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 2].symbol
), stream
);
140 case OP_VAR_MSYM_VALUE
:
143 fputs_filtered (MSYMBOL_PRINT_NAME (exp
->elts
[pc
+ 2].msymbol
), stream
);
147 case OP_FUNC_STATIC_VAR
:
149 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
150 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
151 fputs_filtered (&exp
->elts
[pc
+ 1].string
, stream
);
155 case OP_VAR_ENTRY_VALUE
:
158 fprintf_filtered (stream
, "%s@entry",
159 SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 1].symbol
));
165 fprintf_filtered (stream
, "$%d",
166 longest_to_int (exp
->elts
[pc
+ 1].longconst
));
171 const char *name
= &exp
->elts
[pc
+ 2].string
;
173 (*pos
) += 3 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
174 fprintf_filtered (stream
, "$%s", name
);
180 fprintf_filtered (stream
, "%s",
181 longest_to_int (exp
->elts
[pc
+ 1].longconst
)
187 fprintf_filtered (stream
, "$%s",
188 internalvar_name (exp
->elts
[pc
+ 1].internalvar
));
192 case OP_F77_UNDETERMINED_ARGLIST
:
194 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
195 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
196 fputs_filtered (" (", stream
);
197 for (tem
= 0; tem
< nargs
; tem
++)
200 fputs_filtered (", ", stream
);
201 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
203 fputs_filtered (")", stream
);
207 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
208 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
209 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
214 struct value_print_options opts
;
216 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
217 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
218 /* LA_PRINT_STRING will print using the current repeat count threshold.
219 If necessary, we can temporarily set it to zero, or pass it as an
220 additional parameter to LA_PRINT_STRING. -fnf */
221 get_user_print_options (&opts
);
222 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
223 (gdb_byte
*) &exp
->elts
[pc
+ 2].string
, nargs
,
228 case OP_OBJC_NSSTRING
: /* Objective-C Foundation Class
229 NSString constant. */
231 struct value_print_options opts
;
233 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
234 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
235 fputs_filtered ("@\"", stream
);
236 get_user_print_options (&opts
);
237 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
238 (gdb_byte
*) &exp
->elts
[pc
+ 2].string
, nargs
,
240 fputs_filtered ("\"", stream
);
244 case OP_OBJC_MSGCALL
:
245 { /* Objective C message (method) call. */
246 gdb::unique_xmalloc_ptr
<char> selector
;
249 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
250 fprintf_unfiltered (stream
, "[");
251 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
252 if (0 == target_read_string (exp
->elts
[pc
+ 1].longconst
,
253 &selector
, 1024, NULL
))
255 error (_("bad selector"));
263 for (tem
= 0; tem
< nargs
; tem
++)
265 nextS
= strchr (s
, ':');
266 gdb_assert (nextS
); /* Make sure we found ':'. */
268 fprintf_unfiltered (stream
, " %s: ", s
);
270 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
275 fprintf_unfiltered (stream
, " %s", selector
.get ());
277 fprintf_unfiltered (stream
, "]");
283 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
284 nargs
-= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
287 if (exp
->elts
[pc
+ 4].opcode
== OP_LONG
288 && exp
->elts
[pc
+ 5].type
289 == builtin_type (exp
->gdbarch
)->builtin_char
290 && exp
->language_defn
->la_language
== language_c
)
292 /* Attempt to print C character arrays using string syntax.
293 Walk through the args, picking up one character from each
294 of the OP_LONG expression elements. If any array element
295 does not match our expection of what we should find for
296 a simple string, revert back to array printing. Note that
297 the last expression element is an explicit null terminator
298 byte, which doesn't get printed. */
299 tempstr
= (char *) alloca (nargs
);
303 if (exp
->elts
[pc
].opcode
!= OP_LONG
304 || exp
->elts
[pc
+ 1].type
305 != builtin_type (exp
->gdbarch
)->builtin_char
)
307 /* Not a simple array of char, use regular array
315 longest_to_int (exp
->elts
[pc
+ 2].longconst
);
322 struct value_print_options opts
;
324 get_user_print_options (&opts
);
325 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
326 (gdb_byte
*) tempstr
, nargs
- 1, NULL
, 0, &opts
);
331 fputs_filtered (" {", stream
);
332 for (tem
= 0; tem
< nargs
; tem
++)
336 fputs_filtered (", ", stream
);
338 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
340 fputs_filtered ("}", stream
);
345 if ((int) prec
> (int) PREC_COMMA
)
346 fputs_filtered ("(", stream
);
347 /* Print the subexpressions, forcing parentheses
348 around any binary operations within them.
349 This is more parentheses than are strictly necessary,
350 but it looks clearer. */
351 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
352 fputs_filtered (" ? ", stream
);
353 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
354 fputs_filtered (" : ", stream
);
355 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
356 if ((int) prec
> (int) PREC_COMMA
)
357 fputs_filtered (")", stream
);
361 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
362 fputs_filtered ("(", stream
);
363 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
364 fputs_filtered (opcode
== TERNOP_SLICE
? " : " : " UP ", stream
);
365 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
366 fputs_filtered (")", stream
);
369 case STRUCTOP_STRUCT
:
370 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
371 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
372 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
373 fputs_filtered (".", stream
);
374 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
377 /* Will not occur for Modula-2. */
379 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
380 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
381 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
382 fputs_filtered ("->", stream
);
383 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
386 case STRUCTOP_MEMBER
:
387 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
388 fputs_filtered (".*", stream
);
389 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
393 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
394 fputs_filtered ("->*", stream
);
395 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
398 case BINOP_SUBSCRIPT
:
399 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
400 fputs_filtered ("[", stream
);
401 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
402 fputs_filtered ("]", stream
);
405 case UNOP_POSTINCREMENT
:
406 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
407 fputs_filtered ("++", stream
);
410 case UNOP_POSTDECREMENT
:
411 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
412 fputs_filtered ("--", stream
);
417 if ((int) prec
> (int) PREC_PREFIX
)
418 fputs_filtered ("(", stream
);
419 fputs_filtered ("(", stream
);
420 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
421 fputs_filtered (") ", stream
);
422 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
423 if ((int) prec
> (int) PREC_PREFIX
)
424 fputs_filtered (")", stream
);
428 if ((int) prec
> (int) PREC_PREFIX
)
429 fputs_filtered ("(", stream
);
430 fputs_filtered ("(", stream
);
431 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
432 fputs_filtered (") ", stream
);
433 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
434 if ((int) prec
> (int) PREC_PREFIX
)
435 fputs_filtered (")", stream
);
438 case UNOP_DYNAMIC_CAST
:
439 case UNOP_REINTERPRET_CAST
:
440 fputs_filtered (opcode
== UNOP_DYNAMIC_CAST
? "dynamic_cast"
441 : "reinterpret_cast", stream
);
442 fputs_filtered ("<", stream
);
443 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
444 fputs_filtered ("> (", stream
);
445 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
446 fputs_filtered (")", stream
);
451 if ((int) prec
> (int) PREC_PREFIX
)
452 fputs_filtered ("(", stream
);
453 if (TYPE_CODE (exp
->elts
[pc
+ 1].type
) == TYPE_CODE_FUNC
454 && exp
->elts
[pc
+ 3].opcode
== OP_LONG
)
456 struct value_print_options opts
;
458 /* We have a minimal symbol fn, probably. It's encoded
459 as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address).
460 Swallow the OP_LONG (including both its opcodes); ignore
461 its type; print the value in the type of the MEMVAL. */
463 val
= value_at_lazy (exp
->elts
[pc
+ 1].type
,
464 (CORE_ADDR
) exp
->elts
[pc
+ 5].longconst
);
465 get_no_prettyformat_print_options (&opts
);
466 value_print (val
, stream
, &opts
);
470 fputs_filtered ("{", stream
);
471 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
472 fputs_filtered ("} ", stream
);
473 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
475 if ((int) prec
> (int) PREC_PREFIX
)
476 fputs_filtered (")", stream
);
479 case UNOP_MEMVAL_TYPE
:
480 if ((int) prec
> (int) PREC_PREFIX
)
481 fputs_filtered ("(", stream
);
482 fputs_filtered ("{", stream
);
483 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
484 fputs_filtered ("} ", stream
);
485 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
486 if ((int) prec
> (int) PREC_PREFIX
)
487 fputs_filtered (")", stream
);
490 case BINOP_ASSIGN_MODIFY
:
491 opcode
= exp
->elts
[pc
+ 1].opcode
;
493 myprec
= PREC_ASSIGN
;
497 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
498 if (op_print_tab
[tem
].opcode
== opcode
)
500 op_str
= op_print_tab
[tem
].string
;
503 if (op_print_tab
[tem
].opcode
!= opcode
)
504 /* Not found; don't try to keep going because we don't know how
505 to interpret further elements. */
506 error (_("Invalid expression"));
513 if (exp
->language_defn
->la_name_of_this
)
514 fputs_filtered (exp
->language_defn
->la_name_of_this
, stream
);
516 fprintf_filtered (stream
, _("<language %s has no 'this'>"),
517 exp
->language_defn
->la_name
);
522 case MULTI_SUBSCRIPT
:
524 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
525 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
526 fprintf_unfiltered (stream
, " [");
527 for (tem
= 0; tem
< nargs
; tem
++)
530 fprintf_unfiltered (stream
, ", ");
531 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
533 fprintf_unfiltered (stream
, "]");
538 fprintf_unfiltered (stream
, "VAL(");
539 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
540 fprintf_unfiltered (stream
, ",");
541 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
542 fprintf_unfiltered (stream
, ")");
547 type_instance_flags flags
548 = (type_instance_flag_value
) longest_to_int (exp
->elts
[pc
+ 1].longconst
);
549 LONGEST count
= exp
->elts
[pc
+ 2].longconst
;
555 fputs_unfiltered ("TypeInstance(", stream
);
558 type_print (exp
->elts
[(*pos
)++].type
, "", stream
, 0);
560 fputs_unfiltered (",", stream
);
562 fputs_unfiltered (",", stream
);
563 /* Ending COUNT and ending TYPE_INSTANCE. */
565 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
567 if (flags
& TYPE_INSTANCE_FLAG_CONST
)
568 fputs_unfiltered (",const", stream
);
569 if (flags
& TYPE_INSTANCE_FLAG_VOLATILE
)
570 fputs_unfiltered (",volatile", stream
);
572 fputs_unfiltered (")", stream
);
578 enum range_type range_type
;
580 range_type
= (enum range_type
)
581 longest_to_int (exp
->elts
[pc
+ 1].longconst
);
584 if (range_type
== NONE_BOUND_DEFAULT_EXCLUSIVE
585 || range_type
== LOW_BOUND_DEFAULT_EXCLUSIVE
)
586 fputs_filtered ("EXCLUSIVE_", stream
);
587 fputs_filtered ("RANGE(", stream
);
588 if (range_type
== HIGH_BOUND_DEFAULT
589 || range_type
== NONE_BOUND_DEFAULT
590 || range_type
== NONE_BOUND_DEFAULT_EXCLUSIVE
)
591 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
592 fputs_filtered ("..", stream
);
593 if (range_type
== LOW_BOUND_DEFAULT
594 || range_type
== NONE_BOUND_DEFAULT
)
595 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
596 fputs_filtered (")", stream
);
604 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
605 if (op_print_tab
[tem
].opcode
== opcode
)
607 op_str
= op_print_tab
[tem
].string
;
608 myprec
= op_print_tab
[tem
].precedence
;
609 assoc
= op_print_tab
[tem
].right_assoc
;
612 if (op_print_tab
[tem
].opcode
!= opcode
)
613 /* Not found; don't try to keep going because we don't know how
614 to interpret further elements. For example, this happens
615 if opcode is OP_TYPE. */
616 error (_("Invalid expression"));
619 /* Note that PREC_BUILTIN will always emit parentheses. */
620 if ((int) myprec
< (int) prec
)
621 fputs_filtered ("(", stream
);
622 if ((int) opcode
> (int) BINOP_END
)
626 /* Unary postfix operator. */
627 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
628 fputs_filtered (op_str
, stream
);
632 /* Unary prefix operator. */
633 fputs_filtered (op_str
, stream
);
634 if (myprec
== PREC_BUILTIN_FUNCTION
)
635 fputs_filtered ("(", stream
);
636 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
637 if (myprec
== PREC_BUILTIN_FUNCTION
)
638 fputs_filtered (")", stream
);
643 /* Binary operator. */
644 /* Print left operand.
645 If operator is right-associative,
646 increment precedence for this operand. */
647 print_subexp (exp
, pos
, stream
,
648 (enum precedence
) ((int) myprec
+ assoc
));
649 /* Print the operator itself. */
651 fprintf_filtered (stream
, " %s= ", op_str
);
652 else if (op_str
[0] == ',')
653 fprintf_filtered (stream
, "%s ", op_str
);
655 fprintf_filtered (stream
, " %s ", op_str
);
656 /* Print right operand.
657 If operator is left-associative,
658 increment precedence for this operand. */
659 print_subexp (exp
, pos
, stream
,
660 (enum precedence
) ((int) myprec
+ !assoc
));
663 if ((int) myprec
< (int) prec
)
664 fputs_filtered (")", stream
);
667 /* Return the operator corresponding to opcode OP as
668 a string. NULL indicates that the opcode was not found in the
669 current language table. */
671 op_string (enum exp_opcode op
)
674 const struct op_print
*op_print_tab
;
676 op_print_tab
= current_language
->la_op_print_tab
;
677 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
678 if (op_print_tab
[tem
].opcode
== op
)
679 return op_print_tab
[tem
].string
;
683 /* Support for dumping the raw data from expressions in a human readable
686 static int dump_subexp_body (struct expression
*exp
, struct ui_file
*, int);
688 /* Name for OPCODE, when it appears in expression EXP. */
691 op_name (struct expression
*exp
, enum exp_opcode opcode
)
693 if (opcode
>= OP_UNUSED_LAST
)
695 char *cell
= get_print_cell ();
696 xsnprintf (cell
, PRINT_CELL_SIZE
, "unknown opcode: %u",
700 return exp
->language_defn
->la_exp_desc
->op_name (opcode
);
703 /* Default name for the standard operator OPCODE (i.e., one defined in
704 the definition of enum exp_opcode). */
707 op_name_standard (enum exp_opcode opcode
)
715 xsnprintf (buf
, sizeof (buf
), "<unknown %d>", opcode
);
721 #include "std-operator.def"
726 /* Print a raw dump of expression EXP to STREAM.
727 NOTE, if non-NULL, is printed as extra explanatory text. */
730 dump_raw_expression (struct expression
*exp
, struct ui_file
*stream
,
737 fprintf_filtered (stream
, "Dump of expression @ ");
738 gdb_print_host_address (exp
, stream
);
740 fprintf_filtered (stream
, ", %s:", note
);
741 fprintf_filtered (stream
, "\n\tLanguage %s, %d elements, %ld bytes each.\n",
742 exp
->language_defn
->la_name
, exp
->nelts
,
743 (long) sizeof (union exp_element
));
744 fprintf_filtered (stream
, "\t%5s %20s %16s %s\n", "Index", "Opcode",
745 "Hex Value", "String Value");
746 for (elt
= 0; elt
< exp
->nelts
; elt
++)
748 fprintf_filtered (stream
, "\t%5d ", elt
);
750 const char *opcode_name
= op_name (exp
, exp
->elts
[elt
].opcode
);
751 fprintf_filtered (stream
, "%20s ", opcode_name
);
753 print_longest (stream
, 'd', 0, exp
->elts
[elt
].longconst
);
754 fprintf_filtered (stream
, " ");
756 for (eltscan
= (char *) &exp
->elts
[elt
],
757 eltsize
= sizeof (union exp_element
);
761 fprintf_filtered (stream
, "%c",
762 isprint (*eltscan
) ? (*eltscan
& 0xFF) : '.');
764 fprintf_filtered (stream
, "\n");
768 /* Dump the subexpression of prefix expression EXP whose operator is at
769 position ELT onto STREAM. Returns the position of the next
770 subexpression in EXP. */
773 dump_subexp (struct expression
*exp
, struct ui_file
*stream
, int elt
)
775 static int indent
= 0;
778 fprintf_filtered (stream
, "\n");
779 fprintf_filtered (stream
, "\t%5d ", elt
);
781 for (i
= 1; i
<= indent
; i
++)
782 fprintf_filtered (stream
, " ");
785 fprintf_filtered (stream
, "%-20s ", op_name (exp
, exp
->elts
[elt
].opcode
));
787 elt
= dump_subexp_body (exp
, stream
, elt
);
794 /* Dump the operands of prefix expression EXP whose opcode is at
795 position ELT onto STREAM. Returns the position of the next
796 subexpression in EXP. */
799 dump_subexp_body (struct expression
*exp
, struct ui_file
*stream
, int elt
)
801 return exp
->language_defn
->la_exp_desc
->dump_subexp_body (exp
, stream
, elt
);
804 /* Default value for subexp_body in exp_descriptor vector. */
807 dump_subexp_body_standard (struct expression
*exp
,
808 struct ui_file
*stream
, int elt
)
810 int opcode
= exp
->elts
[elt
++].opcode
;
816 elt
= dump_subexp (exp
, stream
, elt
);
826 case BINOP_LOGICAL_AND
:
827 case BINOP_LOGICAL_OR
:
828 case BINOP_BITWISE_AND
:
829 case BINOP_BITWISE_IOR
:
830 case BINOP_BITWISE_XOR
:
840 case BINOP_SUBSCRIPT
:
845 case BINOP_ASSIGN_MODIFY
:
849 case STRUCTOP_MEMBER
:
851 elt
= dump_subexp (exp
, stream
, elt
);
854 case UNOP_LOGICAL_NOT
:
855 case UNOP_COMPLEMENT
:
858 case UNOP_PREINCREMENT
:
859 case UNOP_POSTINCREMENT
:
860 case UNOP_PREDECREMENT
:
861 case UNOP_POSTDECREMENT
:
876 elt
= dump_subexp (exp
, stream
, elt
);
879 fprintf_filtered (stream
, "Type @");
880 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
881 fprintf_filtered (stream
, " (");
882 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
883 fprintf_filtered (stream
, "), value %ld (0x%lx)",
884 (long) exp
->elts
[elt
+ 1].longconst
,
885 (long) exp
->elts
[elt
+ 1].longconst
);
889 fprintf_filtered (stream
, "Type @");
890 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
891 fprintf_filtered (stream
, " (");
892 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
893 fprintf_filtered (stream
, "), value ");
894 print_floating (exp
->elts
[elt
+ 1].floatconst
,
895 exp
->elts
[elt
].type
, stream
);
899 fprintf_filtered (stream
, "Block @");
900 gdb_print_host_address (exp
->elts
[elt
].block
, stream
);
901 fprintf_filtered (stream
, ", symbol @");
902 gdb_print_host_address (exp
->elts
[elt
+ 1].symbol
, stream
);
903 fprintf_filtered (stream
, " (%s)",
904 SYMBOL_PRINT_NAME (exp
->elts
[elt
+ 1].symbol
));
907 case OP_VAR_MSYM_VALUE
:
908 fprintf_filtered (stream
, "Objfile @");
909 gdb_print_host_address (exp
->elts
[elt
].objfile
, stream
);
910 fprintf_filtered (stream
, ", msymbol @");
911 gdb_print_host_address (exp
->elts
[elt
+ 1].msymbol
, stream
);
912 fprintf_filtered (stream
, " (%s)",
913 MSYMBOL_PRINT_NAME (exp
->elts
[elt
+ 1].msymbol
));
916 case OP_VAR_ENTRY_VALUE
:
917 fprintf_filtered (stream
, "Entry value of symbol @");
918 gdb_print_host_address (exp
->elts
[elt
].symbol
, stream
);
919 fprintf_filtered (stream
, " (%s)",
920 SYMBOL_PRINT_NAME (exp
->elts
[elt
].symbol
));
924 fprintf_filtered (stream
, "History element %ld",
925 (long) exp
->elts
[elt
].longconst
);
929 fprintf_filtered (stream
, "Register $%s", &exp
->elts
[elt
+ 1].string
);
930 elt
+= 3 + BYTES_TO_EXP_ELEM (exp
->elts
[elt
].longconst
+ 1);
933 fprintf_filtered (stream
, "Internal var @");
934 gdb_print_host_address (exp
->elts
[elt
].internalvar
, stream
);
935 fprintf_filtered (stream
, " (%s)",
936 internalvar_name (exp
->elts
[elt
].internalvar
));
940 case OP_F77_UNDETERMINED_ARGLIST
:
944 nargs
= longest_to_int (exp
->elts
[elt
].longconst
);
946 fprintf_filtered (stream
, "Number of args: %d", nargs
);
949 for (i
= 1; i
<= nargs
+ 1; i
++)
950 elt
= dump_subexp (exp
, stream
, elt
);
958 lower
= longest_to_int (exp
->elts
[elt
].longconst
);
959 upper
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
961 fprintf_filtered (stream
, "Bounds [%d:%d]", lower
, upper
);
964 for (i
= 1; i
<= upper
- lower
+ 1; i
++)
965 elt
= dump_subexp (exp
, stream
, elt
);
968 case UNOP_DYNAMIC_CAST
:
969 case UNOP_REINTERPRET_CAST
:
971 case UNOP_MEMVAL_TYPE
:
972 fprintf_filtered (stream
, " (");
973 elt
= dump_subexp (exp
, stream
, elt
);
974 fprintf_filtered (stream
, ")");
975 elt
= dump_subexp (exp
, stream
, elt
);
979 fprintf_filtered (stream
, "Type @");
980 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
981 fprintf_filtered (stream
, " (");
982 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
983 fprintf_filtered (stream
, ")");
984 elt
= dump_subexp (exp
, stream
, elt
+ 2);
987 fprintf_filtered (stream
, "Type @");
988 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
989 fprintf_filtered (stream
, " (");
990 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
991 fprintf_filtered (stream
, ")");
996 fprintf_filtered (stream
, "Typeof (");
997 elt
= dump_subexp (exp
, stream
, elt
);
998 fprintf_filtered (stream
, ")");
1001 fprintf_filtered (stream
, "typeid (");
1002 elt
= dump_subexp (exp
, stream
, elt
);
1003 fprintf_filtered (stream
, ")");
1005 case STRUCTOP_STRUCT
:
1011 len
= longest_to_int (exp
->elts
[elt
].longconst
);
1012 elem_name
= &exp
->elts
[elt
+ 1].string
;
1014 fprintf_filtered (stream
, "Element name: `%.*s'", len
, elem_name
);
1015 elt
= dump_subexp (exp
, stream
, elt
+ 3 + BYTES_TO_EXP_ELEM (len
+ 1));
1023 fprintf_filtered (stream
, "Type @");
1024 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1025 fprintf_filtered (stream
, " (");
1026 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1027 fprintf_filtered (stream
, ") ");
1029 len
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
1030 elem_name
= &exp
->elts
[elt
+ 2].string
;
1032 fprintf_filtered (stream
, "Field name: `%.*s'", len
, elem_name
);
1033 elt
+= 4 + BYTES_TO_EXP_ELEM (len
+ 1);
1037 case OP_FUNC_STATIC_VAR
:
1039 int len
= longest_to_int (exp
->elts
[elt
].longconst
);
1040 const char *var_name
= &exp
->elts
[elt
+ 1].string
;
1041 fprintf_filtered (stream
, "Field name: `%.*s'", len
, var_name
);
1042 elt
+= 3 + BYTES_TO_EXP_ELEM (len
+ 1);
1048 type_instance_flags flags
1049 = (type_instance_flag_value
) longest_to_int (exp
->elts
[elt
++].longconst
);
1050 LONGEST len
= exp
->elts
[elt
++].longconst
;
1051 fprintf_filtered (stream
, "%s TypeInstance: ", plongest (len
));
1054 fprintf_filtered (stream
, "Type @");
1055 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1056 fprintf_filtered (stream
, " (");
1057 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1058 fprintf_filtered (stream
, ")");
1061 fputs_filtered (", ", stream
);
1064 fprintf_filtered (stream
, " Flags: %s (", hex_string (flags
));
1066 auto print_one
= [&] (const char *mod
)
1069 fputs_filtered (" ", stream
);
1071 fprintf_filtered (stream
, "%s", mod
);
1073 if (flags
& TYPE_INSTANCE_FLAG_CONST
)
1074 print_one ("const");
1075 if (flags
& TYPE_INSTANCE_FLAG_VOLATILE
)
1076 print_one ("volatile");
1077 fprintf_filtered (stream
, ")");
1079 /* Ending LEN and ending TYPE_INSTANCE. */
1081 elt
= dump_subexp (exp
, stream
, elt
);
1086 LONGEST len
= exp
->elts
[elt
].longconst
;
1087 LONGEST type
= exp
->elts
[elt
+ 1].longconst
;
1089 fprintf_filtered (stream
, "Language-specific string type: %s",
1095 /* Skip string content. */
1096 elt
+= BYTES_TO_EXP_ELEM (len
);
1098 /* Skip length and ending OP_STRING. */
1104 enum range_type range_type
;
1106 range_type
= (enum range_type
)
1107 longest_to_int (exp
->elts
[elt
].longconst
);
1112 case BOTH_BOUND_DEFAULT
:
1113 fputs_filtered ("Range '..'", stream
);
1115 case LOW_BOUND_DEFAULT
:
1116 fputs_filtered ("Range '..EXP'", stream
);
1118 case LOW_BOUND_DEFAULT_EXCLUSIVE
:
1119 fputs_filtered ("ExclusiveRange '..EXP'", stream
);
1121 case HIGH_BOUND_DEFAULT
:
1122 fputs_filtered ("Range 'EXP..'", stream
);
1124 case NONE_BOUND_DEFAULT
:
1125 fputs_filtered ("Range 'EXP..EXP'", stream
);
1127 case NONE_BOUND_DEFAULT_EXCLUSIVE
:
1128 fputs_filtered ("ExclusiveRange 'EXP..EXP'", stream
);
1131 fputs_filtered ("Invalid Range!", stream
);
1135 if (range_type
== HIGH_BOUND_DEFAULT
1136 || range_type
== NONE_BOUND_DEFAULT
)
1137 elt
= dump_subexp (exp
, stream
, elt
);
1138 if (range_type
== LOW_BOUND_DEFAULT
1139 || range_type
== NONE_BOUND_DEFAULT
)
1140 elt
= dump_subexp (exp
, stream
, elt
);
1146 case MULTI_SUBSCRIPT
:
1152 fprintf_filtered (stream
, "Unknown format");
1159 dump_prefix_expression (struct expression
*exp
, struct ui_file
*stream
)
1163 fprintf_filtered (stream
, "Dump of expression @ ");
1164 gdb_print_host_address (exp
, stream
);
1165 fputs_filtered (", after conversion to prefix form:\nExpression: `", stream
);
1166 print_expression (exp
, stream
);
1167 fprintf_filtered (stream
, "'\n\tLanguage %s, %d elements, %ld bytes each.\n",
1168 exp
->language_defn
->la_name
, exp
->nelts
,
1169 (long) sizeof (union exp_element
));
1170 fputs_filtered ("\n", stream
);
1172 for (elt
= 0; elt
< exp
->nelts
;)
1173 elt
= dump_subexp (exp
, stream
, elt
);
1174 fputs_filtered ("\n", stream
);