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"
39 print_expression (struct expression
*exp
, struct ui_file
*stream
)
43 print_subexp (exp
, &pc
, stream
, PREC_NULL
);
46 /* Print the subexpression of EXP that starts in position POS, on STREAM.
47 PREC is the precedence of the surrounding operator;
48 if the precedence of the main operator of this subexpression is less,
49 parentheses are needed here. */
52 print_subexp (struct expression
*exp
, int *pos
,
53 struct ui_file
*stream
, enum precedence prec
)
55 exp
->language_defn
->expression_ops ()->print_subexp (exp
, pos
, stream
,
59 /* See parser-defs.h. */
62 print_subexp_funcall (struct expression
*exp
, int *pos
,
63 struct ui_file
*stream
)
65 unsigned nargs
= longest_to_int (exp
->elts
[*pos
].longconst
);
67 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
68 fputs_filtered (" (", stream
);
69 for (unsigned tem
= 0; tem
< nargs
; tem
++)
72 fputs_filtered (", ", stream
);
73 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
75 fputs_filtered (")", stream
);
78 /* Standard implementation of print_subexp for use in language_defn
81 print_subexp_standard (struct expression
*exp
, int *pos
,
82 struct ui_file
*stream
, enum precedence prec
)
85 const struct op_print
*op_print_tab
;
89 int assign_modify
= 0;
90 enum exp_opcode opcode
;
91 enum precedence myprec
= PREC_NULL
;
92 /* Set to 1 for a right-associative operator. */
97 op_print_tab
= exp
->language_defn
->opcode_print_table ();
99 opcode
= exp
->elts
[pc
].opcode
;
106 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
110 myprec
= PREC_PREFIX
;
112 fputs_filtered (exp
->elts
[pc
+ 1].type
->name (), stream
);
113 fputs_filtered ("::", stream
);
114 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
115 (*pos
) += 4 + BYTES_TO_EXP_ELEM (nargs
+ 1);
116 fputs_filtered (&exp
->elts
[pc
+ 3].string
, stream
);
121 struct value_print_options opts
;
123 get_no_prettyformat_print_options (&opts
);
125 value_print (value_from_longest (exp
->elts
[pc
+ 1].type
,
126 exp
->elts
[pc
+ 2].longconst
),
133 struct value_print_options opts
;
135 get_no_prettyformat_print_options (&opts
);
137 value_print (value_from_contents (exp
->elts
[pc
+ 1].type
,
138 exp
->elts
[pc
+ 2].floatconst
),
145 const struct block
*b
;
148 b
= exp
->elts
[pc
+ 1].block
;
150 && BLOCK_FUNCTION (b
) != NULL
151 && BLOCK_FUNCTION (b
)->print_name () != NULL
)
153 fputs_filtered (BLOCK_FUNCTION (b
)->print_name (), stream
);
154 fputs_filtered ("::", stream
);
156 fputs_filtered (exp
->elts
[pc
+ 2].symbol
->print_name (), stream
);
160 case OP_VAR_MSYM_VALUE
:
163 fputs_filtered (exp
->elts
[pc
+ 2].msymbol
->print_name (), stream
);
167 case OP_FUNC_STATIC_VAR
:
169 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
170 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
171 fputs_filtered (&exp
->elts
[pc
+ 1].string
, stream
);
175 case OP_VAR_ENTRY_VALUE
:
178 fprintf_filtered (stream
, "%s@entry",
179 exp
->elts
[pc
+ 1].symbol
->print_name ());
185 fprintf_filtered (stream
, "$%d",
186 longest_to_int (exp
->elts
[pc
+ 1].longconst
));
191 const char *name
= &exp
->elts
[pc
+ 2].string
;
193 (*pos
) += 3 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
194 fprintf_filtered (stream
, "$%s", name
);
200 fprintf_filtered (stream
, "%s",
201 longest_to_int (exp
->elts
[pc
+ 1].longconst
)
207 fprintf_filtered (stream
, "$%s",
208 internalvar_name (exp
->elts
[pc
+ 1].internalvar
));
212 print_subexp_funcall (exp
, pos
, stream
);
216 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
217 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
218 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
223 struct value_print_options opts
;
225 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
226 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
227 /* LA_PRINT_STRING will print using the current repeat count threshold.
228 If necessary, we can temporarily set it to zero, or pass it as an
229 additional parameter to LA_PRINT_STRING. -fnf */
230 get_user_print_options (&opts
);
232 ->printstr (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
233 (gdb_byte
*) &exp
->elts
[pc
+ 2].string
, nargs
,
238 case OP_OBJC_NSSTRING
: /* Objective-C Foundation Class
239 NSString constant. */
241 struct value_print_options opts
;
243 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
244 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
245 fputs_filtered ("@\"", stream
);
246 get_user_print_options (&opts
);
248 ->printstr (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
249 (gdb_byte
*) &exp
->elts
[pc
+ 2].string
, nargs
,
251 fputs_filtered ("\"", stream
);
255 case OP_OBJC_MSGCALL
:
256 { /* Objective C message (method) call. */
258 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
259 fprintf_unfiltered (stream
, "[");
260 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
261 gdb::unique_xmalloc_ptr
<char> selector
262 = target_read_string (exp
->elts
[pc
+ 1].longconst
, 1024);
263 if (selector
== nullptr)
264 error (_("bad selector"));
270 for (tem
= 0; tem
< nargs
; tem
++)
272 nextS
= strchr (s
, ':');
273 gdb_assert (nextS
); /* Make sure we found ':'. */
275 fprintf_unfiltered (stream
, " %s: ", s
);
277 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
282 fprintf_unfiltered (stream
, " %s", selector
.get ());
284 fprintf_unfiltered (stream
, "]");
290 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
291 nargs
-= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
294 if (exp
->elts
[pc
+ 4].opcode
== OP_LONG
295 && exp
->elts
[pc
+ 5].type
296 == builtin_type (exp
->gdbarch
)->builtin_char
297 && exp
->language_defn
->la_language
== language_c
)
299 /* Attempt to print C character arrays using string syntax.
300 Walk through the args, picking up one character from each
301 of the OP_LONG expression elements. If any array element
302 does not match our expection of what we should find for
303 a simple string, revert back to array printing. Note that
304 the last expression element is an explicit null terminator
305 byte, which doesn't get printed. */
306 tempstr
= (char *) alloca (nargs
);
310 if (exp
->elts
[pc
].opcode
!= OP_LONG
311 || exp
->elts
[pc
+ 1].type
312 != builtin_type (exp
->gdbarch
)->builtin_char
)
314 /* Not a simple array of char, use regular array
322 longest_to_int (exp
->elts
[pc
+ 2].longconst
);
329 struct value_print_options opts
;
331 get_user_print_options (&opts
);
333 ->printstr (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
334 (gdb_byte
*) tempstr
, nargs
- 1, NULL
, 0, &opts
);
339 fputs_filtered (" {", stream
);
340 for (tem
= 0; tem
< nargs
; tem
++)
344 fputs_filtered (", ", stream
);
346 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
348 fputs_filtered ("}", stream
);
353 if ((int) prec
> (int) PREC_COMMA
)
354 fputs_filtered ("(", stream
);
355 /* Print the subexpressions, forcing parentheses
356 around any binary operations within them.
357 This is more parentheses than are strictly necessary,
358 but it looks clearer. */
359 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
360 fputs_filtered (" ? ", stream
);
361 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
362 fputs_filtered (" : ", stream
);
363 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
364 if ((int) prec
> (int) PREC_COMMA
)
365 fputs_filtered (")", stream
);
369 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
370 fputs_filtered ("(", stream
);
371 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
372 fputs_filtered (opcode
== TERNOP_SLICE
? " : " : " UP ", stream
);
373 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
374 fputs_filtered (")", stream
);
377 case STRUCTOP_STRUCT
:
378 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
379 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
380 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
381 fputs_filtered (".", stream
);
382 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
385 /* Will not occur for Modula-2. */
387 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
388 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
389 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
390 fputs_filtered ("->", stream
);
391 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
394 case STRUCTOP_MEMBER
:
395 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
396 fputs_filtered (".*", stream
);
397 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
401 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
402 fputs_filtered ("->*", stream
);
403 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
406 case BINOP_SUBSCRIPT
:
407 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
408 fputs_filtered ("[", stream
);
409 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
410 fputs_filtered ("]", stream
);
413 case UNOP_POSTINCREMENT
:
414 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
415 fputs_filtered ("++", stream
);
418 case UNOP_POSTDECREMENT
:
419 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
420 fputs_filtered ("--", stream
);
425 if ((int) prec
> (int) PREC_PREFIX
)
426 fputs_filtered ("(", stream
);
427 fputs_filtered ("(", stream
);
428 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
429 fputs_filtered (") ", stream
);
430 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
431 if ((int) prec
> (int) PREC_PREFIX
)
432 fputs_filtered (")", stream
);
436 if ((int) prec
> (int) PREC_PREFIX
)
437 fputs_filtered ("(", stream
);
438 fputs_filtered ("(", stream
);
439 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
440 fputs_filtered (") ", stream
);
441 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
442 if ((int) prec
> (int) PREC_PREFIX
)
443 fputs_filtered (")", stream
);
446 case UNOP_DYNAMIC_CAST
:
447 case UNOP_REINTERPRET_CAST
:
448 fputs_filtered (opcode
== UNOP_DYNAMIC_CAST
? "dynamic_cast"
449 : "reinterpret_cast", stream
);
450 fputs_filtered ("<", stream
);
451 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
452 fputs_filtered ("> (", stream
);
453 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
454 fputs_filtered (")", stream
);
459 if ((int) prec
> (int) PREC_PREFIX
)
460 fputs_filtered ("(", stream
);
461 if (exp
->elts
[pc
+ 1].type
->code () == TYPE_CODE_FUNC
462 && exp
->elts
[pc
+ 3].opcode
== OP_LONG
)
464 struct value_print_options opts
;
466 /* We have a minimal symbol fn, probably. It's encoded
467 as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address).
468 Swallow the OP_LONG (including both its opcodes); ignore
469 its type; print the value in the type of the MEMVAL. */
471 val
= value_at_lazy (exp
->elts
[pc
+ 1].type
,
472 (CORE_ADDR
) exp
->elts
[pc
+ 5].longconst
);
473 get_no_prettyformat_print_options (&opts
);
474 value_print (val
, stream
, &opts
);
478 fputs_filtered ("{", stream
);
479 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
480 fputs_filtered ("} ", stream
);
481 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
483 if ((int) prec
> (int) PREC_PREFIX
)
484 fputs_filtered (")", stream
);
487 case UNOP_MEMVAL_TYPE
:
488 if ((int) prec
> (int) PREC_PREFIX
)
489 fputs_filtered ("(", stream
);
490 fputs_filtered ("{", stream
);
491 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
492 fputs_filtered ("} ", stream
);
493 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
494 if ((int) prec
> (int) PREC_PREFIX
)
495 fputs_filtered (")", stream
);
498 case BINOP_ASSIGN_MODIFY
:
499 opcode
= exp
->elts
[pc
+ 1].opcode
;
501 myprec
= PREC_ASSIGN
;
505 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
506 if (op_print_tab
[tem
].opcode
== opcode
)
508 op_str
= op_print_tab
[tem
].string
;
511 if (op_print_tab
[tem
].opcode
!= opcode
)
512 /* Not found; don't try to keep going because we don't know how
513 to interpret further elements. */
514 error (_("Invalid expression"));
521 if (exp
->language_defn
->name_of_this () != NULL
)
522 fputs_filtered (exp
->language_defn
->name_of_this (), stream
);
524 fprintf_styled (stream
, metadata_style
.style (),
525 _("<language %s has no 'this'>"),
526 exp
->language_defn
->name ());
531 case MULTI_SUBSCRIPT
:
533 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
534 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
535 fprintf_unfiltered (stream
, " [");
536 for (tem
= 0; tem
< nargs
; tem
++)
539 fprintf_unfiltered (stream
, ", ");
540 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
542 fprintf_unfiltered (stream
, "]");
547 fprintf_unfiltered (stream
, "VAL(");
548 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
549 fprintf_unfiltered (stream
, ",");
550 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
551 fprintf_unfiltered (stream
, ")");
556 type_instance_flags flags
557 = (type_instance_flag_value
) longest_to_int (exp
->elts
[pc
+ 1].longconst
);
558 LONGEST count
= exp
->elts
[pc
+ 2].longconst
;
564 fputs_unfiltered ("TypeInstance(", stream
);
567 type_print (exp
->elts
[(*pos
)++].type
, "", stream
, 0);
569 fputs_unfiltered (",", stream
);
571 fputs_unfiltered (",", stream
);
572 /* Ending COUNT and ending TYPE_INSTANCE. */
574 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
576 if (flags
& TYPE_INSTANCE_FLAG_CONST
)
577 fputs_unfiltered (",const", stream
);
578 if (flags
& TYPE_INSTANCE_FLAG_VOLATILE
)
579 fputs_unfiltered (",volatile", stream
);
581 fputs_unfiltered (")", stream
);
587 enum range_flag range_flag
;
589 range_flag
= (enum range_flag
)
590 longest_to_int (exp
->elts
[pc
+ 1].longconst
);
593 if (range_flag
& RANGE_HIGH_BOUND_EXCLUSIVE
)
594 fputs_filtered ("EXCLUSIVE_", stream
);
595 fputs_filtered ("RANGE(", stream
);
596 if (!(range_flag
& RANGE_LOW_BOUND_DEFAULT
))
597 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
598 fputs_filtered ("..", stream
);
599 if (!(range_flag
& RANGE_HIGH_BOUND_DEFAULT
))
600 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
601 fputs_filtered (")", stream
);
609 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
610 if (op_print_tab
[tem
].opcode
== opcode
)
612 op_str
= op_print_tab
[tem
].string
;
613 myprec
= op_print_tab
[tem
].precedence
;
614 assoc
= op_print_tab
[tem
].right_assoc
;
617 if (op_print_tab
[tem
].opcode
!= opcode
)
618 /* Not found; don't try to keep going because we don't know how
619 to interpret further elements. For example, this happens
620 if opcode is OP_TYPE. */
621 error (_("Invalid expression"));
624 /* Note that PREC_BUILTIN will always emit parentheses. */
625 if ((int) myprec
< (int) prec
)
626 fputs_filtered ("(", stream
);
627 if ((int) opcode
> (int) BINOP_END
)
631 /* Unary postfix operator. */
632 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
633 fputs_filtered (op_str
, stream
);
637 /* Unary prefix operator. */
638 fputs_filtered (op_str
, stream
);
639 if (myprec
== PREC_BUILTIN_FUNCTION
)
640 fputs_filtered ("(", stream
);
641 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
642 if (myprec
== PREC_BUILTIN_FUNCTION
)
643 fputs_filtered (")", stream
);
648 /* Binary operator. */
649 /* Print left operand.
650 If operator is right-associative,
651 increment precedence for this operand. */
652 print_subexp (exp
, pos
, stream
,
653 (enum precedence
) ((int) myprec
+ assoc
));
654 /* Print the operator itself. */
656 fprintf_filtered (stream
, " %s= ", op_str
);
657 else if (op_str
[0] == ',')
658 fprintf_filtered (stream
, "%s ", op_str
);
660 fprintf_filtered (stream
, " %s ", op_str
);
661 /* Print right operand.
662 If operator is left-associative,
663 increment precedence for this operand. */
664 print_subexp (exp
, pos
, stream
,
665 (enum precedence
) ((int) myprec
+ !assoc
));
668 if ((int) myprec
< (int) prec
)
669 fputs_filtered (")", stream
);
672 /* Return the operator corresponding to opcode OP as
673 a string. NULL indicates that the opcode was not found in the
674 current language table. */
676 op_string (enum exp_opcode op
)
679 const struct op_print
*op_print_tab
;
681 op_print_tab
= current_language
->opcode_print_table ();
682 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
683 if (op_print_tab
[tem
].opcode
== op
)
684 return op_print_tab
[tem
].string
;
688 /* Support for dumping the raw data from expressions in a human readable
691 static int dump_subexp_body (struct expression
*exp
, struct ui_file
*, int);
693 /* Default name for the standard operator OPCODE (i.e., one defined in
694 the definition of enum exp_opcode). */
697 op_name (enum exp_opcode opcode
)
705 xsnprintf (buf
, sizeof (buf
), "<unknown %d>", opcode
);
711 #include "std-operator.def"
716 /* Print a raw dump of expression EXP to STREAM.
717 NOTE, if non-NULL, is printed as extra explanatory text. */
720 dump_raw_expression (struct expression
*exp
, struct ui_file
*stream
,
727 fprintf_filtered (stream
, "Dump of expression @ ");
728 gdb_print_host_address (exp
, stream
);
730 fprintf_filtered (stream
, ", %s:", note
);
731 fprintf_filtered (stream
, "\n\tLanguage %s, %d elements, %ld bytes each.\n",
732 exp
->language_defn
->name (), exp
->nelts
,
733 (long) sizeof (union exp_element
));
734 fprintf_filtered (stream
, "\t%5s %20s %16s %s\n", "Index", "Opcode",
735 "Hex Value", "String Value");
736 for (elt
= 0; elt
< exp
->nelts
; elt
++)
738 fprintf_filtered (stream
, "\t%5d ", elt
);
740 const char *opcode_name
= op_name (exp
->elts
[elt
].opcode
);
741 fprintf_filtered (stream
, "%20s ", opcode_name
);
743 print_longest (stream
, 'd', 0, exp
->elts
[elt
].longconst
);
744 fprintf_filtered (stream
, " ");
746 for (eltscan
= (char *) &exp
->elts
[elt
],
747 eltsize
= sizeof (union exp_element
);
751 fprintf_filtered (stream
, "%c",
752 isprint (*eltscan
) ? (*eltscan
& 0xFF) : '.');
754 fprintf_filtered (stream
, "\n");
758 /* Dump the subexpression of prefix expression EXP whose operator is at
759 position ELT onto STREAM. Returns the position of the next
760 subexpression in EXP. */
763 dump_subexp (struct expression
*exp
, struct ui_file
*stream
, int elt
)
765 static int indent
= 0;
768 fprintf_filtered (stream
, "\n");
769 fprintf_filtered (stream
, "\t%5d ", elt
);
771 for (i
= 1; i
<= indent
; i
++)
772 fprintf_filtered (stream
, " ");
775 fprintf_filtered (stream
, "%-20s ", op_name (exp
->elts
[elt
].opcode
));
777 elt
= dump_subexp_body (exp
, stream
, elt
);
784 /* Dump the operands of prefix expression EXP whose opcode is at
785 position ELT onto STREAM. Returns the position of the next
786 subexpression in EXP. */
789 dump_subexp_body (struct expression
*exp
, struct ui_file
*stream
, int elt
)
791 return exp
->language_defn
->expression_ops ()->dump_subexp_body (exp
, stream
,
795 /* See parser-defs.h. */
798 dump_subexp_body_funcall (struct expression
*exp
,
799 struct ui_file
*stream
, int elt
)
801 int nargs
= longest_to_int (exp
->elts
[elt
].longconst
);
802 fprintf_filtered (stream
, "Number of args: %d", nargs
);
805 for (int i
= 1; i
<= nargs
+ 1; i
++)
806 elt
= dump_subexp (exp
, stream
, elt
);
811 /* Default value for subexp_body in exp_descriptor vector. */
814 dump_subexp_body_standard (struct expression
*exp
,
815 struct ui_file
*stream
, int elt
)
817 int opcode
= exp
->elts
[elt
++].opcode
;
823 elt
= dump_subexp (exp
, stream
, elt
);
833 case BINOP_LOGICAL_AND
:
834 case BINOP_LOGICAL_OR
:
835 case BINOP_BITWISE_AND
:
836 case BINOP_BITWISE_IOR
:
837 case BINOP_BITWISE_XOR
:
847 case BINOP_SUBSCRIPT
:
852 case BINOP_ASSIGN_MODIFY
:
856 case STRUCTOP_MEMBER
:
858 elt
= dump_subexp (exp
, stream
, elt
);
861 case UNOP_LOGICAL_NOT
:
862 case UNOP_COMPLEMENT
:
865 case UNOP_PREINCREMENT
:
866 case UNOP_POSTINCREMENT
:
867 case UNOP_PREDECREMENT
:
868 case UNOP_POSTDECREMENT
:
882 elt
= dump_subexp (exp
, stream
, elt
);
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 %ld (0x%lx)",
890 (long) exp
->elts
[elt
+ 1].longconst
,
891 (long) exp
->elts
[elt
+ 1].longconst
);
895 fprintf_filtered (stream
, "Type @");
896 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
897 fprintf_filtered (stream
, " (");
898 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
899 fprintf_filtered (stream
, "), value ");
900 print_floating (exp
->elts
[elt
+ 1].floatconst
,
901 exp
->elts
[elt
].type
, stream
);
905 fprintf_filtered (stream
, "Block @");
906 gdb_print_host_address (exp
->elts
[elt
].block
, stream
);
907 fprintf_filtered (stream
, ", symbol @");
908 gdb_print_host_address (exp
->elts
[elt
+ 1].symbol
, stream
);
909 fprintf_filtered (stream
, " (%s)",
910 exp
->elts
[elt
+ 1].symbol
->print_name ());
913 case OP_VAR_MSYM_VALUE
:
914 fprintf_filtered (stream
, "Objfile @");
915 gdb_print_host_address (exp
->elts
[elt
].objfile
, stream
);
916 fprintf_filtered (stream
, ", msymbol @");
917 gdb_print_host_address (exp
->elts
[elt
+ 1].msymbol
, stream
);
918 fprintf_filtered (stream
, " (%s)",
919 exp
->elts
[elt
+ 1].msymbol
->print_name ());
922 case OP_VAR_ENTRY_VALUE
:
923 fprintf_filtered (stream
, "Entry value of symbol @");
924 gdb_print_host_address (exp
->elts
[elt
].symbol
, stream
);
925 fprintf_filtered (stream
, " (%s)",
926 exp
->elts
[elt
].symbol
->print_name ());
930 fprintf_filtered (stream
, "History element %ld",
931 (long) exp
->elts
[elt
].longconst
);
935 fprintf_filtered (stream
, "Register $%s", &exp
->elts
[elt
+ 1].string
);
936 elt
+= 3 + BYTES_TO_EXP_ELEM (exp
->elts
[elt
].longconst
+ 1);
939 fprintf_filtered (stream
, "Internal var @");
940 gdb_print_host_address (exp
->elts
[elt
].internalvar
, stream
);
941 fprintf_filtered (stream
, " (%s)",
942 internalvar_name (exp
->elts
[elt
].internalvar
));
946 elt
= dump_subexp_body_funcall (exp
, stream
, elt
);
953 lower
= longest_to_int (exp
->elts
[elt
].longconst
);
954 upper
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
956 fprintf_filtered (stream
, "Bounds [%d:%d]", lower
, upper
);
959 for (i
= 1; i
<= upper
- lower
+ 1; i
++)
960 elt
= dump_subexp (exp
, stream
, elt
);
963 case UNOP_DYNAMIC_CAST
:
964 case UNOP_REINTERPRET_CAST
:
966 case UNOP_MEMVAL_TYPE
:
967 fprintf_filtered (stream
, " (");
968 elt
= dump_subexp (exp
, stream
, elt
);
969 fprintf_filtered (stream
, ")");
970 elt
= dump_subexp (exp
, stream
, elt
);
974 fprintf_filtered (stream
, "Type @");
975 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
976 fprintf_filtered (stream
, " (");
977 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
978 fprintf_filtered (stream
, ")");
979 elt
= dump_subexp (exp
, stream
, elt
+ 2);
982 fprintf_filtered (stream
, "Type @");
983 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
984 fprintf_filtered (stream
, " (");
985 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
986 fprintf_filtered (stream
, ")");
991 fprintf_filtered (stream
, "Typeof (");
992 elt
= dump_subexp (exp
, stream
, elt
);
993 fprintf_filtered (stream
, ")");
996 fprintf_filtered (stream
, "typeid (");
997 elt
= dump_subexp (exp
, stream
, elt
);
998 fprintf_filtered (stream
, ")");
1000 case STRUCTOP_STRUCT
:
1006 len
= longest_to_int (exp
->elts
[elt
].longconst
);
1007 elem_name
= &exp
->elts
[elt
+ 1].string
;
1009 fprintf_filtered (stream
, "Element name: `%.*s'", len
, elem_name
);
1010 elt
= dump_subexp (exp
, stream
, elt
+ 3 + BYTES_TO_EXP_ELEM (len
+ 1));
1018 fprintf_filtered (stream
, "Type @");
1019 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1020 fprintf_filtered (stream
, " (");
1021 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1022 fprintf_filtered (stream
, ") ");
1024 len
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
1025 elem_name
= &exp
->elts
[elt
+ 2].string
;
1027 fprintf_filtered (stream
, "Field name: `%.*s'", len
, elem_name
);
1028 elt
+= 4 + BYTES_TO_EXP_ELEM (len
+ 1);
1032 case OP_FUNC_STATIC_VAR
:
1034 int len
= longest_to_int (exp
->elts
[elt
].longconst
);
1035 const char *var_name
= &exp
->elts
[elt
+ 1].string
;
1036 fprintf_filtered (stream
, "Field name: `%.*s'", len
, var_name
);
1037 elt
+= 3 + BYTES_TO_EXP_ELEM (len
+ 1);
1043 type_instance_flags flags
1044 = (type_instance_flag_value
) longest_to_int (exp
->elts
[elt
++].longconst
);
1045 LONGEST len
= exp
->elts
[elt
++].longconst
;
1046 fprintf_filtered (stream
, "%s TypeInstance: ", plongest (len
));
1049 fprintf_filtered (stream
, "Type @");
1050 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1051 fprintf_filtered (stream
, " (");
1052 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1053 fprintf_filtered (stream
, ")");
1056 fputs_filtered (", ", stream
);
1059 fprintf_filtered (stream
, " Flags: %s (", hex_string (flags
));
1061 auto print_one
= [&] (const char *mod
)
1064 fputs_filtered (" ", stream
);
1066 fprintf_filtered (stream
, "%s", mod
);
1068 if (flags
& TYPE_INSTANCE_FLAG_CONST
)
1069 print_one ("const");
1070 if (flags
& TYPE_INSTANCE_FLAG_VOLATILE
)
1071 print_one ("volatile");
1072 fprintf_filtered (stream
, ")");
1074 /* Ending LEN and ending TYPE_INSTANCE. */
1076 elt
= dump_subexp (exp
, stream
, elt
);
1081 LONGEST len
= exp
->elts
[elt
].longconst
;
1082 LONGEST type
= exp
->elts
[elt
+ 1].longconst
;
1084 fprintf_filtered (stream
, "Language-specific string type: %s",
1090 /* Skip string content. */
1091 elt
+= BYTES_TO_EXP_ELEM (len
);
1093 /* Skip length and ending OP_STRING. */
1099 enum range_flag range_flag
;
1101 range_flag
= (enum range_flag
)
1102 longest_to_int (exp
->elts
[elt
].longconst
);
1105 if (range_flag
& RANGE_HIGH_BOUND_EXCLUSIVE
)
1106 fputs_filtered ("Exclusive", stream
);
1107 fputs_filtered ("Range '", stream
);
1108 if (!(range_flag
& RANGE_LOW_BOUND_DEFAULT
))
1109 fputs_filtered ("EXP", stream
);
1110 fputs_filtered ("..", stream
);
1111 if (!(range_flag
& RANGE_HIGH_BOUND_DEFAULT
))
1112 fputs_filtered ("EXP", stream
);
1113 if (range_flag
& RANGE_HAS_STRIDE
)
1114 fputs_filtered (":EXP", stream
);
1115 fputs_filtered ("'", stream
);
1117 if (!(range_flag
& RANGE_LOW_BOUND_DEFAULT
))
1118 elt
= dump_subexp (exp
, stream
, elt
);
1119 if (!(range_flag
& RANGE_HIGH_BOUND_DEFAULT
))
1120 elt
= dump_subexp (exp
, stream
, elt
);
1121 if (range_flag
& RANGE_HAS_STRIDE
)
1122 elt
= dump_subexp (exp
, stream
, elt
);
1128 bool val
= (bool) (exp
->elts
[elt
].longconst
);
1129 fputs_filtered (val
? "TRUE" : "FALSE", stream
);
1136 case MULTI_SUBSCRIPT
:
1141 fprintf_filtered (stream
, "Unknown format");
1148 dump_prefix_expression (struct expression
*exp
, struct ui_file
*stream
)
1152 fprintf_filtered (stream
, "Dump of expression @ ");
1153 gdb_print_host_address (exp
, stream
);
1154 fputs_filtered (", after conversion to prefix form:\nExpression: `", stream
);
1155 print_expression (exp
, stream
);
1156 fprintf_filtered (stream
, "'\n\tLanguage %s, %d elements, %ld bytes each.\n",
1157 exp
->language_defn
->name (), exp
->nelts
,
1158 (long) sizeof (union exp_element
));
1159 fputs_filtered ("\n", stream
);
1161 for (elt
= 0; elt
< exp
->nelts
;)
1162 elt
= dump_subexp (exp
, stream
, elt
);
1163 fputs_filtered ("\n", stream
);
1170 dump_for_expression (struct ui_file
*stream
, int depth
, enum exp_opcode op
)
1172 fprintf_filtered (stream
, _("%*sOperation: %s\n"), depth
, "", op_name (op
));
1176 dump_for_expression (struct ui_file
*stream
, int depth
, const std::string
&str
)
1178 fprintf_filtered (stream
, _("%*sString: %s\n"), depth
, "", str
.c_str ());
1182 dump_for_expression (struct ui_file
*stream
, int depth
, struct type
*type
)
1184 fprintf_filtered (stream
, _("%*sType: "), depth
, "");
1185 type_print (type
, nullptr, stream
, 0);
1186 fprintf_filtered (stream
, "\n");
1190 dump_for_expression (struct ui_file
*stream
, int depth
, CORE_ADDR addr
)
1192 fprintf_filtered (stream
, _("%*sConstant: %s\n"), depth
, "",
1193 core_addr_to_string (addr
));
1197 dump_for_expression (struct ui_file
*stream
, int depth
, internalvar
*ivar
)
1199 fprintf_filtered (stream
, _("%*sInternalvar: $%s\n"), depth
, "",
1200 internalvar_name (ivar
));
1204 dump_for_expression (struct ui_file
*stream
, int depth
, symbol
*sym
)
1206 fprintf_filtered (stream
, _("%*sSymbol: %s\n"), depth
, "",
1207 sym
->print_name ());
1211 dump_for_expression (struct ui_file
*stream
, int depth
, minimal_symbol
*msym
)
1213 fprintf_filtered (stream
, _("%*sMinsym: %s\n"), depth
, "",
1214 msym
->print_name ());
1218 dump_for_expression (struct ui_file
*stream
, int depth
, const block
*bl
)
1220 fprintf_filtered (stream
, _("%*sBlock: %p\n"), depth
, "", bl
);
1224 dump_for_expression (struct ui_file
*stream
, int depth
,
1225 type_instance_flags flags
)
1227 fprintf_filtered (stream
, _("%*sType flags: "), depth
, "");
1228 if (flags
& TYPE_INSTANCE_FLAG_CONST
)
1229 fputs_unfiltered ("const ", stream
);
1230 if (flags
& TYPE_INSTANCE_FLAG_VOLATILE
)
1231 fputs_unfiltered ("volatile", stream
);
1232 fprintf_filtered (stream
, "\n");
1236 dump_for_expression (struct ui_file
*stream
, int depth
,
1237 enum c_string_type_values flags
)
1239 fprintf_filtered (stream
, _("%*sC string flags: "), depth
, "");
1240 switch (flags
& ~C_CHAR
)
1243 fputs_unfiltered (_("wide "), stream
);
1246 fputs_unfiltered (_("u16 "), stream
);
1249 fputs_unfiltered (_("u32 "), stream
);
1252 fputs_unfiltered (_("ordinary "), stream
);
1256 if ((flags
& C_CHAR
) != 0)
1257 fputs_unfiltered (_("char"), stream
);
1259 fputs_unfiltered (_("string"), stream
);
1260 fputs_unfiltered ("\n", stream
);
1264 dump_for_expression (struct ui_file
*stream
, int depth
, objfile
*objf
)
1266 fprintf_filtered (stream
, _("%*sObjfile: %s\n"), depth
, "",
1267 objfile_name (objf
));
1271 dump_for_expression (struct ui_file
*stream
, int depth
,
1272 enum range_flag flags
)
1274 fprintf_filtered (stream
, _("%*sRange:"), depth
, "");
1275 if ((flags
& RANGE_LOW_BOUND_DEFAULT
) != 0)
1276 fputs_unfiltered (_("low-default "), stream
);
1277 if ((flags
& RANGE_HIGH_BOUND_DEFAULT
) != 0)
1278 fputs_unfiltered (_("high-default "), stream
);
1279 if ((flags
& RANGE_HIGH_BOUND_EXCLUSIVE
) != 0)
1280 fputs_unfiltered (_("high-exclusive "), stream
);
1281 if ((flags
& RANGE_HAS_STRIDE
) != 0)
1282 fputs_unfiltered (_("has-stride"), stream
);
1283 fprintf_filtered (stream
, "\n");
1286 } /* namespace expr */