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
)
45 print_subexp (exp
, &pc
, stream
, PREC_NULL
);
48 /* Print the subexpression of EXP that starts in position POS, on STREAM.
49 PREC is the precedence of the surrounding operator;
50 if the precedence of the main operator of this subexpression is less,
51 parentheses are needed here. */
54 print_subexp (struct expression
*exp
, int *pos
,
55 struct ui_file
*stream
, enum precedence prec
)
57 exp
->language_defn
->la_exp_desc
->print_subexp (exp
, pos
, stream
, prec
);
60 /* Standard implementation of print_subexp for use in language_defn
63 print_subexp_standard (struct expression
*exp
, int *pos
,
64 struct ui_file
*stream
, enum precedence prec
)
67 const struct op_print
*op_print_tab
;
71 int assign_modify
= 0;
72 enum exp_opcode opcode
;
73 enum precedence myprec
= PREC_NULL
;
74 /* Set to 1 for a right-associative operator. */
79 op_print_tab
= exp
->language_defn
->la_op_print_tab
;
81 opcode
= exp
->elts
[pc
].opcode
;
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
;
99 get_raw_print_options (&opts
);
101 value_print (value_from_longest (exp
->elts
[pc
+ 1].type
,
102 exp
->elts
[pc
+ 2].longconst
),
109 struct value_print_options opts
;
110 get_raw_print_options (&opts
);
112 value_print (value_from_double (exp
->elts
[pc
+ 1].type
,
113 exp
->elts
[pc
+ 2].doubleconst
),
122 b
= exp
->elts
[pc
+ 1].block
;
124 && BLOCK_FUNCTION (b
) != NULL
125 && SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b
)) != NULL
)
127 fputs_filtered (SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b
)), stream
);
128 fputs_filtered ("::", stream
);
130 fputs_filtered (SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 2].symbol
), stream
);
136 fprintf_filtered (stream
, "$%d",
137 longest_to_int (exp
->elts
[pc
+ 1].longconst
));
142 const char *name
= &exp
->elts
[pc
+ 2].string
;
143 (*pos
) += 3 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
144 fprintf_filtered (stream
, "$%s", name
);
150 fprintf_filtered (stream
, "%s",
151 longest_to_int (exp
->elts
[pc
+ 1].longconst
)
157 fprintf_filtered (stream
, "$%s",
158 internalvar_name (exp
->elts
[pc
+ 1].internalvar
));
163 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
164 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
165 fputs_filtered (" (", stream
);
166 for (tem
= 0; tem
< nargs
; tem
++)
169 fputs_filtered (", ", stream
);
170 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
172 fputs_filtered (")", stream
);
176 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
177 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
178 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
183 struct value_print_options opts
;
184 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
185 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
186 /* LA_PRINT_STRING will print using the current repeat count threshold.
187 If necessary, we can temporarily set it to zero, or pass it as an
188 additional parameter to LA_PRINT_STRING. -fnf */
189 get_user_print_options (&opts
);
190 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
191 &exp
->elts
[pc
+ 2].string
, nargs
, NULL
, 0, &opts
);
196 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
198 += 3 + BYTES_TO_EXP_ELEM ((nargs
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
);
199 fprintf_unfiltered (stream
, "B'<unimplemented>'");
202 case OP_OBJC_NSSTRING
: /* Objective-C Foundation Class NSString constant. */
204 struct value_print_options opts
;
205 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
206 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
207 fputs_filtered ("@\"", stream
);
208 get_user_print_options (&opts
);
209 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
210 &exp
->elts
[pc
+ 2].string
, nargs
, NULL
, 0, &opts
);
211 fputs_filtered ("\"", stream
);
215 case OP_OBJC_MSGCALL
:
216 { /* Objective C message (method) call. */
219 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
220 fprintf_unfiltered (stream
, "[");
221 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
222 if (0 == target_read_string (exp
->elts
[pc
+ 1].longconst
,
223 &selector
, 1024, NULL
))
225 error (_("bad selector"));
231 s
= alloca (strlen (selector
) + 1);
232 strcpy (s
, selector
);
233 for (tem
= 0; tem
< nargs
; tem
++)
235 nextS
= strchr (s
, ':');
236 gdb_assert (nextS
); /* Make sure we found ':'. */
238 fprintf_unfiltered (stream
, " %s: ", s
);
240 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
245 fprintf_unfiltered (stream
, " %s", selector
);
247 fprintf_unfiltered (stream
, "]");
248 /* "selector" was malloc'd by target_read_string. Free it. */
255 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
256 nargs
-= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
259 if (exp
->elts
[pc
+ 4].opcode
== OP_LONG
260 && exp
->elts
[pc
+ 5].type
261 == builtin_type (exp
->gdbarch
)->builtin_char
262 && exp
->language_defn
->la_language
== language_c
)
264 /* Attempt to print C character arrays using string syntax.
265 Walk through the args, picking up one character from each
266 of the OP_LONG expression elements. If any array element
267 does not match our expection of what we should find for
268 a simple string, revert back to array printing. Note that
269 the last expression element is an explicit null terminator
270 byte, which doesn't get printed. */
271 tempstr
= alloca (nargs
);
275 if (exp
->elts
[pc
].opcode
!= OP_LONG
276 || exp
->elts
[pc
+ 1].type
277 != builtin_type (exp
->gdbarch
)->builtin_char
)
279 /* Not a simple array of char, use regular array printing. */
286 longest_to_int (exp
->elts
[pc
+ 2].longconst
);
293 struct value_print_options opts
;
294 get_user_print_options (&opts
);
295 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
296 tempstr
, nargs
- 1, NULL
, 0, &opts
);
301 fputs_filtered (" {", stream
);
302 for (tem
= 0; tem
< nargs
; tem
++)
306 fputs_filtered (", ", stream
);
308 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
310 fputs_filtered ("}", stream
);
315 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
316 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
317 /* Gcc support both these syntaxes. Unsure which is preferred. */
319 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
320 fputs_filtered (": ", stream
);
322 fputs_filtered (".", stream
);
323 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
324 fputs_filtered ("=", stream
);
326 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
330 if ((int) prec
> (int) PREC_COMMA
)
331 fputs_filtered ("(", stream
);
332 /* Print the subexpressions, forcing parentheses
333 around any binary operations within them.
334 This is more parentheses than are strictly necessary,
335 but it looks clearer. */
336 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
337 fputs_filtered (" ? ", stream
);
338 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
339 fputs_filtered (" : ", stream
);
340 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
341 if ((int) prec
> (int) PREC_COMMA
)
342 fputs_filtered (")", stream
);
346 case TERNOP_SLICE_COUNT
:
347 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
348 fputs_filtered ("(", stream
);
349 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
350 fputs_filtered (opcode
== TERNOP_SLICE
? " : " : " UP ", stream
);
351 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
352 fputs_filtered (")", stream
);
355 case STRUCTOP_STRUCT
:
356 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
357 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
358 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
359 fputs_filtered (".", stream
);
360 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
363 /* Will not occur for Modula-2 */
365 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
366 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
367 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
368 fputs_filtered ("->", stream
);
369 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
372 case STRUCTOP_MEMBER
:
373 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
374 fputs_filtered (".*", stream
);
375 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
379 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
380 fputs_filtered ("->*", stream
);
381 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
384 case BINOP_SUBSCRIPT
:
385 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
386 fputs_filtered ("[", stream
);
387 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
388 fputs_filtered ("]", stream
);
391 case UNOP_POSTINCREMENT
:
392 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
393 fputs_filtered ("++", stream
);
396 case UNOP_POSTDECREMENT
:
397 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
398 fputs_filtered ("--", stream
);
403 if ((int) prec
> (int) PREC_PREFIX
)
404 fputs_filtered ("(", stream
);
405 fputs_filtered ("(", stream
);
406 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
407 fputs_filtered (") ", stream
);
408 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
409 if ((int) prec
> (int) PREC_PREFIX
)
410 fputs_filtered (")", stream
);
415 if ((int) prec
> (int) PREC_PREFIX
)
416 fputs_filtered ("(", stream
);
417 if (TYPE_CODE (exp
->elts
[pc
+ 1].type
) == TYPE_CODE_FUNC
418 && exp
->elts
[pc
+ 3].opcode
== OP_LONG
)
420 struct value_print_options opts
;
422 /* We have a minimal symbol fn, probably. It's encoded
423 as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address).
424 Swallow the OP_LONG (including both its opcodes); ignore
425 its type; print the value in the type of the MEMVAL. */
427 val
= value_at_lazy (exp
->elts
[pc
+ 1].type
,
428 (CORE_ADDR
) exp
->elts
[pc
+ 5].longconst
);
429 get_raw_print_options (&opts
);
430 value_print (val
, stream
, &opts
);
434 fputs_filtered ("{", stream
);
435 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
436 fputs_filtered ("} ", stream
);
437 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
439 if ((int) prec
> (int) PREC_PREFIX
)
440 fputs_filtered (")", stream
);
443 case UNOP_MEMVAL_TLS
:
445 if ((int) prec
> (int) PREC_PREFIX
)
446 fputs_filtered ("(", stream
);
447 fputs_filtered ("{", stream
);
448 type_print (exp
->elts
[pc
+ 2].type
, "", stream
, 0);
449 fputs_filtered ("} ", stream
);
450 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
451 if ((int) prec
> (int) PREC_PREFIX
)
452 fputs_filtered (")", stream
);
455 case BINOP_ASSIGN_MODIFY
:
456 opcode
= exp
->elts
[pc
+ 1].opcode
;
458 myprec
= PREC_ASSIGN
;
462 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
463 if (op_print_tab
[tem
].opcode
== opcode
)
465 op_str
= op_print_tab
[tem
].string
;
468 if (op_print_tab
[tem
].opcode
!= opcode
)
469 /* Not found; don't try to keep going because we don't know how
470 to interpret further elements. */
471 error (_("Invalid expression"));
478 fputs_filtered ("this", stream
);
481 /* Objective-C ops */
485 fputs_filtered ("self", stream
); /* The ObjC equivalent of "this". */
490 case MULTI_SUBSCRIPT
:
492 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
493 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
494 fprintf_unfiltered (stream
, " [");
495 for (tem
= 0; tem
< nargs
; tem
++)
498 fprintf_unfiltered (stream
, ", ");
499 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
501 fprintf_unfiltered (stream
, "]");
506 fprintf_unfiltered (stream
, "VAL(");
507 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
508 fprintf_unfiltered (stream
, ",");
509 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
510 fprintf_unfiltered (stream
, ")");
515 error (_("print_subexp: Not implemented."));
521 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
522 if (op_print_tab
[tem
].opcode
== opcode
)
524 op_str
= op_print_tab
[tem
].string
;
525 myprec
= op_print_tab
[tem
].precedence
;
526 assoc
= op_print_tab
[tem
].right_assoc
;
529 if (op_print_tab
[tem
].opcode
!= opcode
)
530 /* Not found; don't try to keep going because we don't know how
531 to interpret further elements. For example, this happens
532 if opcode is OP_TYPE. */
533 error (_("Invalid expression"));
536 /* Note that PREC_BUILTIN will always emit parentheses. */
537 if ((int) myprec
< (int) prec
)
538 fputs_filtered ("(", stream
);
539 if ((int) opcode
> (int) BINOP_END
)
543 /* Unary postfix operator. */
544 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
545 fputs_filtered (op_str
, stream
);
549 /* Unary prefix operator. */
550 fputs_filtered (op_str
, stream
);
551 if (myprec
== PREC_BUILTIN_FUNCTION
)
552 fputs_filtered ("(", stream
);
553 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
554 if (myprec
== PREC_BUILTIN_FUNCTION
)
555 fputs_filtered (")", stream
);
560 /* Binary operator. */
561 /* Print left operand.
562 If operator is right-associative,
563 increment precedence for this operand. */
564 print_subexp (exp
, pos
, stream
,
565 (enum precedence
) ((int) myprec
+ assoc
));
566 /* Print the operator itself. */
568 fprintf_filtered (stream
, " %s= ", op_str
);
569 else if (op_str
[0] == ',')
570 fprintf_filtered (stream
, "%s ", op_str
);
572 fprintf_filtered (stream
, " %s ", op_str
);
573 /* Print right operand.
574 If operator is left-associative,
575 increment precedence for this operand. */
576 print_subexp (exp
, pos
, stream
,
577 (enum precedence
) ((int) myprec
+ !assoc
));
580 if ((int) myprec
< (int) prec
)
581 fputs_filtered (")", stream
);
584 /* Return the operator corresponding to opcode OP as
585 a string. NULL indicates that the opcode was not found in the
586 current language table. */
588 op_string (enum exp_opcode op
)
591 const struct op_print
*op_print_tab
;
593 op_print_tab
= current_language
->la_op_print_tab
;
594 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
595 if (op_print_tab
[tem
].opcode
== op
)
596 return op_print_tab
[tem
].string
;
600 /* Support for dumping the raw data from expressions in a human readable
603 static char *op_name (struct expression
*, enum exp_opcode
);
604 static int dump_subexp_body (struct expression
*exp
, struct ui_file
*, int);
606 /* Name for OPCODE, when it appears in expression EXP. */
609 op_name (struct expression
*exp
, enum exp_opcode opcode
)
611 return exp
->language_defn
->la_exp_desc
->op_name (opcode
);
614 /* Default name for the standard operator OPCODE (i.e., one defined in
615 the definition of enum exp_opcode). */
618 op_name_standard (enum exp_opcode opcode
)
626 sprintf (buf
, "<unknown %d>", opcode
);
647 case BINOP_LOGICAL_AND
:
648 return "BINOP_LOGICAL_AND";
649 case BINOP_LOGICAL_OR
:
650 return "BINOP_LOGICAL_OR";
651 case BINOP_BITWISE_AND
:
652 return "BINOP_BITWISE_AND";
653 case BINOP_BITWISE_IOR
:
654 return "BINOP_BITWISE_IOR";
655 case BINOP_BITWISE_XOR
:
656 return "BINOP_BITWISE_XOR";
658 return "BINOP_EQUAL";
660 return "BINOP_NOTEQUAL";
670 return "BINOP_REPEAT";
672 return "BINOP_ASSIGN";
674 return "BINOP_COMMA";
675 case BINOP_SUBSCRIPT
:
676 return "BINOP_SUBSCRIPT";
677 case MULTI_SUBSCRIPT
:
678 return "MULTI_SUBSCRIPT";
685 case STRUCTOP_MEMBER
:
686 return "STRUCTOP_MEMBER";
688 return "STRUCTOP_MPTR";
690 return "BINOP_INTDIV";
691 case BINOP_ASSIGN_MODIFY
:
692 return "BINOP_ASSIGN_MODIFY";
700 return "BINOP_CONCAT";
702 return "BINOP_RANGE";
706 return "TERNOP_COND";
708 return "TERNOP_SLICE";
709 case TERNOP_SLICE_COUNT
:
710 return "TERNOP_SLICE_COUNT";
716 return "OP_VAR_VALUE";
720 return "OP_REGISTER";
722 return "OP_INTERNALVAR";
728 return "OP_BITSTRING";
734 return "UNOP_MEMVAL";
735 case UNOP_MEMVAL_TLS
:
736 return "UNOP_MEMVAL_TLS";
739 case UNOP_LOGICAL_NOT
:
740 return "UNOP_LOGICAL_NOT";
741 case UNOP_COMPLEMENT
:
742 return "UNOP_COMPLEMENT";
747 case UNOP_PREINCREMENT
:
748 return "UNOP_PREINCREMENT";
749 case UNOP_POSTINCREMENT
:
750 return "UNOP_POSTINCREMENT";
751 case UNOP_PREDECREMENT
:
752 return "UNOP_PREDECREMENT";
753 case UNOP_POSTDECREMENT
:
754 return "UNOP_POSTDECREMENT";
756 return "UNOP_SIZEOF";
762 return "UNOP_LENGTH";
788 return "OP_M2_STRING";
789 case STRUCTOP_STRUCT
:
790 return "STRUCTOP_STRUCT";
792 return "STRUCTOP_PTR";
796 return "OP_OBJC_SELF";
806 /* Print a raw dump of expression EXP to STREAM.
807 NOTE, if non-NULL, is printed as extra explanatory text. */
810 dump_raw_expression (struct expression
*exp
, struct ui_file
*stream
,
818 fprintf_filtered (stream
, "Dump of expression @ ");
819 gdb_print_host_address (exp
, stream
);
821 fprintf_filtered (stream
, ", %s:", note
);
822 fprintf_filtered (stream
, "\n\tLanguage %s, %d elements, %ld bytes each.\n",
823 exp
->language_defn
->la_name
, exp
->nelts
,
824 (long) sizeof (union exp_element
));
825 fprintf_filtered (stream
, "\t%5s %20s %16s %s\n", "Index", "Opcode",
826 "Hex Value", "String Value");
827 for (elt
= 0; elt
< exp
->nelts
; elt
++)
829 fprintf_filtered (stream
, "\t%5d ", elt
);
830 opcode_name
= op_name (exp
, exp
->elts
[elt
].opcode
);
832 fprintf_filtered (stream
, "%20s ", opcode_name
);
833 print_longest (stream
, 'd', 0, exp
->elts
[elt
].longconst
);
834 fprintf_filtered (stream
, " ");
836 for (eltscan
= (char *) &exp
->elts
[elt
],
837 eltsize
= sizeof (union exp_element
);
841 fprintf_filtered (stream
, "%c",
842 isprint (*eltscan
) ? (*eltscan
& 0xFF) : '.');
844 fprintf_filtered (stream
, "\n");
848 /* Dump the subexpression of prefix expression EXP whose operator is at
849 position ELT onto STREAM. Returns the position of the next
850 subexpression in EXP. */
853 dump_subexp (struct expression
*exp
, struct ui_file
*stream
, int elt
)
855 static int indent
= 0;
858 fprintf_filtered (stream
, "\n");
859 fprintf_filtered (stream
, "\t%5d ", elt
);
861 for (i
= 1; i
<= indent
; i
++)
862 fprintf_filtered (stream
, " ");
865 fprintf_filtered (stream
, "%-20s ", op_name (exp
, exp
->elts
[elt
].opcode
));
867 elt
= dump_subexp_body (exp
, stream
, elt
);
874 /* Dump the operands of prefix expression EXP whose opcode is at
875 position ELT onto STREAM. Returns the position of the next
876 subexpression in EXP. */
879 dump_subexp_body (struct expression
*exp
, struct ui_file
*stream
, int elt
)
881 return exp
->language_defn
->la_exp_desc
->dump_subexp_body (exp
, stream
, elt
);
884 /* Default value for subexp_body in exp_descriptor vector. */
887 dump_subexp_body_standard (struct expression
*exp
,
888 struct ui_file
*stream
, int elt
)
890 int opcode
= exp
->elts
[elt
++].opcode
;
896 case TERNOP_SLICE_COUNT
:
897 elt
= dump_subexp (exp
, stream
, elt
);
906 case BINOP_LOGICAL_AND
:
907 case BINOP_LOGICAL_OR
:
908 case BINOP_BITWISE_AND
:
909 case BINOP_BITWISE_IOR
:
910 case BINOP_BITWISE_XOR
:
920 case BINOP_SUBSCRIPT
:
925 case BINOP_ASSIGN_MODIFY
:
933 case STRUCTOP_MEMBER
:
935 elt
= dump_subexp (exp
, stream
, elt
);
937 case UNOP_LOGICAL_NOT
:
938 case UNOP_COMPLEMENT
:
941 case UNOP_PREINCREMENT
:
942 case UNOP_POSTINCREMENT
:
943 case UNOP_PREDECREMENT
:
944 case UNOP_POSTDECREMENT
:
963 elt
= dump_subexp (exp
, stream
, elt
);
966 fprintf_filtered (stream
, "Type @");
967 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
968 fprintf_filtered (stream
, " (");
969 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
970 fprintf_filtered (stream
, "), value %ld (0x%lx)",
971 (long) exp
->elts
[elt
+ 1].longconst
,
972 (long) exp
->elts
[elt
+ 1].longconst
);
976 fprintf_filtered (stream
, "Type @");
977 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
978 fprintf_filtered (stream
, " (");
979 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
980 fprintf_filtered (stream
, "), value %g",
981 (double) exp
->elts
[elt
+ 1].doubleconst
);
985 fprintf_filtered (stream
, "Block @");
986 gdb_print_host_address (exp
->elts
[elt
].block
, stream
);
987 fprintf_filtered (stream
, ", symbol @");
988 gdb_print_host_address (exp
->elts
[elt
+ 1].symbol
, stream
);
989 fprintf_filtered (stream
, " (%s)",
990 SYMBOL_PRINT_NAME (exp
->elts
[elt
+ 1].symbol
));
994 fprintf_filtered (stream
, "History element %ld",
995 (long) exp
->elts
[elt
].longconst
);
999 fprintf_filtered (stream
, "Register $%s", &exp
->elts
[elt
+ 1].string
);
1000 elt
+= 3 + BYTES_TO_EXP_ELEM (exp
->elts
[elt
].longconst
+ 1);
1002 case OP_INTERNALVAR
:
1003 fprintf_filtered (stream
, "Internal var @");
1004 gdb_print_host_address (exp
->elts
[elt
].internalvar
, stream
);
1005 fprintf_filtered (stream
, " (%s)",
1006 internalvar_name (exp
->elts
[elt
].internalvar
));
1013 nargs
= longest_to_int (exp
->elts
[elt
].longconst
);
1015 fprintf_filtered (stream
, "Number of args: %d", nargs
);
1018 for (i
= 1; i
<= nargs
+ 1; i
++)
1019 elt
= dump_subexp (exp
, stream
, elt
);
1027 lower
= longest_to_int (exp
->elts
[elt
].longconst
);
1028 upper
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
1030 fprintf_filtered (stream
, "Bounds [%d:%d]", lower
, upper
);
1033 for (i
= 1; i
<= upper
- lower
+ 1; i
++)
1034 elt
= dump_subexp (exp
, stream
, elt
);
1039 fprintf_filtered (stream
, "Type @");
1040 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1041 fprintf_filtered (stream
, " (");
1042 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1043 fprintf_filtered (stream
, ")");
1044 elt
= dump_subexp (exp
, stream
, elt
+ 2);
1046 case UNOP_MEMVAL_TLS
:
1047 fprintf_filtered (stream
, "TLS type @");
1048 gdb_print_host_address (exp
->elts
[elt
+ 1].type
, stream
);
1049 fprintf_filtered (stream
, " (__thread /* \"%s\" */ ",
1050 (exp
->elts
[elt
].objfile
== NULL
? "(null)"
1051 : exp
->elts
[elt
].objfile
->name
));
1052 type_print (exp
->elts
[elt
+ 1].type
, NULL
, stream
, 0);
1053 fprintf_filtered (stream
, ")");
1054 elt
= dump_subexp (exp
, stream
, elt
+ 3);
1057 fprintf_filtered (stream
, "Type @");
1058 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1059 fprintf_filtered (stream
, " (");
1060 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1061 fprintf_filtered (stream
, ")");
1064 case STRUCTOP_STRUCT
:
1070 len
= longest_to_int (exp
->elts
[elt
].longconst
);
1071 elem_name
= &exp
->elts
[elt
+ 1].string
;
1073 fprintf_filtered (stream
, "Element name: `%.*s'", len
, elem_name
);
1074 elt
= dump_subexp (exp
, stream
, elt
+ 3 + BYTES_TO_EXP_ELEM (len
+ 1));
1082 fprintf_filtered (stream
, "Type @");
1083 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1084 fprintf_filtered (stream
, " (");
1085 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1086 fprintf_filtered (stream
, ") ");
1088 len
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
1089 elem_name
= &exp
->elts
[elt
+ 2].string
;
1091 fprintf_filtered (stream
, "Field name: `%.*s'", len
, elem_name
);
1092 elt
+= 4 + BYTES_TO_EXP_ELEM (len
+ 1);
1097 case MULTI_SUBSCRIPT
:
1098 case OP_F77_UNDETERMINED_ARGLIST
:
1107 fprintf_filtered (stream
, "Unknown format");
1114 dump_prefix_expression (struct expression
*exp
, struct ui_file
*stream
)
1118 fprintf_filtered (stream
, "Dump of expression @ ");
1119 gdb_print_host_address (exp
, stream
);
1120 fputs_filtered (", after conversion to prefix form:\nExpression: `", stream
);
1121 if (exp
->elts
[0].opcode
!= OP_TYPE
)
1122 print_expression (exp
, stream
);
1124 fputs_filtered ("Type printing not yet supported....", stream
);
1125 fprintf_filtered (stream
, "'\n\tLanguage %s, %d elements, %ld bytes each.\n",
1126 exp
->language_defn
->la_name
, exp
->nelts
,
1127 (long) sizeof (union exp_element
));
1128 fputs_filtered ("\n", stream
);
1130 for (elt
= 0; elt
< exp
->nelts
;)
1131 elt
= dump_subexp (exp
, stream
, elt
);
1132 fputs_filtered ("\n", stream
);