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 fprintf_filtered (stream
, "Dump of expression @ ");
729 gdb_print_host_address (exp
, stream
);
731 fprintf_filtered (stream
, ", %s:", note
);
732 fprintf_filtered (stream
, "\n\tLanguage %s, %d elements, %ld bytes each.\n",
733 exp
->language_defn
->name (), exp
->nelts
,
734 (long) sizeof (union exp_element
));
735 fprintf_filtered (stream
, "\t%5s %20s %16s %s\n", "Index", "Opcode",
736 "Hex Value", "String Value");
737 for (elt
= 0; elt
< exp
->nelts
; elt
++)
739 fprintf_filtered (stream
, "\t%5d ", elt
);
741 const char *opcode_name
= op_name (exp
->elts
[elt
].opcode
);
742 fprintf_filtered (stream
, "%20s ", opcode_name
);
744 print_longest (stream
, 'd', 0, exp
->elts
[elt
].longconst
);
745 fprintf_filtered (stream
, " ");
747 for (eltscan
= (char *) &exp
->elts
[elt
],
748 eltsize
= sizeof (union exp_element
);
752 fprintf_filtered (stream
, "%c",
753 isprint (*eltscan
) ? (*eltscan
& 0xFF) : '.');
755 fprintf_filtered (stream
, "\n");
759 /* Dump the subexpression of prefix expression EXP whose operator is at
760 position ELT onto STREAM. Returns the position of the next
761 subexpression in EXP. */
764 dump_subexp (struct expression
*exp
, struct ui_file
*stream
, int elt
)
766 static int indent
= 0;
769 fprintf_filtered (stream
, "\n");
770 fprintf_filtered (stream
, "\t%5d ", elt
);
772 for (i
= 1; i
<= indent
; i
++)
773 fprintf_filtered (stream
, " ");
776 fprintf_filtered (stream
, "%-20s ", op_name (exp
->elts
[elt
].opcode
));
778 elt
= dump_subexp_body (exp
, stream
, elt
);
785 /* Dump the operands of prefix expression EXP whose opcode is at
786 position ELT onto STREAM. Returns the position of the next
787 subexpression in EXP. */
790 dump_subexp_body (struct expression
*exp
, struct ui_file
*stream
, int elt
)
792 return exp
->language_defn
->expression_ops ()->dump_subexp_body (exp
, stream
,
796 /* See parser-defs.h. */
799 dump_subexp_body_funcall (struct expression
*exp
,
800 struct ui_file
*stream
, int elt
)
802 int nargs
= longest_to_int (exp
->elts
[elt
].longconst
);
803 fprintf_filtered (stream
, "Number of args: %d", nargs
);
806 for (int i
= 1; i
<= nargs
+ 1; i
++)
807 elt
= dump_subexp (exp
, stream
, elt
);
812 /* Default value for subexp_body in exp_descriptor vector. */
815 dump_subexp_body_standard (struct expression
*exp
,
816 struct ui_file
*stream
, int elt
)
818 int opcode
= exp
->elts
[elt
++].opcode
;
824 elt
= dump_subexp (exp
, stream
, elt
);
834 case BINOP_LOGICAL_AND
:
835 case BINOP_LOGICAL_OR
:
836 case BINOP_BITWISE_AND
:
837 case BINOP_BITWISE_IOR
:
838 case BINOP_BITWISE_XOR
:
848 case BINOP_SUBSCRIPT
:
853 case BINOP_ASSIGN_MODIFY
:
857 case STRUCTOP_MEMBER
:
859 elt
= dump_subexp (exp
, stream
, elt
);
862 case UNOP_LOGICAL_NOT
:
863 case UNOP_COMPLEMENT
:
866 case UNOP_PREINCREMENT
:
867 case UNOP_POSTINCREMENT
:
868 case UNOP_PREDECREMENT
:
869 case UNOP_POSTDECREMENT
:
883 elt
= dump_subexp (exp
, stream
, elt
);
886 fprintf_filtered (stream
, "Type @");
887 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
888 fprintf_filtered (stream
, " (");
889 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
890 fprintf_filtered (stream
, "), value %ld (0x%lx)",
891 (long) exp
->elts
[elt
+ 1].longconst
,
892 (long) exp
->elts
[elt
+ 1].longconst
);
896 fprintf_filtered (stream
, "Type @");
897 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
898 fprintf_filtered (stream
, " (");
899 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
900 fprintf_filtered (stream
, "), value ");
901 print_floating (exp
->elts
[elt
+ 1].floatconst
,
902 exp
->elts
[elt
].type
, stream
);
906 fprintf_filtered (stream
, "Block @");
907 gdb_print_host_address (exp
->elts
[elt
].block
, stream
);
908 fprintf_filtered (stream
, ", symbol @");
909 gdb_print_host_address (exp
->elts
[elt
+ 1].symbol
, stream
);
910 fprintf_filtered (stream
, " (%s)",
911 exp
->elts
[elt
+ 1].symbol
->print_name ());
914 case OP_VAR_MSYM_VALUE
:
915 fprintf_filtered (stream
, "Objfile @");
916 gdb_print_host_address (exp
->elts
[elt
].objfile
, stream
);
917 fprintf_filtered (stream
, ", msymbol @");
918 gdb_print_host_address (exp
->elts
[elt
+ 1].msymbol
, stream
);
919 fprintf_filtered (stream
, " (%s)",
920 exp
->elts
[elt
+ 1].msymbol
->print_name ());
923 case OP_VAR_ENTRY_VALUE
:
924 fprintf_filtered (stream
, "Entry value of symbol @");
925 gdb_print_host_address (exp
->elts
[elt
].symbol
, stream
);
926 fprintf_filtered (stream
, " (%s)",
927 exp
->elts
[elt
].symbol
->print_name ());
931 fprintf_filtered (stream
, "History element %ld",
932 (long) exp
->elts
[elt
].longconst
);
936 fprintf_filtered (stream
, "Register $%s", &exp
->elts
[elt
+ 1].string
);
937 elt
+= 3 + BYTES_TO_EXP_ELEM (exp
->elts
[elt
].longconst
+ 1);
940 fprintf_filtered (stream
, "Internal var @");
941 gdb_print_host_address (exp
->elts
[elt
].internalvar
, stream
);
942 fprintf_filtered (stream
, " (%s)",
943 internalvar_name (exp
->elts
[elt
].internalvar
));
947 elt
= dump_subexp_body_funcall (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_flag range_flag
;
1102 range_flag
= (enum range_flag
)
1103 longest_to_int (exp
->elts
[elt
].longconst
);
1106 if (range_flag
& RANGE_HIGH_BOUND_EXCLUSIVE
)
1107 fputs_filtered ("Exclusive", stream
);
1108 fputs_filtered ("Range '", stream
);
1109 if (!(range_flag
& RANGE_LOW_BOUND_DEFAULT
))
1110 fputs_filtered ("EXP", stream
);
1111 fputs_filtered ("..", stream
);
1112 if (!(range_flag
& RANGE_HIGH_BOUND_DEFAULT
))
1113 fputs_filtered ("EXP", stream
);
1114 if (range_flag
& RANGE_HAS_STRIDE
)
1115 fputs_filtered (":EXP", stream
);
1116 fputs_filtered ("'", stream
);
1118 if (!(range_flag
& RANGE_LOW_BOUND_DEFAULT
))
1119 elt
= dump_subexp (exp
, stream
, elt
);
1120 if (!(range_flag
& RANGE_HIGH_BOUND_DEFAULT
))
1121 elt
= dump_subexp (exp
, stream
, elt
);
1122 if (range_flag
& RANGE_HAS_STRIDE
)
1123 elt
= dump_subexp (exp
, stream
, elt
);
1129 bool val
= (bool) (exp
->elts
[elt
].longconst
);
1130 fputs_filtered (val
? "TRUE" : "FALSE", stream
);
1137 case MULTI_SUBSCRIPT
:
1142 fprintf_filtered (stream
, "Unknown format");
1149 dump_prefix_expression (struct expression
*exp
, struct ui_file
*stream
)
1153 fprintf_filtered (stream
, "Dump of expression @ ");
1154 gdb_print_host_address (exp
, stream
);
1155 fputs_filtered (", after conversion to prefix form:\nExpression: `", stream
);
1156 print_expression (exp
, stream
);
1157 fprintf_filtered (stream
, "'\n\tLanguage %s, %d elements, %ld bytes each.\n",
1158 exp
->language_defn
->name (), exp
->nelts
,
1159 (long) sizeof (union exp_element
));
1160 fputs_filtered ("\n", stream
);
1162 for (elt
= 0; elt
< exp
->nelts
;)
1163 elt
= dump_subexp (exp
, stream
, elt
);
1164 fputs_filtered ("\n", stream
);
1171 dump_for_expression (struct ui_file
*stream
, int depth
, enum exp_opcode op
)
1173 fprintf_filtered (stream
, _("%*sOperation: %s\n"), depth
, "", op_name (op
));
1177 dump_for_expression (struct ui_file
*stream
, int depth
, const std::string
&str
)
1179 fprintf_filtered (stream
, _("%*sString: %s\n"), depth
, "", str
.c_str ());
1183 dump_for_expression (struct ui_file
*stream
, int depth
, struct type
*type
)
1185 fprintf_filtered (stream
, _("%*sType: "), depth
, "");
1186 type_print (type
, nullptr, stream
, 0);
1187 fprintf_filtered (stream
, "\n");
1191 dump_for_expression (struct ui_file
*stream
, int depth
, CORE_ADDR addr
)
1193 fprintf_filtered (stream
, _("%*sConstant: %s\n"), depth
, "",
1194 core_addr_to_string (addr
));
1198 dump_for_expression (struct ui_file
*stream
, int depth
, internalvar
*ivar
)
1200 fprintf_filtered (stream
, _("%*sInternalvar: $%s\n"), depth
, "",
1201 internalvar_name (ivar
));
1205 dump_for_expression (struct ui_file
*stream
, int depth
, symbol
*sym
)
1207 fprintf_filtered (stream
, _("%*sSymbol: %s\n"), depth
, "",
1208 sym
->print_name ());
1212 dump_for_expression (struct ui_file
*stream
, int depth
, minimal_symbol
*msym
)
1214 fprintf_filtered (stream
, _("%*sMinsym: %s\n"), depth
, "",
1215 msym
->print_name ());
1219 dump_for_expression (struct ui_file
*stream
, int depth
, const block
*bl
)
1221 fprintf_filtered (stream
, _("%*sBlock: %p\n"), depth
, "", bl
);
1225 dump_for_expression (struct ui_file
*stream
, int depth
,
1226 type_instance_flags flags
)
1228 fprintf_filtered (stream
, _("%*sType flags: "), depth
, "");
1229 if (flags
& TYPE_INSTANCE_FLAG_CONST
)
1230 fputs_unfiltered ("const ", stream
);
1231 if (flags
& TYPE_INSTANCE_FLAG_VOLATILE
)
1232 fputs_unfiltered ("volatile", stream
);
1233 fprintf_filtered (stream
, "\n");
1237 dump_for_expression (struct ui_file
*stream
, int depth
,
1238 enum c_string_type_values flags
)
1240 fprintf_filtered (stream
, _("%*sC string flags: "), depth
, "");
1241 switch (flags
& ~C_CHAR
)
1244 fputs_unfiltered (_("wide "), stream
);
1247 fputs_unfiltered (_("u16 "), stream
);
1250 fputs_unfiltered (_("u32 "), stream
);
1253 fputs_unfiltered (_("ordinary "), stream
);
1257 if ((flags
& C_CHAR
) != 0)
1258 fputs_unfiltered (_("char"), stream
);
1260 fputs_unfiltered (_("string"), stream
);
1261 fputs_unfiltered ("\n", stream
);
1265 dump_for_expression (struct ui_file
*stream
, int depth
, objfile
*objf
)
1267 fprintf_filtered (stream
, _("%*sObjfile: %s\n"), depth
, "",
1268 objfile_name (objf
));
1272 dump_for_expression (struct ui_file
*stream
, int depth
,
1273 enum range_flag flags
)
1275 fprintf_filtered (stream
, _("%*sRange:"), depth
, "");
1276 if ((flags
& RANGE_LOW_BOUND_DEFAULT
) != 0)
1277 fputs_unfiltered (_("low-default "), stream
);
1278 if ((flags
& RANGE_HIGH_BOUND_DEFAULT
) != 0)
1279 fputs_unfiltered (_("high-default "), stream
);
1280 if ((flags
& RANGE_HIGH_BOUND_EXCLUSIVE
) != 0)
1281 fputs_unfiltered (_("high-exclusive "), stream
);
1282 if ((flags
& RANGE_HAS_STRIDE
) != 0)
1283 fputs_unfiltered (_("has-stride"), stream
);
1284 fprintf_filtered (stream
, "\n");
1288 dump_for_expression (struct ui_file
*stream
, int depth
,
1289 const std::unique_ptr
<ada_component
> &comp
)
1291 comp
->dump (stream
, depth
);
1295 float_const_operation::dump (struct ui_file
*stream
, int depth
) const
1297 fprintf_filtered (stream
, _("%*sFloat: "), depth
, "");
1298 print_floating (m_data
.data (), m_type
, stream
);
1299 fprintf_filtered (stream
, "\n");
1302 } /* namespace expr */