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/>. */
23 #include "expression.h"
26 #include "parser-defs.h"
27 #include "user-regs.h" /* For user_reg_map_regnum_to_name. */
32 #include "cli/cli-style.h"
37 print_expression (struct expression
*exp
, struct ui_file
*stream
)
41 print_subexp (exp
, &pc
, stream
, PREC_NULL
);
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. */
50 print_subexp (struct expression
*exp
, int *pos
,
51 struct ui_file
*stream
, enum precedence prec
)
53 exp
->language_defn
->la_exp_desc
->print_subexp (exp
, pos
, stream
, prec
);
56 /* Standard implementation of print_subexp for use in language_defn
59 print_subexp_standard (struct expression
*exp
, int *pos
,
60 struct ui_file
*stream
, enum precedence prec
)
63 const struct op_print
*op_print_tab
;
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. */
75 op_print_tab
= exp
->language_defn
->la_op_print_tab
;
77 opcode
= exp
->elts
[pc
].opcode
;
84 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
90 fputs_filtered (TYPE_NAME (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
);
99 struct value_print_options opts
;
101 get_no_prettyformat_print_options (&opts
);
103 value_print (value_from_longest (exp
->elts
[pc
+ 1].type
,
104 exp
->elts
[pc
+ 2].longconst
),
111 struct value_print_options opts
;
113 get_no_prettyformat_print_options (&opts
);
115 value_print (value_from_contents (exp
->elts
[pc
+ 1].type
,
116 exp
->elts
[pc
+ 2].floatconst
),
123 const struct block
*b
;
126 b
= exp
->elts
[pc
+ 1].block
;
128 && BLOCK_FUNCTION (b
) != NULL
129 && BLOCK_FUNCTION (b
)->print_name () != NULL
)
131 fputs_filtered (BLOCK_FUNCTION (b
)->print_name (), stream
);
132 fputs_filtered ("::", stream
);
134 fputs_filtered (exp
->elts
[pc
+ 2].symbol
->print_name (), stream
);
138 case OP_VAR_MSYM_VALUE
:
141 fputs_filtered (exp
->elts
[pc
+ 2].msymbol
->print_name (), stream
);
145 case OP_FUNC_STATIC_VAR
:
147 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
148 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
149 fputs_filtered (&exp
->elts
[pc
+ 1].string
, stream
);
153 case OP_VAR_ENTRY_VALUE
:
156 fprintf_filtered (stream
, "%s@entry",
157 exp
->elts
[pc
+ 1].symbol
->print_name ());
163 fprintf_filtered (stream
, "$%d",
164 longest_to_int (exp
->elts
[pc
+ 1].longconst
));
169 const char *name
= &exp
->elts
[pc
+ 2].string
;
171 (*pos
) += 3 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
172 fprintf_filtered (stream
, "$%s", name
);
178 fprintf_filtered (stream
, "%s",
179 longest_to_int (exp
->elts
[pc
+ 1].longconst
)
185 fprintf_filtered (stream
, "$%s",
186 internalvar_name (exp
->elts
[pc
+ 1].internalvar
));
190 case OP_F77_UNDETERMINED_ARGLIST
:
192 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
193 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
194 fputs_filtered (" (", stream
);
195 for (tem
= 0; tem
< nargs
; tem
++)
198 fputs_filtered (", ", stream
);
199 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
201 fputs_filtered (")", stream
);
205 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
206 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
207 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
212 struct value_print_options opts
;
214 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
215 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
216 /* LA_PRINT_STRING will print using the current repeat count threshold.
217 If necessary, we can temporarily set it to zero, or pass it as an
218 additional parameter to LA_PRINT_STRING. -fnf */
219 get_user_print_options (&opts
);
220 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
221 (gdb_byte
*) &exp
->elts
[pc
+ 2].string
, nargs
,
226 case OP_OBJC_NSSTRING
: /* Objective-C Foundation Class
227 NSString constant. */
229 struct value_print_options opts
;
231 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
232 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
233 fputs_filtered ("@\"", stream
);
234 get_user_print_options (&opts
);
235 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
236 (gdb_byte
*) &exp
->elts
[pc
+ 2].string
, nargs
,
238 fputs_filtered ("\"", stream
);
242 case OP_OBJC_MSGCALL
:
243 { /* Objective C message (method) call. */
244 gdb::unique_xmalloc_ptr
<char> selector
;
247 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
248 fprintf_unfiltered (stream
, "[");
249 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
250 if (0 == target_read_string (exp
->elts
[pc
+ 1].longconst
,
251 &selector
, 1024, NULL
))
253 error (_("bad selector"));
261 for (tem
= 0; tem
< nargs
; tem
++)
263 nextS
= strchr (s
, ':');
264 gdb_assert (nextS
); /* Make sure we found ':'. */
266 fprintf_unfiltered (stream
, " %s: ", s
);
268 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
273 fprintf_unfiltered (stream
, " %s", selector
.get ());
275 fprintf_unfiltered (stream
, "]");
281 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
282 nargs
-= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
285 if (exp
->elts
[pc
+ 4].opcode
== OP_LONG
286 && exp
->elts
[pc
+ 5].type
287 == builtin_type (exp
->gdbarch
)->builtin_char
288 && exp
->language_defn
->la_language
== language_c
)
290 /* Attempt to print C character arrays using string syntax.
291 Walk through the args, picking up one character from each
292 of the OP_LONG expression elements. If any array element
293 does not match our expection of what we should find for
294 a simple string, revert back to array printing. Note that
295 the last expression element is an explicit null terminator
296 byte, which doesn't get printed. */
297 tempstr
= (char *) alloca (nargs
);
301 if (exp
->elts
[pc
].opcode
!= OP_LONG
302 || exp
->elts
[pc
+ 1].type
303 != builtin_type (exp
->gdbarch
)->builtin_char
)
305 /* Not a simple array of char, use regular array
313 longest_to_int (exp
->elts
[pc
+ 2].longconst
);
320 struct value_print_options opts
;
322 get_user_print_options (&opts
);
323 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
324 (gdb_byte
*) tempstr
, nargs
- 1, NULL
, 0, &opts
);
329 fputs_filtered (" {", stream
);
330 for (tem
= 0; tem
< nargs
; tem
++)
334 fputs_filtered (", ", stream
);
336 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
338 fputs_filtered ("}", stream
);
343 if ((int) prec
> (int) PREC_COMMA
)
344 fputs_filtered ("(", stream
);
345 /* Print the subexpressions, forcing parentheses
346 around any binary operations within them.
347 This is more parentheses than are strictly necessary,
348 but it looks clearer. */
349 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
350 fputs_filtered (" ? ", stream
);
351 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
352 fputs_filtered (" : ", stream
);
353 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
354 if ((int) prec
> (int) PREC_COMMA
)
355 fputs_filtered (")", stream
);
359 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
360 fputs_filtered ("(", stream
);
361 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
362 fputs_filtered (opcode
== TERNOP_SLICE
? " : " : " UP ", stream
);
363 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
364 fputs_filtered (")", stream
);
367 case STRUCTOP_STRUCT
:
368 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
369 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
370 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
371 fputs_filtered (".", stream
);
372 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
375 /* Will not occur for Modula-2. */
377 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
378 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
379 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
380 fputs_filtered ("->", stream
);
381 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
384 case STRUCTOP_MEMBER
:
385 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
386 fputs_filtered (".*", stream
);
387 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
391 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
392 fputs_filtered ("->*", stream
);
393 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
396 case BINOP_SUBSCRIPT
:
397 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
398 fputs_filtered ("[", stream
);
399 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
400 fputs_filtered ("]", stream
);
403 case UNOP_POSTINCREMENT
:
404 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
405 fputs_filtered ("++", stream
);
408 case UNOP_POSTDECREMENT
:
409 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
410 fputs_filtered ("--", stream
);
415 if ((int) prec
> (int) PREC_PREFIX
)
416 fputs_filtered ("(", stream
);
417 fputs_filtered ("(", stream
);
418 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
419 fputs_filtered (") ", stream
);
420 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
421 if ((int) prec
> (int) PREC_PREFIX
)
422 fputs_filtered (")", stream
);
426 if ((int) prec
> (int) PREC_PREFIX
)
427 fputs_filtered ("(", stream
);
428 fputs_filtered ("(", stream
);
429 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
430 fputs_filtered (") ", stream
);
431 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
432 if ((int) prec
> (int) PREC_PREFIX
)
433 fputs_filtered (")", stream
);
436 case UNOP_DYNAMIC_CAST
:
437 case UNOP_REINTERPRET_CAST
:
438 fputs_filtered (opcode
== UNOP_DYNAMIC_CAST
? "dynamic_cast"
439 : "reinterpret_cast", stream
);
440 fputs_filtered ("<", stream
);
441 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
442 fputs_filtered ("> (", stream
);
443 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
444 fputs_filtered (")", stream
);
449 if ((int) prec
> (int) PREC_PREFIX
)
450 fputs_filtered ("(", stream
);
451 if (TYPE_CODE (exp
->elts
[pc
+ 1].type
) == TYPE_CODE_FUNC
452 && exp
->elts
[pc
+ 3].opcode
== OP_LONG
)
454 struct value_print_options opts
;
456 /* We have a minimal symbol fn, probably. It's encoded
457 as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address).
458 Swallow the OP_LONG (including both its opcodes); ignore
459 its type; print the value in the type of the MEMVAL. */
461 val
= value_at_lazy (exp
->elts
[pc
+ 1].type
,
462 (CORE_ADDR
) exp
->elts
[pc
+ 5].longconst
);
463 get_no_prettyformat_print_options (&opts
);
464 value_print (val
, stream
, &opts
);
468 fputs_filtered ("{", stream
);
469 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
470 fputs_filtered ("} ", stream
);
471 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
473 if ((int) prec
> (int) PREC_PREFIX
)
474 fputs_filtered (")", stream
);
477 case UNOP_MEMVAL_TYPE
:
478 if ((int) prec
> (int) PREC_PREFIX
)
479 fputs_filtered ("(", stream
);
480 fputs_filtered ("{", stream
);
481 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
482 fputs_filtered ("} ", stream
);
483 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
484 if ((int) prec
> (int) PREC_PREFIX
)
485 fputs_filtered (")", stream
);
488 case BINOP_ASSIGN_MODIFY
:
489 opcode
= exp
->elts
[pc
+ 1].opcode
;
491 myprec
= PREC_ASSIGN
;
495 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
496 if (op_print_tab
[tem
].opcode
== opcode
)
498 op_str
= op_print_tab
[tem
].string
;
501 if (op_print_tab
[tem
].opcode
!= opcode
)
502 /* Not found; don't try to keep going because we don't know how
503 to interpret further elements. */
504 error (_("Invalid expression"));
511 if (exp
->language_defn
->la_name_of_this
)
512 fputs_filtered (exp
->language_defn
->la_name_of_this
, stream
);
514 fprintf_styled (stream
, metadata_style
.style (),
515 _("<language %s has no 'this'>"),
516 exp
->language_defn
->la_name
);
521 case MULTI_SUBSCRIPT
:
523 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
524 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
525 fprintf_unfiltered (stream
, " [");
526 for (tem
= 0; tem
< nargs
; tem
++)
529 fprintf_unfiltered (stream
, ", ");
530 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
532 fprintf_unfiltered (stream
, "]");
537 fprintf_unfiltered (stream
, "VAL(");
538 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
539 fprintf_unfiltered (stream
, ",");
540 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
541 fprintf_unfiltered (stream
, ")");
546 type_instance_flags flags
547 = (type_instance_flag_value
) longest_to_int (exp
->elts
[pc
+ 1].longconst
);
548 LONGEST count
= exp
->elts
[pc
+ 2].longconst
;
554 fputs_unfiltered ("TypeInstance(", stream
);
557 type_print (exp
->elts
[(*pos
)++].type
, "", stream
, 0);
559 fputs_unfiltered (",", stream
);
561 fputs_unfiltered (",", stream
);
562 /* Ending COUNT and ending TYPE_INSTANCE. */
564 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
566 if (flags
& TYPE_INSTANCE_FLAG_CONST
)
567 fputs_unfiltered (",const", stream
);
568 if (flags
& TYPE_INSTANCE_FLAG_VOLATILE
)
569 fputs_unfiltered (",volatile", stream
);
571 fputs_unfiltered (")", stream
);
577 enum range_type range_type
;
579 range_type
= (enum range_type
)
580 longest_to_int (exp
->elts
[pc
+ 1].longconst
);
583 if (range_type
== NONE_BOUND_DEFAULT_EXCLUSIVE
584 || range_type
== LOW_BOUND_DEFAULT_EXCLUSIVE
)
585 fputs_filtered ("EXCLUSIVE_", stream
);
586 fputs_filtered ("RANGE(", stream
);
587 if (range_type
== HIGH_BOUND_DEFAULT
588 || range_type
== NONE_BOUND_DEFAULT
589 || range_type
== NONE_BOUND_DEFAULT_EXCLUSIVE
)
590 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
591 fputs_filtered ("..", stream
);
592 if (range_type
== LOW_BOUND_DEFAULT
593 || range_type
== NONE_BOUND_DEFAULT
)
594 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
595 fputs_filtered (")", stream
);
603 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
604 if (op_print_tab
[tem
].opcode
== opcode
)
606 op_str
= op_print_tab
[tem
].string
;
607 myprec
= op_print_tab
[tem
].precedence
;
608 assoc
= op_print_tab
[tem
].right_assoc
;
611 if (op_print_tab
[tem
].opcode
!= opcode
)
612 /* Not found; don't try to keep going because we don't know how
613 to interpret further elements. For example, this happens
614 if opcode is OP_TYPE. */
615 error (_("Invalid expression"));
618 /* Note that PREC_BUILTIN will always emit parentheses. */
619 if ((int) myprec
< (int) prec
)
620 fputs_filtered ("(", stream
);
621 if ((int) opcode
> (int) BINOP_END
)
625 /* Unary postfix operator. */
626 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
627 fputs_filtered (op_str
, stream
);
631 /* Unary prefix operator. */
632 fputs_filtered (op_str
, stream
);
633 if (myprec
== PREC_BUILTIN_FUNCTION
)
634 fputs_filtered ("(", stream
);
635 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
636 if (myprec
== PREC_BUILTIN_FUNCTION
)
637 fputs_filtered (")", stream
);
642 /* Binary operator. */
643 /* Print left operand.
644 If operator is right-associative,
645 increment precedence for this operand. */
646 print_subexp (exp
, pos
, stream
,
647 (enum precedence
) ((int) myprec
+ assoc
));
648 /* Print the operator itself. */
650 fprintf_filtered (stream
, " %s= ", op_str
);
651 else if (op_str
[0] == ',')
652 fprintf_filtered (stream
, "%s ", op_str
);
654 fprintf_filtered (stream
, " %s ", op_str
);
655 /* Print right operand.
656 If operator is left-associative,
657 increment precedence for this operand. */
658 print_subexp (exp
, pos
, stream
,
659 (enum precedence
) ((int) myprec
+ !assoc
));
662 if ((int) myprec
< (int) prec
)
663 fputs_filtered (")", stream
);
666 /* Return the operator corresponding to opcode OP as
667 a string. NULL indicates that the opcode was not found in the
668 current language table. */
670 op_string (enum exp_opcode op
)
673 const struct op_print
*op_print_tab
;
675 op_print_tab
= current_language
->la_op_print_tab
;
676 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
677 if (op_print_tab
[tem
].opcode
== op
)
678 return op_print_tab
[tem
].string
;
682 /* Support for dumping the raw data from expressions in a human readable
685 static int dump_subexp_body (struct expression
*exp
, struct ui_file
*, int);
687 /* Name for OPCODE, when it appears in expression EXP. */
690 op_name (struct expression
*exp
, enum exp_opcode opcode
)
692 if (opcode
>= OP_UNUSED_LAST
)
694 char *cell
= get_print_cell ();
695 xsnprintf (cell
, PRINT_CELL_SIZE
, "unknown opcode: %u",
699 return exp
->language_defn
->la_exp_desc
->op_name (opcode
);
702 /* Default name for the standard operator OPCODE (i.e., one defined in
703 the definition of enum exp_opcode). */
706 op_name_standard (enum exp_opcode opcode
)
714 xsnprintf (buf
, sizeof (buf
), "<unknown %d>", opcode
);
720 #include "std-operator.def"
725 /* Print a raw dump of expression EXP to STREAM.
726 NOTE, if non-NULL, is printed as extra explanatory text. */
729 dump_raw_expression (struct expression
*exp
, struct ui_file
*stream
,
736 fprintf_filtered (stream
, "Dump of expression @ ");
737 gdb_print_host_address (exp
, stream
);
739 fprintf_filtered (stream
, ", %s:", note
);
740 fprintf_filtered (stream
, "\n\tLanguage %s, %d elements, %ld bytes each.\n",
741 exp
->language_defn
->la_name
, exp
->nelts
,
742 (long) sizeof (union exp_element
));
743 fprintf_filtered (stream
, "\t%5s %20s %16s %s\n", "Index", "Opcode",
744 "Hex Value", "String Value");
745 for (elt
= 0; elt
< exp
->nelts
; elt
++)
747 fprintf_filtered (stream
, "\t%5d ", elt
);
749 const char *opcode_name
= op_name (exp
, exp
->elts
[elt
].opcode
);
750 fprintf_filtered (stream
, "%20s ", opcode_name
);
752 print_longest (stream
, 'd', 0, exp
->elts
[elt
].longconst
);
753 fprintf_filtered (stream
, " ");
755 for (eltscan
= (char *) &exp
->elts
[elt
],
756 eltsize
= sizeof (union exp_element
);
760 fprintf_filtered (stream
, "%c",
761 isprint (*eltscan
) ? (*eltscan
& 0xFF) : '.');
763 fprintf_filtered (stream
, "\n");
767 /* Dump the subexpression of prefix expression EXP whose operator is at
768 position ELT onto STREAM. Returns the position of the next
769 subexpression in EXP. */
772 dump_subexp (struct expression
*exp
, struct ui_file
*stream
, int elt
)
774 static int indent
= 0;
777 fprintf_filtered (stream
, "\n");
778 fprintf_filtered (stream
, "\t%5d ", elt
);
780 for (i
= 1; i
<= indent
; i
++)
781 fprintf_filtered (stream
, " ");
784 fprintf_filtered (stream
, "%-20s ", op_name (exp
, exp
->elts
[elt
].opcode
));
786 elt
= dump_subexp_body (exp
, stream
, elt
);
793 /* Dump the operands of prefix expression EXP whose opcode is at
794 position ELT onto STREAM. Returns the position of the next
795 subexpression in EXP. */
798 dump_subexp_body (struct expression
*exp
, struct ui_file
*stream
, int elt
)
800 return exp
->language_defn
->la_exp_desc
->dump_subexp_body (exp
, stream
, elt
);
803 /* Default value for subexp_body in exp_descriptor vector. */
806 dump_subexp_body_standard (struct expression
*exp
,
807 struct ui_file
*stream
, int elt
)
809 int opcode
= exp
->elts
[elt
++].opcode
;
815 elt
= dump_subexp (exp
, stream
, elt
);
825 case BINOP_LOGICAL_AND
:
826 case BINOP_LOGICAL_OR
:
827 case BINOP_BITWISE_AND
:
828 case BINOP_BITWISE_IOR
:
829 case BINOP_BITWISE_XOR
:
839 case BINOP_SUBSCRIPT
:
844 case BINOP_ASSIGN_MODIFY
:
848 case STRUCTOP_MEMBER
:
850 elt
= dump_subexp (exp
, stream
, elt
);
853 case UNOP_LOGICAL_NOT
:
854 case UNOP_COMPLEMENT
:
857 case UNOP_PREINCREMENT
:
858 case UNOP_POSTINCREMENT
:
859 case UNOP_PREDECREMENT
:
860 case UNOP_POSTDECREMENT
:
874 elt
= dump_subexp (exp
, stream
, elt
);
877 fprintf_filtered (stream
, "Type @");
878 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
879 fprintf_filtered (stream
, " (");
880 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
881 fprintf_filtered (stream
, "), value %ld (0x%lx)",
882 (long) exp
->elts
[elt
+ 1].longconst
,
883 (long) exp
->elts
[elt
+ 1].longconst
);
887 fprintf_filtered (stream
, "Type @");
888 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
889 fprintf_filtered (stream
, " (");
890 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
891 fprintf_filtered (stream
, "), value ");
892 print_floating (exp
->elts
[elt
+ 1].floatconst
,
893 exp
->elts
[elt
].type
, stream
);
897 fprintf_filtered (stream
, "Block @");
898 gdb_print_host_address (exp
->elts
[elt
].block
, stream
);
899 fprintf_filtered (stream
, ", symbol @");
900 gdb_print_host_address (exp
->elts
[elt
+ 1].symbol
, stream
);
901 fprintf_filtered (stream
, " (%s)",
902 exp
->elts
[elt
+ 1].symbol
->print_name ());
905 case OP_VAR_MSYM_VALUE
:
906 fprintf_filtered (stream
, "Objfile @");
907 gdb_print_host_address (exp
->elts
[elt
].objfile
, stream
);
908 fprintf_filtered (stream
, ", msymbol @");
909 gdb_print_host_address (exp
->elts
[elt
+ 1].msymbol
, stream
);
910 fprintf_filtered (stream
, " (%s)",
911 exp
->elts
[elt
+ 1].msymbol
->print_name ());
914 case OP_VAR_ENTRY_VALUE
:
915 fprintf_filtered (stream
, "Entry value of symbol @");
916 gdb_print_host_address (exp
->elts
[elt
].symbol
, stream
);
917 fprintf_filtered (stream
, " (%s)",
918 exp
->elts
[elt
].symbol
->print_name ());
922 fprintf_filtered (stream
, "History element %ld",
923 (long) exp
->elts
[elt
].longconst
);
927 fprintf_filtered (stream
, "Register $%s", &exp
->elts
[elt
+ 1].string
);
928 elt
+= 3 + BYTES_TO_EXP_ELEM (exp
->elts
[elt
].longconst
+ 1);
931 fprintf_filtered (stream
, "Internal var @");
932 gdb_print_host_address (exp
->elts
[elt
].internalvar
, stream
);
933 fprintf_filtered (stream
, " (%s)",
934 internalvar_name (exp
->elts
[elt
].internalvar
));
938 case OP_F77_UNDETERMINED_ARGLIST
:
942 nargs
= longest_to_int (exp
->elts
[elt
].longconst
);
944 fprintf_filtered (stream
, "Number of args: %d", nargs
);
947 for (i
= 1; i
<= nargs
+ 1; i
++)
948 elt
= dump_subexp (exp
, stream
, elt
);
956 lower
= longest_to_int (exp
->elts
[elt
].longconst
);
957 upper
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
959 fprintf_filtered (stream
, "Bounds [%d:%d]", lower
, upper
);
962 for (i
= 1; i
<= upper
- lower
+ 1; i
++)
963 elt
= dump_subexp (exp
, stream
, elt
);
966 case UNOP_DYNAMIC_CAST
:
967 case UNOP_REINTERPRET_CAST
:
969 case UNOP_MEMVAL_TYPE
:
970 fprintf_filtered (stream
, " (");
971 elt
= dump_subexp (exp
, stream
, elt
);
972 fprintf_filtered (stream
, ")");
973 elt
= dump_subexp (exp
, stream
, elt
);
977 fprintf_filtered (stream
, "Type @");
978 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
979 fprintf_filtered (stream
, " (");
980 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
981 fprintf_filtered (stream
, ")");
982 elt
= dump_subexp (exp
, stream
, elt
+ 2);
985 fprintf_filtered (stream
, "Type @");
986 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
987 fprintf_filtered (stream
, " (");
988 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
989 fprintf_filtered (stream
, ")");
994 fprintf_filtered (stream
, "Typeof (");
995 elt
= dump_subexp (exp
, stream
, elt
);
996 fprintf_filtered (stream
, ")");
999 fprintf_filtered (stream
, "typeid (");
1000 elt
= dump_subexp (exp
, stream
, elt
);
1001 fprintf_filtered (stream
, ")");
1003 case STRUCTOP_STRUCT
:
1009 len
= longest_to_int (exp
->elts
[elt
].longconst
);
1010 elem_name
= &exp
->elts
[elt
+ 1].string
;
1012 fprintf_filtered (stream
, "Element name: `%.*s'", len
, elem_name
);
1013 elt
= dump_subexp (exp
, stream
, elt
+ 3 + BYTES_TO_EXP_ELEM (len
+ 1));
1021 fprintf_filtered (stream
, "Type @");
1022 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1023 fprintf_filtered (stream
, " (");
1024 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1025 fprintf_filtered (stream
, ") ");
1027 len
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
1028 elem_name
= &exp
->elts
[elt
+ 2].string
;
1030 fprintf_filtered (stream
, "Field name: `%.*s'", len
, elem_name
);
1031 elt
+= 4 + BYTES_TO_EXP_ELEM (len
+ 1);
1035 case OP_FUNC_STATIC_VAR
:
1037 int len
= longest_to_int (exp
->elts
[elt
].longconst
);
1038 const char *var_name
= &exp
->elts
[elt
+ 1].string
;
1039 fprintf_filtered (stream
, "Field name: `%.*s'", len
, var_name
);
1040 elt
+= 3 + BYTES_TO_EXP_ELEM (len
+ 1);
1046 type_instance_flags flags
1047 = (type_instance_flag_value
) longest_to_int (exp
->elts
[elt
++].longconst
);
1048 LONGEST len
= exp
->elts
[elt
++].longconst
;
1049 fprintf_filtered (stream
, "%s TypeInstance: ", plongest (len
));
1052 fprintf_filtered (stream
, "Type @");
1053 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1054 fprintf_filtered (stream
, " (");
1055 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1056 fprintf_filtered (stream
, ")");
1059 fputs_filtered (", ", stream
);
1062 fprintf_filtered (stream
, " Flags: %s (", hex_string (flags
));
1064 auto print_one
= [&] (const char *mod
)
1067 fputs_filtered (" ", stream
);
1069 fprintf_filtered (stream
, "%s", mod
);
1071 if (flags
& TYPE_INSTANCE_FLAG_CONST
)
1072 print_one ("const");
1073 if (flags
& TYPE_INSTANCE_FLAG_VOLATILE
)
1074 print_one ("volatile");
1075 fprintf_filtered (stream
, ")");
1077 /* Ending LEN and ending TYPE_INSTANCE. */
1079 elt
= dump_subexp (exp
, stream
, elt
);
1084 LONGEST len
= exp
->elts
[elt
].longconst
;
1085 LONGEST type
= exp
->elts
[elt
+ 1].longconst
;
1087 fprintf_filtered (stream
, "Language-specific string type: %s",
1093 /* Skip string content. */
1094 elt
+= BYTES_TO_EXP_ELEM (len
);
1096 /* Skip length and ending OP_STRING. */
1102 enum range_type range_type
;
1104 range_type
= (enum range_type
)
1105 longest_to_int (exp
->elts
[elt
].longconst
);
1110 case BOTH_BOUND_DEFAULT
:
1111 fputs_filtered ("Range '..'", stream
);
1113 case LOW_BOUND_DEFAULT
:
1114 fputs_filtered ("Range '..EXP'", stream
);
1116 case LOW_BOUND_DEFAULT_EXCLUSIVE
:
1117 fputs_filtered ("ExclusiveRange '..EXP'", stream
);
1119 case HIGH_BOUND_DEFAULT
:
1120 fputs_filtered ("Range 'EXP..'", stream
);
1122 case NONE_BOUND_DEFAULT
:
1123 fputs_filtered ("Range 'EXP..EXP'", stream
);
1125 case NONE_BOUND_DEFAULT_EXCLUSIVE
:
1126 fputs_filtered ("ExclusiveRange 'EXP..EXP'", stream
);
1129 fputs_filtered ("Invalid Range!", stream
);
1133 if (range_type
== HIGH_BOUND_DEFAULT
1134 || range_type
== NONE_BOUND_DEFAULT
)
1135 elt
= dump_subexp (exp
, stream
, elt
);
1136 if (range_type
== LOW_BOUND_DEFAULT
1137 || range_type
== NONE_BOUND_DEFAULT
)
1138 elt
= dump_subexp (exp
, stream
, elt
);
1144 case MULTI_SUBSCRIPT
:
1150 fprintf_filtered (stream
, "Unknown format");
1157 dump_prefix_expression (struct expression
*exp
, struct ui_file
*stream
)
1161 fprintf_filtered (stream
, "Dump of expression @ ");
1162 gdb_print_host_address (exp
, stream
);
1163 fputs_filtered (", after conversion to prefix form:\nExpression: `", stream
);
1164 print_expression (exp
, stream
);
1165 fprintf_filtered (stream
, "'\n\tLanguage %s, %d elements, %ld bytes each.\n",
1166 exp
->language_defn
->la_name
, exp
->nelts
,
1167 (long) sizeof (union exp_element
));
1168 fputs_filtered ("\n", stream
);
1170 for (elt
= 0; elt
< exp
->nelts
;)
1171 elt
= dump_subexp (exp
, stream
, elt
);
1172 fputs_filtered ("\n", stream
);