1 /* Print in infix form a struct expression.
3 Copyright (C) 1986-2020 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "expression.h"
26 #include "parser-defs.h"
27 #include "user-regs.h" /* For user_reg_map_regnum_to_name. */
32 #include "cli/cli-style.h"
37 print_expression (struct expression
*exp
, struct ui_file
*stream
)
41 print_subexp (exp
, &pc
, stream
, PREC_NULL
);
44 /* Print the subexpression of EXP that starts in position POS, on STREAM.
45 PREC is the precedence of the surrounding operator;
46 if the precedence of the main operator of this subexpression is less,
47 parentheses are needed here. */
50 print_subexp (struct expression
*exp
, int *pos
,
51 struct ui_file
*stream
, enum precedence prec
)
53 exp
->language_defn
->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
)
64 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
);
229 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
230 (gdb_byte
*) &exp
->elts
[pc
+ 2].string
, nargs
,
235 case OP_OBJC_NSSTRING
: /* Objective-C Foundation Class
236 NSString constant. */
238 struct value_print_options opts
;
240 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
241 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
242 fputs_filtered ("@\"", stream
);
243 get_user_print_options (&opts
);
244 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
245 (gdb_byte
*) &exp
->elts
[pc
+ 2].string
, nargs
,
247 fputs_filtered ("\"", stream
);
251 case OP_OBJC_MSGCALL
:
252 { /* Objective C message (method) call. */
254 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
255 fprintf_unfiltered (stream
, "[");
256 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
257 gdb::unique_xmalloc_ptr
<char> selector
258 = target_read_string (exp
->elts
[pc
+ 1].longconst
, 1024);
259 if (selector
== nullptr)
260 error (_("bad selector"));
266 for (tem
= 0; tem
< nargs
; tem
++)
268 nextS
= strchr (s
, ':');
269 gdb_assert (nextS
); /* Make sure we found ':'. */
271 fprintf_unfiltered (stream
, " %s: ", s
);
273 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
278 fprintf_unfiltered (stream
, " %s", selector
.get ());
280 fprintf_unfiltered (stream
, "]");
286 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
287 nargs
-= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
290 if (exp
->elts
[pc
+ 4].opcode
== OP_LONG
291 && exp
->elts
[pc
+ 5].type
292 == builtin_type (exp
->gdbarch
)->builtin_char
293 && exp
->language_defn
->la_language
== language_c
)
295 /* Attempt to print C character arrays using string syntax.
296 Walk through the args, picking up one character from each
297 of the OP_LONG expression elements. If any array element
298 does not match our expection of what we should find for
299 a simple string, revert back to array printing. Note that
300 the last expression element is an explicit null terminator
301 byte, which doesn't get printed. */
302 tempstr
= (char *) alloca (nargs
);
306 if (exp
->elts
[pc
].opcode
!= OP_LONG
307 || exp
->elts
[pc
+ 1].type
308 != builtin_type (exp
->gdbarch
)->builtin_char
)
310 /* Not a simple array of char, use regular array
318 longest_to_int (exp
->elts
[pc
+ 2].longconst
);
325 struct value_print_options opts
;
327 get_user_print_options (&opts
);
328 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
329 (gdb_byte
*) tempstr
, nargs
- 1, NULL
, 0, &opts
);
334 fputs_filtered (" {", stream
);
335 for (tem
= 0; tem
< nargs
; tem
++)
339 fputs_filtered (", ", stream
);
341 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
343 fputs_filtered ("}", stream
);
348 if ((int) prec
> (int) PREC_COMMA
)
349 fputs_filtered ("(", stream
);
350 /* Print the subexpressions, forcing parentheses
351 around any binary operations within them.
352 This is more parentheses than are strictly necessary,
353 but it looks clearer. */
354 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
355 fputs_filtered (" ? ", stream
);
356 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
357 fputs_filtered (" : ", stream
);
358 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
359 if ((int) prec
> (int) PREC_COMMA
)
360 fputs_filtered (")", stream
);
364 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
365 fputs_filtered ("(", stream
);
366 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
367 fputs_filtered (opcode
== TERNOP_SLICE
? " : " : " UP ", stream
);
368 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
369 fputs_filtered (")", stream
);
372 case STRUCTOP_STRUCT
:
373 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
374 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
375 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
376 fputs_filtered (".", stream
);
377 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
380 /* Will not occur for Modula-2. */
382 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
383 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
384 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
385 fputs_filtered ("->", stream
);
386 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
389 case STRUCTOP_MEMBER
:
390 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
391 fputs_filtered (".*", stream
);
392 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
396 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
397 fputs_filtered ("->*", stream
);
398 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
401 case BINOP_SUBSCRIPT
:
402 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
403 fputs_filtered ("[", stream
);
404 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
405 fputs_filtered ("]", stream
);
408 case UNOP_POSTINCREMENT
:
409 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
410 fputs_filtered ("++", stream
);
413 case UNOP_POSTDECREMENT
:
414 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
415 fputs_filtered ("--", stream
);
420 if ((int) prec
> (int) PREC_PREFIX
)
421 fputs_filtered ("(", stream
);
422 fputs_filtered ("(", stream
);
423 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
424 fputs_filtered (") ", stream
);
425 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
426 if ((int) prec
> (int) PREC_PREFIX
)
427 fputs_filtered (")", stream
);
431 if ((int) prec
> (int) PREC_PREFIX
)
432 fputs_filtered ("(", stream
);
433 fputs_filtered ("(", stream
);
434 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
435 fputs_filtered (") ", stream
);
436 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
437 if ((int) prec
> (int) PREC_PREFIX
)
438 fputs_filtered (")", stream
);
441 case UNOP_DYNAMIC_CAST
:
442 case UNOP_REINTERPRET_CAST
:
443 fputs_filtered (opcode
== UNOP_DYNAMIC_CAST
? "dynamic_cast"
444 : "reinterpret_cast", stream
);
445 fputs_filtered ("<", stream
);
446 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
447 fputs_filtered ("> (", stream
);
448 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
449 fputs_filtered (")", stream
);
454 if ((int) prec
> (int) PREC_PREFIX
)
455 fputs_filtered ("(", stream
);
456 if (exp
->elts
[pc
+ 1].type
->code () == TYPE_CODE_FUNC
457 && exp
->elts
[pc
+ 3].opcode
== OP_LONG
)
459 struct value_print_options opts
;
461 /* We have a minimal symbol fn, probably. It's encoded
462 as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address).
463 Swallow the OP_LONG (including both its opcodes); ignore
464 its type; print the value in the type of the MEMVAL. */
466 val
= value_at_lazy (exp
->elts
[pc
+ 1].type
,
467 (CORE_ADDR
) exp
->elts
[pc
+ 5].longconst
);
468 get_no_prettyformat_print_options (&opts
);
469 value_print (val
, stream
, &opts
);
473 fputs_filtered ("{", stream
);
474 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
475 fputs_filtered ("} ", stream
);
476 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
478 if ((int) prec
> (int) PREC_PREFIX
)
479 fputs_filtered (")", stream
);
482 case UNOP_MEMVAL_TYPE
:
483 if ((int) prec
> (int) PREC_PREFIX
)
484 fputs_filtered ("(", stream
);
485 fputs_filtered ("{", stream
);
486 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
487 fputs_filtered ("} ", stream
);
488 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
489 if ((int) prec
> (int) PREC_PREFIX
)
490 fputs_filtered (")", stream
);
493 case BINOP_ASSIGN_MODIFY
:
494 opcode
= exp
->elts
[pc
+ 1].opcode
;
496 myprec
= PREC_ASSIGN
;
500 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
501 if (op_print_tab
[tem
].opcode
== opcode
)
503 op_str
= op_print_tab
[tem
].string
;
506 if (op_print_tab
[tem
].opcode
!= opcode
)
507 /* Not found; don't try to keep going because we don't know how
508 to interpret further elements. */
509 error (_("Invalid expression"));
516 if (exp
->language_defn
->name_of_this () != NULL
)
517 fputs_filtered (exp
->language_defn
->name_of_this (), stream
);
519 fprintf_styled (stream
, metadata_style
.style (),
520 _("<language %s has no 'this'>"),
521 exp
->language_defn
->name ());
526 case MULTI_SUBSCRIPT
:
528 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
529 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
530 fprintf_unfiltered (stream
, " [");
531 for (tem
= 0; tem
< nargs
; tem
++)
534 fprintf_unfiltered (stream
, ", ");
535 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
537 fprintf_unfiltered (stream
, "]");
542 fprintf_unfiltered (stream
, "VAL(");
543 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
544 fprintf_unfiltered (stream
, ",");
545 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
546 fprintf_unfiltered (stream
, ")");
551 type_instance_flags flags
552 = (type_instance_flag_value
) longest_to_int (exp
->elts
[pc
+ 1].longconst
);
553 LONGEST count
= exp
->elts
[pc
+ 2].longconst
;
559 fputs_unfiltered ("TypeInstance(", stream
);
562 type_print (exp
->elts
[(*pos
)++].type
, "", stream
, 0);
564 fputs_unfiltered (",", stream
);
566 fputs_unfiltered (",", stream
);
567 /* Ending COUNT and ending TYPE_INSTANCE. */
569 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
571 if (flags
& TYPE_INSTANCE_FLAG_CONST
)
572 fputs_unfiltered (",const", stream
);
573 if (flags
& TYPE_INSTANCE_FLAG_VOLATILE
)
574 fputs_unfiltered (",volatile", stream
);
576 fputs_unfiltered (")", stream
);
582 enum range_type range_type
;
584 range_type
= (enum range_type
)
585 longest_to_int (exp
->elts
[pc
+ 1].longconst
);
588 if (range_type
== NONE_BOUND_DEFAULT_EXCLUSIVE
589 || range_type
== LOW_BOUND_DEFAULT_EXCLUSIVE
)
590 fputs_filtered ("EXCLUSIVE_", stream
);
591 fputs_filtered ("RANGE(", stream
);
592 if (range_type
== HIGH_BOUND_DEFAULT
593 || range_type
== NONE_BOUND_DEFAULT
594 || range_type
== NONE_BOUND_DEFAULT_EXCLUSIVE
)
595 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
596 fputs_filtered ("..", stream
);
597 if (range_type
== LOW_BOUND_DEFAULT
598 || range_type
== NONE_BOUND_DEFAULT
)
599 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
600 fputs_filtered (")", stream
);
608 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
609 if (op_print_tab
[tem
].opcode
== opcode
)
611 op_str
= op_print_tab
[tem
].string
;
612 myprec
= op_print_tab
[tem
].precedence
;
613 assoc
= op_print_tab
[tem
].right_assoc
;
616 if (op_print_tab
[tem
].opcode
!= opcode
)
617 /* Not found; don't try to keep going because we don't know how
618 to interpret further elements. For example, this happens
619 if opcode is OP_TYPE. */
620 error (_("Invalid expression"));
623 /* Note that PREC_BUILTIN will always emit parentheses. */
624 if ((int) myprec
< (int) prec
)
625 fputs_filtered ("(", stream
);
626 if ((int) opcode
> (int) BINOP_END
)
630 /* Unary postfix operator. */
631 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
632 fputs_filtered (op_str
, stream
);
636 /* Unary prefix operator. */
637 fputs_filtered (op_str
, stream
);
638 if (myprec
== PREC_BUILTIN_FUNCTION
)
639 fputs_filtered ("(", stream
);
640 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
641 if (myprec
== PREC_BUILTIN_FUNCTION
)
642 fputs_filtered (")", stream
);
647 /* Binary operator. */
648 /* Print left operand.
649 If operator is right-associative,
650 increment precedence for this operand. */
651 print_subexp (exp
, pos
, stream
,
652 (enum precedence
) ((int) myprec
+ assoc
));
653 /* Print the operator itself. */
655 fprintf_filtered (stream
, " %s= ", op_str
);
656 else if (op_str
[0] == ',')
657 fprintf_filtered (stream
, "%s ", op_str
);
659 fprintf_filtered (stream
, " %s ", op_str
);
660 /* Print right operand.
661 If operator is left-associative,
662 increment precedence for this operand. */
663 print_subexp (exp
, pos
, stream
,
664 (enum precedence
) ((int) myprec
+ !assoc
));
667 if ((int) myprec
< (int) prec
)
668 fputs_filtered (")", stream
);
671 /* Return the operator corresponding to opcode OP as
672 a string. NULL indicates that the opcode was not found in the
673 current language table. */
675 op_string (enum exp_opcode op
)
678 const struct op_print
*op_print_tab
;
680 op_print_tab
= current_language
->opcode_print_table ();
681 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
682 if (op_print_tab
[tem
].opcode
== op
)
683 return op_print_tab
[tem
].string
;
687 /* Support for dumping the raw data from expressions in a human readable
690 static int dump_subexp_body (struct expression
*exp
, struct ui_file
*, int);
692 /* Name for OPCODE, when it appears in expression EXP. */
695 op_name (struct expression
*exp
, enum exp_opcode opcode
)
697 if (opcode
>= OP_UNUSED_LAST
)
699 char *cell
= get_print_cell ();
700 xsnprintf (cell
, PRINT_CELL_SIZE
, "unknown opcode: %u",
704 return exp
->language_defn
->expression_ops ()->op_name (opcode
);
707 /* Default name for the standard operator OPCODE (i.e., one defined in
708 the definition of enum exp_opcode). */
711 op_name_standard (enum exp_opcode opcode
)
719 xsnprintf (buf
, sizeof (buf
), "<unknown %d>", opcode
);
725 #include "std-operator.def"
730 /* Print a raw dump of expression EXP to STREAM.
731 NOTE, if non-NULL, is printed as extra explanatory text. */
734 dump_raw_expression (struct expression
*exp
, struct ui_file
*stream
,
741 fprintf_filtered (stream
, "Dump of expression @ ");
742 gdb_print_host_address (exp
, stream
);
744 fprintf_filtered (stream
, ", %s:", note
);
745 fprintf_filtered (stream
, "\n\tLanguage %s, %d elements, %ld bytes each.\n",
746 exp
->language_defn
->name (), exp
->nelts
,
747 (long) sizeof (union exp_element
));
748 fprintf_filtered (stream
, "\t%5s %20s %16s %s\n", "Index", "Opcode",
749 "Hex Value", "String Value");
750 for (elt
= 0; elt
< exp
->nelts
; elt
++)
752 fprintf_filtered (stream
, "\t%5d ", elt
);
754 const char *opcode_name
= op_name (exp
, exp
->elts
[elt
].opcode
);
755 fprintf_filtered (stream
, "%20s ", opcode_name
);
757 print_longest (stream
, 'd', 0, exp
->elts
[elt
].longconst
);
758 fprintf_filtered (stream
, " ");
760 for (eltscan
= (char *) &exp
->elts
[elt
],
761 eltsize
= sizeof (union exp_element
);
765 fprintf_filtered (stream
, "%c",
766 isprint (*eltscan
) ? (*eltscan
& 0xFF) : '.');
768 fprintf_filtered (stream
, "\n");
772 /* Dump the subexpression of prefix expression EXP whose operator is at
773 position ELT onto STREAM. Returns the position of the next
774 subexpression in EXP. */
777 dump_subexp (struct expression
*exp
, struct ui_file
*stream
, int elt
)
779 static int indent
= 0;
782 fprintf_filtered (stream
, "\n");
783 fprintf_filtered (stream
, "\t%5d ", elt
);
785 for (i
= 1; i
<= indent
; i
++)
786 fprintf_filtered (stream
, " ");
789 fprintf_filtered (stream
, "%-20s ", op_name (exp
, exp
->elts
[elt
].opcode
));
791 elt
= dump_subexp_body (exp
, stream
, elt
);
798 /* Dump the operands of prefix expression EXP whose opcode is at
799 position ELT onto STREAM. Returns the position of the next
800 subexpression in EXP. */
803 dump_subexp_body (struct expression
*exp
, struct ui_file
*stream
, int elt
)
805 return exp
->language_defn
->expression_ops ()->dump_subexp_body (exp
, stream
,
809 /* See parser-defs.h. */
812 dump_subexp_body_funcall (struct expression
*exp
,
813 struct ui_file
*stream
, int elt
)
815 int nargs
= longest_to_int (exp
->elts
[elt
].longconst
);
816 fprintf_filtered (stream
, "Number of args: %d", nargs
);
819 for (int i
= 1; i
<= nargs
+ 1; i
++)
820 elt
= dump_subexp (exp
, stream
, elt
);
825 /* Default value for subexp_body in exp_descriptor vector. */
828 dump_subexp_body_standard (struct expression
*exp
,
829 struct ui_file
*stream
, int elt
)
831 int opcode
= exp
->elts
[elt
++].opcode
;
837 elt
= dump_subexp (exp
, stream
, elt
);
847 case BINOP_LOGICAL_AND
:
848 case BINOP_LOGICAL_OR
:
849 case BINOP_BITWISE_AND
:
850 case BINOP_BITWISE_IOR
:
851 case BINOP_BITWISE_XOR
:
861 case BINOP_SUBSCRIPT
:
866 case BINOP_ASSIGN_MODIFY
:
870 case STRUCTOP_MEMBER
:
872 elt
= dump_subexp (exp
, stream
, elt
);
875 case UNOP_LOGICAL_NOT
:
876 case UNOP_COMPLEMENT
:
879 case UNOP_PREINCREMENT
:
880 case UNOP_POSTINCREMENT
:
881 case UNOP_PREDECREMENT
:
882 case UNOP_POSTDECREMENT
:
896 elt
= dump_subexp (exp
, stream
, elt
);
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 %ld (0x%lx)",
904 (long) exp
->elts
[elt
+ 1].longconst
,
905 (long) exp
->elts
[elt
+ 1].longconst
);
909 fprintf_filtered (stream
, "Type @");
910 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
911 fprintf_filtered (stream
, " (");
912 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
913 fprintf_filtered (stream
, "), value ");
914 print_floating (exp
->elts
[elt
+ 1].floatconst
,
915 exp
->elts
[elt
].type
, stream
);
919 fprintf_filtered (stream
, "Block @");
920 gdb_print_host_address (exp
->elts
[elt
].block
, stream
);
921 fprintf_filtered (stream
, ", symbol @");
922 gdb_print_host_address (exp
->elts
[elt
+ 1].symbol
, stream
);
923 fprintf_filtered (stream
, " (%s)",
924 exp
->elts
[elt
+ 1].symbol
->print_name ());
927 case OP_VAR_MSYM_VALUE
:
928 fprintf_filtered (stream
, "Objfile @");
929 gdb_print_host_address (exp
->elts
[elt
].objfile
, stream
);
930 fprintf_filtered (stream
, ", msymbol @");
931 gdb_print_host_address (exp
->elts
[elt
+ 1].msymbol
, stream
);
932 fprintf_filtered (stream
, " (%s)",
933 exp
->elts
[elt
+ 1].msymbol
->print_name ());
936 case OP_VAR_ENTRY_VALUE
:
937 fprintf_filtered (stream
, "Entry value of symbol @");
938 gdb_print_host_address (exp
->elts
[elt
].symbol
, stream
);
939 fprintf_filtered (stream
, " (%s)",
940 exp
->elts
[elt
].symbol
->print_name ());
944 fprintf_filtered (stream
, "History element %ld",
945 (long) exp
->elts
[elt
].longconst
);
949 fprintf_filtered (stream
, "Register $%s", &exp
->elts
[elt
+ 1].string
);
950 elt
+= 3 + BYTES_TO_EXP_ELEM (exp
->elts
[elt
].longconst
+ 1);
953 fprintf_filtered (stream
, "Internal var @");
954 gdb_print_host_address (exp
->elts
[elt
].internalvar
, stream
);
955 fprintf_filtered (stream
, " (%s)",
956 internalvar_name (exp
->elts
[elt
].internalvar
));
960 elt
= dump_subexp_body_funcall (exp
, stream
, elt
);
967 lower
= longest_to_int (exp
->elts
[elt
].longconst
);
968 upper
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
970 fprintf_filtered (stream
, "Bounds [%d:%d]", lower
, upper
);
973 for (i
= 1; i
<= upper
- lower
+ 1; i
++)
974 elt
= dump_subexp (exp
, stream
, elt
);
977 case UNOP_DYNAMIC_CAST
:
978 case UNOP_REINTERPRET_CAST
:
980 case UNOP_MEMVAL_TYPE
:
981 fprintf_filtered (stream
, " (");
982 elt
= dump_subexp (exp
, stream
, elt
);
983 fprintf_filtered (stream
, ")");
984 elt
= dump_subexp (exp
, stream
, elt
);
988 fprintf_filtered (stream
, "Type @");
989 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
990 fprintf_filtered (stream
, " (");
991 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
992 fprintf_filtered (stream
, ")");
993 elt
= dump_subexp (exp
, stream
, elt
+ 2);
996 fprintf_filtered (stream
, "Type @");
997 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
998 fprintf_filtered (stream
, " (");
999 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1000 fprintf_filtered (stream
, ")");
1005 fprintf_filtered (stream
, "Typeof (");
1006 elt
= dump_subexp (exp
, stream
, elt
);
1007 fprintf_filtered (stream
, ")");
1010 fprintf_filtered (stream
, "typeid (");
1011 elt
= dump_subexp (exp
, stream
, elt
);
1012 fprintf_filtered (stream
, ")");
1014 case STRUCTOP_STRUCT
:
1020 len
= longest_to_int (exp
->elts
[elt
].longconst
);
1021 elem_name
= &exp
->elts
[elt
+ 1].string
;
1023 fprintf_filtered (stream
, "Element name: `%.*s'", len
, elem_name
);
1024 elt
= dump_subexp (exp
, stream
, elt
+ 3 + BYTES_TO_EXP_ELEM (len
+ 1));
1032 fprintf_filtered (stream
, "Type @");
1033 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1034 fprintf_filtered (stream
, " (");
1035 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1036 fprintf_filtered (stream
, ") ");
1038 len
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
1039 elem_name
= &exp
->elts
[elt
+ 2].string
;
1041 fprintf_filtered (stream
, "Field name: `%.*s'", len
, elem_name
);
1042 elt
+= 4 + BYTES_TO_EXP_ELEM (len
+ 1);
1046 case OP_FUNC_STATIC_VAR
:
1048 int len
= longest_to_int (exp
->elts
[elt
].longconst
);
1049 const char *var_name
= &exp
->elts
[elt
+ 1].string
;
1050 fprintf_filtered (stream
, "Field name: `%.*s'", len
, var_name
);
1051 elt
+= 3 + BYTES_TO_EXP_ELEM (len
+ 1);
1057 type_instance_flags flags
1058 = (type_instance_flag_value
) longest_to_int (exp
->elts
[elt
++].longconst
);
1059 LONGEST len
= exp
->elts
[elt
++].longconst
;
1060 fprintf_filtered (stream
, "%s TypeInstance: ", plongest (len
));
1063 fprintf_filtered (stream
, "Type @");
1064 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1065 fprintf_filtered (stream
, " (");
1066 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1067 fprintf_filtered (stream
, ")");
1070 fputs_filtered (", ", stream
);
1073 fprintf_filtered (stream
, " Flags: %s (", hex_string (flags
));
1075 auto print_one
= [&] (const char *mod
)
1078 fputs_filtered (" ", stream
);
1080 fprintf_filtered (stream
, "%s", mod
);
1082 if (flags
& TYPE_INSTANCE_FLAG_CONST
)
1083 print_one ("const");
1084 if (flags
& TYPE_INSTANCE_FLAG_VOLATILE
)
1085 print_one ("volatile");
1086 fprintf_filtered (stream
, ")");
1088 /* Ending LEN and ending TYPE_INSTANCE. */
1090 elt
= dump_subexp (exp
, stream
, elt
);
1095 LONGEST len
= exp
->elts
[elt
].longconst
;
1096 LONGEST type
= exp
->elts
[elt
+ 1].longconst
;
1098 fprintf_filtered (stream
, "Language-specific string type: %s",
1104 /* Skip string content. */
1105 elt
+= BYTES_TO_EXP_ELEM (len
);
1107 /* Skip length and ending OP_STRING. */
1113 enum range_type range_type
;
1115 range_type
= (enum range_type
)
1116 longest_to_int (exp
->elts
[elt
].longconst
);
1121 case BOTH_BOUND_DEFAULT
:
1122 fputs_filtered ("Range '..'", stream
);
1124 case LOW_BOUND_DEFAULT
:
1125 fputs_filtered ("Range '..EXP'", stream
);
1127 case LOW_BOUND_DEFAULT_EXCLUSIVE
:
1128 fputs_filtered ("ExclusiveRange '..EXP'", stream
);
1130 case HIGH_BOUND_DEFAULT
:
1131 fputs_filtered ("Range 'EXP..'", stream
);
1133 case NONE_BOUND_DEFAULT
:
1134 fputs_filtered ("Range 'EXP..EXP'", stream
);
1136 case NONE_BOUND_DEFAULT_EXCLUSIVE
:
1137 fputs_filtered ("ExclusiveRange 'EXP..EXP'", stream
);
1140 fputs_filtered ("Invalid Range!", stream
);
1144 if (range_type
== HIGH_BOUND_DEFAULT
1145 || range_type
== NONE_BOUND_DEFAULT
)
1146 elt
= dump_subexp (exp
, stream
, elt
);
1147 if (range_type
== LOW_BOUND_DEFAULT
1148 || range_type
== NONE_BOUND_DEFAULT
)
1149 elt
= dump_subexp (exp
, stream
, elt
);
1155 case MULTI_SUBSCRIPT
:
1161 fprintf_filtered (stream
, "Unknown format");
1168 dump_prefix_expression (struct expression
*exp
, struct ui_file
*stream
)
1172 fprintf_filtered (stream
, "Dump of expression @ ");
1173 gdb_print_host_address (exp
, stream
);
1174 fputs_filtered (", after conversion to prefix form:\nExpression: `", stream
);
1175 print_expression (exp
, stream
);
1176 fprintf_filtered (stream
, "'\n\tLanguage %s, %d elements, %ld bytes each.\n",
1177 exp
->language_defn
->name (), exp
->nelts
,
1178 (long) sizeof (union exp_element
));
1179 fputs_filtered ("\n", stream
);
1181 for (elt
= 0; elt
< exp
->nelts
;)
1182 elt
= dump_subexp (exp
, stream
, elt
);
1183 fputs_filtered ("\n", stream
);