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
->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 (exp
->elts
[pc
+ 1].type
->name (), 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. */
245 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
246 fprintf_unfiltered (stream
, "[");
247 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
248 gdb::unique_xmalloc_ptr
<char> selector
249 = target_read_string (exp
->elts
[pc
+ 1].longconst
, 1024);
250 if (selector
== nullptr)
251 error (_("bad selector"));
257 for (tem
= 0; tem
< nargs
; tem
++)
259 nextS
= strchr (s
, ':');
260 gdb_assert (nextS
); /* Make sure we found ':'. */
262 fprintf_unfiltered (stream
, " %s: ", s
);
264 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
269 fprintf_unfiltered (stream
, " %s", selector
.get ());
271 fprintf_unfiltered (stream
, "]");
277 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
278 nargs
-= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
281 if (exp
->elts
[pc
+ 4].opcode
== OP_LONG
282 && exp
->elts
[pc
+ 5].type
283 == builtin_type (exp
->gdbarch
)->builtin_char
284 && exp
->language_defn
->la_language
== language_c
)
286 /* Attempt to print C character arrays using string syntax.
287 Walk through the args, picking up one character from each
288 of the OP_LONG expression elements. If any array element
289 does not match our expection of what we should find for
290 a simple string, revert back to array printing. Note that
291 the last expression element is an explicit null terminator
292 byte, which doesn't get printed. */
293 tempstr
= (char *) alloca (nargs
);
297 if (exp
->elts
[pc
].opcode
!= OP_LONG
298 || exp
->elts
[pc
+ 1].type
299 != builtin_type (exp
->gdbarch
)->builtin_char
)
301 /* Not a simple array of char, use regular array
309 longest_to_int (exp
->elts
[pc
+ 2].longconst
);
316 struct value_print_options opts
;
318 get_user_print_options (&opts
);
319 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
320 (gdb_byte
*) tempstr
, nargs
- 1, NULL
, 0, &opts
);
325 fputs_filtered (" {", stream
);
326 for (tem
= 0; tem
< nargs
; tem
++)
330 fputs_filtered (", ", stream
);
332 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
334 fputs_filtered ("}", stream
);
339 if ((int) prec
> (int) PREC_COMMA
)
340 fputs_filtered ("(", stream
);
341 /* Print the subexpressions, forcing parentheses
342 around any binary operations within them.
343 This is more parentheses than are strictly necessary,
344 but it looks clearer. */
345 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
346 fputs_filtered (" ? ", stream
);
347 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
348 fputs_filtered (" : ", stream
);
349 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
350 if ((int) prec
> (int) PREC_COMMA
)
351 fputs_filtered (")", stream
);
355 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
356 fputs_filtered ("(", stream
);
357 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
358 fputs_filtered (opcode
== TERNOP_SLICE
? " : " : " UP ", stream
);
359 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
360 fputs_filtered (")", stream
);
363 case STRUCTOP_STRUCT
:
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
);
371 /* Will not occur for Modula-2. */
373 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
374 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
375 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
376 fputs_filtered ("->", stream
);
377 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
380 case STRUCTOP_MEMBER
:
381 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
382 fputs_filtered (".*", stream
);
383 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
387 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
388 fputs_filtered ("->*", stream
);
389 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
392 case BINOP_SUBSCRIPT
:
393 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
394 fputs_filtered ("[", stream
);
395 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
396 fputs_filtered ("]", stream
);
399 case UNOP_POSTINCREMENT
:
400 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
401 fputs_filtered ("++", stream
);
404 case UNOP_POSTDECREMENT
:
405 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
406 fputs_filtered ("--", stream
);
411 if ((int) prec
> (int) PREC_PREFIX
)
412 fputs_filtered ("(", stream
);
413 fputs_filtered ("(", stream
);
414 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
415 fputs_filtered (") ", stream
);
416 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
417 if ((int) prec
> (int) PREC_PREFIX
)
418 fputs_filtered (")", stream
);
422 if ((int) prec
> (int) PREC_PREFIX
)
423 fputs_filtered ("(", stream
);
424 fputs_filtered ("(", stream
);
425 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
426 fputs_filtered (") ", stream
);
427 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
428 if ((int) prec
> (int) PREC_PREFIX
)
429 fputs_filtered (")", stream
);
432 case UNOP_DYNAMIC_CAST
:
433 case UNOP_REINTERPRET_CAST
:
434 fputs_filtered (opcode
== UNOP_DYNAMIC_CAST
? "dynamic_cast"
435 : "reinterpret_cast", stream
);
436 fputs_filtered ("<", stream
);
437 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
438 fputs_filtered ("> (", stream
);
439 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
440 fputs_filtered (")", stream
);
445 if ((int) prec
> (int) PREC_PREFIX
)
446 fputs_filtered ("(", stream
);
447 if (exp
->elts
[pc
+ 1].type
->code () == TYPE_CODE_FUNC
448 && exp
->elts
[pc
+ 3].opcode
== OP_LONG
)
450 struct value_print_options opts
;
452 /* We have a minimal symbol fn, probably. It's encoded
453 as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address).
454 Swallow the OP_LONG (including both its opcodes); ignore
455 its type; print the value in the type of the MEMVAL. */
457 val
= value_at_lazy (exp
->elts
[pc
+ 1].type
,
458 (CORE_ADDR
) exp
->elts
[pc
+ 5].longconst
);
459 get_no_prettyformat_print_options (&opts
);
460 value_print (val
, stream
, &opts
);
464 fputs_filtered ("{", stream
);
465 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
466 fputs_filtered ("} ", stream
);
467 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
469 if ((int) prec
> (int) PREC_PREFIX
)
470 fputs_filtered (")", stream
);
473 case UNOP_MEMVAL_TYPE
:
474 if ((int) prec
> (int) PREC_PREFIX
)
475 fputs_filtered ("(", stream
);
476 fputs_filtered ("{", stream
);
477 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
478 fputs_filtered ("} ", stream
);
479 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
480 if ((int) prec
> (int) PREC_PREFIX
)
481 fputs_filtered (")", stream
);
484 case BINOP_ASSIGN_MODIFY
:
485 opcode
= exp
->elts
[pc
+ 1].opcode
;
487 myprec
= PREC_ASSIGN
;
491 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
492 if (op_print_tab
[tem
].opcode
== opcode
)
494 op_str
= op_print_tab
[tem
].string
;
497 if (op_print_tab
[tem
].opcode
!= opcode
)
498 /* Not found; don't try to keep going because we don't know how
499 to interpret further elements. */
500 error (_("Invalid expression"));
507 if (exp
->language_defn
->la_name_of_this
)
508 fputs_filtered (exp
->language_defn
->la_name_of_this
, stream
);
510 fprintf_styled (stream
, metadata_style
.style (),
511 _("<language %s has no 'this'>"),
512 exp
->language_defn
->la_name
);
517 case MULTI_SUBSCRIPT
:
519 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
520 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
521 fprintf_unfiltered (stream
, " [");
522 for (tem
= 0; tem
< nargs
; tem
++)
525 fprintf_unfiltered (stream
, ", ");
526 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
528 fprintf_unfiltered (stream
, "]");
533 fprintf_unfiltered (stream
, "VAL(");
534 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
535 fprintf_unfiltered (stream
, ",");
536 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
537 fprintf_unfiltered (stream
, ")");
542 type_instance_flags flags
543 = (type_instance_flag_value
) longest_to_int (exp
->elts
[pc
+ 1].longconst
);
544 LONGEST count
= exp
->elts
[pc
+ 2].longconst
;
550 fputs_unfiltered ("TypeInstance(", stream
);
553 type_print (exp
->elts
[(*pos
)++].type
, "", stream
, 0);
555 fputs_unfiltered (",", stream
);
557 fputs_unfiltered (",", stream
);
558 /* Ending COUNT and ending TYPE_INSTANCE. */
560 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
562 if (flags
& TYPE_INSTANCE_FLAG_CONST
)
563 fputs_unfiltered (",const", stream
);
564 if (flags
& TYPE_INSTANCE_FLAG_VOLATILE
)
565 fputs_unfiltered (",volatile", stream
);
567 fputs_unfiltered (")", stream
);
573 enum range_type range_type
;
575 range_type
= (enum range_type
)
576 longest_to_int (exp
->elts
[pc
+ 1].longconst
);
579 if (range_type
== NONE_BOUND_DEFAULT_EXCLUSIVE
580 || range_type
== LOW_BOUND_DEFAULT_EXCLUSIVE
)
581 fputs_filtered ("EXCLUSIVE_", stream
);
582 fputs_filtered ("RANGE(", stream
);
583 if (range_type
== HIGH_BOUND_DEFAULT
584 || range_type
== NONE_BOUND_DEFAULT
585 || range_type
== NONE_BOUND_DEFAULT_EXCLUSIVE
)
586 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
587 fputs_filtered ("..", stream
);
588 if (range_type
== LOW_BOUND_DEFAULT
589 || range_type
== NONE_BOUND_DEFAULT
)
590 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
591 fputs_filtered (")", stream
);
599 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
600 if (op_print_tab
[tem
].opcode
== opcode
)
602 op_str
= op_print_tab
[tem
].string
;
603 myprec
= op_print_tab
[tem
].precedence
;
604 assoc
= op_print_tab
[tem
].right_assoc
;
607 if (op_print_tab
[tem
].opcode
!= opcode
)
608 /* Not found; don't try to keep going because we don't know how
609 to interpret further elements. For example, this happens
610 if opcode is OP_TYPE. */
611 error (_("Invalid expression"));
614 /* Note that PREC_BUILTIN will always emit parentheses. */
615 if ((int) myprec
< (int) prec
)
616 fputs_filtered ("(", stream
);
617 if ((int) opcode
> (int) BINOP_END
)
621 /* Unary postfix operator. */
622 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
623 fputs_filtered (op_str
, stream
);
627 /* Unary prefix operator. */
628 fputs_filtered (op_str
, stream
);
629 if (myprec
== PREC_BUILTIN_FUNCTION
)
630 fputs_filtered ("(", stream
);
631 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
632 if (myprec
== PREC_BUILTIN_FUNCTION
)
633 fputs_filtered (")", stream
);
638 /* Binary operator. */
639 /* Print left operand.
640 If operator is right-associative,
641 increment precedence for this operand. */
642 print_subexp (exp
, pos
, stream
,
643 (enum precedence
) ((int) myprec
+ assoc
));
644 /* Print the operator itself. */
646 fprintf_filtered (stream
, " %s= ", op_str
);
647 else if (op_str
[0] == ',')
648 fprintf_filtered (stream
, "%s ", op_str
);
650 fprintf_filtered (stream
, " %s ", op_str
);
651 /* Print right operand.
652 If operator is left-associative,
653 increment precedence for this operand. */
654 print_subexp (exp
, pos
, stream
,
655 (enum precedence
) ((int) myprec
+ !assoc
));
658 if ((int) myprec
< (int) prec
)
659 fputs_filtered (")", stream
);
662 /* Return the operator corresponding to opcode OP as
663 a string. NULL indicates that the opcode was not found in the
664 current language table. */
666 op_string (enum exp_opcode op
)
669 const struct op_print
*op_print_tab
;
671 op_print_tab
= current_language
->la_op_print_tab
;
672 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
673 if (op_print_tab
[tem
].opcode
== op
)
674 return op_print_tab
[tem
].string
;
678 /* Support for dumping the raw data from expressions in a human readable
681 static int dump_subexp_body (struct expression
*exp
, struct ui_file
*, int);
683 /* Name for OPCODE, when it appears in expression EXP. */
686 op_name (struct expression
*exp
, enum exp_opcode opcode
)
688 if (opcode
>= OP_UNUSED_LAST
)
690 char *cell
= get_print_cell ();
691 xsnprintf (cell
, PRINT_CELL_SIZE
, "unknown opcode: %u",
695 return exp
->language_defn
->la_exp_desc
->op_name (opcode
);
698 /* Default name for the standard operator OPCODE (i.e., one defined in
699 the definition of enum exp_opcode). */
702 op_name_standard (enum exp_opcode opcode
)
710 xsnprintf (buf
, sizeof (buf
), "<unknown %d>", opcode
);
716 #include "std-operator.def"
721 /* Print a raw dump of expression EXP to STREAM.
722 NOTE, if non-NULL, is printed as extra explanatory text. */
725 dump_raw_expression (struct expression
*exp
, struct ui_file
*stream
,
732 fprintf_filtered (stream
, "Dump of expression @ ");
733 gdb_print_host_address (exp
, stream
);
735 fprintf_filtered (stream
, ", %s:", note
);
736 fprintf_filtered (stream
, "\n\tLanguage %s, %d elements, %ld bytes each.\n",
737 exp
->language_defn
->la_name
, exp
->nelts
,
738 (long) sizeof (union exp_element
));
739 fprintf_filtered (stream
, "\t%5s %20s %16s %s\n", "Index", "Opcode",
740 "Hex Value", "String Value");
741 for (elt
= 0; elt
< exp
->nelts
; elt
++)
743 fprintf_filtered (stream
, "\t%5d ", elt
);
745 const char *opcode_name
= op_name (exp
, exp
->elts
[elt
].opcode
);
746 fprintf_filtered (stream
, "%20s ", opcode_name
);
748 print_longest (stream
, 'd', 0, exp
->elts
[elt
].longconst
);
749 fprintf_filtered (stream
, " ");
751 for (eltscan
= (char *) &exp
->elts
[elt
],
752 eltsize
= sizeof (union exp_element
);
756 fprintf_filtered (stream
, "%c",
757 isprint (*eltscan
) ? (*eltscan
& 0xFF) : '.');
759 fprintf_filtered (stream
, "\n");
763 /* Dump the subexpression of prefix expression EXP whose operator is at
764 position ELT onto STREAM. Returns the position of the next
765 subexpression in EXP. */
768 dump_subexp (struct expression
*exp
, struct ui_file
*stream
, int elt
)
770 static int indent
= 0;
773 fprintf_filtered (stream
, "\n");
774 fprintf_filtered (stream
, "\t%5d ", elt
);
776 for (i
= 1; i
<= indent
; i
++)
777 fprintf_filtered (stream
, " ");
780 fprintf_filtered (stream
, "%-20s ", op_name (exp
, exp
->elts
[elt
].opcode
));
782 elt
= dump_subexp_body (exp
, stream
, elt
);
789 /* Dump the operands of prefix expression EXP whose opcode is at
790 position ELT onto STREAM. Returns the position of the next
791 subexpression in EXP. */
794 dump_subexp_body (struct expression
*exp
, struct ui_file
*stream
, int elt
)
796 return exp
->language_defn
->la_exp_desc
->dump_subexp_body (exp
, stream
, elt
);
799 /* Default value for subexp_body in exp_descriptor vector. */
802 dump_subexp_body_standard (struct expression
*exp
,
803 struct ui_file
*stream
, int elt
)
805 int opcode
= exp
->elts
[elt
++].opcode
;
811 elt
= dump_subexp (exp
, stream
, elt
);
821 case BINOP_LOGICAL_AND
:
822 case BINOP_LOGICAL_OR
:
823 case BINOP_BITWISE_AND
:
824 case BINOP_BITWISE_IOR
:
825 case BINOP_BITWISE_XOR
:
835 case BINOP_SUBSCRIPT
:
840 case BINOP_ASSIGN_MODIFY
:
844 case STRUCTOP_MEMBER
:
846 elt
= dump_subexp (exp
, stream
, elt
);
849 case UNOP_LOGICAL_NOT
:
850 case UNOP_COMPLEMENT
:
853 case UNOP_PREINCREMENT
:
854 case UNOP_POSTINCREMENT
:
855 case UNOP_PREDECREMENT
:
856 case UNOP_POSTDECREMENT
:
870 elt
= dump_subexp (exp
, stream
, elt
);
873 fprintf_filtered (stream
, "Type @");
874 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
875 fprintf_filtered (stream
, " (");
876 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
877 fprintf_filtered (stream
, "), value %ld (0x%lx)",
878 (long) exp
->elts
[elt
+ 1].longconst
,
879 (long) exp
->elts
[elt
+ 1].longconst
);
883 fprintf_filtered (stream
, "Type @");
884 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
885 fprintf_filtered (stream
, " (");
886 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
887 fprintf_filtered (stream
, "), value ");
888 print_floating (exp
->elts
[elt
+ 1].floatconst
,
889 exp
->elts
[elt
].type
, stream
);
893 fprintf_filtered (stream
, "Block @");
894 gdb_print_host_address (exp
->elts
[elt
].block
, stream
);
895 fprintf_filtered (stream
, ", symbol @");
896 gdb_print_host_address (exp
->elts
[elt
+ 1].symbol
, stream
);
897 fprintf_filtered (stream
, " (%s)",
898 exp
->elts
[elt
+ 1].symbol
->print_name ());
901 case OP_VAR_MSYM_VALUE
:
902 fprintf_filtered (stream
, "Objfile @");
903 gdb_print_host_address (exp
->elts
[elt
].objfile
, stream
);
904 fprintf_filtered (stream
, ", msymbol @");
905 gdb_print_host_address (exp
->elts
[elt
+ 1].msymbol
, stream
);
906 fprintf_filtered (stream
, " (%s)",
907 exp
->elts
[elt
+ 1].msymbol
->print_name ());
910 case OP_VAR_ENTRY_VALUE
:
911 fprintf_filtered (stream
, "Entry value of symbol @");
912 gdb_print_host_address (exp
->elts
[elt
].symbol
, stream
);
913 fprintf_filtered (stream
, " (%s)",
914 exp
->elts
[elt
].symbol
->print_name ());
918 fprintf_filtered (stream
, "History element %ld",
919 (long) exp
->elts
[elt
].longconst
);
923 fprintf_filtered (stream
, "Register $%s", &exp
->elts
[elt
+ 1].string
);
924 elt
+= 3 + BYTES_TO_EXP_ELEM (exp
->elts
[elt
].longconst
+ 1);
927 fprintf_filtered (stream
, "Internal var @");
928 gdb_print_host_address (exp
->elts
[elt
].internalvar
, stream
);
929 fprintf_filtered (stream
, " (%s)",
930 internalvar_name (exp
->elts
[elt
].internalvar
));
934 case OP_F77_UNDETERMINED_ARGLIST
:
938 nargs
= longest_to_int (exp
->elts
[elt
].longconst
);
940 fprintf_filtered (stream
, "Number of args: %d", nargs
);
943 for (i
= 1; i
<= nargs
+ 1; i
++)
944 elt
= dump_subexp (exp
, stream
, elt
);
952 lower
= longest_to_int (exp
->elts
[elt
].longconst
);
953 upper
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
955 fprintf_filtered (stream
, "Bounds [%d:%d]", lower
, upper
);
958 for (i
= 1; i
<= upper
- lower
+ 1; i
++)
959 elt
= dump_subexp (exp
, stream
, elt
);
962 case UNOP_DYNAMIC_CAST
:
963 case UNOP_REINTERPRET_CAST
:
965 case UNOP_MEMVAL_TYPE
:
966 fprintf_filtered (stream
, " (");
967 elt
= dump_subexp (exp
, stream
, elt
);
968 fprintf_filtered (stream
, ")");
969 elt
= dump_subexp (exp
, stream
, elt
);
973 fprintf_filtered (stream
, "Type @");
974 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
975 fprintf_filtered (stream
, " (");
976 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
977 fprintf_filtered (stream
, ")");
978 elt
= dump_subexp (exp
, stream
, elt
+ 2);
981 fprintf_filtered (stream
, "Type @");
982 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
983 fprintf_filtered (stream
, " (");
984 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
985 fprintf_filtered (stream
, ")");
990 fprintf_filtered (stream
, "Typeof (");
991 elt
= dump_subexp (exp
, stream
, elt
);
992 fprintf_filtered (stream
, ")");
995 fprintf_filtered (stream
, "typeid (");
996 elt
= dump_subexp (exp
, stream
, elt
);
997 fprintf_filtered (stream
, ")");
999 case STRUCTOP_STRUCT
:
1005 len
= longest_to_int (exp
->elts
[elt
].longconst
);
1006 elem_name
= &exp
->elts
[elt
+ 1].string
;
1008 fprintf_filtered (stream
, "Element name: `%.*s'", len
, elem_name
);
1009 elt
= dump_subexp (exp
, stream
, elt
+ 3 + BYTES_TO_EXP_ELEM (len
+ 1));
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
, ") ");
1023 len
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
1024 elem_name
= &exp
->elts
[elt
+ 2].string
;
1026 fprintf_filtered (stream
, "Field name: `%.*s'", len
, elem_name
);
1027 elt
+= 4 + BYTES_TO_EXP_ELEM (len
+ 1);
1031 case OP_FUNC_STATIC_VAR
:
1033 int len
= longest_to_int (exp
->elts
[elt
].longconst
);
1034 const char *var_name
= &exp
->elts
[elt
+ 1].string
;
1035 fprintf_filtered (stream
, "Field name: `%.*s'", len
, var_name
);
1036 elt
+= 3 + BYTES_TO_EXP_ELEM (len
+ 1);
1042 type_instance_flags flags
1043 = (type_instance_flag_value
) longest_to_int (exp
->elts
[elt
++].longconst
);
1044 LONGEST len
= exp
->elts
[elt
++].longconst
;
1045 fprintf_filtered (stream
, "%s TypeInstance: ", plongest (len
));
1048 fprintf_filtered (stream
, "Type @");
1049 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1050 fprintf_filtered (stream
, " (");
1051 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1052 fprintf_filtered (stream
, ")");
1055 fputs_filtered (", ", stream
);
1058 fprintf_filtered (stream
, " Flags: %s (", hex_string (flags
));
1060 auto print_one
= [&] (const char *mod
)
1063 fputs_filtered (" ", stream
);
1065 fprintf_filtered (stream
, "%s", mod
);
1067 if (flags
& TYPE_INSTANCE_FLAG_CONST
)
1068 print_one ("const");
1069 if (flags
& TYPE_INSTANCE_FLAG_VOLATILE
)
1070 print_one ("volatile");
1071 fprintf_filtered (stream
, ")");
1073 /* Ending LEN and ending TYPE_INSTANCE. */
1075 elt
= dump_subexp (exp
, stream
, elt
);
1080 LONGEST len
= exp
->elts
[elt
].longconst
;
1081 LONGEST type
= exp
->elts
[elt
+ 1].longconst
;
1083 fprintf_filtered (stream
, "Language-specific string type: %s",
1089 /* Skip string content. */
1090 elt
+= BYTES_TO_EXP_ELEM (len
);
1092 /* Skip length and ending OP_STRING. */
1098 enum range_type range_type
;
1100 range_type
= (enum range_type
)
1101 longest_to_int (exp
->elts
[elt
].longconst
);
1106 case BOTH_BOUND_DEFAULT
:
1107 fputs_filtered ("Range '..'", stream
);
1109 case LOW_BOUND_DEFAULT
:
1110 fputs_filtered ("Range '..EXP'", stream
);
1112 case LOW_BOUND_DEFAULT_EXCLUSIVE
:
1113 fputs_filtered ("ExclusiveRange '..EXP'", stream
);
1115 case HIGH_BOUND_DEFAULT
:
1116 fputs_filtered ("Range 'EXP..'", stream
);
1118 case NONE_BOUND_DEFAULT
:
1119 fputs_filtered ("Range 'EXP..EXP'", stream
);
1121 case NONE_BOUND_DEFAULT_EXCLUSIVE
:
1122 fputs_filtered ("ExclusiveRange 'EXP..EXP'", stream
);
1125 fputs_filtered ("Invalid Range!", stream
);
1129 if (range_type
== HIGH_BOUND_DEFAULT
1130 || range_type
== NONE_BOUND_DEFAULT
)
1131 elt
= dump_subexp (exp
, stream
, elt
);
1132 if (range_type
== LOW_BOUND_DEFAULT
1133 || range_type
== NONE_BOUND_DEFAULT
)
1134 elt
= dump_subexp (exp
, stream
, elt
);
1140 case MULTI_SUBSCRIPT
:
1146 fprintf_filtered (stream
, "Unknown format");
1153 dump_prefix_expression (struct expression
*exp
, struct ui_file
*stream
)
1157 fprintf_filtered (stream
, "Dump of expression @ ");
1158 gdb_print_host_address (exp
, stream
);
1159 fputs_filtered (", after conversion to prefix form:\nExpression: `", stream
);
1160 print_expression (exp
, stream
);
1161 fprintf_filtered (stream
, "'\n\tLanguage %s, %d elements, %ld bytes each.\n",
1162 exp
->language_defn
->la_name
, exp
->nelts
,
1163 (long) sizeof (union exp_element
));
1164 fputs_filtered ("\n", stream
);
1166 for (elt
= 0; elt
< exp
->nelts
;)
1167 elt
= dump_subexp (exp
, stream
, elt
);
1168 fputs_filtered ("\n", stream
);