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"
37 print_expression (struct expression
*exp
, struct ui_file
*stream
)
41 print_subexp (exp
, &pc
, stream
, PREC_NULL
);
44 /* Print the subexpression of EXP that starts in position POS, on STREAM.
45 PREC is the precedence of the surrounding operator;
46 if the precedence of the main operator of this subexpression is less,
47 parentheses are needed here. */
50 print_subexp (struct expression
*exp
, int *pos
,
51 struct ui_file
*stream
, enum precedence prec
)
53 exp
->language_defn
->expression_ops ()->print_subexp (exp
, pos
, stream
,
57 /* See parser-defs.h. */
60 print_subexp_funcall (struct expression
*exp
, int *pos
,
61 struct ui_file
*stream
)
63 unsigned nargs
= longest_to_int (exp
->elts
[*pos
].longconst
);
65 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
66 fputs_filtered (" (", stream
);
67 for (unsigned tem
= 0; tem
< nargs
; tem
++)
70 fputs_filtered (", ", stream
);
71 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
73 fputs_filtered (")", stream
);
76 /* Standard implementation of print_subexp for use in language_defn
79 print_subexp_standard (struct expression
*exp
, int *pos
,
80 struct ui_file
*stream
, enum precedence prec
)
83 const struct op_print
*op_print_tab
;
87 int assign_modify
= 0;
88 enum exp_opcode opcode
;
89 enum precedence myprec
= PREC_NULL
;
90 /* Set to 1 for a right-associative operator. */
95 op_print_tab
= exp
->language_defn
->opcode_print_table ();
97 opcode
= exp
->elts
[pc
].opcode
;
104 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
108 myprec
= PREC_PREFIX
;
110 fputs_filtered (exp
->elts
[pc
+ 1].type
->name (), stream
);
111 fputs_filtered ("::", stream
);
112 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
113 (*pos
) += 4 + BYTES_TO_EXP_ELEM (nargs
+ 1);
114 fputs_filtered (&exp
->elts
[pc
+ 3].string
, stream
);
119 struct value_print_options opts
;
121 get_no_prettyformat_print_options (&opts
);
123 value_print (value_from_longest (exp
->elts
[pc
+ 1].type
,
124 exp
->elts
[pc
+ 2].longconst
),
131 struct value_print_options opts
;
133 get_no_prettyformat_print_options (&opts
);
135 value_print (value_from_contents (exp
->elts
[pc
+ 1].type
,
136 exp
->elts
[pc
+ 2].floatconst
),
143 const struct block
*b
;
146 b
= exp
->elts
[pc
+ 1].block
;
148 && BLOCK_FUNCTION (b
) != NULL
149 && BLOCK_FUNCTION (b
)->print_name () != NULL
)
151 fputs_filtered (BLOCK_FUNCTION (b
)->print_name (), stream
);
152 fputs_filtered ("::", stream
);
154 fputs_filtered (exp
->elts
[pc
+ 2].symbol
->print_name (), stream
);
158 case OP_VAR_MSYM_VALUE
:
161 fputs_filtered (exp
->elts
[pc
+ 2].msymbol
->print_name (), stream
);
165 case OP_FUNC_STATIC_VAR
:
167 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
168 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
169 fputs_filtered (&exp
->elts
[pc
+ 1].string
, stream
);
173 case OP_VAR_ENTRY_VALUE
:
176 fprintf_filtered (stream
, "%s@entry",
177 exp
->elts
[pc
+ 1].symbol
->print_name ());
183 fprintf_filtered (stream
, "$%d",
184 longest_to_int (exp
->elts
[pc
+ 1].longconst
));
189 const char *name
= &exp
->elts
[pc
+ 2].string
;
191 (*pos
) += 3 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
192 fprintf_filtered (stream
, "$%s", name
);
198 fprintf_filtered (stream
, "%s",
199 longest_to_int (exp
->elts
[pc
+ 1].longconst
)
205 fprintf_filtered (stream
, "$%s",
206 internalvar_name (exp
->elts
[pc
+ 1].internalvar
));
210 print_subexp_funcall (exp
, pos
, stream
);
214 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
215 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
216 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
221 struct value_print_options opts
;
223 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
224 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
225 /* LA_PRINT_STRING will print using the current repeat count threshold.
226 If necessary, we can temporarily set it to zero, or pass it as an
227 additional parameter to LA_PRINT_STRING. -fnf */
228 get_user_print_options (&opts
);
230 ->printstr (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
231 (gdb_byte
*) &exp
->elts
[pc
+ 2].string
, nargs
,
236 case OP_OBJC_NSSTRING
: /* Objective-C Foundation Class
237 NSString constant. */
239 struct value_print_options opts
;
241 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
242 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
243 fputs_filtered ("@\"", stream
);
244 get_user_print_options (&opts
);
246 ->printstr (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
247 (gdb_byte
*) &exp
->elts
[pc
+ 2].string
, nargs
,
249 fputs_filtered ("\"", stream
);
253 case OP_OBJC_MSGCALL
:
254 { /* Objective C message (method) call. */
256 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
257 fprintf_unfiltered (stream
, "[");
258 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
259 gdb::unique_xmalloc_ptr
<char> selector
260 = target_read_string (exp
->elts
[pc
+ 1].longconst
, 1024);
261 if (selector
== nullptr)
262 error (_("bad selector"));
268 for (tem
= 0; tem
< nargs
; tem
++)
270 nextS
= strchr (s
, ':');
271 gdb_assert (nextS
); /* Make sure we found ':'. */
273 fprintf_unfiltered (stream
, " %s: ", s
);
275 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
280 fprintf_unfiltered (stream
, " %s", selector
.get ());
282 fprintf_unfiltered (stream
, "]");
288 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
289 nargs
-= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
292 if (exp
->elts
[pc
+ 4].opcode
== OP_LONG
293 && exp
->elts
[pc
+ 5].type
294 == builtin_type (exp
->gdbarch
)->builtin_char
295 && exp
->language_defn
->la_language
== language_c
)
297 /* Attempt to print C character arrays using string syntax.
298 Walk through the args, picking up one character from each
299 of the OP_LONG expression elements. If any array element
300 does not match our expection of what we should find for
301 a simple string, revert back to array printing. Note that
302 the last expression element is an explicit null terminator
303 byte, which doesn't get printed. */
304 tempstr
= (char *) alloca (nargs
);
308 if (exp
->elts
[pc
].opcode
!= OP_LONG
309 || exp
->elts
[pc
+ 1].type
310 != builtin_type (exp
->gdbarch
)->builtin_char
)
312 /* Not a simple array of char, use regular array
320 longest_to_int (exp
->elts
[pc
+ 2].longconst
);
327 struct value_print_options opts
;
329 get_user_print_options (&opts
);
331 ->printstr (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
332 (gdb_byte
*) tempstr
, nargs
- 1, NULL
, 0, &opts
);
337 fputs_filtered (" {", stream
);
338 for (tem
= 0; tem
< nargs
; tem
++)
342 fputs_filtered (", ", stream
);
344 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
346 fputs_filtered ("}", stream
);
351 if ((int) prec
> (int) PREC_COMMA
)
352 fputs_filtered ("(", stream
);
353 /* Print the subexpressions, forcing parentheses
354 around any binary operations within them.
355 This is more parentheses than are strictly necessary,
356 but it looks clearer. */
357 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
358 fputs_filtered (" ? ", stream
);
359 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
360 fputs_filtered (" : ", stream
);
361 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
362 if ((int) prec
> (int) PREC_COMMA
)
363 fputs_filtered (")", stream
);
367 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
368 fputs_filtered ("(", stream
);
369 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
370 fputs_filtered (opcode
== TERNOP_SLICE
? " : " : " UP ", stream
);
371 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
372 fputs_filtered (")", stream
);
375 case STRUCTOP_STRUCT
:
376 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
377 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
378 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
379 fputs_filtered (".", stream
);
380 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
383 /* Will not occur for Modula-2. */
385 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
386 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
387 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
388 fputs_filtered ("->", stream
);
389 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
392 case STRUCTOP_MEMBER
:
393 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
394 fputs_filtered (".*", stream
);
395 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
399 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
400 fputs_filtered ("->*", stream
);
401 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
404 case BINOP_SUBSCRIPT
:
405 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
406 fputs_filtered ("[", stream
);
407 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
408 fputs_filtered ("]", stream
);
411 case UNOP_POSTINCREMENT
:
412 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
413 fputs_filtered ("++", stream
);
416 case UNOP_POSTDECREMENT
:
417 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
418 fputs_filtered ("--", stream
);
423 if ((int) prec
> (int) PREC_PREFIX
)
424 fputs_filtered ("(", stream
);
425 fputs_filtered ("(", stream
);
426 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
427 fputs_filtered (") ", stream
);
428 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
429 if ((int) prec
> (int) PREC_PREFIX
)
430 fputs_filtered (")", stream
);
434 if ((int) prec
> (int) PREC_PREFIX
)
435 fputs_filtered ("(", stream
);
436 fputs_filtered ("(", stream
);
437 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
438 fputs_filtered (") ", stream
);
439 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
440 if ((int) prec
> (int) PREC_PREFIX
)
441 fputs_filtered (")", stream
);
444 case UNOP_DYNAMIC_CAST
:
445 case UNOP_REINTERPRET_CAST
:
446 fputs_filtered (opcode
== UNOP_DYNAMIC_CAST
? "dynamic_cast"
447 : "reinterpret_cast", stream
);
448 fputs_filtered ("<", stream
);
449 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
450 fputs_filtered ("> (", stream
);
451 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
452 fputs_filtered (")", stream
);
457 if ((int) prec
> (int) PREC_PREFIX
)
458 fputs_filtered ("(", stream
);
459 if (exp
->elts
[pc
+ 1].type
->code () == TYPE_CODE_FUNC
460 && exp
->elts
[pc
+ 3].opcode
== OP_LONG
)
462 struct value_print_options opts
;
464 /* We have a minimal symbol fn, probably. It's encoded
465 as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address).
466 Swallow the OP_LONG (including both its opcodes); ignore
467 its type; print the value in the type of the MEMVAL. */
469 val
= value_at_lazy (exp
->elts
[pc
+ 1].type
,
470 (CORE_ADDR
) exp
->elts
[pc
+ 5].longconst
);
471 get_no_prettyformat_print_options (&opts
);
472 value_print (val
, stream
, &opts
);
476 fputs_filtered ("{", stream
);
477 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
478 fputs_filtered ("} ", stream
);
479 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
481 if ((int) prec
> (int) PREC_PREFIX
)
482 fputs_filtered (")", stream
);
485 case UNOP_MEMVAL_TYPE
:
486 if ((int) prec
> (int) PREC_PREFIX
)
487 fputs_filtered ("(", stream
);
488 fputs_filtered ("{", stream
);
489 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
490 fputs_filtered ("} ", stream
);
491 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
492 if ((int) prec
> (int) PREC_PREFIX
)
493 fputs_filtered (")", stream
);
496 case BINOP_ASSIGN_MODIFY
:
497 opcode
= exp
->elts
[pc
+ 1].opcode
;
499 myprec
= PREC_ASSIGN
;
503 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
504 if (op_print_tab
[tem
].opcode
== opcode
)
506 op_str
= op_print_tab
[tem
].string
;
509 if (op_print_tab
[tem
].opcode
!= opcode
)
510 /* Not found; don't try to keep going because we don't know how
511 to interpret further elements. */
512 error (_("Invalid expression"));
519 if (exp
->language_defn
->name_of_this () != NULL
)
520 fputs_filtered (exp
->language_defn
->name_of_this (), stream
);
522 fprintf_styled (stream
, metadata_style
.style (),
523 _("<language %s has no 'this'>"),
524 exp
->language_defn
->name ());
529 case MULTI_SUBSCRIPT
:
531 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
532 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
533 fprintf_unfiltered (stream
, " [");
534 for (tem
= 0; tem
< nargs
; tem
++)
537 fprintf_unfiltered (stream
, ", ");
538 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
540 fprintf_unfiltered (stream
, "]");
545 fprintf_unfiltered (stream
, "VAL(");
546 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
547 fprintf_unfiltered (stream
, ",");
548 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
549 fprintf_unfiltered (stream
, ")");
554 type_instance_flags flags
555 = (type_instance_flag_value
) longest_to_int (exp
->elts
[pc
+ 1].longconst
);
556 LONGEST count
= exp
->elts
[pc
+ 2].longconst
;
562 fputs_unfiltered ("TypeInstance(", stream
);
565 type_print (exp
->elts
[(*pos
)++].type
, "", stream
, 0);
567 fputs_unfiltered (",", stream
);
569 fputs_unfiltered (",", stream
);
570 /* Ending COUNT and ending TYPE_INSTANCE. */
572 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
574 if (flags
& TYPE_INSTANCE_FLAG_CONST
)
575 fputs_unfiltered (",const", stream
);
576 if (flags
& TYPE_INSTANCE_FLAG_VOLATILE
)
577 fputs_unfiltered (",volatile", stream
);
579 fputs_unfiltered (")", stream
);
585 enum range_flag range_flag
;
587 range_flag
= (enum range_flag
)
588 longest_to_int (exp
->elts
[pc
+ 1].longconst
);
591 if (range_flag
& RANGE_HIGH_BOUND_EXCLUSIVE
)
592 fputs_filtered ("EXCLUSIVE_", stream
);
593 fputs_filtered ("RANGE(", stream
);
594 if (!(range_flag
& RANGE_LOW_BOUND_DEFAULT
))
595 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
596 fputs_filtered ("..", stream
);
597 if (!(range_flag
& RANGE_HIGH_BOUND_DEFAULT
))
598 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
599 fputs_filtered (")", stream
);
607 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
608 if (op_print_tab
[tem
].opcode
== opcode
)
610 op_str
= op_print_tab
[tem
].string
;
611 myprec
= op_print_tab
[tem
].precedence
;
612 assoc
= op_print_tab
[tem
].right_assoc
;
615 if (op_print_tab
[tem
].opcode
!= opcode
)
616 /* Not found; don't try to keep going because we don't know how
617 to interpret further elements. For example, this happens
618 if opcode is OP_TYPE. */
619 error (_("Invalid expression"));
622 /* Note that PREC_BUILTIN will always emit parentheses. */
623 if ((int) myprec
< (int) prec
)
624 fputs_filtered ("(", stream
);
625 if ((int) opcode
> (int) BINOP_END
)
629 /* Unary postfix operator. */
630 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
631 fputs_filtered (op_str
, stream
);
635 /* Unary prefix operator. */
636 fputs_filtered (op_str
, stream
);
637 if (myprec
== PREC_BUILTIN_FUNCTION
)
638 fputs_filtered ("(", stream
);
639 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
640 if (myprec
== PREC_BUILTIN_FUNCTION
)
641 fputs_filtered (")", stream
);
646 /* Binary operator. */
647 /* Print left operand.
648 If operator is right-associative,
649 increment precedence for this operand. */
650 print_subexp (exp
, pos
, stream
,
651 (enum precedence
) ((int) myprec
+ assoc
));
652 /* Print the operator itself. */
654 fprintf_filtered (stream
, " %s= ", op_str
);
655 else if (op_str
[0] == ',')
656 fprintf_filtered (stream
, "%s ", op_str
);
658 fprintf_filtered (stream
, " %s ", op_str
);
659 /* Print right operand.
660 If operator is left-associative,
661 increment precedence for this operand. */
662 print_subexp (exp
, pos
, stream
,
663 (enum precedence
) ((int) myprec
+ !assoc
));
666 if ((int) myprec
< (int) prec
)
667 fputs_filtered (")", stream
);
670 /* Return the operator corresponding to opcode OP as
671 a string. NULL indicates that the opcode was not found in the
672 current language table. */
674 op_string (enum exp_opcode op
)
677 const struct op_print
*op_print_tab
;
679 op_print_tab
= current_language
->opcode_print_table ();
680 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
681 if (op_print_tab
[tem
].opcode
== op
)
682 return op_print_tab
[tem
].string
;
686 /* Support for dumping the raw data from expressions in a human readable
689 static int dump_subexp_body (struct expression
*exp
, struct ui_file
*, int);
691 /* Default name for the standard operator OPCODE (i.e., one defined in
692 the definition of enum exp_opcode). */
695 op_name (enum exp_opcode opcode
)
703 xsnprintf (buf
, sizeof (buf
), "<unknown %d>", opcode
);
709 #include "std-operator.def"
714 /* Print a raw dump of expression EXP to STREAM.
715 NOTE, if non-NULL, is printed as extra explanatory text. */
718 dump_raw_expression (struct expression
*exp
, struct ui_file
*stream
,
725 fprintf_filtered (stream
, "Dump of expression @ ");
726 gdb_print_host_address (exp
, stream
);
728 fprintf_filtered (stream
, ", %s:", note
);
729 fprintf_filtered (stream
, "\n\tLanguage %s, %d elements, %ld bytes each.\n",
730 exp
->language_defn
->name (), exp
->nelts
,
731 (long) sizeof (union exp_element
));
732 fprintf_filtered (stream
, "\t%5s %20s %16s %s\n", "Index", "Opcode",
733 "Hex Value", "String Value");
734 for (elt
= 0; elt
< exp
->nelts
; elt
++)
736 fprintf_filtered (stream
, "\t%5d ", elt
);
738 const char *opcode_name
= op_name (exp
->elts
[elt
].opcode
);
739 fprintf_filtered (stream
, "%20s ", opcode_name
);
741 print_longest (stream
, 'd', 0, exp
->elts
[elt
].longconst
);
742 fprintf_filtered (stream
, " ");
744 for (eltscan
= (char *) &exp
->elts
[elt
],
745 eltsize
= sizeof (union exp_element
);
749 fprintf_filtered (stream
, "%c",
750 isprint (*eltscan
) ? (*eltscan
& 0xFF) : '.');
752 fprintf_filtered (stream
, "\n");
756 /* Dump the subexpression of prefix expression EXP whose operator is at
757 position ELT onto STREAM. Returns the position of the next
758 subexpression in EXP. */
761 dump_subexp (struct expression
*exp
, struct ui_file
*stream
, int elt
)
763 static int indent
= 0;
766 fprintf_filtered (stream
, "\n");
767 fprintf_filtered (stream
, "\t%5d ", elt
);
769 for (i
= 1; i
<= indent
; i
++)
770 fprintf_filtered (stream
, " ");
773 fprintf_filtered (stream
, "%-20s ", op_name (exp
->elts
[elt
].opcode
));
775 elt
= dump_subexp_body (exp
, stream
, elt
);
782 /* Dump the operands of prefix expression EXP whose opcode is at
783 position ELT onto STREAM. Returns the position of the next
784 subexpression in EXP. */
787 dump_subexp_body (struct expression
*exp
, struct ui_file
*stream
, int elt
)
789 return exp
->language_defn
->expression_ops ()->dump_subexp_body (exp
, stream
,
793 /* See parser-defs.h. */
796 dump_subexp_body_funcall (struct expression
*exp
,
797 struct ui_file
*stream
, int elt
)
799 int nargs
= longest_to_int (exp
->elts
[elt
].longconst
);
800 fprintf_filtered (stream
, "Number of args: %d", nargs
);
803 for (int i
= 1; i
<= nargs
+ 1; i
++)
804 elt
= dump_subexp (exp
, stream
, elt
);
809 /* Default value for subexp_body in exp_descriptor vector. */
812 dump_subexp_body_standard (struct expression
*exp
,
813 struct ui_file
*stream
, int elt
)
815 int opcode
= exp
->elts
[elt
++].opcode
;
821 elt
= dump_subexp (exp
, stream
, elt
);
831 case BINOP_LOGICAL_AND
:
832 case BINOP_LOGICAL_OR
:
833 case BINOP_BITWISE_AND
:
834 case BINOP_BITWISE_IOR
:
835 case BINOP_BITWISE_XOR
:
845 case BINOP_SUBSCRIPT
:
850 case BINOP_ASSIGN_MODIFY
:
854 case STRUCTOP_MEMBER
:
856 elt
= dump_subexp (exp
, stream
, elt
);
859 case UNOP_LOGICAL_NOT
:
860 case UNOP_COMPLEMENT
:
863 case UNOP_PREINCREMENT
:
864 case UNOP_POSTINCREMENT
:
865 case UNOP_PREDECREMENT
:
866 case UNOP_POSTDECREMENT
:
880 elt
= dump_subexp (exp
, stream
, elt
);
883 fprintf_filtered (stream
, "Type @");
884 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
885 fprintf_filtered (stream
, " (");
886 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
887 fprintf_filtered (stream
, "), value %ld (0x%lx)",
888 (long) exp
->elts
[elt
+ 1].longconst
,
889 (long) exp
->elts
[elt
+ 1].longconst
);
893 fprintf_filtered (stream
, "Type @");
894 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
895 fprintf_filtered (stream
, " (");
896 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
897 fprintf_filtered (stream
, "), value ");
898 print_floating (exp
->elts
[elt
+ 1].floatconst
,
899 exp
->elts
[elt
].type
, stream
);
903 fprintf_filtered (stream
, "Block @");
904 gdb_print_host_address (exp
->elts
[elt
].block
, stream
);
905 fprintf_filtered (stream
, ", symbol @");
906 gdb_print_host_address (exp
->elts
[elt
+ 1].symbol
, stream
);
907 fprintf_filtered (stream
, " (%s)",
908 exp
->elts
[elt
+ 1].symbol
->print_name ());
911 case OP_VAR_MSYM_VALUE
:
912 fprintf_filtered (stream
, "Objfile @");
913 gdb_print_host_address (exp
->elts
[elt
].objfile
, stream
);
914 fprintf_filtered (stream
, ", msymbol @");
915 gdb_print_host_address (exp
->elts
[elt
+ 1].msymbol
, stream
);
916 fprintf_filtered (stream
, " (%s)",
917 exp
->elts
[elt
+ 1].msymbol
->print_name ());
920 case OP_VAR_ENTRY_VALUE
:
921 fprintf_filtered (stream
, "Entry value of symbol @");
922 gdb_print_host_address (exp
->elts
[elt
].symbol
, stream
);
923 fprintf_filtered (stream
, " (%s)",
924 exp
->elts
[elt
].symbol
->print_name ());
928 fprintf_filtered (stream
, "History element %ld",
929 (long) exp
->elts
[elt
].longconst
);
933 fprintf_filtered (stream
, "Register $%s", &exp
->elts
[elt
+ 1].string
);
934 elt
+= 3 + BYTES_TO_EXP_ELEM (exp
->elts
[elt
].longconst
+ 1);
937 fprintf_filtered (stream
, "Internal var @");
938 gdb_print_host_address (exp
->elts
[elt
].internalvar
, stream
);
939 fprintf_filtered (stream
, " (%s)",
940 internalvar_name (exp
->elts
[elt
].internalvar
));
944 elt
= dump_subexp_body_funcall (exp
, stream
, elt
);
951 lower
= longest_to_int (exp
->elts
[elt
].longconst
);
952 upper
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
954 fprintf_filtered (stream
, "Bounds [%d:%d]", lower
, upper
);
957 for (i
= 1; i
<= upper
- lower
+ 1; i
++)
958 elt
= dump_subexp (exp
, stream
, elt
);
961 case UNOP_DYNAMIC_CAST
:
962 case UNOP_REINTERPRET_CAST
:
964 case UNOP_MEMVAL_TYPE
:
965 fprintf_filtered (stream
, " (");
966 elt
= dump_subexp (exp
, stream
, elt
);
967 fprintf_filtered (stream
, ")");
968 elt
= dump_subexp (exp
, stream
, elt
);
972 fprintf_filtered (stream
, "Type @");
973 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
974 fprintf_filtered (stream
, " (");
975 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
976 fprintf_filtered (stream
, ")");
977 elt
= dump_subexp (exp
, stream
, elt
+ 2);
980 fprintf_filtered (stream
, "Type @");
981 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
982 fprintf_filtered (stream
, " (");
983 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
984 fprintf_filtered (stream
, ")");
989 fprintf_filtered (stream
, "Typeof (");
990 elt
= dump_subexp (exp
, stream
, elt
);
991 fprintf_filtered (stream
, ")");
994 fprintf_filtered (stream
, "typeid (");
995 elt
= dump_subexp (exp
, stream
, elt
);
996 fprintf_filtered (stream
, ")");
998 case STRUCTOP_STRUCT
:
1004 len
= longest_to_int (exp
->elts
[elt
].longconst
);
1005 elem_name
= &exp
->elts
[elt
+ 1].string
;
1007 fprintf_filtered (stream
, "Element name: `%.*s'", len
, elem_name
);
1008 elt
= dump_subexp (exp
, stream
, elt
+ 3 + BYTES_TO_EXP_ELEM (len
+ 1));
1016 fprintf_filtered (stream
, "Type @");
1017 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1018 fprintf_filtered (stream
, " (");
1019 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1020 fprintf_filtered (stream
, ") ");
1022 len
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
1023 elem_name
= &exp
->elts
[elt
+ 2].string
;
1025 fprintf_filtered (stream
, "Field name: `%.*s'", len
, elem_name
);
1026 elt
+= 4 + BYTES_TO_EXP_ELEM (len
+ 1);
1030 case OP_FUNC_STATIC_VAR
:
1032 int len
= longest_to_int (exp
->elts
[elt
].longconst
);
1033 const char *var_name
= &exp
->elts
[elt
+ 1].string
;
1034 fprintf_filtered (stream
, "Field name: `%.*s'", len
, var_name
);
1035 elt
+= 3 + BYTES_TO_EXP_ELEM (len
+ 1);
1041 type_instance_flags flags
1042 = (type_instance_flag_value
) longest_to_int (exp
->elts
[elt
++].longconst
);
1043 LONGEST len
= exp
->elts
[elt
++].longconst
;
1044 fprintf_filtered (stream
, "%s TypeInstance: ", plongest (len
));
1047 fprintf_filtered (stream
, "Type @");
1048 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1049 fprintf_filtered (stream
, " (");
1050 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1051 fprintf_filtered (stream
, ")");
1054 fputs_filtered (", ", stream
);
1057 fprintf_filtered (stream
, " Flags: %s (", hex_string (flags
));
1059 auto print_one
= [&] (const char *mod
)
1062 fputs_filtered (" ", stream
);
1064 fprintf_filtered (stream
, "%s", mod
);
1066 if (flags
& TYPE_INSTANCE_FLAG_CONST
)
1067 print_one ("const");
1068 if (flags
& TYPE_INSTANCE_FLAG_VOLATILE
)
1069 print_one ("volatile");
1070 fprintf_filtered (stream
, ")");
1072 /* Ending LEN and ending TYPE_INSTANCE. */
1074 elt
= dump_subexp (exp
, stream
, elt
);
1079 LONGEST len
= exp
->elts
[elt
].longconst
;
1080 LONGEST type
= exp
->elts
[elt
+ 1].longconst
;
1082 fprintf_filtered (stream
, "Language-specific string type: %s",
1088 /* Skip string content. */
1089 elt
+= BYTES_TO_EXP_ELEM (len
);
1091 /* Skip length and ending OP_STRING. */
1097 enum range_flag range_flag
;
1099 range_flag
= (enum range_flag
)
1100 longest_to_int (exp
->elts
[elt
].longconst
);
1103 if (range_flag
& RANGE_HIGH_BOUND_EXCLUSIVE
)
1104 fputs_filtered ("Exclusive", stream
);
1105 fputs_filtered ("Range '", stream
);
1106 if (!(range_flag
& RANGE_LOW_BOUND_DEFAULT
))
1107 fputs_filtered ("EXP", stream
);
1108 fputs_filtered ("..", stream
);
1109 if (!(range_flag
& RANGE_HIGH_BOUND_DEFAULT
))
1110 fputs_filtered ("EXP", stream
);
1111 if (range_flag
& RANGE_HAS_STRIDE
)
1112 fputs_filtered (":EXP", stream
);
1113 fputs_filtered ("'", stream
);
1115 if (!(range_flag
& RANGE_LOW_BOUND_DEFAULT
))
1116 elt
= dump_subexp (exp
, stream
, elt
);
1117 if (!(range_flag
& RANGE_HIGH_BOUND_DEFAULT
))
1118 elt
= dump_subexp (exp
, stream
, elt
);
1119 if (range_flag
& RANGE_HAS_STRIDE
)
1120 elt
= dump_subexp (exp
, stream
, elt
);
1126 bool val
= (bool) (exp
->elts
[elt
].longconst
);
1127 fputs_filtered (val
? "TRUE" : "FALSE", stream
);
1134 case MULTI_SUBSCRIPT
:
1139 fprintf_filtered (stream
, "Unknown format");
1146 dump_prefix_expression (struct expression
*exp
, struct ui_file
*stream
)
1150 fprintf_filtered (stream
, "Dump of expression @ ");
1151 gdb_print_host_address (exp
, stream
);
1152 fputs_filtered (", after conversion to prefix form:\nExpression: `", stream
);
1153 print_expression (exp
, stream
);
1154 fprintf_filtered (stream
, "'\n\tLanguage %s, %d elements, %ld bytes each.\n",
1155 exp
->language_defn
->name (), exp
->nelts
,
1156 (long) sizeof (union exp_element
));
1157 fputs_filtered ("\n", stream
);
1159 for (elt
= 0; elt
< exp
->nelts
;)
1160 elt
= dump_subexp (exp
, stream
, elt
);
1161 fputs_filtered ("\n", stream
);