1 /* Print in infix form a struct expression.
3 Copyright (C) 1986-2018 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. */
36 print_expression (struct expression
*exp
, struct ui_file
*stream
)
40 print_subexp (exp
, &pc
, stream
, PREC_NULL
);
43 /* Print the subexpression of EXP that starts in position POS, on STREAM.
44 PREC is the precedence of the surrounding operator;
45 if the precedence of the main operator of this subexpression is less,
46 parentheses are needed here. */
49 print_subexp (struct expression
*exp
, int *pos
,
50 struct ui_file
*stream
, enum precedence prec
)
52 exp
->language_defn
->la_exp_desc
->print_subexp (exp
, pos
, stream
, prec
);
55 /* Standard implementation of print_subexp for use in language_defn
58 print_subexp_standard (struct expression
*exp
, int *pos
,
59 struct ui_file
*stream
, enum precedence prec
)
62 const struct op_print
*op_print_tab
;
66 int assign_modify
= 0;
67 enum exp_opcode opcode
;
68 enum precedence myprec
= PREC_NULL
;
69 /* Set to 1 for a right-associative operator. */
74 op_print_tab
= exp
->language_defn
->la_op_print_tab
;
76 opcode
= exp
->elts
[pc
].opcode
;
83 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
89 fputs_filtered (type_name_no_tag (exp
->elts
[pc
+ 1].type
), stream
);
90 fputs_filtered ("::", stream
);
91 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
92 (*pos
) += 4 + BYTES_TO_EXP_ELEM (nargs
+ 1);
93 fputs_filtered (&exp
->elts
[pc
+ 3].string
, stream
);
98 struct value_print_options opts
;
100 get_no_prettyformat_print_options (&opts
);
102 value_print (value_from_longest (exp
->elts
[pc
+ 1].type
,
103 exp
->elts
[pc
+ 2].longconst
),
110 struct value_print_options opts
;
112 get_no_prettyformat_print_options (&opts
);
114 value_print (value_from_contents (exp
->elts
[pc
+ 1].type
,
115 exp
->elts
[pc
+ 2].floatconst
),
122 const struct block
*b
;
125 b
= exp
->elts
[pc
+ 1].block
;
127 && BLOCK_FUNCTION (b
) != NULL
128 && SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b
)) != NULL
)
130 fputs_filtered (SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b
)), stream
);
131 fputs_filtered ("::", stream
);
133 fputs_filtered (SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 2].symbol
), stream
);
137 case OP_VAR_MSYM_VALUE
:
140 fputs_filtered (MSYMBOL_PRINT_NAME (exp
->elts
[pc
+ 2].msymbol
), stream
);
144 case OP_FUNC_STATIC_VAR
:
146 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
147 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
148 fputs_filtered (&exp
->elts
[pc
+ 1].string
, stream
);
152 case OP_VAR_ENTRY_VALUE
:
155 fprintf_filtered (stream
, "%s@entry",
156 SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 1].symbol
));
162 fprintf_filtered (stream
, "$%d",
163 longest_to_int (exp
->elts
[pc
+ 1].longconst
));
168 const char *name
= &exp
->elts
[pc
+ 2].string
;
170 (*pos
) += 3 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
171 fprintf_filtered (stream
, "$%s", name
);
177 fprintf_filtered (stream
, "%s",
178 longest_to_int (exp
->elts
[pc
+ 1].longconst
)
184 fprintf_filtered (stream
, "$%s",
185 internalvar_name (exp
->elts
[pc
+ 1].internalvar
));
189 case OP_F77_UNDETERMINED_ARGLIST
:
191 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
192 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
193 fputs_filtered (" (", stream
);
194 for (tem
= 0; tem
< nargs
; tem
++)
197 fputs_filtered (", ", stream
);
198 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
200 fputs_filtered (")", stream
);
204 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
205 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
206 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
211 struct value_print_options opts
;
213 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
214 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
215 /* LA_PRINT_STRING will print using the current repeat count threshold.
216 If necessary, we can temporarily set it to zero, or pass it as an
217 additional parameter to LA_PRINT_STRING. -fnf */
218 get_user_print_options (&opts
);
219 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
220 (gdb_byte
*) &exp
->elts
[pc
+ 2].string
, nargs
,
225 case OP_OBJC_NSSTRING
: /* Objective-C Foundation Class
226 NSString constant. */
228 struct value_print_options opts
;
230 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
231 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
232 fputs_filtered ("@\"", stream
);
233 get_user_print_options (&opts
);
234 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
235 (gdb_byte
*) &exp
->elts
[pc
+ 2].string
, nargs
,
237 fputs_filtered ("\"", stream
);
241 case OP_OBJC_MSGCALL
:
242 { /* Objective C message (method) call. */
243 gdb::unique_xmalloc_ptr
<char> selector
;
246 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
247 fprintf_unfiltered (stream
, "[");
248 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
249 if (0 == target_read_string (exp
->elts
[pc
+ 1].longconst
,
250 &selector
, 1024, NULL
))
252 error (_("bad selector"));
260 for (tem
= 0; tem
< nargs
; tem
++)
262 nextS
= strchr (s
, ':');
263 gdb_assert (nextS
); /* Make sure we found ':'. */
265 fprintf_unfiltered (stream
, " %s: ", s
);
267 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
272 fprintf_unfiltered (stream
, " %s", selector
.get ());
274 fprintf_unfiltered (stream
, "]");
280 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
281 nargs
-= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
284 if (exp
->elts
[pc
+ 4].opcode
== OP_LONG
285 && exp
->elts
[pc
+ 5].type
286 == builtin_type (exp
->gdbarch
)->builtin_char
287 && exp
->language_defn
->la_language
== language_c
)
289 /* Attempt to print C character arrays using string syntax.
290 Walk through the args, picking up one character from each
291 of the OP_LONG expression elements. If any array element
292 does not match our expection of what we should find for
293 a simple string, revert back to array printing. Note that
294 the last expression element is an explicit null terminator
295 byte, which doesn't get printed. */
296 tempstr
= (char *) alloca (nargs
);
300 if (exp
->elts
[pc
].opcode
!= OP_LONG
301 || exp
->elts
[pc
+ 1].type
302 != builtin_type (exp
->gdbarch
)->builtin_char
)
304 /* Not a simple array of char, use regular array
312 longest_to_int (exp
->elts
[pc
+ 2].longconst
);
319 struct value_print_options opts
;
321 get_user_print_options (&opts
);
322 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
323 (gdb_byte
*) tempstr
, nargs
- 1, NULL
, 0, &opts
);
328 fputs_filtered (" {", stream
);
329 for (tem
= 0; tem
< nargs
; tem
++)
333 fputs_filtered (", ", stream
);
335 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
337 fputs_filtered ("}", stream
);
342 if ((int) prec
> (int) PREC_COMMA
)
343 fputs_filtered ("(", stream
);
344 /* Print the subexpressions, forcing parentheses
345 around any binary operations within them.
346 This is more parentheses than are strictly necessary,
347 but it looks clearer. */
348 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
349 fputs_filtered (" ? ", stream
);
350 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
351 fputs_filtered (" : ", stream
);
352 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
353 if ((int) prec
> (int) PREC_COMMA
)
354 fputs_filtered (")", stream
);
358 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
359 fputs_filtered ("(", stream
);
360 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
361 fputs_filtered (opcode
== TERNOP_SLICE
? " : " : " UP ", stream
);
362 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
363 fputs_filtered (")", stream
);
366 case STRUCTOP_STRUCT
:
367 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
368 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
369 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
370 fputs_filtered (".", stream
);
371 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
374 /* Will not occur for Modula-2. */
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 case STRUCTOP_MEMBER
:
384 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
385 fputs_filtered (".*", stream
);
386 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
390 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
391 fputs_filtered ("->*", stream
);
392 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
395 case BINOP_SUBSCRIPT
:
396 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
397 fputs_filtered ("[", stream
);
398 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
399 fputs_filtered ("]", stream
);
402 case UNOP_POSTINCREMENT
:
403 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
404 fputs_filtered ("++", stream
);
407 case UNOP_POSTDECREMENT
:
408 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
409 fputs_filtered ("--", stream
);
414 if ((int) prec
> (int) PREC_PREFIX
)
415 fputs_filtered ("(", stream
);
416 fputs_filtered ("(", stream
);
417 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
418 fputs_filtered (") ", stream
);
419 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
420 if ((int) prec
> (int) PREC_PREFIX
)
421 fputs_filtered (")", stream
);
425 if ((int) prec
> (int) PREC_PREFIX
)
426 fputs_filtered ("(", stream
);
427 fputs_filtered ("(", stream
);
428 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
429 fputs_filtered (") ", stream
);
430 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
431 if ((int) prec
> (int) PREC_PREFIX
)
432 fputs_filtered (")", stream
);
435 case UNOP_DYNAMIC_CAST
:
436 case UNOP_REINTERPRET_CAST
:
437 fputs_filtered (opcode
== UNOP_DYNAMIC_CAST
? "dynamic_cast"
438 : "reinterpret_cast", 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 fputs_filtered (")", stream
);
448 if ((int) prec
> (int) PREC_PREFIX
)
449 fputs_filtered ("(", stream
);
450 if (TYPE_CODE (exp
->elts
[pc
+ 1].type
) == TYPE_CODE_FUNC
451 && exp
->elts
[pc
+ 3].opcode
== OP_LONG
)
453 struct value_print_options opts
;
455 /* We have a minimal symbol fn, probably. It's encoded
456 as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address).
457 Swallow the OP_LONG (including both its opcodes); ignore
458 its type; print the value in the type of the MEMVAL. */
460 val
= value_at_lazy (exp
->elts
[pc
+ 1].type
,
461 (CORE_ADDR
) exp
->elts
[pc
+ 5].longconst
);
462 get_no_prettyformat_print_options (&opts
);
463 value_print (val
, stream
, &opts
);
467 fputs_filtered ("{", stream
);
468 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
469 fputs_filtered ("} ", stream
);
470 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
472 if ((int) prec
> (int) PREC_PREFIX
)
473 fputs_filtered (")", stream
);
476 case UNOP_MEMVAL_TYPE
:
477 if ((int) prec
> (int) PREC_PREFIX
)
478 fputs_filtered ("(", stream
);
479 fputs_filtered ("{", stream
);
480 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
481 fputs_filtered ("} ", stream
);
482 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
483 if ((int) prec
> (int) PREC_PREFIX
)
484 fputs_filtered (")", stream
);
487 case BINOP_ASSIGN_MODIFY
:
488 opcode
= exp
->elts
[pc
+ 1].opcode
;
490 myprec
= PREC_ASSIGN
;
494 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
495 if (op_print_tab
[tem
].opcode
== opcode
)
497 op_str
= op_print_tab
[tem
].string
;
500 if (op_print_tab
[tem
].opcode
!= opcode
)
501 /* Not found; don't try to keep going because we don't know how
502 to interpret further elements. */
503 error (_("Invalid expression"));
510 if (exp
->language_defn
->la_name_of_this
)
511 fputs_filtered (exp
->language_defn
->la_name_of_this
, stream
);
513 fprintf_filtered (stream
, _("<language %s has no 'this'>"),
514 exp
->language_defn
->la_name
);
519 case MULTI_SUBSCRIPT
:
521 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
522 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
523 fprintf_unfiltered (stream
, " [");
524 for (tem
= 0; tem
< nargs
; tem
++)
527 fprintf_unfiltered (stream
, ", ");
528 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
530 fprintf_unfiltered (stream
, "]");
535 fprintf_unfiltered (stream
, "VAL(");
536 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
537 fprintf_unfiltered (stream
, ",");
538 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
539 fprintf_unfiltered (stream
, ")");
544 type_instance_flags flags
545 = (type_instance_flag_value
) longest_to_int (exp
->elts
[pc
+ 1].longconst
);
546 LONGEST count
= exp
->elts
[pc
+ 2].longconst
;
552 fputs_unfiltered ("TypeInstance(", stream
);
555 type_print (exp
->elts
[(*pos
)++].type
, "", stream
, 0);
557 fputs_unfiltered (",", stream
);
559 fputs_unfiltered (",", stream
);
560 /* Ending COUNT and ending TYPE_INSTANCE. */
562 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
564 if (flags
& TYPE_INSTANCE_FLAG_CONST
)
565 fputs_unfiltered (",const", stream
);
566 if (flags
& TYPE_INSTANCE_FLAG_VOLATILE
)
567 fputs_unfiltered (",volatile", stream
);
569 fputs_unfiltered (")", stream
);
575 enum range_type range_type
;
577 range_type
= (enum range_type
)
578 longest_to_int (exp
->elts
[pc
+ 1].longconst
);
581 fputs_filtered ("RANGE(", stream
);
582 if (range_type
== HIGH_BOUND_DEFAULT
583 || range_type
== NONE_BOUND_DEFAULT
)
584 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
585 fputs_filtered ("..", stream
);
586 if (range_type
== LOW_BOUND_DEFAULT
587 || range_type
== NONE_BOUND_DEFAULT
)
588 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
589 fputs_filtered (")", stream
);
597 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
598 if (op_print_tab
[tem
].opcode
== opcode
)
600 op_str
= op_print_tab
[tem
].string
;
601 myprec
= op_print_tab
[tem
].precedence
;
602 assoc
= op_print_tab
[tem
].right_assoc
;
605 if (op_print_tab
[tem
].opcode
!= opcode
)
606 /* Not found; don't try to keep going because we don't know how
607 to interpret further elements. For example, this happens
608 if opcode is OP_TYPE. */
609 error (_("Invalid expression"));
612 /* Note that PREC_BUILTIN will always emit parentheses. */
613 if ((int) myprec
< (int) prec
)
614 fputs_filtered ("(", stream
);
615 if ((int) opcode
> (int) BINOP_END
)
619 /* Unary postfix operator. */
620 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
621 fputs_filtered (op_str
, stream
);
625 /* Unary prefix operator. */
626 fputs_filtered (op_str
, stream
);
627 if (myprec
== PREC_BUILTIN_FUNCTION
)
628 fputs_filtered ("(", stream
);
629 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
630 if (myprec
== PREC_BUILTIN_FUNCTION
)
631 fputs_filtered (")", stream
);
636 /* Binary operator. */
637 /* Print left operand.
638 If operator is right-associative,
639 increment precedence for this operand. */
640 print_subexp (exp
, pos
, stream
,
641 (enum precedence
) ((int) myprec
+ assoc
));
642 /* Print the operator itself. */
644 fprintf_filtered (stream
, " %s= ", op_str
);
645 else if (op_str
[0] == ',')
646 fprintf_filtered (stream
, "%s ", op_str
);
648 fprintf_filtered (stream
, " %s ", op_str
);
649 /* Print right operand.
650 If operator is left-associative,
651 increment precedence for this operand. */
652 print_subexp (exp
, pos
, stream
,
653 (enum precedence
) ((int) myprec
+ !assoc
));
656 if ((int) myprec
< (int) prec
)
657 fputs_filtered (")", stream
);
660 /* Return the operator corresponding to opcode OP as
661 a string. NULL indicates that the opcode was not found in the
662 current language table. */
664 op_string (enum exp_opcode op
)
667 const struct op_print
*op_print_tab
;
669 op_print_tab
= current_language
->la_op_print_tab
;
670 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
671 if (op_print_tab
[tem
].opcode
== op
)
672 return op_print_tab
[tem
].string
;
676 /* Support for dumping the raw data from expressions in a human readable
679 static int dump_subexp_body (struct expression
*exp
, struct ui_file
*, int);
681 /* Name for OPCODE, when it appears in expression EXP. */
684 op_name (struct expression
*exp
, enum exp_opcode opcode
)
686 return exp
->language_defn
->la_exp_desc
->op_name (opcode
);
689 /* Default name for the standard operator OPCODE (i.e., one defined in
690 the definition of enum exp_opcode). */
693 op_name_standard (enum exp_opcode opcode
)
701 xsnprintf (buf
, sizeof (buf
), "<unknown %d>", opcode
);
707 #include "std-operator.def"
712 /* Print a raw dump of expression EXP to STREAM.
713 NOTE, if non-NULL, is printed as extra explanatory text. */
716 dump_raw_expression (struct expression
*exp
, struct ui_file
*stream
,
723 fprintf_filtered (stream
, "Dump of expression @ ");
724 gdb_print_host_address (exp
, stream
);
726 fprintf_filtered (stream
, ", %s:", note
);
727 fprintf_filtered (stream
, "\n\tLanguage %s, %d elements, %ld bytes each.\n",
728 exp
->language_defn
->la_name
, exp
->nelts
,
729 (long) sizeof (union exp_element
));
730 fprintf_filtered (stream
, "\t%5s %20s %16s %s\n", "Index", "Opcode",
731 "Hex Value", "String Value");
732 for (elt
= 0; elt
< exp
->nelts
; elt
++)
734 fprintf_filtered (stream
, "\t%5d ", elt
);
736 const char *opcode_name
= op_name (exp
, exp
->elts
[elt
].opcode
);
737 fprintf_filtered (stream
, "%20s ", opcode_name
);
739 print_longest (stream
, 'd', 0, exp
->elts
[elt
].longconst
);
740 fprintf_filtered (stream
, " ");
742 for (eltscan
= (char *) &exp
->elts
[elt
],
743 eltsize
= sizeof (union exp_element
);
747 fprintf_filtered (stream
, "%c",
748 isprint (*eltscan
) ? (*eltscan
& 0xFF) : '.');
750 fprintf_filtered (stream
, "\n");
754 /* Dump the subexpression of prefix expression EXP whose operator is at
755 position ELT onto STREAM. Returns the position of the next
756 subexpression in EXP. */
759 dump_subexp (struct expression
*exp
, struct ui_file
*stream
, int elt
)
761 static int indent
= 0;
764 fprintf_filtered (stream
, "\n");
765 fprintf_filtered (stream
, "\t%5d ", elt
);
767 for (i
= 1; i
<= indent
; i
++)
768 fprintf_filtered (stream
, " ");
771 fprintf_filtered (stream
, "%-20s ", op_name (exp
, exp
->elts
[elt
].opcode
));
773 elt
= dump_subexp_body (exp
, stream
, elt
);
780 /* Dump the operands of prefix expression EXP whose opcode is at
781 position ELT onto STREAM. Returns the position of the next
782 subexpression in EXP. */
785 dump_subexp_body (struct expression
*exp
, struct ui_file
*stream
, int elt
)
787 return exp
->language_defn
->la_exp_desc
->dump_subexp_body (exp
, stream
, elt
);
790 /* Default value for subexp_body in exp_descriptor vector. */
793 dump_subexp_body_standard (struct expression
*exp
,
794 struct ui_file
*stream
, int elt
)
796 int opcode
= exp
->elts
[elt
++].opcode
;
802 elt
= dump_subexp (exp
, stream
, elt
);
812 case BINOP_LOGICAL_AND
:
813 case BINOP_LOGICAL_OR
:
814 case BINOP_BITWISE_AND
:
815 case BINOP_BITWISE_IOR
:
816 case BINOP_BITWISE_XOR
:
826 case BINOP_SUBSCRIPT
:
831 case BINOP_ASSIGN_MODIFY
:
835 case STRUCTOP_MEMBER
:
837 elt
= dump_subexp (exp
, stream
, elt
);
840 case UNOP_LOGICAL_NOT
:
841 case UNOP_COMPLEMENT
:
844 case UNOP_PREINCREMENT
:
845 case UNOP_POSTINCREMENT
:
846 case UNOP_PREDECREMENT
:
847 case UNOP_POSTDECREMENT
:
860 elt
= dump_subexp (exp
, stream
, elt
);
863 fprintf_filtered (stream
, "Type @");
864 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
865 fprintf_filtered (stream
, " (");
866 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
867 fprintf_filtered (stream
, "), value %ld (0x%lx)",
868 (long) exp
->elts
[elt
+ 1].longconst
,
869 (long) exp
->elts
[elt
+ 1].longconst
);
873 fprintf_filtered (stream
, "Type @");
874 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
875 fprintf_filtered (stream
, " (");
876 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
877 fprintf_filtered (stream
, "), value ");
878 print_floating (exp
->elts
[elt
+ 1].floatconst
,
879 exp
->elts
[elt
].type
, stream
);
883 fprintf_filtered (stream
, "Block @");
884 gdb_print_host_address (exp
->elts
[elt
].block
, stream
);
885 fprintf_filtered (stream
, ", symbol @");
886 gdb_print_host_address (exp
->elts
[elt
+ 1].symbol
, stream
);
887 fprintf_filtered (stream
, " (%s)",
888 SYMBOL_PRINT_NAME (exp
->elts
[elt
+ 1].symbol
));
891 case OP_VAR_MSYM_VALUE
:
892 fprintf_filtered (stream
, "Objfile @");
893 gdb_print_host_address (exp
->elts
[elt
].objfile
, stream
);
894 fprintf_filtered (stream
, ", msymbol @");
895 gdb_print_host_address (exp
->elts
[elt
+ 1].msymbol
, stream
);
896 fprintf_filtered (stream
, " (%s)",
897 MSYMBOL_PRINT_NAME (exp
->elts
[elt
+ 1].msymbol
));
900 case OP_VAR_ENTRY_VALUE
:
901 fprintf_filtered (stream
, "Entry value of symbol @");
902 gdb_print_host_address (exp
->elts
[elt
].symbol
, stream
);
903 fprintf_filtered (stream
, " (%s)",
904 SYMBOL_PRINT_NAME (exp
->elts
[elt
].symbol
));
908 fprintf_filtered (stream
, "History element %ld",
909 (long) exp
->elts
[elt
].longconst
);
913 fprintf_filtered (stream
, "Register $%s", &exp
->elts
[elt
+ 1].string
);
914 elt
+= 3 + BYTES_TO_EXP_ELEM (exp
->elts
[elt
].longconst
+ 1);
917 fprintf_filtered (stream
, "Internal var @");
918 gdb_print_host_address (exp
->elts
[elt
].internalvar
, stream
);
919 fprintf_filtered (stream
, " (%s)",
920 internalvar_name (exp
->elts
[elt
].internalvar
));
924 case OP_F77_UNDETERMINED_ARGLIST
:
928 nargs
= longest_to_int (exp
->elts
[elt
].longconst
);
930 fprintf_filtered (stream
, "Number of args: %d", nargs
);
933 for (i
= 1; i
<= nargs
+ 1; i
++)
934 elt
= dump_subexp (exp
, stream
, elt
);
942 lower
= longest_to_int (exp
->elts
[elt
].longconst
);
943 upper
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
945 fprintf_filtered (stream
, "Bounds [%d:%d]", lower
, upper
);
948 for (i
= 1; i
<= upper
- lower
+ 1; i
++)
949 elt
= dump_subexp (exp
, stream
, elt
);
952 case UNOP_DYNAMIC_CAST
:
953 case UNOP_REINTERPRET_CAST
:
955 case UNOP_MEMVAL_TYPE
:
956 fprintf_filtered (stream
, " (");
957 elt
= dump_subexp (exp
, stream
, elt
);
958 fprintf_filtered (stream
, ")");
959 elt
= dump_subexp (exp
, stream
, elt
);
963 fprintf_filtered (stream
, "Type @");
964 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
965 fprintf_filtered (stream
, " (");
966 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
967 fprintf_filtered (stream
, ")");
968 elt
= dump_subexp (exp
, stream
, elt
+ 2);
971 fprintf_filtered (stream
, "Type @");
972 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
973 fprintf_filtered (stream
, " (");
974 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
975 fprintf_filtered (stream
, ")");
980 fprintf_filtered (stream
, "Typeof (");
981 elt
= dump_subexp (exp
, stream
, elt
);
982 fprintf_filtered (stream
, ")");
985 fprintf_filtered (stream
, "typeid (");
986 elt
= dump_subexp (exp
, stream
, elt
);
987 fprintf_filtered (stream
, ")");
989 case STRUCTOP_STRUCT
:
995 len
= longest_to_int (exp
->elts
[elt
].longconst
);
996 elem_name
= &exp
->elts
[elt
+ 1].string
;
998 fprintf_filtered (stream
, "Element name: `%.*s'", len
, elem_name
);
999 elt
= dump_subexp (exp
, stream
, elt
+ 3 + BYTES_TO_EXP_ELEM (len
+ 1));
1007 fprintf_filtered (stream
, "Type @");
1008 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1009 fprintf_filtered (stream
, " (");
1010 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1011 fprintf_filtered (stream
, ") ");
1013 len
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
1014 elem_name
= &exp
->elts
[elt
+ 2].string
;
1016 fprintf_filtered (stream
, "Field name: `%.*s'", len
, elem_name
);
1017 elt
+= 4 + BYTES_TO_EXP_ELEM (len
+ 1);
1021 case OP_FUNC_STATIC_VAR
:
1023 int len
= longest_to_int (exp
->elts
[elt
].longconst
);
1024 const char *var_name
= &exp
->elts
[elt
+ 1].string
;
1025 fprintf_filtered (stream
, "Field name: `%.*s'", len
, var_name
);
1026 elt
+= 3 + BYTES_TO_EXP_ELEM (len
+ 1);
1032 type_instance_flags flags
1033 = (type_instance_flag_value
) longest_to_int (exp
->elts
[elt
++].longconst
);
1034 LONGEST len
= exp
->elts
[elt
++].longconst
;
1035 fprintf_filtered (stream
, "%s TypeInstance: ", plongest (len
));
1038 fprintf_filtered (stream
, "Type @");
1039 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1040 fprintf_filtered (stream
, " (");
1041 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1042 fprintf_filtered (stream
, ")");
1045 fputs_filtered (", ", stream
);
1048 fprintf_filtered (stream
, " Flags: %s (", hex_string (flags
));
1050 auto print_one
= [&] (const char *mod
)
1053 fputs_filtered (" ", stream
);
1055 fprintf_filtered (stream
, "%s", mod
);
1057 if (flags
& TYPE_INSTANCE_FLAG_CONST
)
1058 print_one ("const");
1059 if (flags
& TYPE_INSTANCE_FLAG_VOLATILE
)
1060 print_one ("volatile");
1061 fprintf_filtered (stream
, ")");
1063 /* Ending LEN and ending TYPE_INSTANCE. */
1065 elt
= dump_subexp (exp
, stream
, elt
);
1070 LONGEST len
= exp
->elts
[elt
].longconst
;
1071 LONGEST type
= exp
->elts
[elt
+ 1].longconst
;
1073 fprintf_filtered (stream
, "Language-specific string type: %s",
1079 /* Skip string content. */
1080 elt
+= BYTES_TO_EXP_ELEM (len
);
1082 /* Skip length and ending OP_STRING. */
1088 enum range_type range_type
;
1090 range_type
= (enum range_type
)
1091 longest_to_int (exp
->elts
[elt
].longconst
);
1096 case BOTH_BOUND_DEFAULT
:
1097 fputs_filtered ("Range '..'", stream
);
1099 case LOW_BOUND_DEFAULT
:
1100 fputs_filtered ("Range '..EXP'", stream
);
1102 case HIGH_BOUND_DEFAULT
:
1103 fputs_filtered ("Range 'EXP..'", stream
);
1105 case NONE_BOUND_DEFAULT
:
1106 fputs_filtered ("Range 'EXP..EXP'", stream
);
1109 fputs_filtered ("Invalid Range!", stream
);
1113 if (range_type
== HIGH_BOUND_DEFAULT
1114 || range_type
== NONE_BOUND_DEFAULT
)
1115 elt
= dump_subexp (exp
, stream
, elt
);
1116 if (range_type
== LOW_BOUND_DEFAULT
1117 || range_type
== NONE_BOUND_DEFAULT
)
1118 elt
= dump_subexp (exp
, stream
, elt
);
1124 case MULTI_SUBSCRIPT
:
1130 fprintf_filtered (stream
, "Unknown format");
1137 dump_prefix_expression (struct expression
*exp
, struct ui_file
*stream
)
1141 fprintf_filtered (stream
, "Dump of expression @ ");
1142 gdb_print_host_address (exp
, stream
);
1143 fputs_filtered (", after conversion to prefix form:\nExpression: `", stream
);
1144 print_expression (exp
, stream
);
1145 fprintf_filtered (stream
, "'\n\tLanguage %s, %d elements, %ld bytes each.\n",
1146 exp
->language_defn
->la_name
, exp
->nelts
,
1147 (long) sizeof (union exp_element
));
1148 fputs_filtered ("\n", stream
);
1150 for (elt
= 0; elt
< exp
->nelts
;)
1151 elt
= dump_subexp (exp
, stream
, elt
);
1152 fputs_filtered ("\n", stream
);