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
);
413 case UNOP_DYNAMIC_CAST
:
414 case UNOP_REINTERPRET_CAST
:
415 fputs_filtered (opcode
== UNOP_DYNAMIC_CAST
? "dynamic_cast"
416 : "reinterpret_cast", stream
);
417 fputs_filtered ("<", stream
);
419 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
420 fputs_filtered ("> (", stream
);
421 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
422 fputs_filtered (")", stream
);
427 if ((int) prec
> (int) PREC_PREFIX
)
428 fputs_filtered ("(", stream
);
429 if (TYPE_CODE (exp
->elts
[pc
+ 1].type
) == TYPE_CODE_FUNC
430 && exp
->elts
[pc
+ 3].opcode
== OP_LONG
)
432 struct value_print_options opts
;
434 /* We have a minimal symbol fn, probably. It's encoded
435 as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address).
436 Swallow the OP_LONG (including both its opcodes); ignore
437 its type; print the value in the type of the MEMVAL. */
439 val
= value_at_lazy (exp
->elts
[pc
+ 1].type
,
440 (CORE_ADDR
) exp
->elts
[pc
+ 5].longconst
);
441 get_raw_print_options (&opts
);
442 value_print (val
, stream
, &opts
);
446 fputs_filtered ("{", stream
);
447 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
448 fputs_filtered ("} ", stream
);
449 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
451 if ((int) prec
> (int) PREC_PREFIX
)
452 fputs_filtered (")", stream
);
455 case UNOP_MEMVAL_TLS
:
457 if ((int) prec
> (int) PREC_PREFIX
)
458 fputs_filtered ("(", stream
);
459 fputs_filtered ("{", stream
);
460 type_print (exp
->elts
[pc
+ 2].type
, "", stream
, 0);
461 fputs_filtered ("} ", stream
);
462 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
463 if ((int) prec
> (int) PREC_PREFIX
)
464 fputs_filtered (")", stream
);
467 case BINOP_ASSIGN_MODIFY
:
468 opcode
= exp
->elts
[pc
+ 1].opcode
;
470 myprec
= PREC_ASSIGN
;
474 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
475 if (op_print_tab
[tem
].opcode
== opcode
)
477 op_str
= op_print_tab
[tem
].string
;
480 if (op_print_tab
[tem
].opcode
!= opcode
)
481 /* Not found; don't try to keep going because we don't know how
482 to interpret further elements. */
483 error (_("Invalid expression"));
490 fputs_filtered ("this", stream
);
493 /* Objective-C ops */
497 fputs_filtered ("self", stream
); /* The ObjC equivalent of "this". */
502 case MULTI_SUBSCRIPT
:
504 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
505 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
506 fprintf_unfiltered (stream
, " [");
507 for (tem
= 0; tem
< nargs
; tem
++)
510 fprintf_unfiltered (stream
, ", ");
511 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
513 fprintf_unfiltered (stream
, "]");
518 fprintf_unfiltered (stream
, "VAL(");
519 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
520 fprintf_unfiltered (stream
, ",");
521 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
522 fprintf_unfiltered (stream
, ")");
527 error (_("print_subexp: Not implemented."));
533 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
534 if (op_print_tab
[tem
].opcode
== opcode
)
536 op_str
= op_print_tab
[tem
].string
;
537 myprec
= op_print_tab
[tem
].precedence
;
538 assoc
= op_print_tab
[tem
].right_assoc
;
541 if (op_print_tab
[tem
].opcode
!= opcode
)
542 /* Not found; don't try to keep going because we don't know how
543 to interpret further elements. For example, this happens
544 if opcode is OP_TYPE. */
545 error (_("Invalid expression"));
548 /* Note that PREC_BUILTIN will always emit parentheses. */
549 if ((int) myprec
< (int) prec
)
550 fputs_filtered ("(", stream
);
551 if ((int) opcode
> (int) BINOP_END
)
555 /* Unary postfix operator. */
556 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
557 fputs_filtered (op_str
, stream
);
561 /* Unary prefix operator. */
562 fputs_filtered (op_str
, stream
);
563 if (myprec
== PREC_BUILTIN_FUNCTION
)
564 fputs_filtered ("(", stream
);
565 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
566 if (myprec
== PREC_BUILTIN_FUNCTION
)
567 fputs_filtered (")", stream
);
572 /* Binary operator. */
573 /* Print left operand.
574 If operator is right-associative,
575 increment precedence for this operand. */
576 print_subexp (exp
, pos
, stream
,
577 (enum precedence
) ((int) myprec
+ assoc
));
578 /* Print the operator itself. */
580 fprintf_filtered (stream
, " %s= ", op_str
);
581 else if (op_str
[0] == ',')
582 fprintf_filtered (stream
, "%s ", op_str
);
584 fprintf_filtered (stream
, " %s ", op_str
);
585 /* Print right operand.
586 If operator is left-associative,
587 increment precedence for this operand. */
588 print_subexp (exp
, pos
, stream
,
589 (enum precedence
) ((int) myprec
+ !assoc
));
592 if ((int) myprec
< (int) prec
)
593 fputs_filtered (")", stream
);
596 /* Return the operator corresponding to opcode OP as
597 a string. NULL indicates that the opcode was not found in the
598 current language table. */
600 op_string (enum exp_opcode op
)
603 const struct op_print
*op_print_tab
;
605 op_print_tab
= current_language
->la_op_print_tab
;
606 for (tem
= 0; op_print_tab
[tem
].opcode
!= OP_NULL
; tem
++)
607 if (op_print_tab
[tem
].opcode
== op
)
608 return op_print_tab
[tem
].string
;
612 /* Support for dumping the raw data from expressions in a human readable
615 static char *op_name (struct expression
*, enum exp_opcode
);
616 static int dump_subexp_body (struct expression
*exp
, struct ui_file
*, int);
618 /* Name for OPCODE, when it appears in expression EXP. */
621 op_name (struct expression
*exp
, enum exp_opcode opcode
)
623 return exp
->language_defn
->la_exp_desc
->op_name (opcode
);
626 /* Default name for the standard operator OPCODE (i.e., one defined in
627 the definition of enum exp_opcode). */
630 op_name_standard (enum exp_opcode opcode
)
638 sprintf (buf
, "<unknown %d>", opcode
);
659 case BINOP_LOGICAL_AND
:
660 return "BINOP_LOGICAL_AND";
661 case BINOP_LOGICAL_OR
:
662 return "BINOP_LOGICAL_OR";
663 case BINOP_BITWISE_AND
:
664 return "BINOP_BITWISE_AND";
665 case BINOP_BITWISE_IOR
:
666 return "BINOP_BITWISE_IOR";
667 case BINOP_BITWISE_XOR
:
668 return "BINOP_BITWISE_XOR";
670 return "BINOP_EQUAL";
672 return "BINOP_NOTEQUAL";
682 return "BINOP_REPEAT";
684 return "BINOP_ASSIGN";
686 return "BINOP_COMMA";
687 case BINOP_SUBSCRIPT
:
688 return "BINOP_SUBSCRIPT";
689 case MULTI_SUBSCRIPT
:
690 return "MULTI_SUBSCRIPT";
697 case STRUCTOP_MEMBER
:
698 return "STRUCTOP_MEMBER";
700 return "STRUCTOP_MPTR";
702 return "BINOP_INTDIV";
703 case BINOP_ASSIGN_MODIFY
:
704 return "BINOP_ASSIGN_MODIFY";
712 return "BINOP_CONCAT";
714 return "BINOP_RANGE";
718 return "TERNOP_COND";
720 return "TERNOP_SLICE";
721 case TERNOP_SLICE_COUNT
:
722 return "TERNOP_SLICE_COUNT";
728 return "OP_VAR_VALUE";
732 return "OP_REGISTER";
734 return "OP_INTERNALVAR";
740 return "OP_BITSTRING";
745 case UNOP_DYNAMIC_CAST
:
746 return "UNOP_DYNAMIC_CAST";
747 case UNOP_REINTERPRET_CAST
:
748 return "UNOP_REINTERPRET_CAST";
750 return "UNOP_MEMVAL";
751 case UNOP_MEMVAL_TLS
:
752 return "UNOP_MEMVAL_TLS";
755 case UNOP_LOGICAL_NOT
:
756 return "UNOP_LOGICAL_NOT";
757 case UNOP_COMPLEMENT
:
758 return "UNOP_COMPLEMENT";
763 case UNOP_PREINCREMENT
:
764 return "UNOP_PREINCREMENT";
765 case UNOP_POSTINCREMENT
:
766 return "UNOP_POSTINCREMENT";
767 case UNOP_PREDECREMENT
:
768 return "UNOP_PREDECREMENT";
769 case UNOP_POSTDECREMENT
:
770 return "UNOP_POSTDECREMENT";
772 return "UNOP_SIZEOF";
778 return "UNOP_LENGTH";
804 return "OP_M2_STRING";
805 case STRUCTOP_STRUCT
:
806 return "STRUCTOP_STRUCT";
808 return "STRUCTOP_PTR";
812 return "OP_OBJC_SELF";
820 return "OP_ADL_FUNC";
824 /* Print a raw dump of expression EXP to STREAM.
825 NOTE, if non-NULL, is printed as extra explanatory text. */
828 dump_raw_expression (struct expression
*exp
, struct ui_file
*stream
,
836 fprintf_filtered (stream
, "Dump of expression @ ");
837 gdb_print_host_address (exp
, stream
);
839 fprintf_filtered (stream
, ", %s:", note
);
840 fprintf_filtered (stream
, "\n\tLanguage %s, %d elements, %ld bytes each.\n",
841 exp
->language_defn
->la_name
, exp
->nelts
,
842 (long) sizeof (union exp_element
));
843 fprintf_filtered (stream
, "\t%5s %20s %16s %s\n", "Index", "Opcode",
844 "Hex Value", "String Value");
845 for (elt
= 0; elt
< exp
->nelts
; elt
++)
847 fprintf_filtered (stream
, "\t%5d ", elt
);
848 opcode_name
= op_name (exp
, exp
->elts
[elt
].opcode
);
850 fprintf_filtered (stream
, "%20s ", opcode_name
);
851 print_longest (stream
, 'd', 0, exp
->elts
[elt
].longconst
);
852 fprintf_filtered (stream
, " ");
854 for (eltscan
= (char *) &exp
->elts
[elt
],
855 eltsize
= sizeof (union exp_element
);
859 fprintf_filtered (stream
, "%c",
860 isprint (*eltscan
) ? (*eltscan
& 0xFF) : '.');
862 fprintf_filtered (stream
, "\n");
866 /* Dump the subexpression of prefix expression EXP whose operator is at
867 position ELT onto STREAM. Returns the position of the next
868 subexpression in EXP. */
871 dump_subexp (struct expression
*exp
, struct ui_file
*stream
, int elt
)
873 static int indent
= 0;
876 fprintf_filtered (stream
, "\n");
877 fprintf_filtered (stream
, "\t%5d ", elt
);
879 for (i
= 1; i
<= indent
; i
++)
880 fprintf_filtered (stream
, " ");
883 fprintf_filtered (stream
, "%-20s ", op_name (exp
, exp
->elts
[elt
].opcode
));
885 elt
= dump_subexp_body (exp
, stream
, elt
);
892 /* Dump the operands of prefix expression EXP whose opcode is at
893 position ELT onto STREAM. Returns the position of the next
894 subexpression in EXP. */
897 dump_subexp_body (struct expression
*exp
, struct ui_file
*stream
, int elt
)
899 return exp
->language_defn
->la_exp_desc
->dump_subexp_body (exp
, stream
, elt
);
902 /* Default value for subexp_body in exp_descriptor vector. */
905 dump_subexp_body_standard (struct expression
*exp
,
906 struct ui_file
*stream
, int elt
)
908 int opcode
= exp
->elts
[elt
++].opcode
;
914 case TERNOP_SLICE_COUNT
:
915 elt
= dump_subexp (exp
, stream
, elt
);
924 case BINOP_LOGICAL_AND
:
925 case BINOP_LOGICAL_OR
:
926 case BINOP_BITWISE_AND
:
927 case BINOP_BITWISE_IOR
:
928 case BINOP_BITWISE_XOR
:
938 case BINOP_SUBSCRIPT
:
943 case BINOP_ASSIGN_MODIFY
:
951 case STRUCTOP_MEMBER
:
953 elt
= dump_subexp (exp
, stream
, elt
);
955 case UNOP_LOGICAL_NOT
:
956 case UNOP_COMPLEMENT
:
959 case UNOP_PREINCREMENT
:
960 case UNOP_POSTINCREMENT
:
961 case UNOP_PREDECREMENT
:
962 case UNOP_POSTDECREMENT
:
981 elt
= dump_subexp (exp
, stream
, elt
);
984 fprintf_filtered (stream
, "Type @");
985 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
986 fprintf_filtered (stream
, " (");
987 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
988 fprintf_filtered (stream
, "), value %ld (0x%lx)",
989 (long) exp
->elts
[elt
+ 1].longconst
,
990 (long) exp
->elts
[elt
+ 1].longconst
);
994 fprintf_filtered (stream
, "Type @");
995 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
996 fprintf_filtered (stream
, " (");
997 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
998 fprintf_filtered (stream
, "), value %g",
999 (double) exp
->elts
[elt
+ 1].doubleconst
);
1003 fprintf_filtered (stream
, "Block @");
1004 gdb_print_host_address (exp
->elts
[elt
].block
, stream
);
1005 fprintf_filtered (stream
, ", symbol @");
1006 gdb_print_host_address (exp
->elts
[elt
+ 1].symbol
, stream
);
1007 fprintf_filtered (stream
, " (%s)",
1008 SYMBOL_PRINT_NAME (exp
->elts
[elt
+ 1].symbol
));
1012 fprintf_filtered (stream
, "History element %ld",
1013 (long) exp
->elts
[elt
].longconst
);
1017 fprintf_filtered (stream
, "Register $%s", &exp
->elts
[elt
+ 1].string
);
1018 elt
+= 3 + BYTES_TO_EXP_ELEM (exp
->elts
[elt
].longconst
+ 1);
1020 case OP_INTERNALVAR
:
1021 fprintf_filtered (stream
, "Internal var @");
1022 gdb_print_host_address (exp
->elts
[elt
].internalvar
, stream
);
1023 fprintf_filtered (stream
, " (%s)",
1024 internalvar_name (exp
->elts
[elt
].internalvar
));
1031 nargs
= longest_to_int (exp
->elts
[elt
].longconst
);
1033 fprintf_filtered (stream
, "Number of args: %d", nargs
);
1036 for (i
= 1; i
<= nargs
+ 1; i
++)
1037 elt
= dump_subexp (exp
, stream
, elt
);
1045 lower
= longest_to_int (exp
->elts
[elt
].longconst
);
1046 upper
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
1048 fprintf_filtered (stream
, "Bounds [%d:%d]", lower
, upper
);
1051 for (i
= 1; i
<= upper
- lower
+ 1; i
++)
1052 elt
= dump_subexp (exp
, stream
, elt
);
1057 case UNOP_DYNAMIC_CAST
:
1058 case UNOP_REINTERPRET_CAST
:
1059 fprintf_filtered (stream
, "Type @");
1060 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1061 fprintf_filtered (stream
, " (");
1062 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1063 fprintf_filtered (stream
, ")");
1064 elt
= dump_subexp (exp
, stream
, elt
+ 2);
1066 case UNOP_MEMVAL_TLS
:
1067 fprintf_filtered (stream
, "TLS type @");
1068 gdb_print_host_address (exp
->elts
[elt
+ 1].type
, stream
);
1069 fprintf_filtered (stream
, " (__thread /* \"%s\" */ ",
1070 (exp
->elts
[elt
].objfile
== NULL
? "(null)"
1071 : exp
->elts
[elt
].objfile
->name
));
1072 type_print (exp
->elts
[elt
+ 1].type
, NULL
, stream
, 0);
1073 fprintf_filtered (stream
, ")");
1074 elt
= dump_subexp (exp
, stream
, elt
+ 3);
1077 fprintf_filtered (stream
, "Type @");
1078 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1079 fprintf_filtered (stream
, " (");
1080 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1081 fprintf_filtered (stream
, ")");
1084 case STRUCTOP_STRUCT
:
1090 len
= longest_to_int (exp
->elts
[elt
].longconst
);
1091 elem_name
= &exp
->elts
[elt
+ 1].string
;
1093 fprintf_filtered (stream
, "Element name: `%.*s'", len
, elem_name
);
1094 elt
= dump_subexp (exp
, stream
, elt
+ 3 + BYTES_TO_EXP_ELEM (len
+ 1));
1102 fprintf_filtered (stream
, "Type @");
1103 gdb_print_host_address (exp
->elts
[elt
].type
, stream
);
1104 fprintf_filtered (stream
, " (");
1105 type_print (exp
->elts
[elt
].type
, NULL
, stream
, 0);
1106 fprintf_filtered (stream
, ") ");
1108 len
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
1109 elem_name
= &exp
->elts
[elt
+ 2].string
;
1111 fprintf_filtered (stream
, "Field name: `%.*s'", len
, elem_name
);
1112 elt
+= 4 + BYTES_TO_EXP_ELEM (len
+ 1);
1117 case MULTI_SUBSCRIPT
:
1118 case OP_F77_UNDETERMINED_ARGLIST
:
1127 fprintf_filtered (stream
, "Unknown format");
1134 dump_prefix_expression (struct expression
*exp
, struct ui_file
*stream
)
1138 fprintf_filtered (stream
, "Dump of expression @ ");
1139 gdb_print_host_address (exp
, stream
);
1140 fputs_filtered (", after conversion to prefix form:\nExpression: `", stream
);
1141 if (exp
->elts
[0].opcode
!= OP_TYPE
)
1142 print_expression (exp
, stream
);
1144 fputs_filtered ("Type printing not yet supported....", 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
);