1 /* Print in infix form a struct expression.
3 Copyright (C) 1986-2020 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
->expression_ops ()->print_subexp (exp
, pos
, stream
,
57 /* Standard implementation of print_subexp for use in language_defn
60 print_subexp_standard (struct expression
*exp
, int *pos
,
61 struct ui_file
*stream
, enum precedence prec
)
64 const struct op_print
*op_print_tab
;
68 int assign_modify
= 0;
69 enum exp_opcode opcode
;
70 enum precedence myprec
= PREC_NULL
;
71 /* Set to 1 for a right-associative operator. */
76 op_print_tab
= exp
->language_defn
->opcode_print_table ();
78 opcode
= exp
->elts
[pc
].opcode
;
85 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
91 fputs_filtered (exp
->elts
[pc
+ 1].type
->name (), stream
);
92 fputs_filtered ("::", stream
);
93 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
94 (*pos
) += 4 + BYTES_TO_EXP_ELEM (nargs
+ 1);
95 fputs_filtered (&exp
->elts
[pc
+ 3].string
, stream
);
100 struct value_print_options opts
;
102 get_no_prettyformat_print_options (&opts
);
104 value_print (value_from_longest (exp
->elts
[pc
+ 1].type
,
105 exp
->elts
[pc
+ 2].longconst
),
112 struct value_print_options opts
;
114 get_no_prettyformat_print_options (&opts
);
116 value_print (value_from_contents (exp
->elts
[pc
+ 1].type
,
117 exp
->elts
[pc
+ 2].floatconst
),
124 const struct block
*b
;
127 b
= exp
->elts
[pc
+ 1].block
;
129 && BLOCK_FUNCTION (b
) != NULL
130 && BLOCK_FUNCTION (b
)->print_name () != NULL
)
132 fputs_filtered (BLOCK_FUNCTION (b
)->print_name (), stream
);
133 fputs_filtered ("::", stream
);
135 fputs_filtered (exp
->elts
[pc
+ 2].symbol
->print_name (), stream
);
139 case OP_VAR_MSYM_VALUE
:
142 fputs_filtered (exp
->elts
[pc
+ 2].msymbol
->print_name (), stream
);
146 case OP_FUNC_STATIC_VAR
:
148 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
149 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
150 fputs_filtered (&exp
->elts
[pc
+ 1].string
, stream
);
154 case OP_VAR_ENTRY_VALUE
:
157 fprintf_filtered (stream
, "%s@entry",
158 exp
->elts
[pc
+ 1].symbol
->print_name ());
164 fprintf_filtered (stream
, "$%d",
165 longest_to_int (exp
->elts
[pc
+ 1].longconst
));
170 const char *name
= &exp
->elts
[pc
+ 2].string
;
172 (*pos
) += 3 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
173 fprintf_filtered (stream
, "$%s", name
);
179 fprintf_filtered (stream
, "%s",
180 longest_to_int (exp
->elts
[pc
+ 1].longconst
)
186 fprintf_filtered (stream
, "$%s",
187 internalvar_name (exp
->elts
[pc
+ 1].internalvar
));
191 case OP_F77_UNDETERMINED_ARGLIST
:
193 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
194 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
195 fputs_filtered (" (", stream
);
196 for (tem
= 0; tem
< nargs
; tem
++)
199 fputs_filtered (", ", stream
);
200 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
202 fputs_filtered (")", stream
);
206 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
207 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
208 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
213 struct value_print_options opts
;
215 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
216 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
217 /* LA_PRINT_STRING will print using the current repeat count threshold.
218 If necessary, we can temporarily set it to zero, or pass it as an
219 additional parameter to LA_PRINT_STRING. -fnf */
220 get_user_print_options (&opts
);
221 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
222 (gdb_byte
*) &exp
->elts
[pc
+ 2].string
, nargs
,
227 case OP_OBJC_NSSTRING
: /* Objective-C Foundation Class
228 NSString constant. */
230 struct value_print_options opts
;
232 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
233 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
234 fputs_filtered ("@\"", stream
);
235 get_user_print_options (&opts
);
236 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
237 (gdb_byte
*) &exp
->elts
[pc
+ 2].string
, nargs
,
239 fputs_filtered ("\"", stream
);
243 case OP_OBJC_MSGCALL
:
244 { /* Objective C message (method) call. */
246 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
247 fprintf_unfiltered (stream
, "[");
248 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
249 gdb::unique_xmalloc_ptr
<char> selector
250 = target_read_string (exp
->elts
[pc
+ 1].longconst
, 1024);
251 if (selector
== nullptr)
252 error (_("bad selector"));
258 for (tem
= 0; tem
< nargs
; tem
++)
260 nextS
= strchr (s
, ':');
261 gdb_assert (nextS
); /* Make sure we found ':'. */
263 fprintf_unfiltered (stream
, " %s: ", s
);
265 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
270 fprintf_unfiltered (stream
, " %s", selector
.get ());
272 fprintf_unfiltered (stream
, "]");
278 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
279 nargs
-= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
282 if (exp
->elts
[pc
+ 4].opcode
== OP_LONG
283 && exp
->elts
[pc
+ 5].type
284 == builtin_type (exp
->gdbarch
)->builtin_char
285 && exp
->language_defn
->la_language
== language_c
)
287 /* Attempt to print C character arrays using string syntax.
288 Walk through the args, picking up one character from each
289 of the OP_LONG expression elements. If any array element
290 does not match our expection of what we should find for
291 a simple string, revert back to array printing. Note that
292 the last expression element is an explicit null terminator
293 byte, which doesn't get printed. */
294 tempstr
= (char *) alloca (nargs
);
298 if (exp
->elts
[pc
].opcode
!= OP_LONG
299 || exp
->elts
[pc
+ 1].type
300 != builtin_type (exp
->gdbarch
)->builtin_char
)
302 /* Not a simple array of char, use regular array
310 longest_to_int (exp
->elts
[pc
+ 2].longconst
);
317 struct value_print_options opts
;
319 get_user_print_options (&opts
);
320 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
321 (gdb_byte
*) tempstr
, nargs
- 1, NULL
, 0, &opts
);
326 fputs_filtered (" {", stream
);
327 for (tem
= 0; tem
< nargs
; tem
++)
331 fputs_filtered (", ", stream
);
333 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
335 fputs_filtered ("}", stream
);
340 if ((int) prec
> (int) PREC_COMMA
)
341 fputs_filtered ("(", stream
);
342 /* Print the subexpressions, forcing parentheses
343 around any binary operations within them.
344 This is more parentheses than are strictly necessary,
345 but it looks clearer. */
346 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
347 fputs_filtered (" ? ", stream
);
348 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
349 fputs_filtered (" : ", stream
);
350 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
351 if ((int) prec
> (int) PREC_COMMA
)
352 fputs_filtered (")", stream
);
356 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
357 fputs_filtered ("(", stream
);
358 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
359 fputs_filtered (opcode
== TERNOP_SLICE
? " : " : " UP ", stream
);
360 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
361 fputs_filtered (")", stream
);
364 case STRUCTOP_STRUCT
:
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
);
372 /* Will not occur for Modula-2. */
374 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
375 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
376 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
377 fputs_filtered ("->", stream
);
378 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
381 case STRUCTOP_MEMBER
:
382 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
383 fputs_filtered (".*", stream
);
384 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
388 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
389 fputs_filtered ("->*", stream
);
390 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
393 case BINOP_SUBSCRIPT
:
394 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
395 fputs_filtered ("[", stream
);
396 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
397 fputs_filtered ("]", stream
);
400 case UNOP_POSTINCREMENT
:
401 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
402 fputs_filtered ("++", stream
);
405 case UNOP_POSTDECREMENT
:
406 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
407 fputs_filtered ("--", stream
);
412 if ((int) prec
> (int) PREC_PREFIX
)
413 fputs_filtered ("(", stream
);
414 fputs_filtered ("(", stream
);
415 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
416 fputs_filtered (") ", stream
);
417 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
418 if ((int) prec
> (int) PREC_PREFIX
)
419 fputs_filtered (")", stream
);
423 if ((int) prec
> (int) PREC_PREFIX
)
424 fputs_filtered ("(", stream
);
425 fputs_filtered ("(", stream
);
426 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
427 fputs_filtered (") ", stream
);
428 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
429 if ((int) prec
> (int) PREC_PREFIX
)
430 fputs_filtered (")", stream
);
433 case UNOP_DYNAMIC_CAST
:
434 case UNOP_REINTERPRET_CAST
:
435 fputs_filtered (opcode
== UNOP_DYNAMIC_CAST
? "dynamic_cast"
436 : "reinterpret_cast", stream
);
437 fputs_filtered ("<", stream
);
438 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
439 fputs_filtered ("> (", stream
);
440 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
441 fputs_filtered (")", stream
);
446 if ((int) prec
> (int) PREC_PREFIX
)
447 fputs_filtered ("(", stream
);
448 if (exp
->elts
[pc
+ 1].type
->code () == TYPE_CODE_FUNC
449 && exp
->elts
[pc
+ 3].opcode
== OP_LONG
)
451 struct value_print_options opts
;
453 /* We have a minimal symbol fn, probably. It's encoded
454 as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address).
455 Swallow the OP_LONG (including both its opcodes); ignore
456 its type; print the value in the type of the MEMVAL. */
458 val
= value_at_lazy (exp
->elts
[pc
+ 1].type
,
459 (CORE_ADDR
) exp
->elts
[pc
+ 5].longconst
);
460 get_no_prettyformat_print_options (&opts
);
461 value_print (val
, stream
, &opts
);
465 fputs_filtered ("{", stream
);
466 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
467 fputs_filtered ("} ", stream
);
468 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
470 if ((int) prec
> (int) PREC_PREFIX
)
471 fputs_filtered (")", stream
);
474 case UNOP_MEMVAL_TYPE
:
475 if ((int) prec
> (int) PREC_PREFIX
)
476 fputs_filtered ("(", stream
);
477 fputs_filtered ("{", stream
);
478 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
479 fputs_filtered ("} ", stream
);
480 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
481 if ((int) prec
> (int) PREC_PREFIX
)
482 fputs_filtered (")", stream
);
485 case BINOP_ASSIGN_MODIFY
:
486 opcode
= exp
->elts
[pc
+ 1].opcode
;
488 myprec
= PREC_ASSIGN
;
492 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
493 if (op_print_tab
[tem
].opcode
== opcode
)
495 op_str
= op_print_tab
[tem
].string
;
498 if (op_print_tab
[tem
].opcode
!= opcode
)
499 /* Not found; don't try to keep going because we don't know how
500 to interpret further elements. */
501 error (_("Invalid expression"));
508 if (exp
->language_defn
->name_of_this () != NULL
)
509 fputs_filtered (exp
->language_defn
->name_of_this (), stream
);
511 fprintf_styled (stream
, metadata_style
.style (),
512 _("<language %s has no 'this'>"),
513 exp
->language_defn
->name ());
518 case MULTI_SUBSCRIPT
:
520 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
521 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
522 fprintf_unfiltered (stream
, " [");
523 for (tem
= 0; tem
< nargs
; tem
++)
526 fprintf_unfiltered (stream
, ", ");
527 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
529 fprintf_unfiltered (stream
, "]");
534 fprintf_unfiltered (stream
, "VAL(");
535 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
536 fprintf_unfiltered (stream
, ",");
537 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
538 fprintf_unfiltered (stream
, ")");
543 type_instance_flags flags
544 = (type_instance_flag_value
) longest_to_int (exp
->elts
[pc
+ 1].longconst
);
545 LONGEST count
= exp
->elts
[pc
+ 2].longconst
;
551 fputs_unfiltered ("TypeInstance(", stream
);
554 type_print (exp
->elts
[(*pos
)++].type
, "", stream
, 0);
556 fputs_unfiltered (",", stream
);
558 fputs_unfiltered (",", stream
);
559 /* Ending COUNT and ending TYPE_INSTANCE. */
561 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
563 if (flags
& TYPE_INSTANCE_FLAG_CONST
)
564 fputs_unfiltered (",const", stream
);
565 if (flags
& TYPE_INSTANCE_FLAG_VOLATILE
)
566 fputs_unfiltered (",volatile", stream
);
568 fputs_unfiltered (")", stream
);
574 enum range_type range_type
;
576 range_type
= (enum range_type
)
577 longest_to_int (exp
->elts
[pc
+ 1].longconst
);
580 if (range_type
== NONE_BOUND_DEFAULT_EXCLUSIVE
581 || range_type
== LOW_BOUND_DEFAULT_EXCLUSIVE
)
582 fputs_filtered ("EXCLUSIVE_", stream
);
583 fputs_filtered ("RANGE(", stream
);
584 if (range_type
== HIGH_BOUND_DEFAULT
585 || range_type
== NONE_BOUND_DEFAULT
586 || range_type
== NONE_BOUND_DEFAULT_EXCLUSIVE
)
587 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
588 fputs_filtered ("..", stream
);
589 if (range_type
== LOW_BOUND_DEFAULT
590 || range_type
== NONE_BOUND_DEFAULT
)
591 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
592 fputs_filtered (")", stream
);
600 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
601 if (op_print_tab
[tem
].opcode
== opcode
)
603 op_str
= op_print_tab
[tem
].string
;
604 myprec
= op_print_tab
[tem
].precedence
;
605 assoc
= op_print_tab
[tem
].right_assoc
;
608 if (op_print_tab
[tem
].opcode
!= opcode
)
609 /* Not found; don't try to keep going because we don't know how
610 to interpret further elements. For example, this happens
611 if opcode is OP_TYPE. */
612 error (_("Invalid expression"));
615 /* Note that PREC_BUILTIN will always emit parentheses. */
616 if ((int) myprec
< (int) prec
)
617 fputs_filtered ("(", stream
);
618 if ((int) opcode
> (int) BINOP_END
)
622 /* Unary postfix operator. */
623 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
624 fputs_filtered (op_str
, stream
);
628 /* Unary prefix operator. */
629 fputs_filtered (op_str
, stream
);
630 if (myprec
== PREC_BUILTIN_FUNCTION
)
631 fputs_filtered ("(", stream
);
632 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
633 if (myprec
== PREC_BUILTIN_FUNCTION
)
634 fputs_filtered (")", stream
);
639 /* Binary operator. */
640 /* Print left operand.
641 If operator is right-associative,
642 increment precedence for this operand. */
643 print_subexp (exp
, pos
, stream
,
644 (enum precedence
) ((int) myprec
+ assoc
));
645 /* Print the operator itself. */
647 fprintf_filtered (stream
, " %s= ", op_str
);
648 else if (op_str
[0] == ',')
649 fprintf_filtered (stream
, "%s ", op_str
);
651 fprintf_filtered (stream
, " %s ", op_str
);
652 /* Print right operand.
653 If operator is left-associative,
654 increment precedence for this operand. */
655 print_subexp (exp
, pos
, stream
,
656 (enum precedence
) ((int) myprec
+ !assoc
));
659 if ((int) myprec
< (int) prec
)
660 fputs_filtered (")", stream
);
663 /* Return the operator corresponding to opcode OP as
664 a string. NULL indicates that the opcode was not found in the
665 current language table. */
667 op_string (enum exp_opcode op
)
670 const struct op_print
*op_print_tab
;
672 op_print_tab
= current_language
->opcode_print_table ();
673 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
674 if (op_print_tab
[tem
].opcode
== op
)
675 return op_print_tab
[tem
].string
;
679 /* Support for dumping the raw data from expressions in a human readable
682 static int dump_subexp_body (struct expression
*exp
, struct ui_file
*, int);
684 /* Name for OPCODE, when it appears in expression EXP. */
687 op_name (struct expression
*exp
, enum exp_opcode opcode
)
689 if (opcode
>= OP_UNUSED_LAST
)
691 char *cell
= get_print_cell ();
692 xsnprintf (cell
, PRINT_CELL_SIZE
, "unknown opcode: %u",
696 return exp
->language_defn
->expression_ops ()->op_name (opcode
);
699 /* Default name for the standard operator OPCODE (i.e., one defined in
700 the definition of enum exp_opcode). */
703 op_name_standard (enum exp_opcode opcode
)
711 xsnprintf (buf
, sizeof (buf
), "<unknown %d>", opcode
);
717 #include "std-operator.def"
722 /* Print a raw dump of expression EXP to STREAM.
723 NOTE, if non-NULL, is printed as extra explanatory text. */
726 dump_raw_expression (struct expression
*exp
, struct ui_file
*stream
,
733 fprintf_filtered (stream
, "Dump of expression @ ");
734 gdb_print_host_address (exp
, stream
);
736 fprintf_filtered (stream
, ", %s:", note
);
737 fprintf_filtered (stream
, "\n\tLanguage %s, %d elements, %ld bytes each.\n",
738 exp
->language_defn
->name (), exp
->nelts
,
739 (long) sizeof (union exp_element
));
740 fprintf_filtered (stream
, "\t%5s %20s %16s %s\n", "Index", "Opcode",
741 "Hex Value", "String Value");
742 for (elt
= 0; elt
< exp
->nelts
; elt
++)
744 fprintf_filtered (stream
, "\t%5d ", elt
);
746 const char *opcode_name
= op_name (exp
, exp
->elts
[elt
].opcode
);
747 fprintf_filtered (stream
, "%20s ", opcode_name
);
749 print_longest (stream
, 'd', 0, exp
->elts
[elt
].longconst
);
750 fprintf_filtered (stream
, " ");
752 for (eltscan
= (char *) &exp
->elts
[elt
],
753 eltsize
= sizeof (union exp_element
);
757 fprintf_filtered (stream
, "%c",
758 isprint (*eltscan
) ? (*eltscan
& 0xFF) : '.');
760 fprintf_filtered (stream
, "\n");
764 /* Dump the subexpression of prefix expression EXP whose operator is at
765 position ELT onto STREAM. Returns the position of the next
766 subexpression in EXP. */
769 dump_subexp (struct expression
*exp
, struct ui_file
*stream
, int elt
)
771 static int indent
= 0;
774 fprintf_filtered (stream
, "\n");
775 fprintf_filtered (stream
, "\t%5d ", elt
);
777 for (i
= 1; i
<= indent
; i
++)
778 fprintf_filtered (stream
, " ");
781 fprintf_filtered (stream
, "%-20s ", op_name (exp
, exp
->elts
[elt
].opcode
));
783 elt
= dump_subexp_body (exp
, stream
, elt
);
790 /* Dump the operands of prefix expression EXP whose opcode is at
791 position ELT onto STREAM. Returns the position of the next
792 subexpression in EXP. */
795 dump_subexp_body (struct expression
*exp
, struct ui_file
*stream
, int elt
)
797 return exp
->language_defn
->expression_ops ()->dump_subexp_body (exp
, stream
,
801 /* Default value for subexp_body in exp_descriptor vector. */
804 dump_subexp_body_standard (struct expression
*exp
,
805 struct ui_file
*stream
, int elt
)
807 int opcode
= exp
->elts
[elt
++].opcode
;
813 elt
= dump_subexp (exp
, stream
, elt
);
823 case BINOP_LOGICAL_AND
:
824 case BINOP_LOGICAL_OR
:
825 case BINOP_BITWISE_AND
:
826 case BINOP_BITWISE_IOR
:
827 case BINOP_BITWISE_XOR
:
837 case BINOP_SUBSCRIPT
:
842 case BINOP_ASSIGN_MODIFY
:
846 case STRUCTOP_MEMBER
:
848 elt
= dump_subexp (exp
, stream
, elt
);
851 case UNOP_LOGICAL_NOT
:
852 case UNOP_COMPLEMENT
:
855 case UNOP_PREINCREMENT
:
856 case UNOP_POSTINCREMENT
:
857 case UNOP_PREDECREMENT
:
858 case UNOP_POSTDECREMENT
:
872 elt
= dump_subexp (exp
, stream
, elt
);
875 fprintf_filtered (stream
, "Type @");
876 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
877 fprintf_filtered (stream
, " (");
878 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
879 fprintf_filtered (stream
, "), value %ld (0x%lx)",
880 (long) exp
->elts
[elt
+ 1].longconst
,
881 (long) exp
->elts
[elt
+ 1].longconst
);
885 fprintf_filtered (stream
, "Type @");
886 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
887 fprintf_filtered (stream
, " (");
888 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
889 fprintf_filtered (stream
, "), value ");
890 print_floating (exp
->elts
[elt
+ 1].floatconst
,
891 exp
->elts
[elt
].type
, stream
);
895 fprintf_filtered (stream
, "Block @");
896 gdb_print_host_address (exp
->elts
[elt
].block
, stream
);
897 fprintf_filtered (stream
, ", symbol @");
898 gdb_print_host_address (exp
->elts
[elt
+ 1].symbol
, stream
);
899 fprintf_filtered (stream
, " (%s)",
900 exp
->elts
[elt
+ 1].symbol
->print_name ());
903 case OP_VAR_MSYM_VALUE
:
904 fprintf_filtered (stream
, "Objfile @");
905 gdb_print_host_address (exp
->elts
[elt
].objfile
, stream
);
906 fprintf_filtered (stream
, ", msymbol @");
907 gdb_print_host_address (exp
->elts
[elt
+ 1].msymbol
, stream
);
908 fprintf_filtered (stream
, " (%s)",
909 exp
->elts
[elt
+ 1].msymbol
->print_name ());
912 case OP_VAR_ENTRY_VALUE
:
913 fprintf_filtered (stream
, "Entry value of symbol @");
914 gdb_print_host_address (exp
->elts
[elt
].symbol
, stream
);
915 fprintf_filtered (stream
, " (%s)",
916 exp
->elts
[elt
].symbol
->print_name ());
920 fprintf_filtered (stream
, "History element %ld",
921 (long) exp
->elts
[elt
].longconst
);
925 fprintf_filtered (stream
, "Register $%s", &exp
->elts
[elt
+ 1].string
);
926 elt
+= 3 + BYTES_TO_EXP_ELEM (exp
->elts
[elt
].longconst
+ 1);
929 fprintf_filtered (stream
, "Internal var @");
930 gdb_print_host_address (exp
->elts
[elt
].internalvar
, stream
);
931 fprintf_filtered (stream
, " (%s)",
932 internalvar_name (exp
->elts
[elt
].internalvar
));
936 case OP_F77_UNDETERMINED_ARGLIST
:
940 nargs
= longest_to_int (exp
->elts
[elt
].longconst
);
942 fprintf_filtered (stream
, "Number of args: %d", nargs
);
945 for (i
= 1; i
<= nargs
+ 1; i
++)
946 elt
= dump_subexp (exp
, stream
, elt
);
954 lower
= longest_to_int (exp
->elts
[elt
].longconst
);
955 upper
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
957 fprintf_filtered (stream
, "Bounds [%d:%d]", lower
, upper
);
960 for (i
= 1; i
<= upper
- lower
+ 1; i
++)
961 elt
= dump_subexp (exp
, stream
, elt
);
964 case UNOP_DYNAMIC_CAST
:
965 case UNOP_REINTERPRET_CAST
:
967 case UNOP_MEMVAL_TYPE
:
968 fprintf_filtered (stream
, " (");
969 elt
= dump_subexp (exp
, stream
, elt
);
970 fprintf_filtered (stream
, ")");
971 elt
= dump_subexp (exp
, stream
, elt
);
975 fprintf_filtered (stream
, "Type @");
976 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
977 fprintf_filtered (stream
, " (");
978 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
979 fprintf_filtered (stream
, ")");
980 elt
= dump_subexp (exp
, stream
, elt
+ 2);
983 fprintf_filtered (stream
, "Type @");
984 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
985 fprintf_filtered (stream
, " (");
986 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
987 fprintf_filtered (stream
, ")");
992 fprintf_filtered (stream
, "Typeof (");
993 elt
= dump_subexp (exp
, stream
, elt
);
994 fprintf_filtered (stream
, ")");
997 fprintf_filtered (stream
, "typeid (");
998 elt
= dump_subexp (exp
, stream
, elt
);
999 fprintf_filtered (stream
, ")");
1001 case STRUCTOP_STRUCT
:
1007 len
= longest_to_int (exp
->elts
[elt
].longconst
);
1008 elem_name
= &exp
->elts
[elt
+ 1].string
;
1010 fprintf_filtered (stream
, "Element name: `%.*s'", len
, elem_name
);
1011 elt
= dump_subexp (exp
, stream
, elt
+ 3 + BYTES_TO_EXP_ELEM (len
+ 1));
1019 fprintf_filtered (stream
, "Type @");
1020 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1021 fprintf_filtered (stream
, " (");
1022 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1023 fprintf_filtered (stream
, ") ");
1025 len
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
1026 elem_name
= &exp
->elts
[elt
+ 2].string
;
1028 fprintf_filtered (stream
, "Field name: `%.*s'", len
, elem_name
);
1029 elt
+= 4 + BYTES_TO_EXP_ELEM (len
+ 1);
1033 case OP_FUNC_STATIC_VAR
:
1035 int len
= longest_to_int (exp
->elts
[elt
].longconst
);
1036 const char *var_name
= &exp
->elts
[elt
+ 1].string
;
1037 fprintf_filtered (stream
, "Field name: `%.*s'", len
, var_name
);
1038 elt
+= 3 + BYTES_TO_EXP_ELEM (len
+ 1);
1044 type_instance_flags flags
1045 = (type_instance_flag_value
) longest_to_int (exp
->elts
[elt
++].longconst
);
1046 LONGEST len
= exp
->elts
[elt
++].longconst
;
1047 fprintf_filtered (stream
, "%s TypeInstance: ", plongest (len
));
1050 fprintf_filtered (stream
, "Type @");
1051 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1052 fprintf_filtered (stream
, " (");
1053 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1054 fprintf_filtered (stream
, ")");
1057 fputs_filtered (", ", stream
);
1060 fprintf_filtered (stream
, " Flags: %s (", hex_string (flags
));
1062 auto print_one
= [&] (const char *mod
)
1065 fputs_filtered (" ", stream
);
1067 fprintf_filtered (stream
, "%s", mod
);
1069 if (flags
& TYPE_INSTANCE_FLAG_CONST
)
1070 print_one ("const");
1071 if (flags
& TYPE_INSTANCE_FLAG_VOLATILE
)
1072 print_one ("volatile");
1073 fprintf_filtered (stream
, ")");
1075 /* Ending LEN and ending TYPE_INSTANCE. */
1077 elt
= dump_subexp (exp
, stream
, elt
);
1082 LONGEST len
= exp
->elts
[elt
].longconst
;
1083 LONGEST type
= exp
->elts
[elt
+ 1].longconst
;
1085 fprintf_filtered (stream
, "Language-specific string type: %s",
1091 /* Skip string content. */
1092 elt
+= BYTES_TO_EXP_ELEM (len
);
1094 /* Skip length and ending OP_STRING. */
1100 enum range_type range_type
;
1102 range_type
= (enum range_type
)
1103 longest_to_int (exp
->elts
[elt
].longconst
);
1108 case BOTH_BOUND_DEFAULT
:
1109 fputs_filtered ("Range '..'", stream
);
1111 case LOW_BOUND_DEFAULT
:
1112 fputs_filtered ("Range '..EXP'", stream
);
1114 case LOW_BOUND_DEFAULT_EXCLUSIVE
:
1115 fputs_filtered ("ExclusiveRange '..EXP'", stream
);
1117 case HIGH_BOUND_DEFAULT
:
1118 fputs_filtered ("Range 'EXP..'", stream
);
1120 case NONE_BOUND_DEFAULT
:
1121 fputs_filtered ("Range 'EXP..EXP'", stream
);
1123 case NONE_BOUND_DEFAULT_EXCLUSIVE
:
1124 fputs_filtered ("ExclusiveRange 'EXP..EXP'", stream
);
1127 fputs_filtered ("Invalid Range!", stream
);
1131 if (range_type
== HIGH_BOUND_DEFAULT
1132 || range_type
== NONE_BOUND_DEFAULT
)
1133 elt
= dump_subexp (exp
, stream
, elt
);
1134 if (range_type
== LOW_BOUND_DEFAULT
1135 || range_type
== NONE_BOUND_DEFAULT
)
1136 elt
= dump_subexp (exp
, stream
, elt
);
1142 case MULTI_SUBSCRIPT
:
1148 fprintf_filtered (stream
, "Unknown format");
1155 dump_prefix_expression (struct expression
*exp
, struct ui_file
*stream
)
1159 fprintf_filtered (stream
, "Dump of expression @ ");
1160 gdb_print_host_address (exp
, stream
);
1161 fputs_filtered (", after conversion to prefix form:\nExpression: `", stream
);
1162 print_expression (exp
, stream
);
1163 fprintf_filtered (stream
, "'\n\tLanguage %s, %d elements, %ld bytes each.\n",
1164 exp
->language_defn
->name (), exp
->nelts
,
1165 (long) sizeof (union exp_element
));
1166 fputs_filtered ("\n", stream
);
1168 for (elt
= 0; elt
< exp
->nelts
;)
1169 elt
= dump_subexp (exp
, stream
, elt
);
1170 fputs_filtered ("\n", stream
);