15796c8dcSSimon Schubert /* Print in infix form a struct expression. 25796c8dcSSimon Schubert 3*a45ae5f8SJohn Marino Copyright (C) 1986, 1988-1989, 1991-2000, 2003, 2007-2012 Free 4*a45ae5f8SJohn Marino Software Foundation, Inc. 55796c8dcSSimon Schubert 65796c8dcSSimon Schubert This file is part of GDB. 75796c8dcSSimon Schubert 85796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 95796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 105796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 115796c8dcSSimon Schubert (at your option) any later version. 125796c8dcSSimon Schubert 135796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 145796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 155796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 165796c8dcSSimon Schubert GNU General Public License for more details. 175796c8dcSSimon Schubert 185796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 195796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 205796c8dcSSimon Schubert 215796c8dcSSimon Schubert #include "defs.h" 225796c8dcSSimon Schubert #include "symtab.h" 235796c8dcSSimon Schubert #include "gdbtypes.h" 245796c8dcSSimon Schubert #include "expression.h" 255796c8dcSSimon Schubert #include "value.h" 265796c8dcSSimon Schubert #include "language.h" 275796c8dcSSimon Schubert #include "parser-defs.h" 285796c8dcSSimon Schubert #include "user-regs.h" /* For user_reg_map_regnum_to_name. */ 295796c8dcSSimon Schubert #include "target.h" 305796c8dcSSimon Schubert #include "gdb_string.h" 315796c8dcSSimon Schubert #include "block.h" 325796c8dcSSimon Schubert #include "objfiles.h" 335796c8dcSSimon Schubert #include "gdb_assert.h" 345796c8dcSSimon Schubert #include "valprint.h" 355796c8dcSSimon Schubert 365796c8dcSSimon Schubert #ifdef HAVE_CTYPE_H 375796c8dcSSimon Schubert #include <ctype.h> 385796c8dcSSimon Schubert #endif 395796c8dcSSimon Schubert 405796c8dcSSimon Schubert void 415796c8dcSSimon Schubert print_expression (struct expression *exp, struct ui_file *stream) 425796c8dcSSimon Schubert { 435796c8dcSSimon Schubert int pc = 0; 44cf7f2e2dSJohn Marino 455796c8dcSSimon Schubert print_subexp (exp, &pc, stream, PREC_NULL); 465796c8dcSSimon Schubert } 475796c8dcSSimon Schubert 485796c8dcSSimon Schubert /* Print the subexpression of EXP that starts in position POS, on STREAM. 495796c8dcSSimon Schubert PREC is the precedence of the surrounding operator; 505796c8dcSSimon Schubert if the precedence of the main operator of this subexpression is less, 515796c8dcSSimon Schubert parentheses are needed here. */ 525796c8dcSSimon Schubert 535796c8dcSSimon Schubert void 545796c8dcSSimon Schubert print_subexp (struct expression *exp, int *pos, 555796c8dcSSimon Schubert struct ui_file *stream, enum precedence prec) 565796c8dcSSimon Schubert { 575796c8dcSSimon Schubert exp->language_defn->la_exp_desc->print_subexp (exp, pos, stream, prec); 585796c8dcSSimon Schubert } 595796c8dcSSimon Schubert 605796c8dcSSimon Schubert /* Standard implementation of print_subexp for use in language_defn 615796c8dcSSimon Schubert vectors. */ 625796c8dcSSimon Schubert void 635796c8dcSSimon Schubert print_subexp_standard (struct expression *exp, int *pos, 645796c8dcSSimon Schubert struct ui_file *stream, enum precedence prec) 655796c8dcSSimon Schubert { 665796c8dcSSimon Schubert unsigned tem; 675796c8dcSSimon Schubert const struct op_print *op_print_tab; 685796c8dcSSimon Schubert int pc; 695796c8dcSSimon Schubert unsigned nargs; 705796c8dcSSimon Schubert char *op_str; 715796c8dcSSimon Schubert int assign_modify = 0; 725796c8dcSSimon Schubert enum exp_opcode opcode; 735796c8dcSSimon Schubert enum precedence myprec = PREC_NULL; 745796c8dcSSimon Schubert /* Set to 1 for a right-associative operator. */ 755796c8dcSSimon Schubert int assoc = 0; 765796c8dcSSimon Schubert struct value *val; 775796c8dcSSimon Schubert char *tempstr = NULL; 785796c8dcSSimon Schubert 795796c8dcSSimon Schubert op_print_tab = exp->language_defn->la_op_print_tab; 805796c8dcSSimon Schubert pc = (*pos)++; 815796c8dcSSimon Schubert opcode = exp->elts[pc].opcode; 825796c8dcSSimon Schubert switch (opcode) 835796c8dcSSimon Schubert { 845796c8dcSSimon Schubert /* Common ops */ 855796c8dcSSimon Schubert 865796c8dcSSimon Schubert case OP_SCOPE: 875796c8dcSSimon Schubert myprec = PREC_PREFIX; 885796c8dcSSimon Schubert assoc = 0; 895796c8dcSSimon Schubert fputs_filtered (type_name_no_tag (exp->elts[pc + 1].type), stream); 905796c8dcSSimon Schubert fputs_filtered ("::", stream); 915796c8dcSSimon Schubert nargs = longest_to_int (exp->elts[pc + 2].longconst); 925796c8dcSSimon Schubert (*pos) += 4 + BYTES_TO_EXP_ELEM (nargs + 1); 935796c8dcSSimon Schubert fputs_filtered (&exp->elts[pc + 3].string, stream); 945796c8dcSSimon Schubert return; 955796c8dcSSimon Schubert 965796c8dcSSimon Schubert case OP_LONG: 975796c8dcSSimon Schubert { 985796c8dcSSimon Schubert struct value_print_options opts; 99cf7f2e2dSJohn Marino 1005796c8dcSSimon Schubert get_raw_print_options (&opts); 1015796c8dcSSimon Schubert (*pos) += 3; 1025796c8dcSSimon Schubert value_print (value_from_longest (exp->elts[pc + 1].type, 1035796c8dcSSimon Schubert exp->elts[pc + 2].longconst), 1045796c8dcSSimon Schubert stream, &opts); 1055796c8dcSSimon Schubert } 1065796c8dcSSimon Schubert return; 1075796c8dcSSimon Schubert 1085796c8dcSSimon Schubert case OP_DOUBLE: 1095796c8dcSSimon Schubert { 1105796c8dcSSimon Schubert struct value_print_options opts; 111cf7f2e2dSJohn Marino 1125796c8dcSSimon Schubert get_raw_print_options (&opts); 1135796c8dcSSimon Schubert (*pos) += 3; 1145796c8dcSSimon Schubert value_print (value_from_double (exp->elts[pc + 1].type, 1155796c8dcSSimon Schubert exp->elts[pc + 2].doubleconst), 1165796c8dcSSimon Schubert stream, &opts); 1175796c8dcSSimon Schubert } 1185796c8dcSSimon Schubert return; 1195796c8dcSSimon Schubert 1205796c8dcSSimon Schubert case OP_VAR_VALUE: 1215796c8dcSSimon Schubert { 1225796c8dcSSimon Schubert struct block *b; 123cf7f2e2dSJohn Marino 1245796c8dcSSimon Schubert (*pos) += 3; 1255796c8dcSSimon Schubert b = exp->elts[pc + 1].block; 1265796c8dcSSimon Schubert if (b != NULL 1275796c8dcSSimon Schubert && BLOCK_FUNCTION (b) != NULL 1285796c8dcSSimon Schubert && SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b)) != NULL) 1295796c8dcSSimon Schubert { 1305796c8dcSSimon Schubert fputs_filtered (SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b)), stream); 1315796c8dcSSimon Schubert fputs_filtered ("::", stream); 1325796c8dcSSimon Schubert } 1335796c8dcSSimon Schubert fputs_filtered (SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol), stream); 1345796c8dcSSimon Schubert } 1355796c8dcSSimon Schubert return; 1365796c8dcSSimon Schubert 137*a45ae5f8SJohn Marino case OP_VAR_ENTRY_VALUE: 138*a45ae5f8SJohn Marino { 139*a45ae5f8SJohn Marino struct block *b; 140*a45ae5f8SJohn Marino 141*a45ae5f8SJohn Marino (*pos) += 2; 142*a45ae5f8SJohn Marino fprintf_filtered (stream, "%s@entry", 143*a45ae5f8SJohn Marino SYMBOL_PRINT_NAME (exp->elts[pc + 1].symbol)); 144*a45ae5f8SJohn Marino } 145*a45ae5f8SJohn Marino return; 146*a45ae5f8SJohn Marino 1475796c8dcSSimon Schubert case OP_LAST: 1485796c8dcSSimon Schubert (*pos) += 2; 1495796c8dcSSimon Schubert fprintf_filtered (stream, "$%d", 1505796c8dcSSimon Schubert longest_to_int (exp->elts[pc + 1].longconst)); 1515796c8dcSSimon Schubert return; 1525796c8dcSSimon Schubert 1535796c8dcSSimon Schubert case OP_REGISTER: 1545796c8dcSSimon Schubert { 1555796c8dcSSimon Schubert const char *name = &exp->elts[pc + 2].string; 156cf7f2e2dSJohn Marino 1575796c8dcSSimon Schubert (*pos) += 3 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1); 1585796c8dcSSimon Schubert fprintf_filtered (stream, "$%s", name); 1595796c8dcSSimon Schubert return; 1605796c8dcSSimon Schubert } 1615796c8dcSSimon Schubert 1625796c8dcSSimon Schubert case OP_BOOL: 1635796c8dcSSimon Schubert (*pos) += 2; 1645796c8dcSSimon Schubert fprintf_filtered (stream, "%s", 1655796c8dcSSimon Schubert longest_to_int (exp->elts[pc + 1].longconst) 1665796c8dcSSimon Schubert ? "TRUE" : "FALSE"); 1675796c8dcSSimon Schubert return; 1685796c8dcSSimon Schubert 1695796c8dcSSimon Schubert case OP_INTERNALVAR: 1705796c8dcSSimon Schubert (*pos) += 2; 1715796c8dcSSimon Schubert fprintf_filtered (stream, "$%s", 1725796c8dcSSimon Schubert internalvar_name (exp->elts[pc + 1].internalvar)); 1735796c8dcSSimon Schubert return; 1745796c8dcSSimon Schubert 1755796c8dcSSimon Schubert case OP_FUNCALL: 1765796c8dcSSimon Schubert (*pos) += 2; 1775796c8dcSSimon Schubert nargs = longest_to_int (exp->elts[pc + 1].longconst); 1785796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX); 1795796c8dcSSimon Schubert fputs_filtered (" (", stream); 1805796c8dcSSimon Schubert for (tem = 0; tem < nargs; tem++) 1815796c8dcSSimon Schubert { 1825796c8dcSSimon Schubert if (tem != 0) 1835796c8dcSSimon Schubert fputs_filtered (", ", stream); 1845796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); 1855796c8dcSSimon Schubert } 1865796c8dcSSimon Schubert fputs_filtered (")", stream); 1875796c8dcSSimon Schubert return; 1885796c8dcSSimon Schubert 1895796c8dcSSimon Schubert case OP_NAME: 1905796c8dcSSimon Schubert nargs = longest_to_int (exp->elts[pc + 1].longconst); 1915796c8dcSSimon Schubert (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1); 1925796c8dcSSimon Schubert fputs_filtered (&exp->elts[pc + 2].string, stream); 1935796c8dcSSimon Schubert return; 1945796c8dcSSimon Schubert 1955796c8dcSSimon Schubert case OP_STRING: 1965796c8dcSSimon Schubert { 1975796c8dcSSimon Schubert struct value_print_options opts; 198cf7f2e2dSJohn Marino 1995796c8dcSSimon Schubert nargs = longest_to_int (exp->elts[pc + 1].longconst); 2005796c8dcSSimon Schubert (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1); 2015796c8dcSSimon Schubert /* LA_PRINT_STRING will print using the current repeat count threshold. 2025796c8dcSSimon Schubert If necessary, we can temporarily set it to zero, or pass it as an 2035796c8dcSSimon Schubert additional parameter to LA_PRINT_STRING. -fnf */ 2045796c8dcSSimon Schubert get_user_print_options (&opts); 2055796c8dcSSimon Schubert LA_PRINT_STRING (stream, builtin_type (exp->gdbarch)->builtin_char, 206cf7f2e2dSJohn Marino &exp->elts[pc + 2].string, nargs, NULL, 0, &opts); 2075796c8dcSSimon Schubert } 2085796c8dcSSimon Schubert return; 2095796c8dcSSimon Schubert 2105796c8dcSSimon Schubert case OP_BITSTRING: 2115796c8dcSSimon Schubert nargs = longest_to_int (exp->elts[pc + 1].longconst); 2125796c8dcSSimon Schubert (*pos) 2135796c8dcSSimon Schubert += 3 + BYTES_TO_EXP_ELEM ((nargs + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT); 2145796c8dcSSimon Schubert fprintf_unfiltered (stream, "B'<unimplemented>'"); 2155796c8dcSSimon Schubert return; 2165796c8dcSSimon Schubert 217c50c785cSJohn Marino case OP_OBJC_NSSTRING: /* Objective-C Foundation Class 218c50c785cSJohn Marino NSString constant. */ 2195796c8dcSSimon Schubert { 2205796c8dcSSimon Schubert struct value_print_options opts; 221cf7f2e2dSJohn Marino 2225796c8dcSSimon Schubert nargs = longest_to_int (exp->elts[pc + 1].longconst); 2235796c8dcSSimon Schubert (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1); 2245796c8dcSSimon Schubert fputs_filtered ("@\"", stream); 2255796c8dcSSimon Schubert get_user_print_options (&opts); 2265796c8dcSSimon Schubert LA_PRINT_STRING (stream, builtin_type (exp->gdbarch)->builtin_char, 227cf7f2e2dSJohn Marino &exp->elts[pc + 2].string, nargs, NULL, 0, &opts); 2285796c8dcSSimon Schubert fputs_filtered ("\"", stream); 2295796c8dcSSimon Schubert } 2305796c8dcSSimon Schubert return; 2315796c8dcSSimon Schubert 2325796c8dcSSimon Schubert case OP_OBJC_MSGCALL: 2335796c8dcSSimon Schubert { /* Objective C message (method) call. */ 2345796c8dcSSimon Schubert char *selector; 235cf7f2e2dSJohn Marino 2365796c8dcSSimon Schubert (*pos) += 3; 2375796c8dcSSimon Schubert nargs = longest_to_int (exp->elts[pc + 2].longconst); 2385796c8dcSSimon Schubert fprintf_unfiltered (stream, "["); 2395796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX); 2405796c8dcSSimon Schubert if (0 == target_read_string (exp->elts[pc + 1].longconst, 2415796c8dcSSimon Schubert &selector, 1024, NULL)) 2425796c8dcSSimon Schubert { 2435796c8dcSSimon Schubert error (_("bad selector")); 2445796c8dcSSimon Schubert return; 2455796c8dcSSimon Schubert } 2465796c8dcSSimon Schubert if (nargs) 2475796c8dcSSimon Schubert { 2485796c8dcSSimon Schubert char *s, *nextS; 249cf7f2e2dSJohn Marino 2505796c8dcSSimon Schubert s = alloca (strlen (selector) + 1); 2515796c8dcSSimon Schubert strcpy (s, selector); 2525796c8dcSSimon Schubert for (tem = 0; tem < nargs; tem++) 2535796c8dcSSimon Schubert { 2545796c8dcSSimon Schubert nextS = strchr (s, ':'); 2555796c8dcSSimon Schubert gdb_assert (nextS); /* Make sure we found ':'. */ 2565796c8dcSSimon Schubert *nextS = '\0'; 2575796c8dcSSimon Schubert fprintf_unfiltered (stream, " %s: ", s); 2585796c8dcSSimon Schubert s = nextS + 1; 2595796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); 2605796c8dcSSimon Schubert } 2615796c8dcSSimon Schubert } 2625796c8dcSSimon Schubert else 2635796c8dcSSimon Schubert { 2645796c8dcSSimon Schubert fprintf_unfiltered (stream, " %s", selector); 2655796c8dcSSimon Schubert } 2665796c8dcSSimon Schubert fprintf_unfiltered (stream, "]"); 2675796c8dcSSimon Schubert /* "selector" was malloc'd by target_read_string. Free it. */ 2685796c8dcSSimon Schubert xfree (selector); 2695796c8dcSSimon Schubert return; 2705796c8dcSSimon Schubert } 2715796c8dcSSimon Schubert 2725796c8dcSSimon Schubert case OP_ARRAY: 2735796c8dcSSimon Schubert (*pos) += 3; 2745796c8dcSSimon Schubert nargs = longest_to_int (exp->elts[pc + 2].longconst); 2755796c8dcSSimon Schubert nargs -= longest_to_int (exp->elts[pc + 1].longconst); 2765796c8dcSSimon Schubert nargs++; 2775796c8dcSSimon Schubert tem = 0; 2785796c8dcSSimon Schubert if (exp->elts[pc + 4].opcode == OP_LONG 2795796c8dcSSimon Schubert && exp->elts[pc + 5].type 2805796c8dcSSimon Schubert == builtin_type (exp->gdbarch)->builtin_char 2815796c8dcSSimon Schubert && exp->language_defn->la_language == language_c) 2825796c8dcSSimon Schubert { 2835796c8dcSSimon Schubert /* Attempt to print C character arrays using string syntax. 2845796c8dcSSimon Schubert Walk through the args, picking up one character from each 2855796c8dcSSimon Schubert of the OP_LONG expression elements. If any array element 2865796c8dcSSimon Schubert does not match our expection of what we should find for 2875796c8dcSSimon Schubert a simple string, revert back to array printing. Note that 2885796c8dcSSimon Schubert the last expression element is an explicit null terminator 2895796c8dcSSimon Schubert byte, which doesn't get printed. */ 2905796c8dcSSimon Schubert tempstr = alloca (nargs); 2915796c8dcSSimon Schubert pc += 4; 2925796c8dcSSimon Schubert while (tem < nargs) 2935796c8dcSSimon Schubert { 2945796c8dcSSimon Schubert if (exp->elts[pc].opcode != OP_LONG 2955796c8dcSSimon Schubert || exp->elts[pc + 1].type 2965796c8dcSSimon Schubert != builtin_type (exp->gdbarch)->builtin_char) 2975796c8dcSSimon Schubert { 298c50c785cSJohn Marino /* Not a simple array of char, use regular array 299c50c785cSJohn Marino printing. */ 3005796c8dcSSimon Schubert tem = 0; 3015796c8dcSSimon Schubert break; 3025796c8dcSSimon Schubert } 3035796c8dcSSimon Schubert else 3045796c8dcSSimon Schubert { 3055796c8dcSSimon Schubert tempstr[tem++] = 3065796c8dcSSimon Schubert longest_to_int (exp->elts[pc + 2].longconst); 3075796c8dcSSimon Schubert pc += 4; 3085796c8dcSSimon Schubert } 3095796c8dcSSimon Schubert } 3105796c8dcSSimon Schubert } 3115796c8dcSSimon Schubert if (tem > 0) 3125796c8dcSSimon Schubert { 3135796c8dcSSimon Schubert struct value_print_options opts; 314cf7f2e2dSJohn Marino 3155796c8dcSSimon Schubert get_user_print_options (&opts); 3165796c8dcSSimon Schubert LA_PRINT_STRING (stream, builtin_type (exp->gdbarch)->builtin_char, 317cf7f2e2dSJohn Marino tempstr, nargs - 1, NULL, 0, &opts); 3185796c8dcSSimon Schubert (*pos) = pc; 3195796c8dcSSimon Schubert } 3205796c8dcSSimon Schubert else 3215796c8dcSSimon Schubert { 3225796c8dcSSimon Schubert fputs_filtered (" {", stream); 3235796c8dcSSimon Schubert for (tem = 0; tem < nargs; tem++) 3245796c8dcSSimon Schubert { 3255796c8dcSSimon Schubert if (tem != 0) 3265796c8dcSSimon Schubert { 3275796c8dcSSimon Schubert fputs_filtered (", ", stream); 3285796c8dcSSimon Schubert } 3295796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); 3305796c8dcSSimon Schubert } 3315796c8dcSSimon Schubert fputs_filtered ("}", stream); 3325796c8dcSSimon Schubert } 3335796c8dcSSimon Schubert return; 3345796c8dcSSimon Schubert 3355796c8dcSSimon Schubert case OP_LABELED: 3365796c8dcSSimon Schubert tem = longest_to_int (exp->elts[pc + 1].longconst); 3375796c8dcSSimon Schubert (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); 3385796c8dcSSimon Schubert /* Gcc support both these syntaxes. Unsure which is preferred. */ 3395796c8dcSSimon Schubert #if 1 3405796c8dcSSimon Schubert fputs_filtered (&exp->elts[pc + 2].string, stream); 3415796c8dcSSimon Schubert fputs_filtered (": ", stream); 3425796c8dcSSimon Schubert #else 3435796c8dcSSimon Schubert fputs_filtered (".", stream); 3445796c8dcSSimon Schubert fputs_filtered (&exp->elts[pc + 2].string, stream); 3455796c8dcSSimon Schubert fputs_filtered ("=", stream); 3465796c8dcSSimon Schubert #endif 3475796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX); 3485796c8dcSSimon Schubert return; 3495796c8dcSSimon Schubert 3505796c8dcSSimon Schubert case TERNOP_COND: 3515796c8dcSSimon Schubert if ((int) prec > (int) PREC_COMMA) 3525796c8dcSSimon Schubert fputs_filtered ("(", stream); 3535796c8dcSSimon Schubert /* Print the subexpressions, forcing parentheses 3545796c8dcSSimon Schubert around any binary operations within them. 3555796c8dcSSimon Schubert This is more parentheses than are strictly necessary, 3565796c8dcSSimon Schubert but it looks clearer. */ 3575796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_HYPER); 3585796c8dcSSimon Schubert fputs_filtered (" ? ", stream); 3595796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_HYPER); 3605796c8dcSSimon Schubert fputs_filtered (" : ", stream); 3615796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_HYPER); 3625796c8dcSSimon Schubert if ((int) prec > (int) PREC_COMMA) 3635796c8dcSSimon Schubert fputs_filtered (")", stream); 3645796c8dcSSimon Schubert return; 3655796c8dcSSimon Schubert 3665796c8dcSSimon Schubert case TERNOP_SLICE: 3675796c8dcSSimon Schubert case TERNOP_SLICE_COUNT: 3685796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX); 3695796c8dcSSimon Schubert fputs_filtered ("(", stream); 3705796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); 3715796c8dcSSimon Schubert fputs_filtered (opcode == TERNOP_SLICE ? " : " : " UP ", stream); 3725796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); 3735796c8dcSSimon Schubert fputs_filtered (")", stream); 3745796c8dcSSimon Schubert return; 3755796c8dcSSimon Schubert 3765796c8dcSSimon Schubert case STRUCTOP_STRUCT: 3775796c8dcSSimon Schubert tem = longest_to_int (exp->elts[pc + 1].longconst); 3785796c8dcSSimon Schubert (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); 3795796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX); 3805796c8dcSSimon Schubert fputs_filtered (".", stream); 3815796c8dcSSimon Schubert fputs_filtered (&exp->elts[pc + 2].string, stream); 3825796c8dcSSimon Schubert return; 3835796c8dcSSimon Schubert 384c50c785cSJohn Marino /* Will not occur for Modula-2. */ 3855796c8dcSSimon Schubert case STRUCTOP_PTR: 3865796c8dcSSimon Schubert tem = longest_to_int (exp->elts[pc + 1].longconst); 3875796c8dcSSimon Schubert (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); 3885796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX); 3895796c8dcSSimon Schubert fputs_filtered ("->", stream); 3905796c8dcSSimon Schubert fputs_filtered (&exp->elts[pc + 2].string, stream); 3915796c8dcSSimon Schubert return; 3925796c8dcSSimon Schubert 3935796c8dcSSimon Schubert case STRUCTOP_MEMBER: 3945796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX); 3955796c8dcSSimon Schubert fputs_filtered (".*", stream); 3965796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX); 3975796c8dcSSimon Schubert return; 3985796c8dcSSimon Schubert 3995796c8dcSSimon Schubert case STRUCTOP_MPTR: 4005796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX); 4015796c8dcSSimon Schubert fputs_filtered ("->*", stream); 4025796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX); 4035796c8dcSSimon Schubert return; 4045796c8dcSSimon Schubert 4055796c8dcSSimon Schubert case BINOP_SUBSCRIPT: 4065796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX); 4075796c8dcSSimon Schubert fputs_filtered ("[", stream); 4085796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); 4095796c8dcSSimon Schubert fputs_filtered ("]", stream); 4105796c8dcSSimon Schubert return; 4115796c8dcSSimon Schubert 4125796c8dcSSimon Schubert case UNOP_POSTINCREMENT: 4135796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX); 4145796c8dcSSimon Schubert fputs_filtered ("++", stream); 4155796c8dcSSimon Schubert return; 4165796c8dcSSimon Schubert 4175796c8dcSSimon Schubert case UNOP_POSTDECREMENT: 4185796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX); 4195796c8dcSSimon Schubert fputs_filtered ("--", stream); 4205796c8dcSSimon Schubert return; 4215796c8dcSSimon Schubert 4225796c8dcSSimon Schubert case UNOP_CAST: 4235796c8dcSSimon Schubert (*pos) += 2; 4245796c8dcSSimon Schubert if ((int) prec > (int) PREC_PREFIX) 4255796c8dcSSimon Schubert fputs_filtered ("(", stream); 4265796c8dcSSimon Schubert fputs_filtered ("(", stream); 4275796c8dcSSimon Schubert type_print (exp->elts[pc + 1].type, "", stream, 0); 4285796c8dcSSimon Schubert fputs_filtered (") ", stream); 4295796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_PREFIX); 4305796c8dcSSimon Schubert if ((int) prec > (int) PREC_PREFIX) 4315796c8dcSSimon Schubert fputs_filtered (")", stream); 4325796c8dcSSimon Schubert return; 4335796c8dcSSimon Schubert 434cf7f2e2dSJohn Marino case UNOP_DYNAMIC_CAST: 435cf7f2e2dSJohn Marino case UNOP_REINTERPRET_CAST: 436cf7f2e2dSJohn Marino fputs_filtered (opcode == UNOP_DYNAMIC_CAST ? "dynamic_cast" 437cf7f2e2dSJohn Marino : "reinterpret_cast", stream); 438cf7f2e2dSJohn Marino fputs_filtered ("<", stream); 439cf7f2e2dSJohn Marino (*pos) += 2; 440cf7f2e2dSJohn Marino type_print (exp->elts[pc + 1].type, "", stream, 0); 441cf7f2e2dSJohn Marino fputs_filtered ("> (", stream); 442cf7f2e2dSJohn Marino print_subexp (exp, pos, stream, PREC_PREFIX); 443cf7f2e2dSJohn Marino fputs_filtered (")", stream); 444cf7f2e2dSJohn Marino return; 445cf7f2e2dSJohn Marino 4465796c8dcSSimon Schubert case UNOP_MEMVAL: 4475796c8dcSSimon Schubert (*pos) += 2; 4485796c8dcSSimon Schubert if ((int) prec > (int) PREC_PREFIX) 4495796c8dcSSimon Schubert fputs_filtered ("(", stream); 450cf7f2e2dSJohn Marino if (TYPE_CODE (exp->elts[pc + 1].type) == TYPE_CODE_FUNC 451cf7f2e2dSJohn Marino && exp->elts[pc + 3].opcode == OP_LONG) 4525796c8dcSSimon Schubert { 4535796c8dcSSimon Schubert struct value_print_options opts; 4545796c8dcSSimon Schubert 4555796c8dcSSimon Schubert /* We have a minimal symbol fn, probably. It's encoded 4565796c8dcSSimon Schubert as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address). 4575796c8dcSSimon Schubert Swallow the OP_LONG (including both its opcodes); ignore 4585796c8dcSSimon Schubert its type; print the value in the type of the MEMVAL. */ 4595796c8dcSSimon Schubert (*pos) += 4; 4605796c8dcSSimon Schubert val = value_at_lazy (exp->elts[pc + 1].type, 4615796c8dcSSimon Schubert (CORE_ADDR) exp->elts[pc + 5].longconst); 4625796c8dcSSimon Schubert get_raw_print_options (&opts); 4635796c8dcSSimon Schubert value_print (val, stream, &opts); 4645796c8dcSSimon Schubert } 4655796c8dcSSimon Schubert else 4665796c8dcSSimon Schubert { 4675796c8dcSSimon Schubert fputs_filtered ("{", stream); 4685796c8dcSSimon Schubert type_print (exp->elts[pc + 1].type, "", stream, 0); 4695796c8dcSSimon Schubert fputs_filtered ("} ", stream); 4705796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_PREFIX); 4715796c8dcSSimon Schubert } 4725796c8dcSSimon Schubert if ((int) prec > (int) PREC_PREFIX) 4735796c8dcSSimon Schubert fputs_filtered (")", stream); 4745796c8dcSSimon Schubert return; 4755796c8dcSSimon Schubert 4765796c8dcSSimon Schubert case UNOP_MEMVAL_TLS: 4775796c8dcSSimon Schubert (*pos) += 3; 4785796c8dcSSimon Schubert if ((int) prec > (int) PREC_PREFIX) 4795796c8dcSSimon Schubert fputs_filtered ("(", stream); 4805796c8dcSSimon Schubert fputs_filtered ("{", stream); 4815796c8dcSSimon Schubert type_print (exp->elts[pc + 2].type, "", stream, 0); 4825796c8dcSSimon Schubert fputs_filtered ("} ", stream); 4835796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_PREFIX); 4845796c8dcSSimon Schubert if ((int) prec > (int) PREC_PREFIX) 4855796c8dcSSimon Schubert fputs_filtered (")", stream); 4865796c8dcSSimon Schubert return; 4875796c8dcSSimon Schubert 4885796c8dcSSimon Schubert case BINOP_ASSIGN_MODIFY: 4895796c8dcSSimon Schubert opcode = exp->elts[pc + 1].opcode; 4905796c8dcSSimon Schubert (*pos) += 2; 4915796c8dcSSimon Schubert myprec = PREC_ASSIGN; 4925796c8dcSSimon Schubert assoc = 1; 4935796c8dcSSimon Schubert assign_modify = 1; 4945796c8dcSSimon Schubert op_str = "???"; 4955796c8dcSSimon Schubert for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++) 4965796c8dcSSimon Schubert if (op_print_tab[tem].opcode == opcode) 4975796c8dcSSimon Schubert { 4985796c8dcSSimon Schubert op_str = op_print_tab[tem].string; 4995796c8dcSSimon Schubert break; 5005796c8dcSSimon Schubert } 5015796c8dcSSimon Schubert if (op_print_tab[tem].opcode != opcode) 5025796c8dcSSimon Schubert /* Not found; don't try to keep going because we don't know how 5035796c8dcSSimon Schubert to interpret further elements. */ 5045796c8dcSSimon Schubert error (_("Invalid expression")); 5055796c8dcSSimon Schubert break; 5065796c8dcSSimon Schubert 5075796c8dcSSimon Schubert /* C++ ops */ 5085796c8dcSSimon Schubert 5095796c8dcSSimon Schubert case OP_THIS: 5105796c8dcSSimon Schubert ++(*pos); 511*a45ae5f8SJohn Marino if (exp->language_defn->la_name_of_this) 512*a45ae5f8SJohn Marino fputs_filtered (exp->language_defn->la_name_of_this, stream); 513*a45ae5f8SJohn Marino else 514*a45ae5f8SJohn Marino fprintf_filtered (stream, _("<language %s has no 'this'>"), 515*a45ae5f8SJohn Marino exp->language_defn->la_name); 5165796c8dcSSimon Schubert return; 5175796c8dcSSimon Schubert 5185796c8dcSSimon Schubert /* Modula-2 ops */ 5195796c8dcSSimon Schubert 5205796c8dcSSimon Schubert case MULTI_SUBSCRIPT: 5215796c8dcSSimon Schubert (*pos) += 2; 5225796c8dcSSimon Schubert nargs = longest_to_int (exp->elts[pc + 1].longconst); 5235796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX); 5245796c8dcSSimon Schubert fprintf_unfiltered (stream, " ["); 5255796c8dcSSimon Schubert for (tem = 0; tem < nargs; tem++) 5265796c8dcSSimon Schubert { 5275796c8dcSSimon Schubert if (tem != 0) 5285796c8dcSSimon Schubert fprintf_unfiltered (stream, ", "); 5295796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); 5305796c8dcSSimon Schubert } 5315796c8dcSSimon Schubert fprintf_unfiltered (stream, "]"); 5325796c8dcSSimon Schubert return; 5335796c8dcSSimon Schubert 5345796c8dcSSimon Schubert case BINOP_VAL: 5355796c8dcSSimon Schubert (*pos) += 2; 5365796c8dcSSimon Schubert fprintf_unfiltered (stream, "VAL("); 5375796c8dcSSimon Schubert type_print (exp->elts[pc + 1].type, "", stream, 0); 5385796c8dcSSimon Schubert fprintf_unfiltered (stream, ","); 5395796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_PREFIX); 5405796c8dcSSimon Schubert fprintf_unfiltered (stream, ")"); 5415796c8dcSSimon Schubert return; 5425796c8dcSSimon Schubert 543c50c785cSJohn Marino case TYPE_INSTANCE: 544c50c785cSJohn Marino { 545c50c785cSJohn Marino LONGEST count = exp->elts[pc + 1].longconst; 546c50c785cSJohn Marino 547c50c785cSJohn Marino /* The COUNT. */ 548c50c785cSJohn Marino (*pos)++; 549c50c785cSJohn Marino fputs_unfiltered ("TypesInstance(", stream); 550c50c785cSJohn Marino while (count-- > 0) 551c50c785cSJohn Marino { 552c50c785cSJohn Marino type_print (exp->elts[(*pos)++].type, "", stream, 0); 553c50c785cSJohn Marino if (count > 0) 554c50c785cSJohn Marino fputs_unfiltered (",", stream); 555c50c785cSJohn Marino } 556c50c785cSJohn Marino fputs_unfiltered (",", stream); 557c50c785cSJohn Marino /* Ending COUNT and ending TYPE_INSTANCE. */ 558c50c785cSJohn Marino (*pos) += 2; 559c50c785cSJohn Marino print_subexp (exp, pos, stream, PREC_PREFIX); 560c50c785cSJohn Marino fputs_unfiltered (")", stream); 561c50c785cSJohn Marino return; 562c50c785cSJohn Marino } 563c50c785cSJohn Marino 5645796c8dcSSimon Schubert /* Default ops */ 5655796c8dcSSimon Schubert 5665796c8dcSSimon Schubert default: 5675796c8dcSSimon Schubert op_str = "???"; 5685796c8dcSSimon Schubert for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++) 5695796c8dcSSimon Schubert if (op_print_tab[tem].opcode == opcode) 5705796c8dcSSimon Schubert { 5715796c8dcSSimon Schubert op_str = op_print_tab[tem].string; 5725796c8dcSSimon Schubert myprec = op_print_tab[tem].precedence; 5735796c8dcSSimon Schubert assoc = op_print_tab[tem].right_assoc; 5745796c8dcSSimon Schubert break; 5755796c8dcSSimon Schubert } 5765796c8dcSSimon Schubert if (op_print_tab[tem].opcode != opcode) 5775796c8dcSSimon Schubert /* Not found; don't try to keep going because we don't know how 5785796c8dcSSimon Schubert to interpret further elements. For example, this happens 5795796c8dcSSimon Schubert if opcode is OP_TYPE. */ 5805796c8dcSSimon Schubert error (_("Invalid expression")); 5815796c8dcSSimon Schubert } 5825796c8dcSSimon Schubert 5835796c8dcSSimon Schubert /* Note that PREC_BUILTIN will always emit parentheses. */ 5845796c8dcSSimon Schubert if ((int) myprec < (int) prec) 5855796c8dcSSimon Schubert fputs_filtered ("(", stream); 5865796c8dcSSimon Schubert if ((int) opcode > (int) BINOP_END) 5875796c8dcSSimon Schubert { 5885796c8dcSSimon Schubert if (assoc) 5895796c8dcSSimon Schubert { 5905796c8dcSSimon Schubert /* Unary postfix operator. */ 5915796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX); 5925796c8dcSSimon Schubert fputs_filtered (op_str, stream); 5935796c8dcSSimon Schubert } 5945796c8dcSSimon Schubert else 5955796c8dcSSimon Schubert { 5965796c8dcSSimon Schubert /* Unary prefix operator. */ 5975796c8dcSSimon Schubert fputs_filtered (op_str, stream); 5985796c8dcSSimon Schubert if (myprec == PREC_BUILTIN_FUNCTION) 5995796c8dcSSimon Schubert fputs_filtered ("(", stream); 6005796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_PREFIX); 6015796c8dcSSimon Schubert if (myprec == PREC_BUILTIN_FUNCTION) 6025796c8dcSSimon Schubert fputs_filtered (")", stream); 6035796c8dcSSimon Schubert } 6045796c8dcSSimon Schubert } 6055796c8dcSSimon Schubert else 6065796c8dcSSimon Schubert { 6075796c8dcSSimon Schubert /* Binary operator. */ 6085796c8dcSSimon Schubert /* Print left operand. 6095796c8dcSSimon Schubert If operator is right-associative, 6105796c8dcSSimon Schubert increment precedence for this operand. */ 6115796c8dcSSimon Schubert print_subexp (exp, pos, stream, 6125796c8dcSSimon Schubert (enum precedence) ((int) myprec + assoc)); 6135796c8dcSSimon Schubert /* Print the operator itself. */ 6145796c8dcSSimon Schubert if (assign_modify) 6155796c8dcSSimon Schubert fprintf_filtered (stream, " %s= ", op_str); 6165796c8dcSSimon Schubert else if (op_str[0] == ',') 6175796c8dcSSimon Schubert fprintf_filtered (stream, "%s ", op_str); 6185796c8dcSSimon Schubert else 6195796c8dcSSimon Schubert fprintf_filtered (stream, " %s ", op_str); 6205796c8dcSSimon Schubert /* Print right operand. 6215796c8dcSSimon Schubert If operator is left-associative, 6225796c8dcSSimon Schubert increment precedence for this operand. */ 6235796c8dcSSimon Schubert print_subexp (exp, pos, stream, 6245796c8dcSSimon Schubert (enum precedence) ((int) myprec + !assoc)); 6255796c8dcSSimon Schubert } 6265796c8dcSSimon Schubert 6275796c8dcSSimon Schubert if ((int) myprec < (int) prec) 6285796c8dcSSimon Schubert fputs_filtered (")", stream); 6295796c8dcSSimon Schubert } 6305796c8dcSSimon Schubert 6315796c8dcSSimon Schubert /* Return the operator corresponding to opcode OP as 6325796c8dcSSimon Schubert a string. NULL indicates that the opcode was not found in the 6335796c8dcSSimon Schubert current language table. */ 6345796c8dcSSimon Schubert char * 6355796c8dcSSimon Schubert op_string (enum exp_opcode op) 6365796c8dcSSimon Schubert { 6375796c8dcSSimon Schubert int tem; 6385796c8dcSSimon Schubert const struct op_print *op_print_tab; 6395796c8dcSSimon Schubert 6405796c8dcSSimon Schubert op_print_tab = current_language->la_op_print_tab; 6415796c8dcSSimon Schubert for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++) 6425796c8dcSSimon Schubert if (op_print_tab[tem].opcode == op) 6435796c8dcSSimon Schubert return op_print_tab[tem].string; 6445796c8dcSSimon Schubert return NULL; 6455796c8dcSSimon Schubert } 6465796c8dcSSimon Schubert 6475796c8dcSSimon Schubert /* Support for dumping the raw data from expressions in a human readable 6485796c8dcSSimon Schubert form. */ 6495796c8dcSSimon Schubert 6505796c8dcSSimon Schubert static char *op_name (struct expression *, enum exp_opcode); 6515796c8dcSSimon Schubert static int dump_subexp_body (struct expression *exp, struct ui_file *, int); 6525796c8dcSSimon Schubert 6535796c8dcSSimon Schubert /* Name for OPCODE, when it appears in expression EXP. */ 6545796c8dcSSimon Schubert 6555796c8dcSSimon Schubert static char * 6565796c8dcSSimon Schubert op_name (struct expression *exp, enum exp_opcode opcode) 6575796c8dcSSimon Schubert { 6585796c8dcSSimon Schubert return exp->language_defn->la_exp_desc->op_name (opcode); 6595796c8dcSSimon Schubert } 6605796c8dcSSimon Schubert 6615796c8dcSSimon Schubert /* Default name for the standard operator OPCODE (i.e., one defined in 6625796c8dcSSimon Schubert the definition of enum exp_opcode). */ 6635796c8dcSSimon Schubert 6645796c8dcSSimon Schubert char * 6655796c8dcSSimon Schubert op_name_standard (enum exp_opcode opcode) 6665796c8dcSSimon Schubert { 6675796c8dcSSimon Schubert switch (opcode) 6685796c8dcSSimon Schubert { 6695796c8dcSSimon Schubert default: 6705796c8dcSSimon Schubert { 6715796c8dcSSimon Schubert static char buf[30]; 6725796c8dcSSimon Schubert 6735796c8dcSSimon Schubert sprintf (buf, "<unknown %d>", opcode); 6745796c8dcSSimon Schubert return buf; 6755796c8dcSSimon Schubert } 676c50c785cSJohn Marino #define OP(name) \ 677c50c785cSJohn Marino case name: \ 678c50c785cSJohn Marino return #name ; 679c50c785cSJohn Marino #include "std-operator.def" 680c50c785cSJohn Marino #undef OP 6815796c8dcSSimon Schubert } 6825796c8dcSSimon Schubert } 6835796c8dcSSimon Schubert 6845796c8dcSSimon Schubert /* Print a raw dump of expression EXP to STREAM. 6855796c8dcSSimon Schubert NOTE, if non-NULL, is printed as extra explanatory text. */ 6865796c8dcSSimon Schubert 6875796c8dcSSimon Schubert void 6885796c8dcSSimon Schubert dump_raw_expression (struct expression *exp, struct ui_file *stream, 6895796c8dcSSimon Schubert char *note) 6905796c8dcSSimon Schubert { 6915796c8dcSSimon Schubert int elt; 6925796c8dcSSimon Schubert char *opcode_name; 6935796c8dcSSimon Schubert char *eltscan; 6945796c8dcSSimon Schubert int eltsize; 6955796c8dcSSimon Schubert 6965796c8dcSSimon Schubert fprintf_filtered (stream, "Dump of expression @ "); 6975796c8dcSSimon Schubert gdb_print_host_address (exp, stream); 6985796c8dcSSimon Schubert if (note) 6995796c8dcSSimon Schubert fprintf_filtered (stream, ", %s:", note); 7005796c8dcSSimon Schubert fprintf_filtered (stream, "\n\tLanguage %s, %d elements, %ld bytes each.\n", 7015796c8dcSSimon Schubert exp->language_defn->la_name, exp->nelts, 7025796c8dcSSimon Schubert (long) sizeof (union exp_element)); 7035796c8dcSSimon Schubert fprintf_filtered (stream, "\t%5s %20s %16s %s\n", "Index", "Opcode", 7045796c8dcSSimon Schubert "Hex Value", "String Value"); 7055796c8dcSSimon Schubert for (elt = 0; elt < exp->nelts; elt++) 7065796c8dcSSimon Schubert { 7075796c8dcSSimon Schubert fprintf_filtered (stream, "\t%5d ", elt); 7085796c8dcSSimon Schubert opcode_name = op_name (exp, exp->elts[elt].opcode); 7095796c8dcSSimon Schubert 7105796c8dcSSimon Schubert fprintf_filtered (stream, "%20s ", opcode_name); 7115796c8dcSSimon Schubert print_longest (stream, 'd', 0, exp->elts[elt].longconst); 7125796c8dcSSimon Schubert fprintf_filtered (stream, " "); 7135796c8dcSSimon Schubert 7145796c8dcSSimon Schubert for (eltscan = (char *) &exp->elts[elt], 7155796c8dcSSimon Schubert eltsize = sizeof (union exp_element); 7165796c8dcSSimon Schubert eltsize-- > 0; 7175796c8dcSSimon Schubert eltscan++) 7185796c8dcSSimon Schubert { 7195796c8dcSSimon Schubert fprintf_filtered (stream, "%c", 7205796c8dcSSimon Schubert isprint (*eltscan) ? (*eltscan & 0xFF) : '.'); 7215796c8dcSSimon Schubert } 7225796c8dcSSimon Schubert fprintf_filtered (stream, "\n"); 7235796c8dcSSimon Schubert } 7245796c8dcSSimon Schubert } 7255796c8dcSSimon Schubert 7265796c8dcSSimon Schubert /* Dump the subexpression of prefix expression EXP whose operator is at 7275796c8dcSSimon Schubert position ELT onto STREAM. Returns the position of the next 7285796c8dcSSimon Schubert subexpression in EXP. */ 7295796c8dcSSimon Schubert 7305796c8dcSSimon Schubert int 7315796c8dcSSimon Schubert dump_subexp (struct expression *exp, struct ui_file *stream, int elt) 7325796c8dcSSimon Schubert { 7335796c8dcSSimon Schubert static int indent = 0; 7345796c8dcSSimon Schubert int i; 7355796c8dcSSimon Schubert 7365796c8dcSSimon Schubert fprintf_filtered (stream, "\n"); 7375796c8dcSSimon Schubert fprintf_filtered (stream, "\t%5d ", elt); 7385796c8dcSSimon Schubert 7395796c8dcSSimon Schubert for (i = 1; i <= indent; i++) 7405796c8dcSSimon Schubert fprintf_filtered (stream, " "); 7415796c8dcSSimon Schubert indent += 2; 7425796c8dcSSimon Schubert 7435796c8dcSSimon Schubert fprintf_filtered (stream, "%-20s ", op_name (exp, exp->elts[elt].opcode)); 7445796c8dcSSimon Schubert 7455796c8dcSSimon Schubert elt = dump_subexp_body (exp, stream, elt); 7465796c8dcSSimon Schubert 7475796c8dcSSimon Schubert indent -= 2; 7485796c8dcSSimon Schubert 7495796c8dcSSimon Schubert return elt; 7505796c8dcSSimon Schubert } 7515796c8dcSSimon Schubert 7525796c8dcSSimon Schubert /* Dump the operands of prefix expression EXP whose opcode is at 7535796c8dcSSimon Schubert position ELT onto STREAM. Returns the position of the next 7545796c8dcSSimon Schubert subexpression in EXP. */ 7555796c8dcSSimon Schubert 7565796c8dcSSimon Schubert static int 7575796c8dcSSimon Schubert dump_subexp_body (struct expression *exp, struct ui_file *stream, int elt) 7585796c8dcSSimon Schubert { 7595796c8dcSSimon Schubert return exp->language_defn->la_exp_desc->dump_subexp_body (exp, stream, elt); 7605796c8dcSSimon Schubert } 7615796c8dcSSimon Schubert 7625796c8dcSSimon Schubert /* Default value for subexp_body in exp_descriptor vector. */ 7635796c8dcSSimon Schubert 7645796c8dcSSimon Schubert int 7655796c8dcSSimon Schubert dump_subexp_body_standard (struct expression *exp, 7665796c8dcSSimon Schubert struct ui_file *stream, int elt) 7675796c8dcSSimon Schubert { 7685796c8dcSSimon Schubert int opcode = exp->elts[elt++].opcode; 7695796c8dcSSimon Schubert 7705796c8dcSSimon Schubert switch (opcode) 7715796c8dcSSimon Schubert { 7725796c8dcSSimon Schubert case TERNOP_COND: 7735796c8dcSSimon Schubert case TERNOP_SLICE: 7745796c8dcSSimon Schubert case TERNOP_SLICE_COUNT: 7755796c8dcSSimon Schubert elt = dump_subexp (exp, stream, elt); 776c50c785cSJohn Marino /* FALL THROUGH */ 7775796c8dcSSimon Schubert case BINOP_ADD: 7785796c8dcSSimon Schubert case BINOP_SUB: 7795796c8dcSSimon Schubert case BINOP_MUL: 7805796c8dcSSimon Schubert case BINOP_DIV: 7815796c8dcSSimon Schubert case BINOP_REM: 7825796c8dcSSimon Schubert case BINOP_MOD: 7835796c8dcSSimon Schubert case BINOP_LSH: 7845796c8dcSSimon Schubert case BINOP_RSH: 7855796c8dcSSimon Schubert case BINOP_LOGICAL_AND: 7865796c8dcSSimon Schubert case BINOP_LOGICAL_OR: 7875796c8dcSSimon Schubert case BINOP_BITWISE_AND: 7885796c8dcSSimon Schubert case BINOP_BITWISE_IOR: 7895796c8dcSSimon Schubert case BINOP_BITWISE_XOR: 7905796c8dcSSimon Schubert case BINOP_EQUAL: 7915796c8dcSSimon Schubert case BINOP_NOTEQUAL: 7925796c8dcSSimon Schubert case BINOP_LESS: 7935796c8dcSSimon Schubert case BINOP_GTR: 7945796c8dcSSimon Schubert case BINOP_LEQ: 7955796c8dcSSimon Schubert case BINOP_GEQ: 7965796c8dcSSimon Schubert case BINOP_REPEAT: 7975796c8dcSSimon Schubert case BINOP_ASSIGN: 7985796c8dcSSimon Schubert case BINOP_COMMA: 7995796c8dcSSimon Schubert case BINOP_SUBSCRIPT: 8005796c8dcSSimon Schubert case BINOP_EXP: 8015796c8dcSSimon Schubert case BINOP_MIN: 8025796c8dcSSimon Schubert case BINOP_MAX: 8035796c8dcSSimon Schubert case BINOP_INTDIV: 8045796c8dcSSimon Schubert case BINOP_ASSIGN_MODIFY: 8055796c8dcSSimon Schubert case BINOP_VAL: 8065796c8dcSSimon Schubert case BINOP_CONCAT: 8075796c8dcSSimon Schubert case BINOP_IN: 8085796c8dcSSimon Schubert case BINOP_RANGE: 8095796c8dcSSimon Schubert case BINOP_END: 8105796c8dcSSimon Schubert case STRUCTOP_MEMBER: 8115796c8dcSSimon Schubert case STRUCTOP_MPTR: 8125796c8dcSSimon Schubert elt = dump_subexp (exp, stream, elt); 813c50c785cSJohn Marino /* FALL THROUGH */ 8145796c8dcSSimon Schubert case UNOP_NEG: 8155796c8dcSSimon Schubert case UNOP_LOGICAL_NOT: 8165796c8dcSSimon Schubert case UNOP_COMPLEMENT: 8175796c8dcSSimon Schubert case UNOP_IND: 8185796c8dcSSimon Schubert case UNOP_ADDR: 8195796c8dcSSimon Schubert case UNOP_PREINCREMENT: 8205796c8dcSSimon Schubert case UNOP_POSTINCREMENT: 8215796c8dcSSimon Schubert case UNOP_PREDECREMENT: 8225796c8dcSSimon Schubert case UNOP_POSTDECREMENT: 8235796c8dcSSimon Schubert case UNOP_SIZEOF: 8245796c8dcSSimon Schubert case UNOP_PLUS: 8255796c8dcSSimon Schubert case UNOP_CAP: 8265796c8dcSSimon Schubert case UNOP_CHR: 8275796c8dcSSimon Schubert case UNOP_ORD: 8285796c8dcSSimon Schubert case UNOP_ABS: 8295796c8dcSSimon Schubert case UNOP_FLOAT: 8305796c8dcSSimon Schubert case UNOP_HIGH: 8315796c8dcSSimon Schubert case UNOP_MAX: 8325796c8dcSSimon Schubert case UNOP_MIN: 8335796c8dcSSimon Schubert case UNOP_ODD: 8345796c8dcSSimon Schubert case UNOP_TRUNC: 8355796c8dcSSimon Schubert elt = dump_subexp (exp, stream, elt); 8365796c8dcSSimon Schubert break; 8375796c8dcSSimon Schubert case OP_LONG: 8385796c8dcSSimon Schubert fprintf_filtered (stream, "Type @"); 8395796c8dcSSimon Schubert gdb_print_host_address (exp->elts[elt].type, stream); 8405796c8dcSSimon Schubert fprintf_filtered (stream, " ("); 8415796c8dcSSimon Schubert type_print (exp->elts[elt].type, NULL, stream, 0); 8425796c8dcSSimon Schubert fprintf_filtered (stream, "), value %ld (0x%lx)", 8435796c8dcSSimon Schubert (long) exp->elts[elt + 1].longconst, 8445796c8dcSSimon Schubert (long) exp->elts[elt + 1].longconst); 8455796c8dcSSimon Schubert elt += 3; 8465796c8dcSSimon Schubert break; 8475796c8dcSSimon Schubert case OP_DOUBLE: 8485796c8dcSSimon Schubert fprintf_filtered (stream, "Type @"); 8495796c8dcSSimon Schubert gdb_print_host_address (exp->elts[elt].type, stream); 8505796c8dcSSimon Schubert fprintf_filtered (stream, " ("); 8515796c8dcSSimon Schubert type_print (exp->elts[elt].type, NULL, stream, 0); 8525796c8dcSSimon Schubert fprintf_filtered (stream, "), value %g", 8535796c8dcSSimon Schubert (double) exp->elts[elt + 1].doubleconst); 8545796c8dcSSimon Schubert elt += 3; 8555796c8dcSSimon Schubert break; 8565796c8dcSSimon Schubert case OP_VAR_VALUE: 8575796c8dcSSimon Schubert fprintf_filtered (stream, "Block @"); 8585796c8dcSSimon Schubert gdb_print_host_address (exp->elts[elt].block, stream); 8595796c8dcSSimon Schubert fprintf_filtered (stream, ", symbol @"); 8605796c8dcSSimon Schubert gdb_print_host_address (exp->elts[elt + 1].symbol, stream); 8615796c8dcSSimon Schubert fprintf_filtered (stream, " (%s)", 8625796c8dcSSimon Schubert SYMBOL_PRINT_NAME (exp->elts[elt + 1].symbol)); 8635796c8dcSSimon Schubert elt += 3; 8645796c8dcSSimon Schubert break; 865*a45ae5f8SJohn Marino case OP_VAR_ENTRY_VALUE: 866*a45ae5f8SJohn Marino fprintf_filtered (stream, "Entry value of symbol @"); 867*a45ae5f8SJohn Marino gdb_print_host_address (exp->elts[elt].symbol, stream); 868*a45ae5f8SJohn Marino fprintf_filtered (stream, " (%s)", 869*a45ae5f8SJohn Marino SYMBOL_PRINT_NAME (exp->elts[elt].symbol)); 870*a45ae5f8SJohn Marino elt += 2; 871*a45ae5f8SJohn Marino break; 8725796c8dcSSimon Schubert case OP_LAST: 8735796c8dcSSimon Schubert fprintf_filtered (stream, "History element %ld", 8745796c8dcSSimon Schubert (long) exp->elts[elt].longconst); 8755796c8dcSSimon Schubert elt += 2; 8765796c8dcSSimon Schubert break; 8775796c8dcSSimon Schubert case OP_REGISTER: 8785796c8dcSSimon Schubert fprintf_filtered (stream, "Register $%s", &exp->elts[elt + 1].string); 8795796c8dcSSimon Schubert elt += 3 + BYTES_TO_EXP_ELEM (exp->elts[elt].longconst + 1); 8805796c8dcSSimon Schubert break; 8815796c8dcSSimon Schubert case OP_INTERNALVAR: 8825796c8dcSSimon Schubert fprintf_filtered (stream, "Internal var @"); 8835796c8dcSSimon Schubert gdb_print_host_address (exp->elts[elt].internalvar, stream); 8845796c8dcSSimon Schubert fprintf_filtered (stream, " (%s)", 8855796c8dcSSimon Schubert internalvar_name (exp->elts[elt].internalvar)); 8865796c8dcSSimon Schubert elt += 2; 8875796c8dcSSimon Schubert break; 8885796c8dcSSimon Schubert case OP_FUNCALL: 8895796c8dcSSimon Schubert { 8905796c8dcSSimon Schubert int i, nargs; 8915796c8dcSSimon Schubert 8925796c8dcSSimon Schubert nargs = longest_to_int (exp->elts[elt].longconst); 8935796c8dcSSimon Schubert 8945796c8dcSSimon Schubert fprintf_filtered (stream, "Number of args: %d", nargs); 8955796c8dcSSimon Schubert elt += 2; 8965796c8dcSSimon Schubert 8975796c8dcSSimon Schubert for (i = 1; i <= nargs + 1; i++) 8985796c8dcSSimon Schubert elt = dump_subexp (exp, stream, elt); 8995796c8dcSSimon Schubert } 9005796c8dcSSimon Schubert break; 9015796c8dcSSimon Schubert case OP_ARRAY: 9025796c8dcSSimon Schubert { 9035796c8dcSSimon Schubert int lower, upper; 9045796c8dcSSimon Schubert int i; 9055796c8dcSSimon Schubert 9065796c8dcSSimon Schubert lower = longest_to_int (exp->elts[elt].longconst); 9075796c8dcSSimon Schubert upper = longest_to_int (exp->elts[elt + 1].longconst); 9085796c8dcSSimon Schubert 9095796c8dcSSimon Schubert fprintf_filtered (stream, "Bounds [%d:%d]", lower, upper); 9105796c8dcSSimon Schubert elt += 3; 9115796c8dcSSimon Schubert 9125796c8dcSSimon Schubert for (i = 1; i <= upper - lower + 1; i++) 9135796c8dcSSimon Schubert elt = dump_subexp (exp, stream, elt); 9145796c8dcSSimon Schubert } 9155796c8dcSSimon Schubert break; 9165796c8dcSSimon Schubert case UNOP_MEMVAL: 9175796c8dcSSimon Schubert case UNOP_CAST: 918cf7f2e2dSJohn Marino case UNOP_DYNAMIC_CAST: 919cf7f2e2dSJohn Marino case UNOP_REINTERPRET_CAST: 9205796c8dcSSimon Schubert fprintf_filtered (stream, "Type @"); 9215796c8dcSSimon Schubert gdb_print_host_address (exp->elts[elt].type, stream); 9225796c8dcSSimon Schubert fprintf_filtered (stream, " ("); 9235796c8dcSSimon Schubert type_print (exp->elts[elt].type, NULL, stream, 0); 9245796c8dcSSimon Schubert fprintf_filtered (stream, ")"); 9255796c8dcSSimon Schubert elt = dump_subexp (exp, stream, elt + 2); 9265796c8dcSSimon Schubert break; 9275796c8dcSSimon Schubert case UNOP_MEMVAL_TLS: 9285796c8dcSSimon Schubert fprintf_filtered (stream, "TLS type @"); 9295796c8dcSSimon Schubert gdb_print_host_address (exp->elts[elt + 1].type, stream); 9305796c8dcSSimon Schubert fprintf_filtered (stream, " (__thread /* \"%s\" */ ", 9315796c8dcSSimon Schubert (exp->elts[elt].objfile == NULL ? "(null)" 9325796c8dcSSimon Schubert : exp->elts[elt].objfile->name)); 9335796c8dcSSimon Schubert type_print (exp->elts[elt + 1].type, NULL, stream, 0); 9345796c8dcSSimon Schubert fprintf_filtered (stream, ")"); 9355796c8dcSSimon Schubert elt = dump_subexp (exp, stream, elt + 3); 9365796c8dcSSimon Schubert break; 9375796c8dcSSimon Schubert case OP_TYPE: 9385796c8dcSSimon Schubert fprintf_filtered (stream, "Type @"); 9395796c8dcSSimon Schubert gdb_print_host_address (exp->elts[elt].type, stream); 9405796c8dcSSimon Schubert fprintf_filtered (stream, " ("); 9415796c8dcSSimon Schubert type_print (exp->elts[elt].type, NULL, stream, 0); 9425796c8dcSSimon Schubert fprintf_filtered (stream, ")"); 9435796c8dcSSimon Schubert elt += 2; 9445796c8dcSSimon Schubert break; 9455796c8dcSSimon Schubert case STRUCTOP_STRUCT: 9465796c8dcSSimon Schubert case STRUCTOP_PTR: 9475796c8dcSSimon Schubert { 9485796c8dcSSimon Schubert char *elem_name; 9495796c8dcSSimon Schubert int len; 9505796c8dcSSimon Schubert 9515796c8dcSSimon Schubert len = longest_to_int (exp->elts[elt].longconst); 9525796c8dcSSimon Schubert elem_name = &exp->elts[elt + 1].string; 9535796c8dcSSimon Schubert 9545796c8dcSSimon Schubert fprintf_filtered (stream, "Element name: `%.*s'", len, elem_name); 9555796c8dcSSimon Schubert elt = dump_subexp (exp, stream, elt + 3 + BYTES_TO_EXP_ELEM (len + 1)); 9565796c8dcSSimon Schubert } 9575796c8dcSSimon Schubert break; 9585796c8dcSSimon Schubert case OP_SCOPE: 9595796c8dcSSimon Schubert { 9605796c8dcSSimon Schubert char *elem_name; 9615796c8dcSSimon Schubert int len; 9625796c8dcSSimon Schubert 9635796c8dcSSimon Schubert fprintf_filtered (stream, "Type @"); 9645796c8dcSSimon Schubert gdb_print_host_address (exp->elts[elt].type, stream); 9655796c8dcSSimon Schubert fprintf_filtered (stream, " ("); 9665796c8dcSSimon Schubert type_print (exp->elts[elt].type, NULL, stream, 0); 9675796c8dcSSimon Schubert fprintf_filtered (stream, ") "); 9685796c8dcSSimon Schubert 9695796c8dcSSimon Schubert len = longest_to_int (exp->elts[elt + 1].longconst); 9705796c8dcSSimon Schubert elem_name = &exp->elts[elt + 2].string; 9715796c8dcSSimon Schubert 9725796c8dcSSimon Schubert fprintf_filtered (stream, "Field name: `%.*s'", len, elem_name); 9735796c8dcSSimon Schubert elt += 4 + BYTES_TO_EXP_ELEM (len + 1); 9745796c8dcSSimon Schubert } 9755796c8dcSSimon Schubert break; 976c50c785cSJohn Marino case TYPE_INSTANCE: 977c50c785cSJohn Marino { 978c50c785cSJohn Marino char *elem_name; 979c50c785cSJohn Marino LONGEST len; 980c50c785cSJohn Marino 981c50c785cSJohn Marino len = exp->elts[elt++].longconst; 982c50c785cSJohn Marino fprintf_filtered (stream, "%s TypeInstance: ", plongest (len)); 983c50c785cSJohn Marino while (len-- > 0) 984c50c785cSJohn Marino { 985c50c785cSJohn Marino fprintf_filtered (stream, "Type @"); 986c50c785cSJohn Marino gdb_print_host_address (exp->elts[elt].type, stream); 987c50c785cSJohn Marino fprintf_filtered (stream, " ("); 988c50c785cSJohn Marino type_print (exp->elts[elt].type, NULL, stream, 0); 989c50c785cSJohn Marino fprintf_filtered (stream, ")"); 990c50c785cSJohn Marino elt++; 991c50c785cSJohn Marino if (len > 0) 992c50c785cSJohn Marino fputs_filtered (", ", stream); 993c50c785cSJohn Marino } 994c50c785cSJohn Marino /* Ending LEN and ending TYPE_INSTANCE. */ 995c50c785cSJohn Marino elt += 2; 996c50c785cSJohn Marino elt = dump_subexp (exp, stream, elt); 997c50c785cSJohn Marino } 998c50c785cSJohn Marino break; 9995796c8dcSSimon Schubert default: 10005796c8dcSSimon Schubert case OP_NULL: 10015796c8dcSSimon Schubert case MULTI_SUBSCRIPT: 10025796c8dcSSimon Schubert case OP_F77_UNDETERMINED_ARGLIST: 10035796c8dcSSimon Schubert case OP_COMPLEX: 10045796c8dcSSimon Schubert case OP_STRING: 10055796c8dcSSimon Schubert case OP_BITSTRING: 10065796c8dcSSimon Schubert case OP_BOOL: 10075796c8dcSSimon Schubert case OP_M2_STRING: 10085796c8dcSSimon Schubert case OP_THIS: 10095796c8dcSSimon Schubert case OP_LABELED: 10105796c8dcSSimon Schubert case OP_NAME: 10115796c8dcSSimon Schubert fprintf_filtered (stream, "Unknown format"); 10125796c8dcSSimon Schubert } 10135796c8dcSSimon Schubert 10145796c8dcSSimon Schubert return elt; 10155796c8dcSSimon Schubert } 10165796c8dcSSimon Schubert 10175796c8dcSSimon Schubert void 10185796c8dcSSimon Schubert dump_prefix_expression (struct expression *exp, struct ui_file *stream) 10195796c8dcSSimon Schubert { 10205796c8dcSSimon Schubert int elt; 10215796c8dcSSimon Schubert 10225796c8dcSSimon Schubert fprintf_filtered (stream, "Dump of expression @ "); 10235796c8dcSSimon Schubert gdb_print_host_address (exp, stream); 10245796c8dcSSimon Schubert fputs_filtered (", after conversion to prefix form:\nExpression: `", stream); 10255796c8dcSSimon Schubert if (exp->elts[0].opcode != OP_TYPE) 10265796c8dcSSimon Schubert print_expression (exp, stream); 10275796c8dcSSimon Schubert else 10285796c8dcSSimon Schubert fputs_filtered ("Type printing not yet supported....", stream); 10295796c8dcSSimon Schubert fprintf_filtered (stream, "'\n\tLanguage %s, %d elements, %ld bytes each.\n", 10305796c8dcSSimon Schubert exp->language_defn->la_name, exp->nelts, 10315796c8dcSSimon Schubert (long) sizeof (union exp_element)); 10325796c8dcSSimon Schubert fputs_filtered ("\n", stream); 10335796c8dcSSimon Schubert 10345796c8dcSSimon Schubert for (elt = 0; elt < exp->nelts;) 10355796c8dcSSimon Schubert elt = dump_subexp (exp, stream, elt); 10365796c8dcSSimon Schubert fputs_filtered ("\n", stream); 10375796c8dcSSimon Schubert } 1038