1 /* Print in infix form a struct expression.
3 Copyright (C) 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
4 1998, 1999, 2000, 2003, 2007, 2008, 2009, 2010
5 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "expression.h"
28 #include "parser-defs.h"
29 #include "user-regs.h" /* For user_reg_map_regnum_to_name. */
31 #include "gdb_string.h"
34 #include "gdb_assert.h"
42 print_expression (struct expression
*exp
, struct ui_file
*stream
)
46 print_subexp (exp
, &pc
, stream
, PREC_NULL
);
49 /* Print the subexpression of EXP that starts in position POS, on STREAM.
50 PREC is the precedence of the surrounding operator;
51 if the precedence of the main operator of this subexpression is less,
52 parentheses are needed here. */
55 print_subexp (struct expression
*exp
, int *pos
,
56 struct ui_file
*stream
, enum precedence prec
)
58 exp
->language_defn
->la_exp_desc
->print_subexp (exp
, pos
, stream
, prec
);
61 /* Standard implementation of print_subexp for use in language_defn
64 print_subexp_standard (struct expression
*exp
, int *pos
,
65 struct ui_file
*stream
, enum precedence prec
)
68 const struct op_print
*op_print_tab
;
72 int assign_modify
= 0;
73 enum exp_opcode opcode
;
74 enum precedence myprec
= PREC_NULL
;
75 /* Set to 1 for a right-associative operator. */
80 op_print_tab
= exp
->language_defn
->la_op_print_tab
;
82 opcode
= exp
->elts
[pc
].opcode
;
90 fputs_filtered (type_name_no_tag (exp
->elts
[pc
+ 1].type
), stream
);
91 fputs_filtered ("::", stream
);
92 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
93 (*pos
) += 4 + BYTES_TO_EXP_ELEM (nargs
+ 1);
94 fputs_filtered (&exp
->elts
[pc
+ 3].string
, stream
);
99 struct value_print_options opts
;
101 get_raw_print_options (&opts
);
103 value_print (value_from_longest (exp
->elts
[pc
+ 1].type
,
104 exp
->elts
[pc
+ 2].longconst
),
111 struct value_print_options opts
;
113 get_raw_print_options (&opts
);
115 value_print (value_from_double (exp
->elts
[pc
+ 1].type
,
116 exp
->elts
[pc
+ 2].doubleconst
),
126 b
= exp
->elts
[pc
+ 1].block
;
128 && BLOCK_FUNCTION (b
) != NULL
129 && SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b
)) != NULL
)
131 fputs_filtered (SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b
)), stream
);
132 fputs_filtered ("::", stream
);
134 fputs_filtered (SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 2].symbol
), stream
);
140 fprintf_filtered (stream
, "$%d",
141 longest_to_int (exp
->elts
[pc
+ 1].longconst
));
146 const char *name
= &exp
->elts
[pc
+ 2].string
;
148 (*pos
) += 3 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
149 fprintf_filtered (stream
, "$%s", name
);
155 fprintf_filtered (stream
, "%s",
156 longest_to_int (exp
->elts
[pc
+ 1].longconst
)
162 fprintf_filtered (stream
, "$%s",
163 internalvar_name (exp
->elts
[pc
+ 1].internalvar
));
168 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
169 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
170 fputs_filtered (" (", stream
);
171 for (tem
= 0; tem
< nargs
; tem
++)
174 fputs_filtered (", ", stream
);
175 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
177 fputs_filtered (")", stream
);
181 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
182 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
183 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
188 struct value_print_options opts
;
190 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
191 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
192 /* LA_PRINT_STRING will print using the current repeat count threshold.
193 If necessary, we can temporarily set it to zero, or pass it as an
194 additional parameter to LA_PRINT_STRING. -fnf */
195 get_user_print_options (&opts
);
196 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
197 &exp
->elts
[pc
+ 2].string
, nargs
, NULL
, 0, &opts
);
202 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
204 += 3 + BYTES_TO_EXP_ELEM ((nargs
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
);
205 fprintf_unfiltered (stream
, "B'<unimplemented>'");
208 case OP_OBJC_NSSTRING
: /* Objective-C Foundation Class NSString constant. */
210 struct value_print_options opts
;
212 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
213 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
214 fputs_filtered ("@\"", stream
);
215 get_user_print_options (&opts
);
216 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
217 &exp
->elts
[pc
+ 2].string
, nargs
, NULL
, 0, &opts
);
218 fputs_filtered ("\"", stream
);
222 case OP_OBJC_MSGCALL
:
223 { /* Objective C message (method) call. */
227 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
228 fprintf_unfiltered (stream
, "[");
229 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
230 if (0 == target_read_string (exp
->elts
[pc
+ 1].longconst
,
231 &selector
, 1024, NULL
))
233 error (_("bad selector"));
240 s
= alloca (strlen (selector
) + 1);
241 strcpy (s
, selector
);
242 for (tem
= 0; tem
< nargs
; tem
++)
244 nextS
= strchr (s
, ':');
245 gdb_assert (nextS
); /* Make sure we found ':'. */
247 fprintf_unfiltered (stream
, " %s: ", s
);
249 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
254 fprintf_unfiltered (stream
, " %s", selector
);
256 fprintf_unfiltered (stream
, "]");
257 /* "selector" was malloc'd by target_read_string. Free it. */
264 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
265 nargs
-= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
268 if (exp
->elts
[pc
+ 4].opcode
== OP_LONG
269 && exp
->elts
[pc
+ 5].type
270 == builtin_type (exp
->gdbarch
)->builtin_char
271 && exp
->language_defn
->la_language
== language_c
)
273 /* Attempt to print C character arrays using string syntax.
274 Walk through the args, picking up one character from each
275 of the OP_LONG expression elements. If any array element
276 does not match our expection of what we should find for
277 a simple string, revert back to array printing. Note that
278 the last expression element is an explicit null terminator
279 byte, which doesn't get printed. */
280 tempstr
= alloca (nargs
);
284 if (exp
->elts
[pc
].opcode
!= OP_LONG
285 || exp
->elts
[pc
+ 1].type
286 != builtin_type (exp
->gdbarch
)->builtin_char
)
288 /* Not a simple array of char, use regular array printing. */
295 longest_to_int (exp
->elts
[pc
+ 2].longconst
);
302 struct value_print_options opts
;
304 get_user_print_options (&opts
);
305 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
306 tempstr
, nargs
- 1, NULL
, 0, &opts
);
311 fputs_filtered (" {", stream
);
312 for (tem
= 0; tem
< nargs
; tem
++)
316 fputs_filtered (", ", stream
);
318 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
320 fputs_filtered ("}", stream
);
325 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
326 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
327 /* Gcc support both these syntaxes. Unsure which is preferred. */
329 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
330 fputs_filtered (": ", stream
);
332 fputs_filtered (".", stream
);
333 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
334 fputs_filtered ("=", stream
);
336 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
340 if ((int) prec
> (int) PREC_COMMA
)
341 fputs_filtered ("(", stream
);
342 /* Print the subexpressions, forcing parentheses
343 around any binary operations within them.
344 This is more parentheses than are strictly necessary,
345 but it looks clearer. */
346 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
347 fputs_filtered (" ? ", stream
);
348 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
349 fputs_filtered (" : ", stream
);
350 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
351 if ((int) prec
> (int) PREC_COMMA
)
352 fputs_filtered (")", stream
);
356 case TERNOP_SLICE_COUNT
:
357 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
358 fputs_filtered ("(", stream
);
359 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
360 fputs_filtered (opcode
== TERNOP_SLICE
? " : " : " UP ", stream
);
361 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
362 fputs_filtered (")", stream
);
365 case STRUCTOP_STRUCT
:
366 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
367 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
368 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
369 fputs_filtered (".", stream
);
370 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
373 /* Will not occur for Modula-2 */
375 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
376 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
377 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
378 fputs_filtered ("->", stream
);
379 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
382 case STRUCTOP_MEMBER
:
383 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
384 fputs_filtered (".*", stream
);
385 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
389 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
390 fputs_filtered ("->*", stream
);
391 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
394 case BINOP_SUBSCRIPT
:
395 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
396 fputs_filtered ("[", stream
);
397 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
398 fputs_filtered ("]", stream
);
401 case UNOP_POSTINCREMENT
:
402 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
403 fputs_filtered ("++", stream
);
406 case UNOP_POSTDECREMENT
:
407 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
408 fputs_filtered ("--", stream
);
413 if ((int) prec
> (int) PREC_PREFIX
)
414 fputs_filtered ("(", stream
);
415 fputs_filtered ("(", stream
);
416 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
417 fputs_filtered (") ", stream
);
418 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
419 if ((int) prec
> (int) PREC_PREFIX
)
420 fputs_filtered (")", stream
);
423 case UNOP_DYNAMIC_CAST
:
424 case UNOP_REINTERPRET_CAST
:
425 fputs_filtered (opcode
== UNOP_DYNAMIC_CAST
? "dynamic_cast"
426 : "reinterpret_cast", stream
);
427 fputs_filtered ("<", stream
);
429 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
430 fputs_filtered ("> (", stream
);
431 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
432 fputs_filtered (")", stream
);
437 if ((int) prec
> (int) PREC_PREFIX
)
438 fputs_filtered ("(", stream
);
439 if (TYPE_CODE (exp
->elts
[pc
+ 1].type
) == TYPE_CODE_FUNC
440 && exp
->elts
[pc
+ 3].opcode
== OP_LONG
)
442 struct value_print_options opts
;
444 /* We have a minimal symbol fn, probably. It's encoded
445 as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address).
446 Swallow the OP_LONG (including both its opcodes); ignore
447 its type; print the value in the type of the MEMVAL. */
449 val
= value_at_lazy (exp
->elts
[pc
+ 1].type
,
450 (CORE_ADDR
) exp
->elts
[pc
+ 5].longconst
);
451 get_raw_print_options (&opts
);
452 value_print (val
, stream
, &opts
);
456 fputs_filtered ("{", stream
);
457 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
458 fputs_filtered ("} ", stream
);
459 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
461 if ((int) prec
> (int) PREC_PREFIX
)
462 fputs_filtered (")", stream
);
465 case UNOP_MEMVAL_TLS
:
467 if ((int) prec
> (int) PREC_PREFIX
)
468 fputs_filtered ("(", stream
);
469 fputs_filtered ("{", stream
);
470 type_print (exp
->elts
[pc
+ 2].type
, "", stream
, 0);
471 fputs_filtered ("} ", stream
);
472 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
473 if ((int) prec
> (int) PREC_PREFIX
)
474 fputs_filtered (")", stream
);
477 case BINOP_ASSIGN_MODIFY
:
478 opcode
= exp
->elts
[pc
+ 1].opcode
;
480 myprec
= PREC_ASSIGN
;
484 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
485 if (op_print_tab
[tem
].opcode
== opcode
)
487 op_str
= op_print_tab
[tem
].string
;
490 if (op_print_tab
[tem
].opcode
!= opcode
)
491 /* Not found; don't try to keep going because we don't know how
492 to interpret further elements. */
493 error (_("Invalid expression"));
500 fputs_filtered ("this", stream
);
503 /* Objective-C ops */
507 fputs_filtered ("self", stream
); /* The ObjC equivalent of "this". */
512 case MULTI_SUBSCRIPT
:
514 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
515 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
516 fprintf_unfiltered (stream
, " [");
517 for (tem
= 0; tem
< nargs
; tem
++)
520 fprintf_unfiltered (stream
, ", ");
521 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
523 fprintf_unfiltered (stream
, "]");
528 fprintf_unfiltered (stream
, "VAL(");
529 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
530 fprintf_unfiltered (stream
, ",");
531 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
532 fprintf_unfiltered (stream
, ")");
539 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
540 if (op_print_tab
[tem
].opcode
== opcode
)
542 op_str
= op_print_tab
[tem
].string
;
543 myprec
= op_print_tab
[tem
].precedence
;
544 assoc
= op_print_tab
[tem
].right_assoc
;
547 if (op_print_tab
[tem
].opcode
!= opcode
)
548 /* Not found; don't try to keep going because we don't know how
549 to interpret further elements. For example, this happens
550 if opcode is OP_TYPE. */
551 error (_("Invalid expression"));
554 /* Note that PREC_BUILTIN will always emit parentheses. */
555 if ((int) myprec
< (int) prec
)
556 fputs_filtered ("(", stream
);
557 if ((int) opcode
> (int) BINOP_END
)
561 /* Unary postfix operator. */
562 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
563 fputs_filtered (op_str
, stream
);
567 /* Unary prefix operator. */
568 fputs_filtered (op_str
, stream
);
569 if (myprec
== PREC_BUILTIN_FUNCTION
)
570 fputs_filtered ("(", stream
);
571 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
572 if (myprec
== PREC_BUILTIN_FUNCTION
)
573 fputs_filtered (")", stream
);
578 /* Binary operator. */
579 /* Print left operand.
580 If operator is right-associative,
581 increment precedence for this operand. */
582 print_subexp (exp
, pos
, stream
,
583 (enum precedence
) ((int) myprec
+ assoc
));
584 /* Print the operator itself. */
586 fprintf_filtered (stream
, " %s= ", op_str
);
587 else if (op_str
[0] == ',')
588 fprintf_filtered (stream
, "%s ", op_str
);
590 fprintf_filtered (stream
, " %s ", op_str
);
591 /* Print right operand.
592 If operator is left-associative,
593 increment precedence for this operand. */
594 print_subexp (exp
, pos
, stream
,
595 (enum precedence
) ((int) myprec
+ !assoc
));
598 if ((int) myprec
< (int) prec
)
599 fputs_filtered (")", stream
);
602 /* Return the operator corresponding to opcode OP as
603 a string. NULL indicates that the opcode was not found in the
604 current language table. */
606 op_string (enum exp_opcode op
)
609 const struct op_print
*op_print_tab
;
611 op_print_tab
= current_language
->la_op_print_tab
;
612 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
613 if (op_print_tab
[tem
].opcode
== op
)
614 return op_print_tab
[tem
].string
;
618 /* Support for dumping the raw data from expressions in a human readable
621 static char *op_name (struct expression
*, enum exp_opcode
);
622 static int dump_subexp_body (struct expression
*exp
, struct ui_file
*, int);
624 /* Name for OPCODE, when it appears in expression EXP. */
627 op_name (struct expression
*exp
, enum exp_opcode opcode
)
629 return exp
->language_defn
->la_exp_desc
->op_name (opcode
);
632 /* Default name for the standard operator OPCODE (i.e., one defined in
633 the definition of enum exp_opcode). */
636 op_name_standard (enum exp_opcode opcode
)
644 sprintf (buf
, "<unknown %d>", opcode
);
665 case BINOP_LOGICAL_AND
:
666 return "BINOP_LOGICAL_AND";
667 case BINOP_LOGICAL_OR
:
668 return "BINOP_LOGICAL_OR";
669 case BINOP_BITWISE_AND
:
670 return "BINOP_BITWISE_AND";
671 case BINOP_BITWISE_IOR
:
672 return "BINOP_BITWISE_IOR";
673 case BINOP_BITWISE_XOR
:
674 return "BINOP_BITWISE_XOR";
676 return "BINOP_EQUAL";
678 return "BINOP_NOTEQUAL";
688 return "BINOP_REPEAT";
690 return "BINOP_ASSIGN";
692 return "BINOP_COMMA";
693 case BINOP_SUBSCRIPT
:
694 return "BINOP_SUBSCRIPT";
695 case MULTI_SUBSCRIPT
:
696 return "MULTI_SUBSCRIPT";
703 case STRUCTOP_MEMBER
:
704 return "STRUCTOP_MEMBER";
706 return "STRUCTOP_MPTR";
708 return "BINOP_INTDIV";
709 case BINOP_ASSIGN_MODIFY
:
710 return "BINOP_ASSIGN_MODIFY";
714 return "BINOP_CONCAT";
716 return "BINOP_RANGE";
720 return "TERNOP_COND";
722 return "TERNOP_SLICE";
723 case TERNOP_SLICE_COUNT
:
724 return "TERNOP_SLICE_COUNT";
730 return "OP_VAR_VALUE";
734 return "OP_REGISTER";
736 return "OP_INTERNALVAR";
742 return "OP_BITSTRING";
747 case UNOP_DYNAMIC_CAST
:
748 return "UNOP_DYNAMIC_CAST";
749 case UNOP_REINTERPRET_CAST
:
750 return "UNOP_REINTERPRET_CAST";
752 return "UNOP_MEMVAL";
753 case UNOP_MEMVAL_TLS
:
754 return "UNOP_MEMVAL_TLS";
757 case UNOP_LOGICAL_NOT
:
758 return "UNOP_LOGICAL_NOT";
759 case UNOP_COMPLEMENT
:
760 return "UNOP_COMPLEMENT";
765 case UNOP_PREINCREMENT
:
766 return "UNOP_PREINCREMENT";
767 case UNOP_POSTINCREMENT
:
768 return "UNOP_POSTINCREMENT";
769 case UNOP_PREDECREMENT
:
770 return "UNOP_PREDECREMENT";
771 case UNOP_POSTDECREMENT
:
772 return "UNOP_POSTDECREMENT";
774 return "UNOP_SIZEOF";
800 return "OP_M2_STRING";
801 case STRUCTOP_STRUCT
:
802 return "STRUCTOP_STRUCT";
804 return "STRUCTOP_PTR";
808 return "OP_OBJC_SELF";
816 return "OP_ADL_FUNC";
820 /* Print a raw dump of expression EXP to STREAM.
821 NOTE, if non-NULL, is printed as extra explanatory text. */
824 dump_raw_expression (struct expression
*exp
, struct ui_file
*stream
,
832 fprintf_filtered (stream
, "Dump of expression @ ");
833 gdb_print_host_address (exp
, stream
);
835 fprintf_filtered (stream
, ", %s:", note
);
836 fprintf_filtered (stream
, "\n\tLanguage %s, %d elements, %ld bytes each.\n",
837 exp
->language_defn
->la_name
, exp
->nelts
,
838 (long) sizeof (union exp_element
));
839 fprintf_filtered (stream
, "\t%5s %20s %16s %s\n", "Index", "Opcode",
840 "Hex Value", "String Value");
841 for (elt
= 0; elt
< exp
->nelts
; elt
++)
843 fprintf_filtered (stream
, "\t%5d ", elt
);
844 opcode_name
= op_name (exp
, exp
->elts
[elt
].opcode
);
846 fprintf_filtered (stream
, "%20s ", opcode_name
);
847 print_longest (stream
, 'd', 0, exp
->elts
[elt
].longconst
);
848 fprintf_filtered (stream
, " ");
850 for (eltscan
= (char *) &exp
->elts
[elt
],
851 eltsize
= sizeof (union exp_element
);
855 fprintf_filtered (stream
, "%c",
856 isprint (*eltscan
) ? (*eltscan
& 0xFF) : '.');
858 fprintf_filtered (stream
, "\n");
862 /* Dump the subexpression of prefix expression EXP whose operator is at
863 position ELT onto STREAM. Returns the position of the next
864 subexpression in EXP. */
867 dump_subexp (struct expression
*exp
, struct ui_file
*stream
, int elt
)
869 static int indent
= 0;
872 fprintf_filtered (stream
, "\n");
873 fprintf_filtered (stream
, "\t%5d ", elt
);
875 for (i
= 1; i
<= indent
; i
++)
876 fprintf_filtered (stream
, " ");
879 fprintf_filtered (stream
, "%-20s ", op_name (exp
, exp
->elts
[elt
].opcode
));
881 elt
= dump_subexp_body (exp
, stream
, elt
);
888 /* Dump the operands of prefix expression EXP whose opcode is at
889 position ELT onto STREAM. Returns the position of the next
890 subexpression in EXP. */
893 dump_subexp_body (struct expression
*exp
, struct ui_file
*stream
, int elt
)
895 return exp
->language_defn
->la_exp_desc
->dump_subexp_body (exp
, stream
, elt
);
898 /* Default value for subexp_body in exp_descriptor vector. */
901 dump_subexp_body_standard (struct expression
*exp
,
902 struct ui_file
*stream
, int elt
)
904 int opcode
= exp
->elts
[elt
++].opcode
;
910 case TERNOP_SLICE_COUNT
:
911 elt
= dump_subexp (exp
, stream
, elt
);
920 case BINOP_LOGICAL_AND
:
921 case BINOP_LOGICAL_OR
:
922 case BINOP_BITWISE_AND
:
923 case BINOP_BITWISE_IOR
:
924 case BINOP_BITWISE_XOR
:
934 case BINOP_SUBSCRIPT
:
939 case BINOP_ASSIGN_MODIFY
:
945 case STRUCTOP_MEMBER
:
947 elt
= dump_subexp (exp
, stream
, elt
);
949 case UNOP_LOGICAL_NOT
:
950 case UNOP_COMPLEMENT
:
953 case UNOP_PREINCREMENT
:
954 case UNOP_POSTINCREMENT
:
955 case UNOP_PREDECREMENT
:
956 case UNOP_POSTDECREMENT
:
969 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
, "), value %ld (0x%lx)",
977 (long) exp
->elts
[elt
+ 1].longconst
,
978 (long) exp
->elts
[elt
+ 1].longconst
);
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
, "), value %g",
987 (double) exp
->elts
[elt
+ 1].doubleconst
);
991 fprintf_filtered (stream
, "Block @");
992 gdb_print_host_address (exp
->elts
[elt
].block
, stream
);
993 fprintf_filtered (stream
, ", symbol @");
994 gdb_print_host_address (exp
->elts
[elt
+ 1].symbol
, stream
);
995 fprintf_filtered (stream
, " (%s)",
996 SYMBOL_PRINT_NAME (exp
->elts
[elt
+ 1].symbol
));
1000 fprintf_filtered (stream
, "History element %ld",
1001 (long) exp
->elts
[elt
].longconst
);
1005 fprintf_filtered (stream
, "Register $%s", &exp
->elts
[elt
+ 1].string
);
1006 elt
+= 3 + BYTES_TO_EXP_ELEM (exp
->elts
[elt
].longconst
+ 1);
1008 case OP_INTERNALVAR
:
1009 fprintf_filtered (stream
, "Internal var @");
1010 gdb_print_host_address (exp
->elts
[elt
].internalvar
, stream
);
1011 fprintf_filtered (stream
, " (%s)",
1012 internalvar_name (exp
->elts
[elt
].internalvar
));
1019 nargs
= longest_to_int (exp
->elts
[elt
].longconst
);
1021 fprintf_filtered (stream
, "Number of args: %d", nargs
);
1024 for (i
= 1; i
<= nargs
+ 1; i
++)
1025 elt
= dump_subexp (exp
, stream
, elt
);
1033 lower
= longest_to_int (exp
->elts
[elt
].longconst
);
1034 upper
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
1036 fprintf_filtered (stream
, "Bounds [%d:%d]", lower
, upper
);
1039 for (i
= 1; i
<= upper
- lower
+ 1; i
++)
1040 elt
= dump_subexp (exp
, stream
, elt
);
1045 case UNOP_DYNAMIC_CAST
:
1046 case UNOP_REINTERPRET_CAST
:
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
, ")");
1052 elt
= dump_subexp (exp
, stream
, elt
+ 2);
1054 case UNOP_MEMVAL_TLS
:
1055 fprintf_filtered (stream
, "TLS type @");
1056 gdb_print_host_address (exp
->elts
[elt
+ 1].type
, stream
);
1057 fprintf_filtered (stream
, " (__thread /* \"%s\" */ ",
1058 (exp
->elts
[elt
].objfile
== NULL
? "(null)"
1059 : exp
->elts
[elt
].objfile
->name
));
1060 type_print (exp
->elts
[elt
+ 1].type
, NULL
, stream
, 0);
1061 fprintf_filtered (stream
, ")");
1062 elt
= dump_subexp (exp
, stream
, elt
+ 3);
1065 fprintf_filtered (stream
, "Type @");
1066 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1067 fprintf_filtered (stream
, " (");
1068 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1069 fprintf_filtered (stream
, ")");
1072 case STRUCTOP_STRUCT
:
1078 len
= longest_to_int (exp
->elts
[elt
].longconst
);
1079 elem_name
= &exp
->elts
[elt
+ 1].string
;
1081 fprintf_filtered (stream
, "Element name: `%.*s'", len
, elem_name
);
1082 elt
= dump_subexp (exp
, stream
, elt
+ 3 + BYTES_TO_EXP_ELEM (len
+ 1));
1090 fprintf_filtered (stream
, "Type @");
1091 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1092 fprintf_filtered (stream
, " (");
1093 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1094 fprintf_filtered (stream
, ") ");
1096 len
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
1097 elem_name
= &exp
->elts
[elt
+ 2].string
;
1099 fprintf_filtered (stream
, "Field name: `%.*s'", len
, elem_name
);
1100 elt
+= 4 + BYTES_TO_EXP_ELEM (len
+ 1);
1105 case MULTI_SUBSCRIPT
:
1106 case OP_F77_UNDETERMINED_ARGLIST
:
1115 fprintf_filtered (stream
, "Unknown format");
1122 dump_prefix_expression (struct expression
*exp
, struct ui_file
*stream
)
1126 fprintf_filtered (stream
, "Dump of expression @ ");
1127 gdb_print_host_address (exp
, stream
);
1128 fputs_filtered (", after conversion to prefix form:\nExpression: `", stream
);
1129 if (exp
->elts
[0].opcode
!= OP_TYPE
)
1130 print_expression (exp
, stream
);
1132 fputs_filtered ("Type printing not yet supported....", stream
);
1133 fprintf_filtered (stream
, "'\n\tLanguage %s, %d elements, %ld bytes each.\n",
1134 exp
->language_defn
->la_name
, exp
->nelts
,
1135 (long) sizeof (union exp_element
));
1136 fputs_filtered ("\n", stream
);
1138 for (elt
= 0; elt
< exp
->nelts
;)
1139 elt
= dump_subexp (exp
, stream
, elt
);
1140 fputs_filtered ("\n", stream
);