1 /* Print in infix form a struct expression.
3 Copyright (C) 1986-2021 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"
40 print_expression (struct expression
*exp
, struct ui_file
*stream
)
44 print_subexp (exp
, &pc
, stream
, PREC_NULL
);
47 /* Print the subexpression of EXP that starts in position POS, on STREAM.
48 PREC is the precedence of the surrounding operator;
49 if the precedence of the main operator of this subexpression is less,
50 parentheses are needed here. */
53 print_subexp (struct expression
*exp
, int *pos
,
54 struct ui_file
*stream
, enum precedence prec
)
56 exp
->language_defn
->expression_ops ()->print_subexp (exp
, pos
, stream
,
60 /* See parser-defs.h. */
63 print_subexp_funcall (struct expression
*exp
, int *pos
,
64 struct ui_file
*stream
)
66 unsigned nargs
= longest_to_int (exp
->elts
[*pos
].longconst
);
68 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
69 fputs_filtered (" (", stream
);
70 for (unsigned tem
= 0; tem
< nargs
; tem
++)
73 fputs_filtered (", ", stream
);
74 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
76 fputs_filtered (")", stream
);
79 /* Standard implementation of print_subexp for use in language_defn
82 print_subexp_standard (struct expression
*exp
, int *pos
,
83 struct ui_file
*stream
, enum precedence prec
)
86 const struct op_print
*op_print_tab
;
90 int assign_modify
= 0;
91 enum exp_opcode opcode
;
92 enum precedence myprec
= PREC_NULL
;
93 /* Set to 1 for a right-associative operator. */
98 op_print_tab
= exp
->language_defn
->opcode_print_table ();
100 opcode
= exp
->elts
[pc
].opcode
;
107 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
111 myprec
= PREC_PREFIX
;
113 fputs_filtered (exp
->elts
[pc
+ 1].type
->name (), stream
);
114 fputs_filtered ("::", stream
);
115 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
116 (*pos
) += 4 + BYTES_TO_EXP_ELEM (nargs
+ 1);
117 fputs_filtered (&exp
->elts
[pc
+ 3].string
, stream
);
122 struct value_print_options opts
;
124 get_no_prettyformat_print_options (&opts
);
126 value_print (value_from_longest (exp
->elts
[pc
+ 1].type
,
127 exp
->elts
[pc
+ 2].longconst
),
134 struct value_print_options opts
;
136 get_no_prettyformat_print_options (&opts
);
138 value_print (value_from_contents (exp
->elts
[pc
+ 1].type
,
139 exp
->elts
[pc
+ 2].floatconst
),
146 const struct block
*b
;
149 b
= exp
->elts
[pc
+ 1].block
;
151 && BLOCK_FUNCTION (b
) != NULL
152 && BLOCK_FUNCTION (b
)->print_name () != NULL
)
154 fputs_filtered (BLOCK_FUNCTION (b
)->print_name (), stream
);
155 fputs_filtered ("::", stream
);
157 fputs_filtered (exp
->elts
[pc
+ 2].symbol
->print_name (), stream
);
161 case OP_VAR_MSYM_VALUE
:
164 fputs_filtered (exp
->elts
[pc
+ 2].msymbol
->print_name (), stream
);
168 case OP_FUNC_STATIC_VAR
:
170 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
171 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
172 fputs_filtered (&exp
->elts
[pc
+ 1].string
, stream
);
176 case OP_VAR_ENTRY_VALUE
:
179 fprintf_filtered (stream
, "%s@entry",
180 exp
->elts
[pc
+ 1].symbol
->print_name ());
186 fprintf_filtered (stream
, "$%d",
187 longest_to_int (exp
->elts
[pc
+ 1].longconst
));
192 const char *name
= &exp
->elts
[pc
+ 2].string
;
194 (*pos
) += 3 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
195 fprintf_filtered (stream
, "$%s", name
);
201 fprintf_filtered (stream
, "%s",
202 longest_to_int (exp
->elts
[pc
+ 1].longconst
)
208 fprintf_filtered (stream
, "$%s",
209 internalvar_name (exp
->elts
[pc
+ 1].internalvar
));
213 print_subexp_funcall (exp
, pos
, stream
);
217 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
218 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
219 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
224 struct value_print_options opts
;
226 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
227 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
228 /* LA_PRINT_STRING will print using the current repeat count threshold.
229 If necessary, we can temporarily set it to zero, or pass it as an
230 additional parameter to LA_PRINT_STRING. -fnf */
231 get_user_print_options (&opts
);
233 ->printstr (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
234 (gdb_byte
*) &exp
->elts
[pc
+ 2].string
, nargs
,
239 case OP_OBJC_NSSTRING
: /* Objective-C Foundation Class
240 NSString constant. */
242 struct value_print_options opts
;
244 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
245 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
246 fputs_filtered ("@\"", stream
);
247 get_user_print_options (&opts
);
249 ->printstr (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
250 (gdb_byte
*) &exp
->elts
[pc
+ 2].string
, nargs
,
252 fputs_filtered ("\"", stream
);
256 case OP_OBJC_MSGCALL
:
257 { /* Objective C message (method) call. */
259 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
260 fprintf_unfiltered (stream
, "[");
261 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
262 gdb::unique_xmalloc_ptr
<char> selector
263 = target_read_string (exp
->elts
[pc
+ 1].longconst
, 1024);
264 if (selector
== nullptr)
265 error (_("bad selector"));
271 for (tem
= 0; tem
< nargs
; tem
++)
273 nextS
= strchr (s
, ':');
274 gdb_assert (nextS
); /* Make sure we found ':'. */
276 fprintf_unfiltered (stream
, " %s: ", s
);
278 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
283 fprintf_unfiltered (stream
, " %s", selector
.get ());
285 fprintf_unfiltered (stream
, "]");
291 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
292 nargs
-= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
295 if (exp
->elts
[pc
+ 4].opcode
== OP_LONG
296 && exp
->elts
[pc
+ 5].type
297 == builtin_type (exp
->gdbarch
)->builtin_char
298 && exp
->language_defn
->la_language
== language_c
)
300 /* Attempt to print C character arrays using string syntax.
301 Walk through the args, picking up one character from each
302 of the OP_LONG expression elements. If any array element
303 does not match our expection of what we should find for
304 a simple string, revert back to array printing. Note that
305 the last expression element is an explicit null terminator
306 byte, which doesn't get printed. */
307 tempstr
= (char *) alloca (nargs
);
311 if (exp
->elts
[pc
].opcode
!= OP_LONG
312 || exp
->elts
[pc
+ 1].type
313 != builtin_type (exp
->gdbarch
)->builtin_char
)
315 /* Not a simple array of char, use regular array
323 longest_to_int (exp
->elts
[pc
+ 2].longconst
);
330 struct value_print_options opts
;
332 get_user_print_options (&opts
);
334 ->printstr (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
335 (gdb_byte
*) tempstr
, nargs
- 1, NULL
, 0, &opts
);
340 fputs_filtered (" {", stream
);
341 for (tem
= 0; tem
< nargs
; tem
++)
345 fputs_filtered (", ", stream
);
347 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
349 fputs_filtered ("}", stream
);
354 if ((int) prec
> (int) PREC_COMMA
)
355 fputs_filtered ("(", stream
);
356 /* Print the subexpressions, forcing parentheses
357 around any binary operations within them.
358 This is more parentheses than are strictly necessary,
359 but it looks clearer. */
360 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
361 fputs_filtered (" ? ", stream
);
362 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
363 fputs_filtered (" : ", stream
);
364 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
365 if ((int) prec
> (int) PREC_COMMA
)
366 fputs_filtered (")", stream
);
370 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
371 fputs_filtered ("(", stream
);
372 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
373 fputs_filtered (opcode
== TERNOP_SLICE
? " : " : " UP ", stream
);
374 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
375 fputs_filtered (")", stream
);
378 case STRUCTOP_STRUCT
:
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 /* Will not occur for Modula-2. */
388 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
389 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
390 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
391 fputs_filtered ("->", stream
);
392 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
395 case STRUCTOP_MEMBER
:
396 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
397 fputs_filtered (".*", stream
);
398 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
402 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
403 fputs_filtered ("->*", stream
);
404 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
407 case BINOP_SUBSCRIPT
:
408 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
409 fputs_filtered ("[", stream
);
410 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
411 fputs_filtered ("]", stream
);
414 case UNOP_POSTINCREMENT
:
415 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
416 fputs_filtered ("++", stream
);
419 case UNOP_POSTDECREMENT
:
420 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
421 fputs_filtered ("--", stream
);
426 if ((int) prec
> (int) PREC_PREFIX
)
427 fputs_filtered ("(", stream
);
428 fputs_filtered ("(", stream
);
429 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
430 fputs_filtered (") ", stream
);
431 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
432 if ((int) prec
> (int) PREC_PREFIX
)
433 fputs_filtered (")", stream
);
437 if ((int) prec
> (int) PREC_PREFIX
)
438 fputs_filtered ("(", stream
);
439 fputs_filtered ("(", stream
);
440 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
441 fputs_filtered (") ", stream
);
442 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
443 if ((int) prec
> (int) PREC_PREFIX
)
444 fputs_filtered (")", stream
);
447 case UNOP_DYNAMIC_CAST
:
448 case UNOP_REINTERPRET_CAST
:
449 fputs_filtered (opcode
== UNOP_DYNAMIC_CAST
? "dynamic_cast"
450 : "reinterpret_cast", stream
);
451 fputs_filtered ("<", stream
);
452 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
453 fputs_filtered ("> (", stream
);
454 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
455 fputs_filtered (")", stream
);
460 if ((int) prec
> (int) PREC_PREFIX
)
461 fputs_filtered ("(", stream
);
462 if (exp
->elts
[pc
+ 1].type
->code () == TYPE_CODE_FUNC
463 && exp
->elts
[pc
+ 3].opcode
== OP_LONG
)
465 struct value_print_options opts
;
467 /* We have a minimal symbol fn, probably. It's encoded
468 as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address).
469 Swallow the OP_LONG (including both its opcodes); ignore
470 its type; print the value in the type of the MEMVAL. */
472 val
= value_at_lazy (exp
->elts
[pc
+ 1].type
,
473 (CORE_ADDR
) exp
->elts
[pc
+ 5].longconst
);
474 get_no_prettyformat_print_options (&opts
);
475 value_print (val
, stream
, &opts
);
479 fputs_filtered ("{", stream
);
480 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
481 fputs_filtered ("} ", stream
);
482 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
484 if ((int) prec
> (int) PREC_PREFIX
)
485 fputs_filtered (")", stream
);
488 case UNOP_MEMVAL_TYPE
:
489 if ((int) prec
> (int) PREC_PREFIX
)
490 fputs_filtered ("(", stream
);
491 fputs_filtered ("{", stream
);
492 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
493 fputs_filtered ("} ", stream
);
494 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
495 if ((int) prec
> (int) PREC_PREFIX
)
496 fputs_filtered (")", stream
);
499 case BINOP_ASSIGN_MODIFY
:
500 opcode
= exp
->elts
[pc
+ 1].opcode
;
502 myprec
= PREC_ASSIGN
;
506 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
507 if (op_print_tab
[tem
].opcode
== opcode
)
509 op_str
= op_print_tab
[tem
].string
;
512 if (op_print_tab
[tem
].opcode
!= opcode
)
513 /* Not found; don't try to keep going because we don't know how
514 to interpret further elements. */
515 error (_("Invalid expression"));
522 if (exp
->language_defn
->name_of_this () != NULL
)
523 fputs_filtered (exp
->language_defn
->name_of_this (), stream
);
525 fprintf_styled (stream
, metadata_style
.style (),
526 _("<language %s has no 'this'>"),
527 exp
->language_defn
->name ());
532 case MULTI_SUBSCRIPT
:
534 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
535 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
536 fprintf_unfiltered (stream
, " [");
537 for (tem
= 0; tem
< nargs
; tem
++)
540 fprintf_unfiltered (stream
, ", ");
541 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
543 fprintf_unfiltered (stream
, "]");
548 fprintf_unfiltered (stream
, "VAL(");
549 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
550 fprintf_unfiltered (stream
, ",");
551 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
552 fprintf_unfiltered (stream
, ")");
557 type_instance_flags flags
558 = (type_instance_flag_value
) longest_to_int (exp
->elts
[pc
+ 1].longconst
);
559 LONGEST count
= exp
->elts
[pc
+ 2].longconst
;
565 fputs_unfiltered ("TypeInstance(", stream
);
568 type_print (exp
->elts
[(*pos
)++].type
, "", stream
, 0);
570 fputs_unfiltered (",", stream
);
572 fputs_unfiltered (",", stream
);
573 /* Ending COUNT and ending TYPE_INSTANCE. */
575 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
577 if (flags
& TYPE_INSTANCE_FLAG_CONST
)
578 fputs_unfiltered (",const", stream
);
579 if (flags
& TYPE_INSTANCE_FLAG_VOLATILE
)
580 fputs_unfiltered (",volatile", stream
);
582 fputs_unfiltered (")", stream
);
588 enum range_flag range_flag
;
590 range_flag
= (enum range_flag
)
591 longest_to_int (exp
->elts
[pc
+ 1].longconst
);
594 if (range_flag
& RANGE_HIGH_BOUND_EXCLUSIVE
)
595 fputs_filtered ("EXCLUSIVE_", stream
);
596 fputs_filtered ("RANGE(", stream
);
597 if (!(range_flag
& RANGE_LOW_BOUND_DEFAULT
))
598 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
599 fputs_filtered ("..", stream
);
600 if (!(range_flag
& RANGE_HIGH_BOUND_DEFAULT
))
601 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
602 fputs_filtered (")", stream
);
610 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
611 if (op_print_tab
[tem
].opcode
== opcode
)
613 op_str
= op_print_tab
[tem
].string
;
614 myprec
= op_print_tab
[tem
].precedence
;
615 assoc
= op_print_tab
[tem
].right_assoc
;
618 if (op_print_tab
[tem
].opcode
!= opcode
)
619 /* Not found; don't try to keep going because we don't know how
620 to interpret further elements. For example, this happens
621 if opcode is OP_TYPE. */
622 error (_("Invalid expression"));
625 /* Note that PREC_BUILTIN will always emit parentheses. */
626 if ((int) myprec
< (int) prec
)
627 fputs_filtered ("(", stream
);
628 if ((int) opcode
> (int) BINOP_END
)
632 /* Unary postfix operator. */
633 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
634 fputs_filtered (op_str
, stream
);
638 /* Unary prefix operator. */
639 fputs_filtered (op_str
, stream
);
640 if (myprec
== PREC_BUILTIN_FUNCTION
)
641 fputs_filtered ("(", stream
);
642 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
643 if (myprec
== PREC_BUILTIN_FUNCTION
)
644 fputs_filtered (")", stream
);
649 /* Binary operator. */
650 /* Print left operand.
651 If operator is right-associative,
652 increment precedence for this operand. */
653 print_subexp (exp
, pos
, stream
,
654 (enum precedence
) ((int) myprec
+ assoc
));
655 /* Print the operator itself. */
657 fprintf_filtered (stream
, " %s= ", op_str
);
658 else if (op_str
[0] == ',')
659 fprintf_filtered (stream
, "%s ", op_str
);
661 fprintf_filtered (stream
, " %s ", op_str
);
662 /* Print right operand.
663 If operator is left-associative,
664 increment precedence for this operand. */
665 print_subexp (exp
, pos
, stream
,
666 (enum precedence
) ((int) myprec
+ !assoc
));
669 if ((int) myprec
< (int) prec
)
670 fputs_filtered (")", stream
);
673 /* Return the operator corresponding to opcode OP as
674 a string. NULL indicates that the opcode was not found in the
675 current language table. */
677 op_string (enum exp_opcode op
)
680 const struct op_print
*op_print_tab
;
682 op_print_tab
= current_language
->opcode_print_table ();
683 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
684 if (op_print_tab
[tem
].opcode
== op
)
685 return op_print_tab
[tem
].string
;
689 /* Support for dumping the raw data from expressions in a human readable
692 static int dump_subexp_body (struct expression
*exp
, struct ui_file
*, int);
694 /* Default name for the standard operator OPCODE (i.e., one defined in
695 the definition of enum exp_opcode). */
698 op_name (enum exp_opcode opcode
)
706 xsnprintf (buf
, sizeof (buf
), "<unknown %d>", opcode
);
712 #include "std-operator.def"
717 /* Print a raw dump of expression EXP to STREAM.
718 NOTE, if non-NULL, is printed as extra explanatory text. */
721 dump_raw_expression (struct expression
*exp
, struct ui_file
*stream
,
728 if (exp
->op
!= nullptr)
731 fprintf_filtered (stream
, "Dump of expression @ ");
732 gdb_print_host_address (exp
, stream
);
734 fprintf_filtered (stream
, ", %s:", note
);
735 fprintf_filtered (stream
, "\n\tLanguage %s, %d elements, %ld bytes each.\n",
736 exp
->language_defn
->name (), exp
->nelts
,
737 (long) sizeof (union exp_element
));
738 fprintf_filtered (stream
, "\t%5s %20s %16s %s\n", "Index", "Opcode",
739 "Hex Value", "String Value");
740 for (elt
= 0; elt
< exp
->nelts
; elt
++)
742 fprintf_filtered (stream
, "\t%5d ", elt
);
744 const char *opcode_name
= op_name (exp
->elts
[elt
].opcode
);
745 fprintf_filtered (stream
, "%20s ", opcode_name
);
747 print_longest (stream
, 'd', 0, exp
->elts
[elt
].longconst
);
748 fprintf_filtered (stream
, " ");
750 for (eltscan
= (char *) &exp
->elts
[elt
],
751 eltsize
= sizeof (union exp_element
);
755 fprintf_filtered (stream
, "%c",
756 isprint (*eltscan
) ? (*eltscan
& 0xFF) : '.');
758 fprintf_filtered (stream
, "\n");
762 /* Dump the subexpression of prefix expression EXP whose operator is at
763 position ELT onto STREAM. Returns the position of the next
764 subexpression in EXP. */
767 dump_subexp (struct expression
*exp
, struct ui_file
*stream
, int elt
)
769 static int indent
= 0;
772 fprintf_filtered (stream
, "\n");
773 fprintf_filtered (stream
, "\t%5d ", elt
);
775 for (i
= 1; i
<= indent
; i
++)
776 fprintf_filtered (stream
, " ");
779 fprintf_filtered (stream
, "%-20s ", op_name (exp
->elts
[elt
].opcode
));
781 elt
= dump_subexp_body (exp
, stream
, elt
);
788 /* Dump the operands of prefix expression EXP whose opcode is at
789 position ELT onto STREAM. Returns the position of the next
790 subexpression in EXP. */
793 dump_subexp_body (struct expression
*exp
, struct ui_file
*stream
, int elt
)
795 return exp
->language_defn
->expression_ops ()->dump_subexp_body (exp
, stream
,
799 /* See parser-defs.h. */
802 dump_subexp_body_funcall (struct expression
*exp
,
803 struct ui_file
*stream
, int elt
)
805 int nargs
= longest_to_int (exp
->elts
[elt
].longconst
);
806 fprintf_filtered (stream
, "Number of args: %d", nargs
);
809 for (int i
= 1; i
<= nargs
+ 1; i
++)
810 elt
= dump_subexp (exp
, stream
, elt
);
815 /* Default value for subexp_body in exp_descriptor vector. */
818 dump_subexp_body_standard (struct expression
*exp
,
819 struct ui_file
*stream
, int elt
)
821 int opcode
= exp
->elts
[elt
++].opcode
;
827 elt
= dump_subexp (exp
, stream
, elt
);
837 case BINOP_LOGICAL_AND
:
838 case BINOP_LOGICAL_OR
:
839 case BINOP_BITWISE_AND
:
840 case BINOP_BITWISE_IOR
:
841 case BINOP_BITWISE_XOR
:
851 case BINOP_SUBSCRIPT
:
856 case BINOP_ASSIGN_MODIFY
:
860 case STRUCTOP_MEMBER
:
862 elt
= dump_subexp (exp
, stream
, elt
);
865 case UNOP_LOGICAL_NOT
:
866 case UNOP_COMPLEMENT
:
869 case UNOP_PREINCREMENT
:
870 case UNOP_POSTINCREMENT
:
871 case UNOP_PREDECREMENT
:
872 case UNOP_POSTDECREMENT
:
886 elt
= dump_subexp (exp
, stream
, elt
);
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 %ld (0x%lx)",
894 (long) exp
->elts
[elt
+ 1].longconst
,
895 (long) exp
->elts
[elt
+ 1].longconst
);
899 fprintf_filtered (stream
, "Type @");
900 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
901 fprintf_filtered (stream
, " (");
902 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
903 fprintf_filtered (stream
, "), value ");
904 print_floating (exp
->elts
[elt
+ 1].floatconst
,
905 exp
->elts
[elt
].type
, stream
);
909 fprintf_filtered (stream
, "Block @");
910 gdb_print_host_address (exp
->elts
[elt
].block
, stream
);
911 fprintf_filtered (stream
, ", symbol @");
912 gdb_print_host_address (exp
->elts
[elt
+ 1].symbol
, stream
);
913 fprintf_filtered (stream
, " (%s)",
914 exp
->elts
[elt
+ 1].symbol
->print_name ());
917 case OP_VAR_MSYM_VALUE
:
918 fprintf_filtered (stream
, "Objfile @");
919 gdb_print_host_address (exp
->elts
[elt
].objfile
, stream
);
920 fprintf_filtered (stream
, ", msymbol @");
921 gdb_print_host_address (exp
->elts
[elt
+ 1].msymbol
, stream
);
922 fprintf_filtered (stream
, " (%s)",
923 exp
->elts
[elt
+ 1].msymbol
->print_name ());
926 case OP_VAR_ENTRY_VALUE
:
927 fprintf_filtered (stream
, "Entry value of symbol @");
928 gdb_print_host_address (exp
->elts
[elt
].symbol
, stream
);
929 fprintf_filtered (stream
, " (%s)",
930 exp
->elts
[elt
].symbol
->print_name ());
934 fprintf_filtered (stream
, "History element %ld",
935 (long) exp
->elts
[elt
].longconst
);
939 fprintf_filtered (stream
, "Register $%s", &exp
->elts
[elt
+ 1].string
);
940 elt
+= 3 + BYTES_TO_EXP_ELEM (exp
->elts
[elt
].longconst
+ 1);
943 fprintf_filtered (stream
, "Internal var @");
944 gdb_print_host_address (exp
->elts
[elt
].internalvar
, stream
);
945 fprintf_filtered (stream
, " (%s)",
946 internalvar_name (exp
->elts
[elt
].internalvar
));
950 elt
= dump_subexp_body_funcall (exp
, stream
, elt
);
957 lower
= longest_to_int (exp
->elts
[elt
].longconst
);
958 upper
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
960 fprintf_filtered (stream
, "Bounds [%d:%d]", lower
, upper
);
963 for (i
= 1; i
<= upper
- lower
+ 1; i
++)
964 elt
= dump_subexp (exp
, stream
, elt
);
967 case UNOP_DYNAMIC_CAST
:
968 case UNOP_REINTERPRET_CAST
:
970 case UNOP_MEMVAL_TYPE
:
971 fprintf_filtered (stream
, " (");
972 elt
= dump_subexp (exp
, stream
, elt
);
973 fprintf_filtered (stream
, ")");
974 elt
= dump_subexp (exp
, stream
, elt
);
978 fprintf_filtered (stream
, "Type @");
979 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
980 fprintf_filtered (stream
, " (");
981 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
982 fprintf_filtered (stream
, ")");
983 elt
= dump_subexp (exp
, stream
, elt
+ 2);
986 fprintf_filtered (stream
, "Type @");
987 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
988 fprintf_filtered (stream
, " (");
989 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
990 fprintf_filtered (stream
, ")");
995 fprintf_filtered (stream
, "Typeof (");
996 elt
= dump_subexp (exp
, stream
, elt
);
997 fprintf_filtered (stream
, ")");
1000 fprintf_filtered (stream
, "typeid (");
1001 elt
= dump_subexp (exp
, stream
, elt
);
1002 fprintf_filtered (stream
, ")");
1004 case STRUCTOP_STRUCT
:
1010 len
= longest_to_int (exp
->elts
[elt
].longconst
);
1011 elem_name
= &exp
->elts
[elt
+ 1].string
;
1013 fprintf_filtered (stream
, "Element name: `%.*s'", len
, elem_name
);
1014 elt
= dump_subexp (exp
, stream
, elt
+ 3 + BYTES_TO_EXP_ELEM (len
+ 1));
1022 fprintf_filtered (stream
, "Type @");
1023 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1024 fprintf_filtered (stream
, " (");
1025 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1026 fprintf_filtered (stream
, ") ");
1028 len
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
1029 elem_name
= &exp
->elts
[elt
+ 2].string
;
1031 fprintf_filtered (stream
, "Field name: `%.*s'", len
, elem_name
);
1032 elt
+= 4 + BYTES_TO_EXP_ELEM (len
+ 1);
1036 case OP_FUNC_STATIC_VAR
:
1038 int len
= longest_to_int (exp
->elts
[elt
].longconst
);
1039 const char *var_name
= &exp
->elts
[elt
+ 1].string
;
1040 fprintf_filtered (stream
, "Field name: `%.*s'", len
, var_name
);
1041 elt
+= 3 + BYTES_TO_EXP_ELEM (len
+ 1);
1047 type_instance_flags flags
1048 = (type_instance_flag_value
) longest_to_int (exp
->elts
[elt
++].longconst
);
1049 LONGEST len
= exp
->elts
[elt
++].longconst
;
1050 fprintf_filtered (stream
, "%s TypeInstance: ", plongest (len
));
1053 fprintf_filtered (stream
, "Type @");
1054 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1055 fprintf_filtered (stream
, " (");
1056 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1057 fprintf_filtered (stream
, ")");
1060 fputs_filtered (", ", stream
);
1063 fprintf_filtered (stream
, " Flags: %s (", hex_string (flags
));
1065 auto print_one
= [&] (const char *mod
)
1068 fputs_filtered (" ", stream
);
1070 fprintf_filtered (stream
, "%s", mod
);
1072 if (flags
& TYPE_INSTANCE_FLAG_CONST
)
1073 print_one ("const");
1074 if (flags
& TYPE_INSTANCE_FLAG_VOLATILE
)
1075 print_one ("volatile");
1076 fprintf_filtered (stream
, ")");
1078 /* Ending LEN and ending TYPE_INSTANCE. */
1080 elt
= dump_subexp (exp
, stream
, elt
);
1085 LONGEST len
= exp
->elts
[elt
].longconst
;
1086 LONGEST type
= exp
->elts
[elt
+ 1].longconst
;
1088 fprintf_filtered (stream
, "Language-specific string type: %s",
1094 /* Skip string content. */
1095 elt
+= BYTES_TO_EXP_ELEM (len
);
1097 /* Skip length and ending OP_STRING. */
1103 enum range_flag range_flag
;
1105 range_flag
= (enum range_flag
)
1106 longest_to_int (exp
->elts
[elt
].longconst
);
1109 if (range_flag
& RANGE_HIGH_BOUND_EXCLUSIVE
)
1110 fputs_filtered ("Exclusive", stream
);
1111 fputs_filtered ("Range '", stream
);
1112 if (!(range_flag
& RANGE_LOW_BOUND_DEFAULT
))
1113 fputs_filtered ("EXP", stream
);
1114 fputs_filtered ("..", stream
);
1115 if (!(range_flag
& RANGE_HIGH_BOUND_DEFAULT
))
1116 fputs_filtered ("EXP", stream
);
1117 if (range_flag
& RANGE_HAS_STRIDE
)
1118 fputs_filtered (":EXP", stream
);
1119 fputs_filtered ("'", stream
);
1121 if (!(range_flag
& RANGE_LOW_BOUND_DEFAULT
))
1122 elt
= dump_subexp (exp
, stream
, elt
);
1123 if (!(range_flag
& RANGE_HIGH_BOUND_DEFAULT
))
1124 elt
= dump_subexp (exp
, stream
, elt
);
1125 if (range_flag
& RANGE_HAS_STRIDE
)
1126 elt
= dump_subexp (exp
, stream
, elt
);
1132 bool val
= (bool) (exp
->elts
[elt
].longconst
);
1133 fputs_filtered (val
? "TRUE" : "FALSE", stream
);
1140 case MULTI_SUBSCRIPT
:
1145 fprintf_filtered (stream
, "Unknown format");
1152 dump_prefix_expression (struct expression
*exp
, struct ui_file
*stream
)
1156 if (exp
->op
!= nullptr)
1158 exp
->op
->dump (stream
, 0);
1162 fprintf_filtered (stream
, "Dump of expression @ ");
1163 gdb_print_host_address (exp
, stream
);
1164 fputs_filtered (", after conversion to prefix form:\nExpression: `", stream
);
1166 if (exp
->op
!= nullptr)
1168 exp
->op
->dump (stream
, 0);
1172 print_expression (exp
, stream
);
1173 fprintf_filtered (stream
, "'\n\tLanguage %s, %d elements, %ld bytes each.\n",
1174 exp
->language_defn
->name (), exp
->nelts
,
1175 (long) sizeof (union exp_element
));
1176 fputs_filtered ("\n", stream
);
1178 for (elt
= 0; elt
< exp
->nelts
;)
1179 elt
= dump_subexp (exp
, stream
, elt
);
1180 fputs_filtered ("\n", stream
);
1187 dump_for_expression (struct ui_file
*stream
, int depth
, enum exp_opcode op
)
1189 fprintf_filtered (stream
, _("%*sOperation: %s\n"), depth
, "", op_name (op
));
1193 dump_for_expression (struct ui_file
*stream
, int depth
, const std::string
&str
)
1195 fprintf_filtered (stream
, _("%*sString: %s\n"), depth
, "", str
.c_str ());
1199 dump_for_expression (struct ui_file
*stream
, int depth
, struct type
*type
)
1201 fprintf_filtered (stream
, _("%*sType: "), depth
, "");
1202 type_print (type
, nullptr, stream
, 0);
1203 fprintf_filtered (stream
, "\n");
1207 dump_for_expression (struct ui_file
*stream
, int depth
, CORE_ADDR addr
)
1209 fprintf_filtered (stream
, _("%*sConstant: %s\n"), depth
, "",
1210 core_addr_to_string (addr
));
1214 dump_for_expression (struct ui_file
*stream
, int depth
, internalvar
*ivar
)
1216 fprintf_filtered (stream
, _("%*sInternalvar: $%s\n"), depth
, "",
1217 internalvar_name (ivar
));
1221 dump_for_expression (struct ui_file
*stream
, int depth
, symbol
*sym
)
1223 fprintf_filtered (stream
, _("%*sSymbol: %s\n"), depth
, "",
1224 sym
->print_name ());
1228 dump_for_expression (struct ui_file
*stream
, int depth
, minimal_symbol
*msym
)
1230 fprintf_filtered (stream
, _("%*sMinsym: %s\n"), depth
, "",
1231 msym
->print_name ());
1235 dump_for_expression (struct ui_file
*stream
, int depth
, const block
*bl
)
1237 fprintf_filtered (stream
, _("%*sBlock: %p\n"), depth
, "", bl
);
1241 dump_for_expression (struct ui_file
*stream
, int depth
,
1242 type_instance_flags flags
)
1244 fprintf_filtered (stream
, _("%*sType flags: "), depth
, "");
1245 if (flags
& TYPE_INSTANCE_FLAG_CONST
)
1246 fputs_unfiltered ("const ", stream
);
1247 if (flags
& TYPE_INSTANCE_FLAG_VOLATILE
)
1248 fputs_unfiltered ("volatile", stream
);
1249 fprintf_filtered (stream
, "\n");
1253 dump_for_expression (struct ui_file
*stream
, int depth
,
1254 enum c_string_type_values flags
)
1256 fprintf_filtered (stream
, _("%*sC string flags: "), depth
, "");
1257 switch (flags
& ~C_CHAR
)
1260 fputs_unfiltered (_("wide "), stream
);
1263 fputs_unfiltered (_("u16 "), stream
);
1266 fputs_unfiltered (_("u32 "), stream
);
1269 fputs_unfiltered (_("ordinary "), stream
);
1273 if ((flags
& C_CHAR
) != 0)
1274 fputs_unfiltered (_("char"), stream
);
1276 fputs_unfiltered (_("string"), stream
);
1277 fputs_unfiltered ("\n", stream
);
1281 dump_for_expression (struct ui_file
*stream
, int depth
, objfile
*objf
)
1283 fprintf_filtered (stream
, _("%*sObjfile: %s\n"), depth
, "",
1284 objfile_name (objf
));
1288 dump_for_expression (struct ui_file
*stream
, int depth
,
1289 enum range_flag flags
)
1291 fprintf_filtered (stream
, _("%*sRange:"), depth
, "");
1292 if ((flags
& RANGE_LOW_BOUND_DEFAULT
) != 0)
1293 fputs_unfiltered (_("low-default "), stream
);
1294 if ((flags
& RANGE_HIGH_BOUND_DEFAULT
) != 0)
1295 fputs_unfiltered (_("high-default "), stream
);
1296 if ((flags
& RANGE_HIGH_BOUND_EXCLUSIVE
) != 0)
1297 fputs_unfiltered (_("high-exclusive "), stream
);
1298 if ((flags
& RANGE_HAS_STRIDE
) != 0)
1299 fputs_unfiltered (_("has-stride"), stream
);
1300 fprintf_filtered (stream
, "\n");
1304 dump_for_expression (struct ui_file
*stream
, int depth
,
1305 const std::unique_ptr
<ada_component
> &comp
)
1307 comp
->dump (stream
, depth
);
1311 float_const_operation::dump (struct ui_file
*stream
, int depth
) const
1313 fprintf_filtered (stream
, _("%*sFloat: "), depth
, "");
1314 print_floating (m_data
.data (), m_type
, stream
);
1315 fprintf_filtered (stream
, "\n");
1318 } /* namespace expr */