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 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "expression.h"
27 #include "parser-defs.h"
28 #include "user-regs.h" /* For user_reg_map_regnum_to_name. */
30 #include "gdb_string.h"
33 #include "gdb_assert.h"
41 print_expression (struct expression
*exp
, struct ui_file
*stream
)
44 print_subexp (exp
, &pc
, stream
, PREC_NULL
);
47 /* Print the subexpression of EXP that starts in position POS, on STREAM.
48 PREC is the precedence of the surrounding operator;
49 if the precedence of the main operator of this subexpression is less,
50 parentheses are needed here. */
53 print_subexp (struct expression
*exp
, int *pos
,
54 struct ui_file
*stream
, enum precedence prec
)
56 exp
->language_defn
->la_exp_desc
->print_subexp (exp
, pos
, stream
, prec
);
59 /* Standard implementation of print_subexp for use in language_defn
62 print_subexp_standard (struct expression
*exp
, int *pos
,
63 struct ui_file
*stream
, enum precedence prec
)
66 const struct op_print
*op_print_tab
;
70 int assign_modify
= 0;
71 enum exp_opcode opcode
;
72 enum precedence myprec
= PREC_NULL
;
73 /* Set to 1 for a right-associative operator. */
78 op_print_tab
= exp
->language_defn
->la_op_print_tab
;
80 opcode
= exp
->elts
[pc
].opcode
;
88 fputs_filtered (type_name_no_tag (exp
->elts
[pc
+ 1].type
), stream
);
89 fputs_filtered ("::", stream
);
90 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
91 (*pos
) += 4 + BYTES_TO_EXP_ELEM (nargs
+ 1);
92 fputs_filtered (&exp
->elts
[pc
+ 3].string
, stream
);
97 struct value_print_options opts
;
98 get_raw_print_options (&opts
);
100 value_print (value_from_longest (exp
->elts
[pc
+ 1].type
,
101 exp
->elts
[pc
+ 2].longconst
),
108 struct value_print_options opts
;
109 get_raw_print_options (&opts
);
111 value_print (value_from_double (exp
->elts
[pc
+ 1].type
,
112 exp
->elts
[pc
+ 2].doubleconst
),
121 b
= exp
->elts
[pc
+ 1].block
;
123 && BLOCK_FUNCTION (b
) != NULL
124 && SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b
)) != NULL
)
126 fputs_filtered (SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b
)), stream
);
127 fputs_filtered ("::", stream
);
129 fputs_filtered (SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 2].symbol
), stream
);
135 fprintf_filtered (stream
, "$%d",
136 longest_to_int (exp
->elts
[pc
+ 1].longconst
));
141 const char *name
= &exp
->elts
[pc
+ 2].string
;
142 (*pos
) += 3 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
143 fprintf_filtered (stream
, "$%s", name
);
149 fprintf_filtered (stream
, "%s",
150 longest_to_int (exp
->elts
[pc
+ 1].longconst
)
156 fprintf_filtered (stream
, "$%s",
157 internalvar_name (exp
->elts
[pc
+ 1].internalvar
));
162 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
163 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
164 fputs_filtered (" (", stream
);
165 for (tem
= 0; tem
< nargs
; tem
++)
168 fputs_filtered (", ", stream
);
169 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
171 fputs_filtered (")", stream
);
175 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
176 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
177 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
182 struct value_print_options opts
;
183 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
184 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
185 /* LA_PRINT_STRING will print using the current repeat count threshold.
186 If necessary, we can temporarily set it to zero, or pass it as an
187 additional parameter to LA_PRINT_STRING. -fnf */
188 get_user_print_options (&opts
);
189 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
190 &exp
->elts
[pc
+ 2].string
, nargs
, 0, &opts
);
195 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
197 += 3 + BYTES_TO_EXP_ELEM ((nargs
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
);
198 fprintf_unfiltered (stream
, "B'<unimplemented>'");
201 case OP_OBJC_NSSTRING
: /* Objective-C Foundation Class NSString constant. */
203 struct value_print_options opts
;
204 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
205 (*pos
) += 3 + BYTES_TO_EXP_ELEM (nargs
+ 1);
206 fputs_filtered ("@\"", stream
);
207 get_user_print_options (&opts
);
208 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
209 &exp
->elts
[pc
+ 2].string
, nargs
, 0, &opts
);
210 fputs_filtered ("\"", stream
);
214 case OP_OBJC_MSGCALL
:
215 { /* Objective C message (method) call. */
218 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
219 fprintf_unfiltered (stream
, "[");
220 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
221 if (0 == target_read_string (exp
->elts
[pc
+ 1].longconst
,
222 &selector
, 1024, NULL
))
224 error (_("bad selector"));
230 s
= alloca (strlen (selector
) + 1);
231 strcpy (s
, selector
);
232 for (tem
= 0; tem
< nargs
; tem
++)
234 nextS
= strchr (s
, ':');
235 gdb_assert (nextS
); /* Make sure we found ':'. */
237 fprintf_unfiltered (stream
, " %s: ", s
);
239 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
244 fprintf_unfiltered (stream
, " %s", selector
);
246 fprintf_unfiltered (stream
, "]");
247 /* "selector" was malloc'd by target_read_string. Free it. */
254 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
255 nargs
-= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
258 if (exp
->elts
[pc
+ 4].opcode
== OP_LONG
259 && exp
->elts
[pc
+ 5].type
260 == builtin_type (exp
->gdbarch
)->builtin_char
261 && exp
->language_defn
->la_language
== language_c
)
263 /* Attempt to print C character arrays using string syntax.
264 Walk through the args, picking up one character from each
265 of the OP_LONG expression elements. If any array element
266 does not match our expection of what we should find for
267 a simple string, revert back to array printing. Note that
268 the last expression element is an explicit null terminator
269 byte, which doesn't get printed. */
270 tempstr
= alloca (nargs
);
274 if (exp
->elts
[pc
].opcode
!= OP_LONG
275 || exp
->elts
[pc
+ 1].type
276 != builtin_type (exp
->gdbarch
)->builtin_char
)
278 /* Not a simple array of char, use regular array printing. */
285 longest_to_int (exp
->elts
[pc
+ 2].longconst
);
292 struct value_print_options opts
;
293 get_user_print_options (&opts
);
294 LA_PRINT_STRING (stream
, builtin_type (exp
->gdbarch
)->builtin_char
,
295 tempstr
, nargs
- 1, 0, &opts
);
300 fputs_filtered (" {", stream
);
301 for (tem
= 0; tem
< nargs
; tem
++)
305 fputs_filtered (", ", stream
);
307 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
309 fputs_filtered ("}", stream
);
314 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
315 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
316 /* Gcc support both these syntaxes. Unsure which is preferred. */
318 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
319 fputs_filtered (": ", stream
);
321 fputs_filtered (".", stream
);
322 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
323 fputs_filtered ("=", stream
);
325 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
329 if ((int) prec
> (int) PREC_COMMA
)
330 fputs_filtered ("(", stream
);
331 /* Print the subexpressions, forcing parentheses
332 around any binary operations within them.
333 This is more parentheses than are strictly necessary,
334 but it looks clearer. */
335 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
336 fputs_filtered (" ? ", stream
);
337 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
338 fputs_filtered (" : ", stream
);
339 print_subexp (exp
, pos
, stream
, PREC_HYPER
);
340 if ((int) prec
> (int) PREC_COMMA
)
341 fputs_filtered (")", stream
);
345 case TERNOP_SLICE_COUNT
:
346 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
347 fputs_filtered ("(", stream
);
348 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
349 fputs_filtered (opcode
== TERNOP_SLICE
? " : " : " UP ", stream
);
350 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
351 fputs_filtered (")", stream
);
354 case STRUCTOP_STRUCT
:
355 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
356 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
357 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
358 fputs_filtered (".", stream
);
359 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
362 /* Will not occur for Modula-2 */
364 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
365 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
366 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
367 fputs_filtered ("->", stream
);
368 fputs_filtered (&exp
->elts
[pc
+ 2].string
, stream
);
371 case STRUCTOP_MEMBER
:
372 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
373 fputs_filtered (".*", stream
);
374 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
378 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
379 fputs_filtered ("->*", stream
);
380 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
383 case BINOP_SUBSCRIPT
:
384 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
385 fputs_filtered ("[", stream
);
386 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
387 fputs_filtered ("]", stream
);
390 case UNOP_POSTINCREMENT
:
391 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
392 fputs_filtered ("++", stream
);
395 case UNOP_POSTDECREMENT
:
396 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
397 fputs_filtered ("--", stream
);
402 if ((int) prec
> (int) PREC_PREFIX
)
403 fputs_filtered ("(", stream
);
404 fputs_filtered ("(", stream
);
405 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
406 fputs_filtered (") ", stream
);
407 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
408 if ((int) prec
> (int) PREC_PREFIX
)
409 fputs_filtered (")", stream
);
414 if ((int) prec
> (int) PREC_PREFIX
)
415 fputs_filtered ("(", stream
);
416 if (TYPE_CODE (exp
->elts
[pc
+ 1].type
) == TYPE_CODE_FUNC
417 && exp
->elts
[pc
+ 3].opcode
== OP_LONG
)
419 struct value_print_options opts
;
421 /* We have a minimal symbol fn, probably. It's encoded
422 as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address).
423 Swallow the OP_LONG (including both its opcodes); ignore
424 its type; print the value in the type of the MEMVAL. */
426 val
= value_at_lazy (exp
->elts
[pc
+ 1].type
,
427 (CORE_ADDR
) exp
->elts
[pc
+ 5].longconst
);
428 get_raw_print_options (&opts
);
429 value_print (val
, stream
, &opts
);
433 fputs_filtered ("{", stream
);
434 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
435 fputs_filtered ("} ", stream
);
436 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
438 if ((int) prec
> (int) PREC_PREFIX
)
439 fputs_filtered (")", stream
);
442 case UNOP_MEMVAL_TLS
:
444 if ((int) prec
> (int) PREC_PREFIX
)
445 fputs_filtered ("(", stream
);
446 fputs_filtered ("{", stream
);
447 type_print (exp
->elts
[pc
+ 2].type
, "", stream
, 0);
448 fputs_filtered ("} ", stream
);
449 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
450 if ((int) prec
> (int) PREC_PREFIX
)
451 fputs_filtered (")", stream
);
454 case BINOP_ASSIGN_MODIFY
:
455 opcode
= exp
->elts
[pc
+ 1].opcode
;
457 myprec
= PREC_ASSIGN
;
461 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
462 if (op_print_tab
[tem
].opcode
== opcode
)
464 op_str
= op_print_tab
[tem
].string
;
467 if (op_print_tab
[tem
].opcode
!= opcode
)
468 /* Not found; don't try to keep going because we don't know how
469 to interpret further elements. */
470 error (_("Invalid expression"));
477 fputs_filtered ("this", stream
);
480 /* Objective-C ops */
484 fputs_filtered ("self", stream
); /* The ObjC equivalent of "this". */
489 case MULTI_SUBSCRIPT
:
491 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
492 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
493 fprintf_unfiltered (stream
, " [");
494 for (tem
= 0; tem
< nargs
; tem
++)
497 fprintf_unfiltered (stream
, ", ");
498 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
500 fprintf_unfiltered (stream
, "]");
505 fprintf_unfiltered (stream
, "VAL(");
506 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
507 fprintf_unfiltered (stream
, ",");
508 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
509 fprintf_unfiltered (stream
, ")");
514 error (_("print_subexp: Not implemented."));
520 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
521 if (op_print_tab
[tem
].opcode
== opcode
)
523 op_str
= op_print_tab
[tem
].string
;
524 myprec
= op_print_tab
[tem
].precedence
;
525 assoc
= op_print_tab
[tem
].right_assoc
;
528 if (op_print_tab
[tem
].opcode
!= opcode
)
529 /* Not found; don't try to keep going because we don't know how
530 to interpret further elements. For example, this happens
531 if opcode is OP_TYPE. */
532 error (_("Invalid expression"));
535 /* Note that PREC_BUILTIN will always emit parentheses. */
536 if ((int) myprec
< (int) prec
)
537 fputs_filtered ("(", stream
);
538 if ((int) opcode
> (int) BINOP_END
)
542 /* Unary postfix operator. */
543 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
544 fputs_filtered (op_str
, stream
);
548 /* Unary prefix operator. */
549 fputs_filtered (op_str
, stream
);
550 if (myprec
== PREC_BUILTIN_FUNCTION
)
551 fputs_filtered ("(", stream
);
552 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
553 if (myprec
== PREC_BUILTIN_FUNCTION
)
554 fputs_filtered (")", stream
);
559 /* Binary operator. */
560 /* Print left operand.
561 If operator is right-associative,
562 increment precedence for this operand. */
563 print_subexp (exp
, pos
, stream
,
564 (enum precedence
) ((int) myprec
+ assoc
));
565 /* Print the operator itself. */
567 fprintf_filtered (stream
, " %s= ", op_str
);
568 else if (op_str
[0] == ',')
569 fprintf_filtered (stream
, "%s ", op_str
);
571 fprintf_filtered (stream
, " %s ", op_str
);
572 /* Print right operand.
573 If operator is left-associative,
574 increment precedence for this operand. */
575 print_subexp (exp
, pos
, stream
,
576 (enum precedence
) ((int) myprec
+ !assoc
));
579 if ((int) myprec
< (int) prec
)
580 fputs_filtered (")", stream
);
583 /* Return the operator corresponding to opcode OP as
584 a string. NULL indicates that the opcode was not found in the
585 current language table. */
587 op_string (enum exp_opcode op
)
590 const struct op_print
*op_print_tab
;
592 op_print_tab
= current_language
->la_op_print_tab
;
593 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
594 if (op_print_tab
[tem
].opcode
== op
)
595 return op_print_tab
[tem
].string
;
599 /* Support for dumping the raw data from expressions in a human readable
602 static char *op_name (struct expression
*, enum exp_opcode
);
603 static int dump_subexp_body (struct expression
*exp
, struct ui_file
*, int);
605 /* Name for OPCODE, when it appears in expression EXP. */
608 op_name (struct expression
*exp
, enum exp_opcode opcode
)
610 return exp
->language_defn
->la_exp_desc
->op_name (opcode
);
613 /* Default name for the standard operator OPCODE (i.e., one defined in
614 the definition of enum exp_opcode). */
617 op_name_standard (enum exp_opcode opcode
)
625 sprintf (buf
, "<unknown %d>", opcode
);
646 case BINOP_LOGICAL_AND
:
647 return "BINOP_LOGICAL_AND";
648 case BINOP_LOGICAL_OR
:
649 return "BINOP_LOGICAL_OR";
650 case BINOP_BITWISE_AND
:
651 return "BINOP_BITWISE_AND";
652 case BINOP_BITWISE_IOR
:
653 return "BINOP_BITWISE_IOR";
654 case BINOP_BITWISE_XOR
:
655 return "BINOP_BITWISE_XOR";
657 return "BINOP_EQUAL";
659 return "BINOP_NOTEQUAL";
669 return "BINOP_REPEAT";
671 return "BINOP_ASSIGN";
673 return "BINOP_COMMA";
674 case BINOP_SUBSCRIPT
:
675 return "BINOP_SUBSCRIPT";
676 case MULTI_SUBSCRIPT
:
677 return "MULTI_SUBSCRIPT";
684 case STRUCTOP_MEMBER
:
685 return "STRUCTOP_MEMBER";
687 return "STRUCTOP_MPTR";
689 return "BINOP_INTDIV";
690 case BINOP_ASSIGN_MODIFY
:
691 return "BINOP_ASSIGN_MODIFY";
699 return "BINOP_CONCAT";
701 return "BINOP_RANGE";
705 return "TERNOP_COND";
707 return "TERNOP_SLICE";
708 case TERNOP_SLICE_COUNT
:
709 return "TERNOP_SLICE_COUNT";
715 return "OP_VAR_VALUE";
719 return "OP_REGISTER";
721 return "OP_INTERNALVAR";
727 return "OP_BITSTRING";
733 return "UNOP_MEMVAL";
734 case UNOP_MEMVAL_TLS
:
735 return "UNOP_MEMVAL_TLS";
738 case UNOP_LOGICAL_NOT
:
739 return "UNOP_LOGICAL_NOT";
740 case UNOP_COMPLEMENT
:
741 return "UNOP_COMPLEMENT";
746 case UNOP_PREINCREMENT
:
747 return "UNOP_PREINCREMENT";
748 case UNOP_POSTINCREMENT
:
749 return "UNOP_POSTINCREMENT";
750 case UNOP_PREDECREMENT
:
751 return "UNOP_PREDECREMENT";
752 case UNOP_POSTDECREMENT
:
753 return "UNOP_POSTDECREMENT";
755 return "UNOP_SIZEOF";
761 return "UNOP_LENGTH";
787 return "OP_M2_STRING";
788 case STRUCTOP_STRUCT
:
789 return "STRUCTOP_STRUCT";
791 return "STRUCTOP_PTR";
795 return "OP_OBJC_SELF";
805 /* Print a raw dump of expression EXP to STREAM.
806 NOTE, if non-NULL, is printed as extra explanatory text. */
809 dump_raw_expression (struct expression
*exp
, struct ui_file
*stream
,
817 fprintf_filtered (stream
, "Dump of expression @ ");
818 gdb_print_host_address (exp
, stream
);
820 fprintf_filtered (stream
, ", %s:", note
);
821 fprintf_filtered (stream
, "\n\tLanguage %s, %d elements, %ld bytes each.\n",
822 exp
->language_defn
->la_name
, exp
->nelts
,
823 (long) sizeof (union exp_element
));
824 fprintf_filtered (stream
, "\t%5s %20s %16s %s\n", "Index", "Opcode",
825 "Hex Value", "String Value");
826 for (elt
= 0; elt
< exp
->nelts
; elt
++)
828 fprintf_filtered (stream
, "\t%5d ", elt
);
829 opcode_name
= op_name (exp
, exp
->elts
[elt
].opcode
);
831 fprintf_filtered (stream
, "%20s ", opcode_name
);
832 print_longest (stream
, 'd', 0, exp
->elts
[elt
].longconst
);
833 fprintf_filtered (stream
, " ");
835 for (eltscan
= (char *) &exp
->elts
[elt
],
836 eltsize
= sizeof (union exp_element
);
840 fprintf_filtered (stream
, "%c",
841 isprint (*eltscan
) ? (*eltscan
& 0xFF) : '.');
843 fprintf_filtered (stream
, "\n");
847 /* Dump the subexpression of prefix expression EXP whose operator is at
848 position ELT onto STREAM. Returns the position of the next
849 subexpression in EXP. */
852 dump_subexp (struct expression
*exp
, struct ui_file
*stream
, int elt
)
854 static int indent
= 0;
857 fprintf_filtered (stream
, "\n");
858 fprintf_filtered (stream
, "\t%5d ", elt
);
860 for (i
= 1; i
<= indent
; i
++)
861 fprintf_filtered (stream
, " ");
864 fprintf_filtered (stream
, "%-20s ", op_name (exp
, exp
->elts
[elt
].opcode
));
866 elt
= dump_subexp_body (exp
, stream
, elt
);
873 /* Dump the operands of prefix expression EXP whose opcode is at
874 position ELT onto STREAM. Returns the position of the next
875 subexpression in EXP. */
878 dump_subexp_body (struct expression
*exp
, struct ui_file
*stream
, int elt
)
880 return exp
->language_defn
->la_exp_desc
->dump_subexp_body (exp
, stream
, elt
);
883 /* Default value for subexp_body in exp_descriptor vector. */
886 dump_subexp_body_standard (struct expression
*exp
,
887 struct ui_file
*stream
, int elt
)
889 int opcode
= exp
->elts
[elt
++].opcode
;
895 case TERNOP_SLICE_COUNT
:
896 elt
= dump_subexp (exp
, stream
, elt
);
905 case BINOP_LOGICAL_AND
:
906 case BINOP_LOGICAL_OR
:
907 case BINOP_BITWISE_AND
:
908 case BINOP_BITWISE_IOR
:
909 case BINOP_BITWISE_XOR
:
919 case BINOP_SUBSCRIPT
:
924 case BINOP_ASSIGN_MODIFY
:
932 case STRUCTOP_MEMBER
:
934 elt
= dump_subexp (exp
, stream
, elt
);
936 case UNOP_LOGICAL_NOT
:
937 case UNOP_COMPLEMENT
:
940 case UNOP_PREINCREMENT
:
941 case UNOP_POSTINCREMENT
:
942 case UNOP_PREDECREMENT
:
943 case UNOP_POSTDECREMENT
:
962 elt
= dump_subexp (exp
, stream
, elt
);
965 fprintf_filtered (stream
, "Type @");
966 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
967 fprintf_filtered (stream
, " (");
968 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
969 fprintf_filtered (stream
, "), value %ld (0x%lx)",
970 (long) exp
->elts
[elt
+ 1].longconst
,
971 (long) exp
->elts
[elt
+ 1].longconst
);
975 fprintf_filtered (stream
, "Type @");
976 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
977 fprintf_filtered (stream
, " (");
978 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
979 fprintf_filtered (stream
, "), value %g",
980 (double) exp
->elts
[elt
+ 1].doubleconst
);
984 fprintf_filtered (stream
, "Block @");
985 gdb_print_host_address (exp
->elts
[elt
].block
, stream
);
986 fprintf_filtered (stream
, ", symbol @");
987 gdb_print_host_address (exp
->elts
[elt
+ 1].symbol
, stream
);
988 fprintf_filtered (stream
, " (%s)",
989 SYMBOL_PRINT_NAME (exp
->elts
[elt
+ 1].symbol
));
993 fprintf_filtered (stream
, "History element %ld",
994 (long) exp
->elts
[elt
].longconst
);
998 fprintf_filtered (stream
, "Register $%s", &exp
->elts
[elt
+ 1].string
);
999 elt
+= 3 + BYTES_TO_EXP_ELEM (exp
->elts
[elt
].longconst
+ 1);
1001 case OP_INTERNALVAR
:
1002 fprintf_filtered (stream
, "Internal var @");
1003 gdb_print_host_address (exp
->elts
[elt
].internalvar
, stream
);
1004 fprintf_filtered (stream
, " (%s)",
1005 internalvar_name (exp
->elts
[elt
].internalvar
));
1012 nargs
= longest_to_int (exp
->elts
[elt
].longconst
);
1014 fprintf_filtered (stream
, "Number of args: %d", nargs
);
1017 for (i
= 1; i
<= nargs
+ 1; i
++)
1018 elt
= dump_subexp (exp
, stream
, elt
);
1026 lower
= longest_to_int (exp
->elts
[elt
].longconst
);
1027 upper
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
1029 fprintf_filtered (stream
, "Bounds [%d:%d]", lower
, upper
);
1032 for (i
= 1; i
<= upper
- lower
+ 1; i
++)
1033 elt
= dump_subexp (exp
, stream
, elt
);
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
, ")");
1043 elt
= dump_subexp (exp
, stream
, elt
+ 2);
1045 case UNOP_MEMVAL_TLS
:
1046 fprintf_filtered (stream
, "TLS type @");
1047 gdb_print_host_address (exp
->elts
[elt
+ 1].type
, stream
);
1048 fprintf_filtered (stream
, " (__thread /* \"%s\" */ ",
1049 (exp
->elts
[elt
].objfile
== NULL
? "(null)"
1050 : exp
->elts
[elt
].objfile
->name
));
1051 type_print (exp
->elts
[elt
+ 1].type
, NULL
, stream
, 0);
1052 fprintf_filtered (stream
, ")");
1053 elt
= dump_subexp (exp
, stream
, elt
+ 3);
1056 fprintf_filtered (stream
, "Type @");
1057 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1058 fprintf_filtered (stream
, " (");
1059 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1060 fprintf_filtered (stream
, ")");
1063 case STRUCTOP_STRUCT
:
1069 len
= longest_to_int (exp
->elts
[elt
].longconst
);
1070 elem_name
= &exp
->elts
[elt
+ 1].string
;
1072 fprintf_filtered (stream
, "Element name: `%.*s'", len
, elem_name
);
1073 elt
= dump_subexp (exp
, stream
, elt
+ 3 + BYTES_TO_EXP_ELEM (len
+ 1));
1081 fprintf_filtered (stream
, "Type @");
1082 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1083 fprintf_filtered (stream
, " (");
1084 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1085 fprintf_filtered (stream
, ") ");
1087 len
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
1088 elem_name
= &exp
->elts
[elt
+ 2].string
;
1090 fprintf_filtered (stream
, "Field name: `%.*s'", len
, elem_name
);
1091 elt
+= 4 + BYTES_TO_EXP_ELEM (len
+ 1);
1096 case MULTI_SUBSCRIPT
:
1097 case OP_F77_UNDETERMINED_ARGLIST
:
1106 fprintf_filtered (stream
, "Unknown format");
1113 dump_prefix_expression (struct expression
*exp
, struct ui_file
*stream
)
1117 fprintf_filtered (stream
, "Dump of expression @ ");
1118 gdb_print_host_address (exp
, stream
);
1119 fputs_filtered (", after conversion to prefix form:\nExpression: `", stream
);
1120 if (exp
->elts
[0].opcode
!= OP_TYPE
)
1121 print_expression (exp
, stream
);
1123 fputs_filtered ("Type printing not yet supported....", stream
);
1124 fprintf_filtered (stream
, "'\n\tLanguage %s, %d elements, %ld bytes each.\n",
1125 exp
->language_defn
->la_name
, exp
->nelts
,
1126 (long) sizeof (union exp_element
));
1127 fputs_filtered ("\n", stream
);
1129 for (elt
= 0; elt
< exp
->nelts
;)
1130 elt
= dump_subexp (exp
, stream
, elt
);
1131 fputs_filtered ("\n", stream
);