15796c8dcSSimon Schubert /* Parse expressions for GDB. 25796c8dcSSimon Schubert 35796c8dcSSimon Schubert Copyright (C) 1986, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 4*cf7f2e2dSJohn Marino 1998, 1999, 2000, 2001, 2004, 2005, 2007, 2008, 2009, 2010 55796c8dcSSimon Schubert Free Software Foundation, Inc. 65796c8dcSSimon Schubert 75796c8dcSSimon Schubert Modified from expread.y by the Department of Computer Science at the 85796c8dcSSimon Schubert State University of New York at Buffalo, 1991. 95796c8dcSSimon Schubert 105796c8dcSSimon Schubert This file is part of GDB. 115796c8dcSSimon Schubert 125796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 135796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 145796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 155796c8dcSSimon Schubert (at your option) any later version. 165796c8dcSSimon Schubert 175796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 185796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 195796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 205796c8dcSSimon Schubert GNU General Public License for more details. 215796c8dcSSimon Schubert 225796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 235796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 245796c8dcSSimon Schubert 255796c8dcSSimon Schubert /* Parse an expression from text in a string, 265796c8dcSSimon Schubert and return the result as a struct expression pointer. 275796c8dcSSimon Schubert That structure contains arithmetic operations in reverse polish, 285796c8dcSSimon Schubert with constants represented by operations that are followed by special data. 295796c8dcSSimon Schubert See expression.h for the details of the format. 305796c8dcSSimon Schubert What is important here is that it can be built up sequentially 315796c8dcSSimon Schubert during the process of parsing; the lower levels of the tree always 325796c8dcSSimon Schubert come first in the result. */ 335796c8dcSSimon Schubert 345796c8dcSSimon Schubert #include "defs.h" 35*cf7f2e2dSJohn Marino #include <ctype.h> 365796c8dcSSimon Schubert #include "arch-utils.h" 375796c8dcSSimon Schubert #include "gdb_string.h" 385796c8dcSSimon Schubert #include "symtab.h" 395796c8dcSSimon Schubert #include "gdbtypes.h" 405796c8dcSSimon Schubert #include "frame.h" 415796c8dcSSimon Schubert #include "expression.h" 425796c8dcSSimon Schubert #include "value.h" 435796c8dcSSimon Schubert #include "command.h" 445796c8dcSSimon Schubert #include "language.h" 455796c8dcSSimon Schubert #include "f-lang.h" 465796c8dcSSimon Schubert #include "parser-defs.h" 475796c8dcSSimon Schubert #include "gdbcmd.h" 485796c8dcSSimon Schubert #include "symfile.h" /* for overlay functions */ 495796c8dcSSimon Schubert #include "inferior.h" 505796c8dcSSimon Schubert #include "doublest.h" 515796c8dcSSimon Schubert #include "gdb_assert.h" 525796c8dcSSimon Schubert #include "block.h" 535796c8dcSSimon Schubert #include "source.h" 545796c8dcSSimon Schubert #include "objfiles.h" 555796c8dcSSimon Schubert #include "exceptions.h" 565796c8dcSSimon Schubert #include "user-regs.h" 575796c8dcSSimon Schubert 585796c8dcSSimon Schubert /* Standard set of definitions for printing, dumping, prefixifying, 595796c8dcSSimon Schubert * and evaluating expressions. */ 605796c8dcSSimon Schubert 615796c8dcSSimon Schubert const struct exp_descriptor exp_descriptor_standard = 625796c8dcSSimon Schubert { 635796c8dcSSimon Schubert print_subexp_standard, 645796c8dcSSimon Schubert operator_length_standard, 65*cf7f2e2dSJohn Marino operator_check_standard, 665796c8dcSSimon Schubert op_name_standard, 675796c8dcSSimon Schubert dump_subexp_body_standard, 685796c8dcSSimon Schubert evaluate_subexp_standard 695796c8dcSSimon Schubert }; 705796c8dcSSimon Schubert 715796c8dcSSimon Schubert /* Global variables declared in parser-defs.h (and commented there). */ 725796c8dcSSimon Schubert struct expression *expout; 735796c8dcSSimon Schubert int expout_size; 745796c8dcSSimon Schubert int expout_ptr; 755796c8dcSSimon Schubert struct block *expression_context_block; 765796c8dcSSimon Schubert CORE_ADDR expression_context_pc; 775796c8dcSSimon Schubert struct block *innermost_block; 785796c8dcSSimon Schubert int arglist_len; 795796c8dcSSimon Schubert union type_stack_elt *type_stack; 805796c8dcSSimon Schubert int type_stack_depth, type_stack_size; 815796c8dcSSimon Schubert char *lexptr; 825796c8dcSSimon Schubert char *prev_lexptr; 835796c8dcSSimon Schubert int paren_depth; 845796c8dcSSimon Schubert int comma_terminates; 855796c8dcSSimon Schubert 865796c8dcSSimon Schubert /* True if parsing an expression to find a field reference. This is 875796c8dcSSimon Schubert only used by completion. */ 885796c8dcSSimon Schubert int in_parse_field; 895796c8dcSSimon Schubert 905796c8dcSSimon Schubert /* The index of the last struct expression directly before a '.' or 915796c8dcSSimon Schubert '->'. This is set when parsing and is only used when completing a 925796c8dcSSimon Schubert field name. It is -1 if no dereference operation was found. */ 935796c8dcSSimon Schubert static int expout_last_struct = -1; 945796c8dcSSimon Schubert 955796c8dcSSimon Schubert /* A temporary buffer for identifiers, so we can null-terminate them. 965796c8dcSSimon Schubert 975796c8dcSSimon Schubert We allocate this with xrealloc. parse_exp_1 used to allocate with 985796c8dcSSimon Schubert alloca, using the size of the whole expression as a conservative 995796c8dcSSimon Schubert estimate of the space needed. However, macro expansion can 1005796c8dcSSimon Schubert introduce names longer than the original expression; there's no 1015796c8dcSSimon Schubert practical way to know beforehand how large that might be. */ 1025796c8dcSSimon Schubert char *namecopy; 1035796c8dcSSimon Schubert size_t namecopy_size; 1045796c8dcSSimon Schubert 1055796c8dcSSimon Schubert static int expressiondebug = 0; 1065796c8dcSSimon Schubert static void 1075796c8dcSSimon Schubert show_expressiondebug (struct ui_file *file, int from_tty, 1085796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 1095796c8dcSSimon Schubert { 1105796c8dcSSimon Schubert fprintf_filtered (file, _("Expression debugging is %s.\n"), value); 1115796c8dcSSimon Schubert } 1125796c8dcSSimon Schubert 113*cf7f2e2dSJohn Marino 114*cf7f2e2dSJohn Marino /* Non-zero if an expression parser should set yydebug. */ 115*cf7f2e2dSJohn Marino int parser_debug; 116*cf7f2e2dSJohn Marino 117*cf7f2e2dSJohn Marino static void 118*cf7f2e2dSJohn Marino show_parserdebug (struct ui_file *file, int from_tty, 119*cf7f2e2dSJohn Marino struct cmd_list_element *c, const char *value) 120*cf7f2e2dSJohn Marino { 121*cf7f2e2dSJohn Marino fprintf_filtered (file, _("Parser debugging is %s.\n"), value); 122*cf7f2e2dSJohn Marino } 123*cf7f2e2dSJohn Marino 124*cf7f2e2dSJohn Marino 1255796c8dcSSimon Schubert static void free_funcalls (void *ignore); 1265796c8dcSSimon Schubert 1275796c8dcSSimon Schubert static int prefixify_expression (struct expression *); 1285796c8dcSSimon Schubert 1295796c8dcSSimon Schubert static int prefixify_subexp (struct expression *, struct expression *, int, 1305796c8dcSSimon Schubert int); 1315796c8dcSSimon Schubert 1325796c8dcSSimon Schubert static struct expression *parse_exp_in_context (char **, struct block *, int, 1335796c8dcSSimon Schubert int, int *); 1345796c8dcSSimon Schubert 1355796c8dcSSimon Schubert void _initialize_parse (void); 1365796c8dcSSimon Schubert 1375796c8dcSSimon Schubert /* Data structure for saving values of arglist_len for function calls whose 1385796c8dcSSimon Schubert arguments contain other function calls. */ 1395796c8dcSSimon Schubert 1405796c8dcSSimon Schubert struct funcall 1415796c8dcSSimon Schubert { 1425796c8dcSSimon Schubert struct funcall *next; 1435796c8dcSSimon Schubert int arglist_len; 1445796c8dcSSimon Schubert }; 1455796c8dcSSimon Schubert 1465796c8dcSSimon Schubert static struct funcall *funcall_chain; 1475796c8dcSSimon Schubert 1485796c8dcSSimon Schubert /* Begin counting arguments for a function call, 1495796c8dcSSimon Schubert saving the data about any containing call. */ 1505796c8dcSSimon Schubert 1515796c8dcSSimon Schubert void 1525796c8dcSSimon Schubert start_arglist (void) 1535796c8dcSSimon Schubert { 1545796c8dcSSimon Schubert struct funcall *new; 1555796c8dcSSimon Schubert 1565796c8dcSSimon Schubert new = (struct funcall *) xmalloc (sizeof (struct funcall)); 1575796c8dcSSimon Schubert new->next = funcall_chain; 1585796c8dcSSimon Schubert new->arglist_len = arglist_len; 1595796c8dcSSimon Schubert arglist_len = 0; 1605796c8dcSSimon Schubert funcall_chain = new; 1615796c8dcSSimon Schubert } 1625796c8dcSSimon Schubert 1635796c8dcSSimon Schubert /* Return the number of arguments in a function call just terminated, 1645796c8dcSSimon Schubert and restore the data for the containing function call. */ 1655796c8dcSSimon Schubert 1665796c8dcSSimon Schubert int 1675796c8dcSSimon Schubert end_arglist (void) 1685796c8dcSSimon Schubert { 1695796c8dcSSimon Schubert int val = arglist_len; 1705796c8dcSSimon Schubert struct funcall *call = funcall_chain; 171*cf7f2e2dSJohn Marino 1725796c8dcSSimon Schubert funcall_chain = call->next; 1735796c8dcSSimon Schubert arglist_len = call->arglist_len; 1745796c8dcSSimon Schubert xfree (call); 1755796c8dcSSimon Schubert return val; 1765796c8dcSSimon Schubert } 1775796c8dcSSimon Schubert 1785796c8dcSSimon Schubert /* Free everything in the funcall chain. 1795796c8dcSSimon Schubert Used when there is an error inside parsing. */ 1805796c8dcSSimon Schubert 1815796c8dcSSimon Schubert static void 1825796c8dcSSimon Schubert free_funcalls (void *ignore) 1835796c8dcSSimon Schubert { 1845796c8dcSSimon Schubert struct funcall *call, *next; 1855796c8dcSSimon Schubert 1865796c8dcSSimon Schubert for (call = funcall_chain; call; call = next) 1875796c8dcSSimon Schubert { 1885796c8dcSSimon Schubert next = call->next; 1895796c8dcSSimon Schubert xfree (call); 1905796c8dcSSimon Schubert } 1915796c8dcSSimon Schubert } 1925796c8dcSSimon Schubert 1935796c8dcSSimon Schubert /* This page contains the functions for adding data to the struct expression 1945796c8dcSSimon Schubert being constructed. */ 1955796c8dcSSimon Schubert 1965796c8dcSSimon Schubert /* Add one element to the end of the expression. */ 1975796c8dcSSimon Schubert 1985796c8dcSSimon Schubert /* To avoid a bug in the Sun 4 compiler, we pass things that can fit into 1995796c8dcSSimon Schubert a register through here */ 2005796c8dcSSimon Schubert 2015796c8dcSSimon Schubert void 2025796c8dcSSimon Schubert write_exp_elt (union exp_element expelt) 2035796c8dcSSimon Schubert { 2045796c8dcSSimon Schubert if (expout_ptr >= expout_size) 2055796c8dcSSimon Schubert { 2065796c8dcSSimon Schubert expout_size *= 2; 2075796c8dcSSimon Schubert expout = (struct expression *) 2085796c8dcSSimon Schubert xrealloc ((char *) expout, sizeof (struct expression) 2095796c8dcSSimon Schubert + EXP_ELEM_TO_BYTES (expout_size)); 2105796c8dcSSimon Schubert } 2115796c8dcSSimon Schubert expout->elts[expout_ptr++] = expelt; 2125796c8dcSSimon Schubert } 2135796c8dcSSimon Schubert 2145796c8dcSSimon Schubert void 2155796c8dcSSimon Schubert write_exp_elt_opcode (enum exp_opcode expelt) 2165796c8dcSSimon Schubert { 2175796c8dcSSimon Schubert union exp_element tmp; 218*cf7f2e2dSJohn Marino 2195796c8dcSSimon Schubert memset (&tmp, 0, sizeof (union exp_element)); 2205796c8dcSSimon Schubert tmp.opcode = expelt; 2215796c8dcSSimon Schubert write_exp_elt (tmp); 2225796c8dcSSimon Schubert } 2235796c8dcSSimon Schubert 2245796c8dcSSimon Schubert void 2255796c8dcSSimon Schubert write_exp_elt_sym (struct symbol *expelt) 2265796c8dcSSimon Schubert { 2275796c8dcSSimon Schubert union exp_element tmp; 228*cf7f2e2dSJohn Marino 2295796c8dcSSimon Schubert memset (&tmp, 0, sizeof (union exp_element)); 2305796c8dcSSimon Schubert tmp.symbol = expelt; 2315796c8dcSSimon Schubert write_exp_elt (tmp); 2325796c8dcSSimon Schubert } 2335796c8dcSSimon Schubert 2345796c8dcSSimon Schubert void 2355796c8dcSSimon Schubert write_exp_elt_block (struct block *b) 2365796c8dcSSimon Schubert { 2375796c8dcSSimon Schubert union exp_element tmp; 238*cf7f2e2dSJohn Marino 2395796c8dcSSimon Schubert memset (&tmp, 0, sizeof (union exp_element)); 2405796c8dcSSimon Schubert tmp.block = b; 2415796c8dcSSimon Schubert write_exp_elt (tmp); 2425796c8dcSSimon Schubert } 2435796c8dcSSimon Schubert 2445796c8dcSSimon Schubert void 2455796c8dcSSimon Schubert write_exp_elt_objfile (struct objfile *objfile) 2465796c8dcSSimon Schubert { 2475796c8dcSSimon Schubert union exp_element tmp; 248*cf7f2e2dSJohn Marino 2495796c8dcSSimon Schubert memset (&tmp, 0, sizeof (union exp_element)); 2505796c8dcSSimon Schubert tmp.objfile = objfile; 2515796c8dcSSimon Schubert write_exp_elt (tmp); 2525796c8dcSSimon Schubert } 2535796c8dcSSimon Schubert 2545796c8dcSSimon Schubert void 2555796c8dcSSimon Schubert write_exp_elt_longcst (LONGEST expelt) 2565796c8dcSSimon Schubert { 2575796c8dcSSimon Schubert union exp_element tmp; 258*cf7f2e2dSJohn Marino 2595796c8dcSSimon Schubert memset (&tmp, 0, sizeof (union exp_element)); 2605796c8dcSSimon Schubert tmp.longconst = expelt; 2615796c8dcSSimon Schubert write_exp_elt (tmp); 2625796c8dcSSimon Schubert } 2635796c8dcSSimon Schubert 2645796c8dcSSimon Schubert void 2655796c8dcSSimon Schubert write_exp_elt_dblcst (DOUBLEST expelt) 2665796c8dcSSimon Schubert { 2675796c8dcSSimon Schubert union exp_element tmp; 268*cf7f2e2dSJohn Marino 2695796c8dcSSimon Schubert memset (&tmp, 0, sizeof (union exp_element)); 2705796c8dcSSimon Schubert tmp.doubleconst = expelt; 2715796c8dcSSimon Schubert write_exp_elt (tmp); 2725796c8dcSSimon Schubert } 2735796c8dcSSimon Schubert 2745796c8dcSSimon Schubert void 2755796c8dcSSimon Schubert write_exp_elt_decfloatcst (gdb_byte expelt[16]) 2765796c8dcSSimon Schubert { 2775796c8dcSSimon Schubert union exp_element tmp; 2785796c8dcSSimon Schubert int index; 2795796c8dcSSimon Schubert 2805796c8dcSSimon Schubert for (index = 0; index < 16; index++) 2815796c8dcSSimon Schubert tmp.decfloatconst[index] = expelt[index]; 2825796c8dcSSimon Schubert 2835796c8dcSSimon Schubert write_exp_elt (tmp); 2845796c8dcSSimon Schubert } 2855796c8dcSSimon Schubert 2865796c8dcSSimon Schubert void 2875796c8dcSSimon Schubert write_exp_elt_type (struct type *expelt) 2885796c8dcSSimon Schubert { 2895796c8dcSSimon Schubert union exp_element tmp; 290*cf7f2e2dSJohn Marino 2915796c8dcSSimon Schubert memset (&tmp, 0, sizeof (union exp_element)); 2925796c8dcSSimon Schubert tmp.type = expelt; 2935796c8dcSSimon Schubert write_exp_elt (tmp); 2945796c8dcSSimon Schubert } 2955796c8dcSSimon Schubert 2965796c8dcSSimon Schubert void 2975796c8dcSSimon Schubert write_exp_elt_intern (struct internalvar *expelt) 2985796c8dcSSimon Schubert { 2995796c8dcSSimon Schubert union exp_element tmp; 300*cf7f2e2dSJohn Marino 3015796c8dcSSimon Schubert memset (&tmp, 0, sizeof (union exp_element)); 3025796c8dcSSimon Schubert tmp.internalvar = expelt; 3035796c8dcSSimon Schubert write_exp_elt (tmp); 3045796c8dcSSimon Schubert } 3055796c8dcSSimon Schubert 3065796c8dcSSimon Schubert /* Add a string constant to the end of the expression. 3075796c8dcSSimon Schubert 3085796c8dcSSimon Schubert String constants are stored by first writing an expression element 3095796c8dcSSimon Schubert that contains the length of the string, then stuffing the string 3105796c8dcSSimon Schubert constant itself into however many expression elements are needed 3115796c8dcSSimon Schubert to hold it, and then writing another expression element that contains 3125796c8dcSSimon Schubert the length of the string. I.E. an expression element at each end of 3135796c8dcSSimon Schubert the string records the string length, so you can skip over the 3145796c8dcSSimon Schubert expression elements containing the actual string bytes from either 3155796c8dcSSimon Schubert end of the string. Note that this also allows gdb to handle 3165796c8dcSSimon Schubert strings with embedded null bytes, as is required for some languages. 3175796c8dcSSimon Schubert 3185796c8dcSSimon Schubert Don't be fooled by the fact that the string is null byte terminated, 3195796c8dcSSimon Schubert this is strictly for the convenience of debugging gdb itself. 3205796c8dcSSimon Schubert Gdb does not depend up the string being null terminated, since the 3215796c8dcSSimon Schubert actual length is recorded in expression elements at each end of the 3225796c8dcSSimon Schubert string. The null byte is taken into consideration when computing how 3235796c8dcSSimon Schubert many expression elements are required to hold the string constant, of 3245796c8dcSSimon Schubert course. */ 3255796c8dcSSimon Schubert 3265796c8dcSSimon Schubert 3275796c8dcSSimon Schubert void 3285796c8dcSSimon Schubert write_exp_string (struct stoken str) 3295796c8dcSSimon Schubert { 3305796c8dcSSimon Schubert int len = str.length; 3315796c8dcSSimon Schubert int lenelt; 3325796c8dcSSimon Schubert char *strdata; 3335796c8dcSSimon Schubert 3345796c8dcSSimon Schubert /* Compute the number of expression elements required to hold the string 3355796c8dcSSimon Schubert (including a null byte terminator), along with one expression element 3365796c8dcSSimon Schubert at each end to record the actual string length (not including the 3375796c8dcSSimon Schubert null byte terminator). */ 3385796c8dcSSimon Schubert 3395796c8dcSSimon Schubert lenelt = 2 + BYTES_TO_EXP_ELEM (len + 1); 3405796c8dcSSimon Schubert 3415796c8dcSSimon Schubert /* Ensure that we have enough available expression elements to store 3425796c8dcSSimon Schubert everything. */ 3435796c8dcSSimon Schubert 3445796c8dcSSimon Schubert if ((expout_ptr + lenelt) >= expout_size) 3455796c8dcSSimon Schubert { 3465796c8dcSSimon Schubert expout_size = max (expout_size * 2, expout_ptr + lenelt + 10); 3475796c8dcSSimon Schubert expout = (struct expression *) 3485796c8dcSSimon Schubert xrealloc ((char *) expout, (sizeof (struct expression) 3495796c8dcSSimon Schubert + EXP_ELEM_TO_BYTES (expout_size))); 3505796c8dcSSimon Schubert } 3515796c8dcSSimon Schubert 3525796c8dcSSimon Schubert /* Write the leading length expression element (which advances the current 3535796c8dcSSimon Schubert expression element index), then write the string constant followed by a 3545796c8dcSSimon Schubert terminating null byte, and then write the trailing length expression 3555796c8dcSSimon Schubert element. */ 3565796c8dcSSimon Schubert 3575796c8dcSSimon Schubert write_exp_elt_longcst ((LONGEST) len); 3585796c8dcSSimon Schubert strdata = (char *) &expout->elts[expout_ptr]; 3595796c8dcSSimon Schubert memcpy (strdata, str.ptr, len); 3605796c8dcSSimon Schubert *(strdata + len) = '\0'; 3615796c8dcSSimon Schubert expout_ptr += lenelt - 2; 3625796c8dcSSimon Schubert write_exp_elt_longcst ((LONGEST) len); 3635796c8dcSSimon Schubert } 3645796c8dcSSimon Schubert 3655796c8dcSSimon Schubert /* Add a vector of string constants to the end of the expression. 3665796c8dcSSimon Schubert 3675796c8dcSSimon Schubert This adds an OP_STRING operation, but encodes the contents 3685796c8dcSSimon Schubert differently from write_exp_string. The language is expected to 3695796c8dcSSimon Schubert handle evaluation of this expression itself. 3705796c8dcSSimon Schubert 3715796c8dcSSimon Schubert After the usual OP_STRING header, TYPE is written into the 3725796c8dcSSimon Schubert expression as a long constant. The interpretation of this field is 3735796c8dcSSimon Schubert up to the language evaluator. 3745796c8dcSSimon Schubert 3755796c8dcSSimon Schubert Next, each string in VEC is written. The length is written as a 3765796c8dcSSimon Schubert long constant, followed by the contents of the string. */ 3775796c8dcSSimon Schubert 3785796c8dcSSimon Schubert void 3795796c8dcSSimon Schubert write_exp_string_vector (int type, struct stoken_vector *vec) 3805796c8dcSSimon Schubert { 3815796c8dcSSimon Schubert int i, n_slots, len; 3825796c8dcSSimon Schubert 3835796c8dcSSimon Schubert /* Compute the size. We compute the size in number of slots to 3845796c8dcSSimon Schubert avoid issues with string padding. */ 3855796c8dcSSimon Schubert n_slots = 0; 3865796c8dcSSimon Schubert for (i = 0; i < vec->len; ++i) 3875796c8dcSSimon Schubert { 3885796c8dcSSimon Schubert /* One slot for the length of this element, plus the number of 3895796c8dcSSimon Schubert slots needed for this string. */ 3905796c8dcSSimon Schubert n_slots += 1 + BYTES_TO_EXP_ELEM (vec->tokens[i].length); 3915796c8dcSSimon Schubert } 3925796c8dcSSimon Schubert 3935796c8dcSSimon Schubert /* One more slot for the type of the string. */ 3945796c8dcSSimon Schubert ++n_slots; 3955796c8dcSSimon Schubert 3965796c8dcSSimon Schubert /* Now compute a phony string length. */ 3975796c8dcSSimon Schubert len = EXP_ELEM_TO_BYTES (n_slots) - 1; 3985796c8dcSSimon Schubert 3995796c8dcSSimon Schubert n_slots += 4; 4005796c8dcSSimon Schubert if ((expout_ptr + n_slots) >= expout_size) 4015796c8dcSSimon Schubert { 4025796c8dcSSimon Schubert expout_size = max (expout_size * 2, expout_ptr + n_slots + 10); 4035796c8dcSSimon Schubert expout = (struct expression *) 4045796c8dcSSimon Schubert xrealloc ((char *) expout, (sizeof (struct expression) 4055796c8dcSSimon Schubert + EXP_ELEM_TO_BYTES (expout_size))); 4065796c8dcSSimon Schubert } 4075796c8dcSSimon Schubert 4085796c8dcSSimon Schubert write_exp_elt_opcode (OP_STRING); 4095796c8dcSSimon Schubert write_exp_elt_longcst (len); 4105796c8dcSSimon Schubert write_exp_elt_longcst (type); 4115796c8dcSSimon Schubert 4125796c8dcSSimon Schubert for (i = 0; i < vec->len; ++i) 4135796c8dcSSimon Schubert { 4145796c8dcSSimon Schubert write_exp_elt_longcst (vec->tokens[i].length); 4155796c8dcSSimon Schubert memcpy (&expout->elts[expout_ptr], vec->tokens[i].ptr, 4165796c8dcSSimon Schubert vec->tokens[i].length); 4175796c8dcSSimon Schubert expout_ptr += BYTES_TO_EXP_ELEM (vec->tokens[i].length); 4185796c8dcSSimon Schubert } 4195796c8dcSSimon Schubert 4205796c8dcSSimon Schubert write_exp_elt_longcst (len); 4215796c8dcSSimon Schubert write_exp_elt_opcode (OP_STRING); 4225796c8dcSSimon Schubert } 4235796c8dcSSimon Schubert 4245796c8dcSSimon Schubert /* Add a bitstring constant to the end of the expression. 4255796c8dcSSimon Schubert 4265796c8dcSSimon Schubert Bitstring constants are stored by first writing an expression element 4275796c8dcSSimon Schubert that contains the length of the bitstring (in bits), then stuffing the 4285796c8dcSSimon Schubert bitstring constant itself into however many expression elements are 4295796c8dcSSimon Schubert needed to hold it, and then writing another expression element that 4305796c8dcSSimon Schubert contains the length of the bitstring. I.E. an expression element at 4315796c8dcSSimon Schubert each end of the bitstring records the bitstring length, so you can skip 4325796c8dcSSimon Schubert over the expression elements containing the actual bitstring bytes from 4335796c8dcSSimon Schubert either end of the bitstring. */ 4345796c8dcSSimon Schubert 4355796c8dcSSimon Schubert void 4365796c8dcSSimon Schubert write_exp_bitstring (struct stoken str) 4375796c8dcSSimon Schubert { 4385796c8dcSSimon Schubert int bits = str.length; /* length in bits */ 4395796c8dcSSimon Schubert int len = (bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT; 4405796c8dcSSimon Schubert int lenelt; 4415796c8dcSSimon Schubert char *strdata; 4425796c8dcSSimon Schubert 4435796c8dcSSimon Schubert /* Compute the number of expression elements required to hold the bitstring, 4445796c8dcSSimon Schubert along with one expression element at each end to record the actual 4455796c8dcSSimon Schubert bitstring length in bits. */ 4465796c8dcSSimon Schubert 4475796c8dcSSimon Schubert lenelt = 2 + BYTES_TO_EXP_ELEM (len); 4485796c8dcSSimon Schubert 4495796c8dcSSimon Schubert /* Ensure that we have enough available expression elements to store 4505796c8dcSSimon Schubert everything. */ 4515796c8dcSSimon Schubert 4525796c8dcSSimon Schubert if ((expout_ptr + lenelt) >= expout_size) 4535796c8dcSSimon Schubert { 4545796c8dcSSimon Schubert expout_size = max (expout_size * 2, expout_ptr + lenelt + 10); 4555796c8dcSSimon Schubert expout = (struct expression *) 4565796c8dcSSimon Schubert xrealloc ((char *) expout, (sizeof (struct expression) 4575796c8dcSSimon Schubert + EXP_ELEM_TO_BYTES (expout_size))); 4585796c8dcSSimon Schubert } 4595796c8dcSSimon Schubert 4605796c8dcSSimon Schubert /* Write the leading length expression element (which advances the current 4615796c8dcSSimon Schubert expression element index), then write the bitstring constant, and then 4625796c8dcSSimon Schubert write the trailing length expression element. */ 4635796c8dcSSimon Schubert 4645796c8dcSSimon Schubert write_exp_elt_longcst ((LONGEST) bits); 4655796c8dcSSimon Schubert strdata = (char *) &expout->elts[expout_ptr]; 4665796c8dcSSimon Schubert memcpy (strdata, str.ptr, len); 4675796c8dcSSimon Schubert expout_ptr += lenelt - 2; 4685796c8dcSSimon Schubert write_exp_elt_longcst ((LONGEST) bits); 4695796c8dcSSimon Schubert } 4705796c8dcSSimon Schubert 4715796c8dcSSimon Schubert /* Add the appropriate elements for a minimal symbol to the end of 4725796c8dcSSimon Schubert the expression. */ 4735796c8dcSSimon Schubert 4745796c8dcSSimon Schubert void 4755796c8dcSSimon Schubert write_exp_msymbol (struct minimal_symbol *msymbol) 4765796c8dcSSimon Schubert { 4775796c8dcSSimon Schubert struct objfile *objfile = msymbol_objfile (msymbol); 4785796c8dcSSimon Schubert struct gdbarch *gdbarch = get_objfile_arch (objfile); 4795796c8dcSSimon Schubert 4805796c8dcSSimon Schubert CORE_ADDR addr = SYMBOL_VALUE_ADDRESS (msymbol); 4815796c8dcSSimon Schubert struct obj_section *section = SYMBOL_OBJ_SECTION (msymbol); 4825796c8dcSSimon Schubert enum minimal_symbol_type type = MSYMBOL_TYPE (msymbol); 4835796c8dcSSimon Schubert CORE_ADDR pc; 4845796c8dcSSimon Schubert 4855796c8dcSSimon Schubert /* The minimal symbol might point to a function descriptor; 4865796c8dcSSimon Schubert resolve it to the actual code address instead. */ 4875796c8dcSSimon Schubert pc = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, ¤t_target); 4885796c8dcSSimon Schubert if (pc != addr) 4895796c8dcSSimon Schubert { 4905796c8dcSSimon Schubert /* In this case, assume we have a code symbol instead of 4915796c8dcSSimon Schubert a data symbol. */ 4925796c8dcSSimon Schubert type = mst_text; 4935796c8dcSSimon Schubert section = NULL; 4945796c8dcSSimon Schubert addr = pc; 4955796c8dcSSimon Schubert } 4965796c8dcSSimon Schubert 4975796c8dcSSimon Schubert if (overlay_debugging) 4985796c8dcSSimon Schubert addr = symbol_overlayed_address (addr, section); 4995796c8dcSSimon Schubert 5005796c8dcSSimon Schubert write_exp_elt_opcode (OP_LONG); 5015796c8dcSSimon Schubert /* Let's make the type big enough to hold a 64-bit address. */ 5025796c8dcSSimon Schubert write_exp_elt_type (objfile_type (objfile)->builtin_core_addr); 5035796c8dcSSimon Schubert write_exp_elt_longcst ((LONGEST) addr); 5045796c8dcSSimon Schubert write_exp_elt_opcode (OP_LONG); 5055796c8dcSSimon Schubert 5065796c8dcSSimon Schubert if (section && section->the_bfd_section->flags & SEC_THREAD_LOCAL) 5075796c8dcSSimon Schubert { 5085796c8dcSSimon Schubert write_exp_elt_opcode (UNOP_MEMVAL_TLS); 5095796c8dcSSimon Schubert write_exp_elt_objfile (objfile); 5105796c8dcSSimon Schubert write_exp_elt_type (objfile_type (objfile)->nodebug_tls_symbol); 5115796c8dcSSimon Schubert write_exp_elt_opcode (UNOP_MEMVAL_TLS); 5125796c8dcSSimon Schubert return; 5135796c8dcSSimon Schubert } 5145796c8dcSSimon Schubert 5155796c8dcSSimon Schubert write_exp_elt_opcode (UNOP_MEMVAL); 5165796c8dcSSimon Schubert switch (type) 5175796c8dcSSimon Schubert { 5185796c8dcSSimon Schubert case mst_text: 5195796c8dcSSimon Schubert case mst_file_text: 5205796c8dcSSimon Schubert case mst_solib_trampoline: 5215796c8dcSSimon Schubert write_exp_elt_type (objfile_type (objfile)->nodebug_text_symbol); 5225796c8dcSSimon Schubert break; 5235796c8dcSSimon Schubert 5245796c8dcSSimon Schubert case mst_data: 5255796c8dcSSimon Schubert case mst_file_data: 5265796c8dcSSimon Schubert case mst_bss: 5275796c8dcSSimon Schubert case mst_file_bss: 5285796c8dcSSimon Schubert write_exp_elt_type (objfile_type (objfile)->nodebug_data_symbol); 5295796c8dcSSimon Schubert break; 5305796c8dcSSimon Schubert 5315796c8dcSSimon Schubert default: 5325796c8dcSSimon Schubert write_exp_elt_type (objfile_type (objfile)->nodebug_unknown_symbol); 5335796c8dcSSimon Schubert break; 5345796c8dcSSimon Schubert } 5355796c8dcSSimon Schubert write_exp_elt_opcode (UNOP_MEMVAL); 5365796c8dcSSimon Schubert } 5375796c8dcSSimon Schubert 5385796c8dcSSimon Schubert /* Mark the current index as the starting location of a structure 5395796c8dcSSimon Schubert expression. This is used when completing on field names. */ 5405796c8dcSSimon Schubert 5415796c8dcSSimon Schubert void 5425796c8dcSSimon Schubert mark_struct_expression (void) 5435796c8dcSSimon Schubert { 5445796c8dcSSimon Schubert expout_last_struct = expout_ptr; 5455796c8dcSSimon Schubert } 5465796c8dcSSimon Schubert 5475796c8dcSSimon Schubert 5485796c8dcSSimon Schubert /* Recognize tokens that start with '$'. These include: 5495796c8dcSSimon Schubert 5505796c8dcSSimon Schubert $regname A native register name or a "standard 5515796c8dcSSimon Schubert register name". 5525796c8dcSSimon Schubert 5535796c8dcSSimon Schubert $variable A convenience variable with a name chosen 5545796c8dcSSimon Schubert by the user. 5555796c8dcSSimon Schubert 5565796c8dcSSimon Schubert $digits Value history with index <digits>, starting 5575796c8dcSSimon Schubert from the first value which has index 1. 5585796c8dcSSimon Schubert 5595796c8dcSSimon Schubert $$digits Value history with index <digits> relative 5605796c8dcSSimon Schubert to the last value. I.E. $$0 is the last 5615796c8dcSSimon Schubert value, $$1 is the one previous to that, $$2 5625796c8dcSSimon Schubert is the one previous to $$1, etc. 5635796c8dcSSimon Schubert 5645796c8dcSSimon Schubert $ | $0 | $$0 The last value in the value history. 5655796c8dcSSimon Schubert 5665796c8dcSSimon Schubert $$ An abbreviation for the second to the last 5675796c8dcSSimon Schubert value in the value history, I.E. $$1 5685796c8dcSSimon Schubert 5695796c8dcSSimon Schubert */ 5705796c8dcSSimon Schubert 5715796c8dcSSimon Schubert void 5725796c8dcSSimon Schubert write_dollar_variable (struct stoken str) 5735796c8dcSSimon Schubert { 5745796c8dcSSimon Schubert struct symbol *sym = NULL; 5755796c8dcSSimon Schubert struct minimal_symbol *msym = NULL; 5765796c8dcSSimon Schubert struct internalvar *isym = NULL; 5775796c8dcSSimon Schubert 5785796c8dcSSimon Schubert /* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1) 5795796c8dcSSimon Schubert and $$digits (equivalent to $<-digits> if you could type that). */ 5805796c8dcSSimon Schubert 5815796c8dcSSimon Schubert int negate = 0; 5825796c8dcSSimon Schubert int i = 1; 5835796c8dcSSimon Schubert /* Double dollar means negate the number and add -1 as well. 5845796c8dcSSimon Schubert Thus $$ alone means -1. */ 5855796c8dcSSimon Schubert if (str.length >= 2 && str.ptr[1] == '$') 5865796c8dcSSimon Schubert { 5875796c8dcSSimon Schubert negate = 1; 5885796c8dcSSimon Schubert i = 2; 5895796c8dcSSimon Schubert } 5905796c8dcSSimon Schubert if (i == str.length) 5915796c8dcSSimon Schubert { 5925796c8dcSSimon Schubert /* Just dollars (one or two) */ 5935796c8dcSSimon Schubert i = -negate; 5945796c8dcSSimon Schubert goto handle_last; 5955796c8dcSSimon Schubert } 5965796c8dcSSimon Schubert /* Is the rest of the token digits? */ 5975796c8dcSSimon Schubert for (; i < str.length; i++) 5985796c8dcSSimon Schubert if (!(str.ptr[i] >= '0' && str.ptr[i] <= '9')) 5995796c8dcSSimon Schubert break; 6005796c8dcSSimon Schubert if (i == str.length) 6015796c8dcSSimon Schubert { 6025796c8dcSSimon Schubert i = atoi (str.ptr + 1 + negate); 6035796c8dcSSimon Schubert if (negate) 6045796c8dcSSimon Schubert i = -i; 6055796c8dcSSimon Schubert goto handle_last; 6065796c8dcSSimon Schubert } 6075796c8dcSSimon Schubert 6085796c8dcSSimon Schubert /* Handle tokens that refer to machine registers: 6095796c8dcSSimon Schubert $ followed by a register name. */ 6105796c8dcSSimon Schubert i = user_reg_map_name_to_regnum (parse_gdbarch, 6115796c8dcSSimon Schubert str.ptr + 1, str.length - 1); 6125796c8dcSSimon Schubert if (i >= 0) 6135796c8dcSSimon Schubert goto handle_register; 6145796c8dcSSimon Schubert 6155796c8dcSSimon Schubert /* Any names starting with $ are probably debugger internal variables. */ 6165796c8dcSSimon Schubert 6175796c8dcSSimon Schubert isym = lookup_only_internalvar (copy_name (str) + 1); 6185796c8dcSSimon Schubert if (isym) 6195796c8dcSSimon Schubert { 6205796c8dcSSimon Schubert write_exp_elt_opcode (OP_INTERNALVAR); 6215796c8dcSSimon Schubert write_exp_elt_intern (isym); 6225796c8dcSSimon Schubert write_exp_elt_opcode (OP_INTERNALVAR); 6235796c8dcSSimon Schubert return; 6245796c8dcSSimon Schubert } 6255796c8dcSSimon Schubert 6265796c8dcSSimon Schubert /* On some systems, such as HP-UX and hppa-linux, certain system routines 6275796c8dcSSimon Schubert have names beginning with $ or $$. Check for those, first. */ 6285796c8dcSSimon Schubert 6295796c8dcSSimon Schubert sym = lookup_symbol (copy_name (str), (struct block *) NULL, 6305796c8dcSSimon Schubert VAR_DOMAIN, (int *) NULL); 6315796c8dcSSimon Schubert if (sym) 6325796c8dcSSimon Schubert { 6335796c8dcSSimon Schubert write_exp_elt_opcode (OP_VAR_VALUE); 6345796c8dcSSimon Schubert write_exp_elt_block (block_found); /* set by lookup_symbol */ 6355796c8dcSSimon Schubert write_exp_elt_sym (sym); 6365796c8dcSSimon Schubert write_exp_elt_opcode (OP_VAR_VALUE); 6375796c8dcSSimon Schubert return; 6385796c8dcSSimon Schubert } 6395796c8dcSSimon Schubert msym = lookup_minimal_symbol (copy_name (str), NULL, NULL); 6405796c8dcSSimon Schubert if (msym) 6415796c8dcSSimon Schubert { 6425796c8dcSSimon Schubert write_exp_msymbol (msym); 6435796c8dcSSimon Schubert return; 6445796c8dcSSimon Schubert } 6455796c8dcSSimon Schubert 6465796c8dcSSimon Schubert /* Any other names are assumed to be debugger internal variables. */ 6475796c8dcSSimon Schubert 6485796c8dcSSimon Schubert write_exp_elt_opcode (OP_INTERNALVAR); 6495796c8dcSSimon Schubert write_exp_elt_intern (create_internalvar (copy_name (str) + 1)); 6505796c8dcSSimon Schubert write_exp_elt_opcode (OP_INTERNALVAR); 6515796c8dcSSimon Schubert return; 6525796c8dcSSimon Schubert handle_last: 6535796c8dcSSimon Schubert write_exp_elt_opcode (OP_LAST); 6545796c8dcSSimon Schubert write_exp_elt_longcst ((LONGEST) i); 6555796c8dcSSimon Schubert write_exp_elt_opcode (OP_LAST); 6565796c8dcSSimon Schubert return; 6575796c8dcSSimon Schubert handle_register: 6585796c8dcSSimon Schubert write_exp_elt_opcode (OP_REGISTER); 6595796c8dcSSimon Schubert str.length--; 6605796c8dcSSimon Schubert str.ptr++; 6615796c8dcSSimon Schubert write_exp_string (str); 6625796c8dcSSimon Schubert write_exp_elt_opcode (OP_REGISTER); 6635796c8dcSSimon Schubert return; 6645796c8dcSSimon Schubert } 6655796c8dcSSimon Schubert 6665796c8dcSSimon Schubert 6675796c8dcSSimon Schubert char * 6685796c8dcSSimon Schubert find_template_name_end (char *p) 6695796c8dcSSimon Schubert { 6705796c8dcSSimon Schubert int depth = 1; 6715796c8dcSSimon Schubert int just_seen_right = 0; 6725796c8dcSSimon Schubert int just_seen_colon = 0; 6735796c8dcSSimon Schubert int just_seen_space = 0; 6745796c8dcSSimon Schubert 6755796c8dcSSimon Schubert if (!p || (*p != '<')) 6765796c8dcSSimon Schubert return 0; 6775796c8dcSSimon Schubert 6785796c8dcSSimon Schubert while (*++p) 6795796c8dcSSimon Schubert { 6805796c8dcSSimon Schubert switch (*p) 6815796c8dcSSimon Schubert { 6825796c8dcSSimon Schubert case '\'': 6835796c8dcSSimon Schubert case '\"': 6845796c8dcSSimon Schubert case '{': 6855796c8dcSSimon Schubert case '}': 6865796c8dcSSimon Schubert /* In future, may want to allow these?? */ 6875796c8dcSSimon Schubert return 0; 6885796c8dcSSimon Schubert case '<': 6895796c8dcSSimon Schubert depth++; /* start nested template */ 6905796c8dcSSimon Schubert if (just_seen_colon || just_seen_right || just_seen_space) 6915796c8dcSSimon Schubert return 0; /* but not after : or :: or > or space */ 6925796c8dcSSimon Schubert break; 6935796c8dcSSimon Schubert case '>': 6945796c8dcSSimon Schubert if (just_seen_colon || just_seen_right) 6955796c8dcSSimon Schubert return 0; /* end a (nested?) template */ 6965796c8dcSSimon Schubert just_seen_right = 1; /* but not after : or :: */ 6975796c8dcSSimon Schubert if (--depth == 0) /* also disallow >>, insist on > > */ 6985796c8dcSSimon Schubert return ++p; /* if outermost ended, return */ 6995796c8dcSSimon Schubert break; 7005796c8dcSSimon Schubert case ':': 7015796c8dcSSimon Schubert if (just_seen_space || (just_seen_colon > 1)) 7025796c8dcSSimon Schubert return 0; /* nested class spec coming up */ 7035796c8dcSSimon Schubert just_seen_colon++; /* we allow :: but not :::: */ 7045796c8dcSSimon Schubert break; 7055796c8dcSSimon Schubert case ' ': 7065796c8dcSSimon Schubert break; 7075796c8dcSSimon Schubert default: 7085796c8dcSSimon Schubert if (!((*p >= 'a' && *p <= 'z') || /* allow token chars */ 7095796c8dcSSimon Schubert (*p >= 'A' && *p <= 'Z') || 7105796c8dcSSimon Schubert (*p >= '0' && *p <= '9') || 7115796c8dcSSimon Schubert (*p == '_') || (*p == ',') || /* commas for template args */ 7125796c8dcSSimon Schubert (*p == '&') || (*p == '*') || /* pointer and ref types */ 7135796c8dcSSimon Schubert (*p == '(') || (*p == ')') || /* function types */ 7145796c8dcSSimon Schubert (*p == '[') || (*p == ']'))) /* array types */ 7155796c8dcSSimon Schubert return 0; 7165796c8dcSSimon Schubert } 7175796c8dcSSimon Schubert if (*p != ' ') 7185796c8dcSSimon Schubert just_seen_space = 0; 7195796c8dcSSimon Schubert if (*p != ':') 7205796c8dcSSimon Schubert just_seen_colon = 0; 7215796c8dcSSimon Schubert if (*p != '>') 7225796c8dcSSimon Schubert just_seen_right = 0; 7235796c8dcSSimon Schubert } 7245796c8dcSSimon Schubert return 0; 7255796c8dcSSimon Schubert } 7265796c8dcSSimon Schubert 7275796c8dcSSimon Schubert 7285796c8dcSSimon Schubert 7295796c8dcSSimon Schubert /* Return a null-terminated temporary copy of the name 7305796c8dcSSimon Schubert of a string token. */ 7315796c8dcSSimon Schubert 7325796c8dcSSimon Schubert char * 7335796c8dcSSimon Schubert copy_name (struct stoken token) 7345796c8dcSSimon Schubert { 7355796c8dcSSimon Schubert /* Make sure there's enough space for the token. */ 7365796c8dcSSimon Schubert if (namecopy_size < token.length + 1) 7375796c8dcSSimon Schubert { 7385796c8dcSSimon Schubert namecopy_size = token.length + 1; 7395796c8dcSSimon Schubert namecopy = xrealloc (namecopy, token.length + 1); 7405796c8dcSSimon Schubert } 7415796c8dcSSimon Schubert 7425796c8dcSSimon Schubert memcpy (namecopy, token.ptr, token.length); 7435796c8dcSSimon Schubert namecopy[token.length] = 0; 7445796c8dcSSimon Schubert 7455796c8dcSSimon Schubert return namecopy; 7465796c8dcSSimon Schubert } 7475796c8dcSSimon Schubert 7485796c8dcSSimon Schubert /* Reverse an expression from suffix form (in which it is constructed) 7495796c8dcSSimon Schubert to prefix form (in which we can conveniently print or execute it). 7505796c8dcSSimon Schubert Ordinarily this always returns -1. However, if EXPOUT_LAST_STRUCT 7515796c8dcSSimon Schubert is not -1 (i.e., we are trying to complete a field name), it will 7525796c8dcSSimon Schubert return the index of the subexpression which is the left-hand-side 7535796c8dcSSimon Schubert of the struct operation at EXPOUT_LAST_STRUCT. */ 7545796c8dcSSimon Schubert 7555796c8dcSSimon Schubert static int 7565796c8dcSSimon Schubert prefixify_expression (struct expression *expr) 7575796c8dcSSimon Schubert { 7585796c8dcSSimon Schubert int len = sizeof (struct expression) + EXP_ELEM_TO_BYTES (expr->nelts); 7595796c8dcSSimon Schubert struct expression *temp; 7605796c8dcSSimon Schubert int inpos = expr->nelts, outpos = 0; 7615796c8dcSSimon Schubert 7625796c8dcSSimon Schubert temp = (struct expression *) alloca (len); 7635796c8dcSSimon Schubert 7645796c8dcSSimon Schubert /* Copy the original expression into temp. */ 7655796c8dcSSimon Schubert memcpy (temp, expr, len); 7665796c8dcSSimon Schubert 7675796c8dcSSimon Schubert return prefixify_subexp (temp, expr, inpos, outpos); 7685796c8dcSSimon Schubert } 7695796c8dcSSimon Schubert 7705796c8dcSSimon Schubert /* Return the number of exp_elements in the postfix subexpression 7715796c8dcSSimon Schubert of EXPR whose operator is at index ENDPOS - 1 in EXPR. */ 7725796c8dcSSimon Schubert 7735796c8dcSSimon Schubert int 7745796c8dcSSimon Schubert length_of_subexp (struct expression *expr, int endpos) 7755796c8dcSSimon Schubert { 776*cf7f2e2dSJohn Marino int oplen, args; 7775796c8dcSSimon Schubert 7785796c8dcSSimon Schubert operator_length (expr, endpos, &oplen, &args); 7795796c8dcSSimon Schubert 7805796c8dcSSimon Schubert while (args > 0) 7815796c8dcSSimon Schubert { 7825796c8dcSSimon Schubert oplen += length_of_subexp (expr, endpos - oplen); 7835796c8dcSSimon Schubert args--; 7845796c8dcSSimon Schubert } 7855796c8dcSSimon Schubert 7865796c8dcSSimon Schubert return oplen; 7875796c8dcSSimon Schubert } 7885796c8dcSSimon Schubert 7895796c8dcSSimon Schubert /* Sets *OPLENP to the length of the operator whose (last) index is 7905796c8dcSSimon Schubert ENDPOS - 1 in EXPR, and sets *ARGSP to the number of arguments that 7915796c8dcSSimon Schubert operator takes. */ 7925796c8dcSSimon Schubert 7935796c8dcSSimon Schubert void 794*cf7f2e2dSJohn Marino operator_length (const struct expression *expr, int endpos, int *oplenp, 795*cf7f2e2dSJohn Marino int *argsp) 7965796c8dcSSimon Schubert { 7975796c8dcSSimon Schubert expr->language_defn->la_exp_desc->operator_length (expr, endpos, 7985796c8dcSSimon Schubert oplenp, argsp); 7995796c8dcSSimon Schubert } 8005796c8dcSSimon Schubert 8015796c8dcSSimon Schubert /* Default value for operator_length in exp_descriptor vectors. */ 8025796c8dcSSimon Schubert 8035796c8dcSSimon Schubert void 804*cf7f2e2dSJohn Marino operator_length_standard (const struct expression *expr, int endpos, 8055796c8dcSSimon Schubert int *oplenp, int *argsp) 8065796c8dcSSimon Schubert { 8075796c8dcSSimon Schubert int oplen = 1; 8085796c8dcSSimon Schubert int args = 0; 8095796c8dcSSimon Schubert enum f90_range_type range_type; 8105796c8dcSSimon Schubert int i; 8115796c8dcSSimon Schubert 8125796c8dcSSimon Schubert if (endpos < 1) 8135796c8dcSSimon Schubert error (_("?error in operator_length_standard")); 8145796c8dcSSimon Schubert 8155796c8dcSSimon Schubert i = (int) expr->elts[endpos - 1].opcode; 8165796c8dcSSimon Schubert 8175796c8dcSSimon Schubert switch (i) 8185796c8dcSSimon Schubert { 8195796c8dcSSimon Schubert /* C++ */ 8205796c8dcSSimon Schubert case OP_SCOPE: 8215796c8dcSSimon Schubert oplen = longest_to_int (expr->elts[endpos - 2].longconst); 8225796c8dcSSimon Schubert oplen = 5 + BYTES_TO_EXP_ELEM (oplen + 1); 8235796c8dcSSimon Schubert break; 8245796c8dcSSimon Schubert 8255796c8dcSSimon Schubert case OP_LONG: 8265796c8dcSSimon Schubert case OP_DOUBLE: 8275796c8dcSSimon Schubert case OP_DECFLOAT: 8285796c8dcSSimon Schubert case OP_VAR_VALUE: 8295796c8dcSSimon Schubert oplen = 4; 8305796c8dcSSimon Schubert break; 8315796c8dcSSimon Schubert 8325796c8dcSSimon Schubert case OP_TYPE: 8335796c8dcSSimon Schubert case OP_BOOL: 8345796c8dcSSimon Schubert case OP_LAST: 8355796c8dcSSimon Schubert case OP_INTERNALVAR: 8365796c8dcSSimon Schubert oplen = 3; 8375796c8dcSSimon Schubert break; 8385796c8dcSSimon Schubert 8395796c8dcSSimon Schubert case OP_COMPLEX: 8405796c8dcSSimon Schubert oplen = 3; 8415796c8dcSSimon Schubert args = 2; 8425796c8dcSSimon Schubert break; 8435796c8dcSSimon Schubert 8445796c8dcSSimon Schubert case OP_FUNCALL: 8455796c8dcSSimon Schubert case OP_F77_UNDETERMINED_ARGLIST: 8465796c8dcSSimon Schubert oplen = 3; 8475796c8dcSSimon Schubert args = 1 + longest_to_int (expr->elts[endpos - 2].longconst); 8485796c8dcSSimon Schubert break; 8495796c8dcSSimon Schubert 850*cf7f2e2dSJohn Marino case TYPE_INSTANCE: 851*cf7f2e2dSJohn Marino oplen = 4 + longest_to_int (expr->elts[endpos - 2].longconst); 852*cf7f2e2dSJohn Marino args = 1; 853*cf7f2e2dSJohn Marino break; 854*cf7f2e2dSJohn Marino 8555796c8dcSSimon Schubert case OP_OBJC_MSGCALL: /* Objective C message (method) call */ 8565796c8dcSSimon Schubert oplen = 4; 8575796c8dcSSimon Schubert args = 1 + longest_to_int (expr->elts[endpos - 2].longconst); 8585796c8dcSSimon Schubert break; 8595796c8dcSSimon Schubert 8605796c8dcSSimon Schubert case UNOP_MAX: 8615796c8dcSSimon Schubert case UNOP_MIN: 8625796c8dcSSimon Schubert oplen = 3; 8635796c8dcSSimon Schubert break; 8645796c8dcSSimon Schubert 8655796c8dcSSimon Schubert case BINOP_VAL: 8665796c8dcSSimon Schubert case UNOP_CAST: 867*cf7f2e2dSJohn Marino case UNOP_DYNAMIC_CAST: 868*cf7f2e2dSJohn Marino case UNOP_REINTERPRET_CAST: 8695796c8dcSSimon Schubert case UNOP_MEMVAL: 8705796c8dcSSimon Schubert oplen = 3; 8715796c8dcSSimon Schubert args = 1; 8725796c8dcSSimon Schubert break; 8735796c8dcSSimon Schubert 8745796c8dcSSimon Schubert case UNOP_MEMVAL_TLS: 8755796c8dcSSimon Schubert oplen = 4; 8765796c8dcSSimon Schubert args = 1; 8775796c8dcSSimon Schubert break; 8785796c8dcSSimon Schubert 8795796c8dcSSimon Schubert case UNOP_ABS: 8805796c8dcSSimon Schubert case UNOP_CAP: 8815796c8dcSSimon Schubert case UNOP_CHR: 8825796c8dcSSimon Schubert case UNOP_FLOAT: 8835796c8dcSSimon Schubert case UNOP_HIGH: 8845796c8dcSSimon Schubert case UNOP_ODD: 8855796c8dcSSimon Schubert case UNOP_ORD: 8865796c8dcSSimon Schubert case UNOP_TRUNC: 8875796c8dcSSimon Schubert oplen = 1; 8885796c8dcSSimon Schubert args = 1; 8895796c8dcSSimon Schubert break; 8905796c8dcSSimon Schubert 891*cf7f2e2dSJohn Marino case OP_ADL_FUNC: 892*cf7f2e2dSJohn Marino oplen = longest_to_int (expr->elts[endpos - 2].longconst); 893*cf7f2e2dSJohn Marino oplen = 4 + BYTES_TO_EXP_ELEM (oplen + 1); 894*cf7f2e2dSJohn Marino oplen++; 895*cf7f2e2dSJohn Marino oplen++; 896*cf7f2e2dSJohn Marino break; 897*cf7f2e2dSJohn Marino 8985796c8dcSSimon Schubert case OP_LABELED: 8995796c8dcSSimon Schubert case STRUCTOP_STRUCT: 9005796c8dcSSimon Schubert case STRUCTOP_PTR: 9015796c8dcSSimon Schubert args = 1; 9025796c8dcSSimon Schubert /* fall through */ 9035796c8dcSSimon Schubert case OP_REGISTER: 9045796c8dcSSimon Schubert case OP_M2_STRING: 9055796c8dcSSimon Schubert case OP_STRING: 9065796c8dcSSimon Schubert case OP_OBJC_NSSTRING: /* Objective C Foundation Class NSString constant */ 9075796c8dcSSimon Schubert case OP_OBJC_SELECTOR: /* Objective C "@selector" pseudo-op */ 9085796c8dcSSimon Schubert case OP_NAME: 9095796c8dcSSimon Schubert oplen = longest_to_int (expr->elts[endpos - 2].longconst); 9105796c8dcSSimon Schubert oplen = 4 + BYTES_TO_EXP_ELEM (oplen + 1); 9115796c8dcSSimon Schubert break; 9125796c8dcSSimon Schubert 9135796c8dcSSimon Schubert case OP_BITSTRING: 9145796c8dcSSimon Schubert oplen = longest_to_int (expr->elts[endpos - 2].longconst); 9155796c8dcSSimon Schubert oplen = (oplen + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT; 9165796c8dcSSimon Schubert oplen = 4 + BYTES_TO_EXP_ELEM (oplen); 9175796c8dcSSimon Schubert break; 9185796c8dcSSimon Schubert 9195796c8dcSSimon Schubert case OP_ARRAY: 9205796c8dcSSimon Schubert oplen = 4; 9215796c8dcSSimon Schubert args = longest_to_int (expr->elts[endpos - 2].longconst); 9225796c8dcSSimon Schubert args -= longest_to_int (expr->elts[endpos - 3].longconst); 9235796c8dcSSimon Schubert args += 1; 9245796c8dcSSimon Schubert break; 9255796c8dcSSimon Schubert 9265796c8dcSSimon Schubert case TERNOP_COND: 9275796c8dcSSimon Schubert case TERNOP_SLICE: 9285796c8dcSSimon Schubert case TERNOP_SLICE_COUNT: 9295796c8dcSSimon Schubert args = 3; 9305796c8dcSSimon Schubert break; 9315796c8dcSSimon Schubert 9325796c8dcSSimon Schubert /* Modula-2 */ 9335796c8dcSSimon Schubert case MULTI_SUBSCRIPT: 9345796c8dcSSimon Schubert oplen = 3; 9355796c8dcSSimon Schubert args = 1 + longest_to_int (expr->elts[endpos - 2].longconst); 9365796c8dcSSimon Schubert break; 9375796c8dcSSimon Schubert 9385796c8dcSSimon Schubert case BINOP_ASSIGN_MODIFY: 9395796c8dcSSimon Schubert oplen = 3; 9405796c8dcSSimon Schubert args = 2; 9415796c8dcSSimon Schubert break; 9425796c8dcSSimon Schubert 9435796c8dcSSimon Schubert /* C++ */ 9445796c8dcSSimon Schubert case OP_THIS: 9455796c8dcSSimon Schubert case OP_OBJC_SELF: 9465796c8dcSSimon Schubert oplen = 2; 9475796c8dcSSimon Schubert break; 9485796c8dcSSimon Schubert 9495796c8dcSSimon Schubert case OP_F90_RANGE: 9505796c8dcSSimon Schubert oplen = 3; 9515796c8dcSSimon Schubert 9525796c8dcSSimon Schubert range_type = longest_to_int (expr->elts[endpos - 2].longconst); 9535796c8dcSSimon Schubert switch (range_type) 9545796c8dcSSimon Schubert { 9555796c8dcSSimon Schubert case LOW_BOUND_DEFAULT: 9565796c8dcSSimon Schubert case HIGH_BOUND_DEFAULT: 9575796c8dcSSimon Schubert args = 1; 9585796c8dcSSimon Schubert break; 9595796c8dcSSimon Schubert case BOTH_BOUND_DEFAULT: 9605796c8dcSSimon Schubert args = 0; 9615796c8dcSSimon Schubert break; 9625796c8dcSSimon Schubert case NONE_BOUND_DEFAULT: 9635796c8dcSSimon Schubert args = 2; 9645796c8dcSSimon Schubert break; 9655796c8dcSSimon Schubert } 9665796c8dcSSimon Schubert 9675796c8dcSSimon Schubert break; 9685796c8dcSSimon Schubert 9695796c8dcSSimon Schubert default: 9705796c8dcSSimon Schubert args = 1 + (i < (int) BINOP_END); 9715796c8dcSSimon Schubert } 9725796c8dcSSimon Schubert 9735796c8dcSSimon Schubert *oplenp = oplen; 9745796c8dcSSimon Schubert *argsp = args; 9755796c8dcSSimon Schubert } 9765796c8dcSSimon Schubert 9775796c8dcSSimon Schubert /* Copy the subexpression ending just before index INEND in INEXPR 9785796c8dcSSimon Schubert into OUTEXPR, starting at index OUTBEG. 9795796c8dcSSimon Schubert In the process, convert it from suffix to prefix form. 9805796c8dcSSimon Schubert If EXPOUT_LAST_STRUCT is -1, then this function always returns -1. 9815796c8dcSSimon Schubert Otherwise, it returns the index of the subexpression which is the 9825796c8dcSSimon Schubert left-hand-side of the expression at EXPOUT_LAST_STRUCT. */ 9835796c8dcSSimon Schubert 9845796c8dcSSimon Schubert static int 9855796c8dcSSimon Schubert prefixify_subexp (struct expression *inexpr, 9865796c8dcSSimon Schubert struct expression *outexpr, int inend, int outbeg) 9875796c8dcSSimon Schubert { 9885796c8dcSSimon Schubert int oplen; 9895796c8dcSSimon Schubert int args; 9905796c8dcSSimon Schubert int i; 9915796c8dcSSimon Schubert int *arglens; 9925796c8dcSSimon Schubert int result = -1; 9935796c8dcSSimon Schubert 9945796c8dcSSimon Schubert operator_length (inexpr, inend, &oplen, &args); 9955796c8dcSSimon Schubert 9965796c8dcSSimon Schubert /* Copy the final operator itself, from the end of the input 9975796c8dcSSimon Schubert to the beginning of the output. */ 9985796c8dcSSimon Schubert inend -= oplen; 9995796c8dcSSimon Schubert memcpy (&outexpr->elts[outbeg], &inexpr->elts[inend], 10005796c8dcSSimon Schubert EXP_ELEM_TO_BYTES (oplen)); 10015796c8dcSSimon Schubert outbeg += oplen; 10025796c8dcSSimon Schubert 10035796c8dcSSimon Schubert if (expout_last_struct == inend) 10045796c8dcSSimon Schubert result = outbeg - oplen; 10055796c8dcSSimon Schubert 10065796c8dcSSimon Schubert /* Find the lengths of the arg subexpressions. */ 10075796c8dcSSimon Schubert arglens = (int *) alloca (args * sizeof (int)); 10085796c8dcSSimon Schubert for (i = args - 1; i >= 0; i--) 10095796c8dcSSimon Schubert { 10105796c8dcSSimon Schubert oplen = length_of_subexp (inexpr, inend); 10115796c8dcSSimon Schubert arglens[i] = oplen; 10125796c8dcSSimon Schubert inend -= oplen; 10135796c8dcSSimon Schubert } 10145796c8dcSSimon Schubert 10155796c8dcSSimon Schubert /* Now copy each subexpression, preserving the order of 10165796c8dcSSimon Schubert the subexpressions, but prefixifying each one. 10175796c8dcSSimon Schubert In this loop, inend starts at the beginning of 10185796c8dcSSimon Schubert the expression this level is working on 10195796c8dcSSimon Schubert and marches forward over the arguments. 10205796c8dcSSimon Schubert outbeg does similarly in the output. */ 10215796c8dcSSimon Schubert for (i = 0; i < args; i++) 10225796c8dcSSimon Schubert { 10235796c8dcSSimon Schubert int r; 1024*cf7f2e2dSJohn Marino 10255796c8dcSSimon Schubert oplen = arglens[i]; 10265796c8dcSSimon Schubert inend += oplen; 10275796c8dcSSimon Schubert r = prefixify_subexp (inexpr, outexpr, inend, outbeg); 10285796c8dcSSimon Schubert if (r != -1) 10295796c8dcSSimon Schubert { 10305796c8dcSSimon Schubert /* Return immediately. We probably have only parsed a 10315796c8dcSSimon Schubert partial expression, so we don't want to try to reverse 10325796c8dcSSimon Schubert the other operands. */ 10335796c8dcSSimon Schubert return r; 10345796c8dcSSimon Schubert } 10355796c8dcSSimon Schubert outbeg += oplen; 10365796c8dcSSimon Schubert } 10375796c8dcSSimon Schubert 10385796c8dcSSimon Schubert return result; 10395796c8dcSSimon Schubert } 10405796c8dcSSimon Schubert 10415796c8dcSSimon Schubert /* This page contains the two entry points to this file. */ 10425796c8dcSSimon Schubert 10435796c8dcSSimon Schubert /* Read an expression from the string *STRINGPTR points to, 10445796c8dcSSimon Schubert parse it, and return a pointer to a struct expression that we malloc. 10455796c8dcSSimon Schubert Use block BLOCK as the lexical context for variable names; 10465796c8dcSSimon Schubert if BLOCK is zero, use the block of the selected stack frame. 10475796c8dcSSimon Schubert Meanwhile, advance *STRINGPTR to point after the expression, 10485796c8dcSSimon Schubert at the first nonwhite character that is not part of the expression 10495796c8dcSSimon Schubert (possibly a null character). 10505796c8dcSSimon Schubert 10515796c8dcSSimon Schubert If COMMA is nonzero, stop if a comma is reached. */ 10525796c8dcSSimon Schubert 10535796c8dcSSimon Schubert struct expression * 10545796c8dcSSimon Schubert parse_exp_1 (char **stringptr, struct block *block, int comma) 10555796c8dcSSimon Schubert { 10565796c8dcSSimon Schubert return parse_exp_in_context (stringptr, block, comma, 0, NULL); 10575796c8dcSSimon Schubert } 10585796c8dcSSimon Schubert 10595796c8dcSSimon Schubert /* As for parse_exp_1, except that if VOID_CONTEXT_P, then 10605796c8dcSSimon Schubert no value is expected from the expression. 10615796c8dcSSimon Schubert OUT_SUBEXP is set when attempting to complete a field name; in this 10625796c8dcSSimon Schubert case it is set to the index of the subexpression on the 10635796c8dcSSimon Schubert left-hand-side of the struct op. If not doing such completion, it 10645796c8dcSSimon Schubert is left untouched. */ 10655796c8dcSSimon Schubert 10665796c8dcSSimon Schubert static struct expression * 10675796c8dcSSimon Schubert parse_exp_in_context (char **stringptr, struct block *block, int comma, 10685796c8dcSSimon Schubert int void_context_p, int *out_subexp) 10695796c8dcSSimon Schubert { 10705796c8dcSSimon Schubert volatile struct gdb_exception except; 10715796c8dcSSimon Schubert struct cleanup *old_chain; 1072*cf7f2e2dSJohn Marino const struct language_defn *lang = NULL; 10735796c8dcSSimon Schubert int subexp; 10745796c8dcSSimon Schubert 10755796c8dcSSimon Schubert lexptr = *stringptr; 10765796c8dcSSimon Schubert prev_lexptr = NULL; 10775796c8dcSSimon Schubert 10785796c8dcSSimon Schubert paren_depth = 0; 10795796c8dcSSimon Schubert type_stack_depth = 0; 10805796c8dcSSimon Schubert expout_last_struct = -1; 10815796c8dcSSimon Schubert 10825796c8dcSSimon Schubert comma_terminates = comma; 10835796c8dcSSimon Schubert 10845796c8dcSSimon Schubert if (lexptr == 0 || *lexptr == 0) 10855796c8dcSSimon Schubert error_no_arg (_("expression to compute")); 10865796c8dcSSimon Schubert 10875796c8dcSSimon Schubert old_chain = make_cleanup (free_funcalls, 0 /*ignore*/); 10885796c8dcSSimon Schubert funcall_chain = 0; 10895796c8dcSSimon Schubert 10905796c8dcSSimon Schubert expression_context_block = block; 10915796c8dcSSimon Schubert 10925796c8dcSSimon Schubert /* If no context specified, try using the current frame, if any. */ 10935796c8dcSSimon Schubert if (!expression_context_block) 10945796c8dcSSimon Schubert expression_context_block = get_selected_block (&expression_context_pc); 10955796c8dcSSimon Schubert else 10965796c8dcSSimon Schubert expression_context_pc = BLOCK_START (expression_context_block); 10975796c8dcSSimon Schubert 10985796c8dcSSimon Schubert /* Fall back to using the current source static context, if any. */ 10995796c8dcSSimon Schubert 11005796c8dcSSimon Schubert if (!expression_context_block) 11015796c8dcSSimon Schubert { 11025796c8dcSSimon Schubert struct symtab_and_line cursal = get_current_source_symtab_and_line (); 11035796c8dcSSimon Schubert if (cursal.symtab) 11045796c8dcSSimon Schubert expression_context_block 11055796c8dcSSimon Schubert = BLOCKVECTOR_BLOCK (BLOCKVECTOR (cursal.symtab), STATIC_BLOCK); 11065796c8dcSSimon Schubert if (expression_context_block) 11075796c8dcSSimon Schubert expression_context_pc = BLOCK_START (expression_context_block); 11085796c8dcSSimon Schubert } 11095796c8dcSSimon Schubert 1110*cf7f2e2dSJohn Marino if (language_mode == language_mode_auto && block != NULL) 1111*cf7f2e2dSJohn Marino { 1112*cf7f2e2dSJohn Marino /* Find the language associated to the given context block. 1113*cf7f2e2dSJohn Marino Default to the current language if it can not be determined. 1114*cf7f2e2dSJohn Marino 1115*cf7f2e2dSJohn Marino Note that using the language corresponding to the current frame 1116*cf7f2e2dSJohn Marino can sometimes give unexpected results. For instance, this 1117*cf7f2e2dSJohn Marino routine is often called several times during the inferior 1118*cf7f2e2dSJohn Marino startup phase to re-parse breakpoint expressions after 1119*cf7f2e2dSJohn Marino a new shared library has been loaded. The language associated 1120*cf7f2e2dSJohn Marino to the current frame at this moment is not relevant for 1121*cf7f2e2dSJohn Marino the breakpoint. Using it would therefore be silly, so it seems 1122*cf7f2e2dSJohn Marino better to rely on the current language rather than relying on 1123*cf7f2e2dSJohn Marino the current frame language to parse the expression. That's why 1124*cf7f2e2dSJohn Marino we do the following language detection only if the context block 1125*cf7f2e2dSJohn Marino has been specifically provided. */ 1126*cf7f2e2dSJohn Marino struct symbol *func = block_linkage_function (block); 1127*cf7f2e2dSJohn Marino 1128*cf7f2e2dSJohn Marino if (func != NULL) 1129*cf7f2e2dSJohn Marino lang = language_def (SYMBOL_LANGUAGE (func)); 1130*cf7f2e2dSJohn Marino if (lang == NULL || lang->la_language == language_unknown) 1131*cf7f2e2dSJohn Marino lang = current_language; 1132*cf7f2e2dSJohn Marino } 1133*cf7f2e2dSJohn Marino else 1134*cf7f2e2dSJohn Marino lang = current_language; 1135*cf7f2e2dSJohn Marino 11365796c8dcSSimon Schubert expout_size = 10; 11375796c8dcSSimon Schubert expout_ptr = 0; 11385796c8dcSSimon Schubert expout = (struct expression *) 11395796c8dcSSimon Schubert xmalloc (sizeof (struct expression) + EXP_ELEM_TO_BYTES (expout_size)); 1140*cf7f2e2dSJohn Marino expout->language_defn = lang; 11415796c8dcSSimon Schubert expout->gdbarch = get_current_arch (); 11425796c8dcSSimon Schubert 11435796c8dcSSimon Schubert TRY_CATCH (except, RETURN_MASK_ALL) 11445796c8dcSSimon Schubert { 1145*cf7f2e2dSJohn Marino if (lang->la_parser ()) 1146*cf7f2e2dSJohn Marino lang->la_error (NULL); 11475796c8dcSSimon Schubert } 11485796c8dcSSimon Schubert if (except.reason < 0) 11495796c8dcSSimon Schubert { 11505796c8dcSSimon Schubert if (! in_parse_field) 11515796c8dcSSimon Schubert { 11525796c8dcSSimon Schubert xfree (expout); 11535796c8dcSSimon Schubert throw_exception (except); 11545796c8dcSSimon Schubert } 11555796c8dcSSimon Schubert } 11565796c8dcSSimon Schubert 11575796c8dcSSimon Schubert discard_cleanups (old_chain); 11585796c8dcSSimon Schubert 11595796c8dcSSimon Schubert /* Record the actual number of expression elements, and then 11605796c8dcSSimon Schubert reallocate the expression memory so that we free up any 11615796c8dcSSimon Schubert excess elements. */ 11625796c8dcSSimon Schubert 11635796c8dcSSimon Schubert expout->nelts = expout_ptr; 11645796c8dcSSimon Schubert expout = (struct expression *) 11655796c8dcSSimon Schubert xrealloc ((char *) expout, 11665796c8dcSSimon Schubert sizeof (struct expression) + EXP_ELEM_TO_BYTES (expout_ptr));; 11675796c8dcSSimon Schubert 11685796c8dcSSimon Schubert /* Convert expression from postfix form as generated by yacc 11695796c8dcSSimon Schubert parser, to a prefix form. */ 11705796c8dcSSimon Schubert 11715796c8dcSSimon Schubert if (expressiondebug) 11725796c8dcSSimon Schubert dump_raw_expression (expout, gdb_stdlog, 11735796c8dcSSimon Schubert "before conversion to prefix form"); 11745796c8dcSSimon Schubert 11755796c8dcSSimon Schubert subexp = prefixify_expression (expout); 11765796c8dcSSimon Schubert if (out_subexp) 11775796c8dcSSimon Schubert *out_subexp = subexp; 11785796c8dcSSimon Schubert 1179*cf7f2e2dSJohn Marino lang->la_post_parser (&expout, void_context_p); 11805796c8dcSSimon Schubert 11815796c8dcSSimon Schubert if (expressiondebug) 11825796c8dcSSimon Schubert dump_prefix_expression (expout, gdb_stdlog); 11835796c8dcSSimon Schubert 11845796c8dcSSimon Schubert *stringptr = lexptr; 11855796c8dcSSimon Schubert return expout; 11865796c8dcSSimon Schubert } 11875796c8dcSSimon Schubert 11885796c8dcSSimon Schubert /* Parse STRING as an expression, and complain if this fails 11895796c8dcSSimon Schubert to use up all of the contents of STRING. */ 11905796c8dcSSimon Schubert 11915796c8dcSSimon Schubert struct expression * 11925796c8dcSSimon Schubert parse_expression (char *string) 11935796c8dcSSimon Schubert { 11945796c8dcSSimon Schubert struct expression *exp; 1195*cf7f2e2dSJohn Marino 11965796c8dcSSimon Schubert exp = parse_exp_1 (&string, 0, 0); 11975796c8dcSSimon Schubert if (*string) 11985796c8dcSSimon Schubert error (_("Junk after end of expression.")); 11995796c8dcSSimon Schubert return exp; 12005796c8dcSSimon Schubert } 12015796c8dcSSimon Schubert 12025796c8dcSSimon Schubert /* Parse STRING as an expression. If parsing ends in the middle of a 12035796c8dcSSimon Schubert field reference, return the type of the left-hand-side of the 12045796c8dcSSimon Schubert reference; furthermore, if the parsing ends in the field name, 12055796c8dcSSimon Schubert return the field name in *NAME. In all other cases, return NULL. 12065796c8dcSSimon Schubert Returned non-NULL *NAME must be freed by the caller. */ 12075796c8dcSSimon Schubert 12085796c8dcSSimon Schubert struct type * 12095796c8dcSSimon Schubert parse_field_expression (char *string, char **name) 12105796c8dcSSimon Schubert { 12115796c8dcSSimon Schubert struct expression *exp = NULL; 12125796c8dcSSimon Schubert struct value *val; 12135796c8dcSSimon Schubert int subexp; 12145796c8dcSSimon Schubert volatile struct gdb_exception except; 12155796c8dcSSimon Schubert 12165796c8dcSSimon Schubert TRY_CATCH (except, RETURN_MASK_ALL) 12175796c8dcSSimon Schubert { 12185796c8dcSSimon Schubert in_parse_field = 1; 12195796c8dcSSimon Schubert exp = parse_exp_in_context (&string, 0, 0, 0, &subexp); 12205796c8dcSSimon Schubert } 12215796c8dcSSimon Schubert in_parse_field = 0; 12225796c8dcSSimon Schubert if (except.reason < 0 || ! exp) 12235796c8dcSSimon Schubert return NULL; 12245796c8dcSSimon Schubert if (expout_last_struct == -1) 12255796c8dcSSimon Schubert { 12265796c8dcSSimon Schubert xfree (exp); 12275796c8dcSSimon Schubert return NULL; 12285796c8dcSSimon Schubert } 12295796c8dcSSimon Schubert 12305796c8dcSSimon Schubert *name = extract_field_op (exp, &subexp); 12315796c8dcSSimon Schubert if (!*name) 12325796c8dcSSimon Schubert { 12335796c8dcSSimon Schubert xfree (exp); 12345796c8dcSSimon Schubert return NULL; 12355796c8dcSSimon Schubert } 12365796c8dcSSimon Schubert /* (*NAME) is a part of the EXP memory block freed below. */ 12375796c8dcSSimon Schubert *name = xstrdup (*name); 12385796c8dcSSimon Schubert 12395796c8dcSSimon Schubert val = evaluate_subexpression_type (exp, subexp); 12405796c8dcSSimon Schubert xfree (exp); 12415796c8dcSSimon Schubert 12425796c8dcSSimon Schubert return value_type (val); 12435796c8dcSSimon Schubert } 12445796c8dcSSimon Schubert 12455796c8dcSSimon Schubert /* A post-parser that does nothing */ 12465796c8dcSSimon Schubert 12475796c8dcSSimon Schubert void 12485796c8dcSSimon Schubert null_post_parser (struct expression **exp, int void_context_p) 12495796c8dcSSimon Schubert { 12505796c8dcSSimon Schubert } 12515796c8dcSSimon Schubert 12525796c8dcSSimon Schubert /* Stuff for maintaining a stack of types. Currently just used by C, but 12535796c8dcSSimon Schubert probably useful for any language which declares its types "backwards". */ 12545796c8dcSSimon Schubert 12555796c8dcSSimon Schubert static void 12565796c8dcSSimon Schubert check_type_stack_depth (void) 12575796c8dcSSimon Schubert { 12585796c8dcSSimon Schubert if (type_stack_depth == type_stack_size) 12595796c8dcSSimon Schubert { 12605796c8dcSSimon Schubert type_stack_size *= 2; 12615796c8dcSSimon Schubert type_stack = (union type_stack_elt *) 12625796c8dcSSimon Schubert xrealloc ((char *) type_stack, type_stack_size * sizeof (*type_stack)); 12635796c8dcSSimon Schubert } 12645796c8dcSSimon Schubert } 12655796c8dcSSimon Schubert 12665796c8dcSSimon Schubert void 12675796c8dcSSimon Schubert push_type (enum type_pieces tp) 12685796c8dcSSimon Schubert { 12695796c8dcSSimon Schubert check_type_stack_depth (); 12705796c8dcSSimon Schubert type_stack[type_stack_depth++].piece = tp; 12715796c8dcSSimon Schubert } 12725796c8dcSSimon Schubert 12735796c8dcSSimon Schubert void 12745796c8dcSSimon Schubert push_type_int (int n) 12755796c8dcSSimon Schubert { 12765796c8dcSSimon Schubert check_type_stack_depth (); 12775796c8dcSSimon Schubert type_stack[type_stack_depth++].int_val = n; 12785796c8dcSSimon Schubert } 12795796c8dcSSimon Schubert 12805796c8dcSSimon Schubert void 12815796c8dcSSimon Schubert push_type_address_space (char *string) 12825796c8dcSSimon Schubert { 12835796c8dcSSimon Schubert push_type_int (address_space_name_to_int (parse_gdbarch, string)); 12845796c8dcSSimon Schubert } 12855796c8dcSSimon Schubert 12865796c8dcSSimon Schubert enum type_pieces 12875796c8dcSSimon Schubert pop_type (void) 12885796c8dcSSimon Schubert { 12895796c8dcSSimon Schubert if (type_stack_depth) 12905796c8dcSSimon Schubert return type_stack[--type_stack_depth].piece; 12915796c8dcSSimon Schubert return tp_end; 12925796c8dcSSimon Schubert } 12935796c8dcSSimon Schubert 12945796c8dcSSimon Schubert int 12955796c8dcSSimon Schubert pop_type_int (void) 12965796c8dcSSimon Schubert { 12975796c8dcSSimon Schubert if (type_stack_depth) 12985796c8dcSSimon Schubert return type_stack[--type_stack_depth].int_val; 12995796c8dcSSimon Schubert /* "Can't happen". */ 13005796c8dcSSimon Schubert return 0; 13015796c8dcSSimon Schubert } 13025796c8dcSSimon Schubert 13035796c8dcSSimon Schubert /* Pop the type stack and return the type which corresponds to FOLLOW_TYPE 13045796c8dcSSimon Schubert as modified by all the stuff on the stack. */ 13055796c8dcSSimon Schubert struct type * 13065796c8dcSSimon Schubert follow_types (struct type *follow_type) 13075796c8dcSSimon Schubert { 13085796c8dcSSimon Schubert int done = 0; 13095796c8dcSSimon Schubert int make_const = 0; 13105796c8dcSSimon Schubert int make_volatile = 0; 13115796c8dcSSimon Schubert int make_addr_space = 0; 13125796c8dcSSimon Schubert int array_size; 13135796c8dcSSimon Schubert 13145796c8dcSSimon Schubert while (!done) 13155796c8dcSSimon Schubert switch (pop_type ()) 13165796c8dcSSimon Schubert { 13175796c8dcSSimon Schubert case tp_end: 13185796c8dcSSimon Schubert done = 1; 13195796c8dcSSimon Schubert if (make_const) 13205796c8dcSSimon Schubert follow_type = make_cv_type (make_const, 13215796c8dcSSimon Schubert TYPE_VOLATILE (follow_type), 13225796c8dcSSimon Schubert follow_type, 0); 13235796c8dcSSimon Schubert if (make_volatile) 13245796c8dcSSimon Schubert follow_type = make_cv_type (TYPE_CONST (follow_type), 13255796c8dcSSimon Schubert make_volatile, 13265796c8dcSSimon Schubert follow_type, 0); 13275796c8dcSSimon Schubert if (make_addr_space) 13285796c8dcSSimon Schubert follow_type = make_type_with_address_space (follow_type, 13295796c8dcSSimon Schubert make_addr_space); 13305796c8dcSSimon Schubert make_const = make_volatile = 0; 13315796c8dcSSimon Schubert make_addr_space = 0; 13325796c8dcSSimon Schubert break; 13335796c8dcSSimon Schubert case tp_const: 13345796c8dcSSimon Schubert make_const = 1; 13355796c8dcSSimon Schubert break; 13365796c8dcSSimon Schubert case tp_volatile: 13375796c8dcSSimon Schubert make_volatile = 1; 13385796c8dcSSimon Schubert break; 13395796c8dcSSimon Schubert case tp_space_identifier: 13405796c8dcSSimon Schubert make_addr_space = pop_type_int (); 13415796c8dcSSimon Schubert break; 13425796c8dcSSimon Schubert case tp_pointer: 13435796c8dcSSimon Schubert follow_type = lookup_pointer_type (follow_type); 13445796c8dcSSimon Schubert if (make_const) 13455796c8dcSSimon Schubert follow_type = make_cv_type (make_const, 13465796c8dcSSimon Schubert TYPE_VOLATILE (follow_type), 13475796c8dcSSimon Schubert follow_type, 0); 13485796c8dcSSimon Schubert if (make_volatile) 13495796c8dcSSimon Schubert follow_type = make_cv_type (TYPE_CONST (follow_type), 13505796c8dcSSimon Schubert make_volatile, 13515796c8dcSSimon Schubert follow_type, 0); 13525796c8dcSSimon Schubert if (make_addr_space) 13535796c8dcSSimon Schubert follow_type = make_type_with_address_space (follow_type, 13545796c8dcSSimon Schubert make_addr_space); 13555796c8dcSSimon Schubert make_const = make_volatile = 0; 13565796c8dcSSimon Schubert make_addr_space = 0; 13575796c8dcSSimon Schubert break; 13585796c8dcSSimon Schubert case tp_reference: 13595796c8dcSSimon Schubert follow_type = lookup_reference_type (follow_type); 13605796c8dcSSimon Schubert if (make_const) 13615796c8dcSSimon Schubert follow_type = make_cv_type (make_const, 13625796c8dcSSimon Schubert TYPE_VOLATILE (follow_type), 13635796c8dcSSimon Schubert follow_type, 0); 13645796c8dcSSimon Schubert if (make_volatile) 13655796c8dcSSimon Schubert follow_type = make_cv_type (TYPE_CONST (follow_type), 13665796c8dcSSimon Schubert make_volatile, 13675796c8dcSSimon Schubert follow_type, 0); 13685796c8dcSSimon Schubert if (make_addr_space) 13695796c8dcSSimon Schubert follow_type = make_type_with_address_space (follow_type, 13705796c8dcSSimon Schubert make_addr_space); 13715796c8dcSSimon Schubert make_const = make_volatile = 0; 13725796c8dcSSimon Schubert make_addr_space = 0; 13735796c8dcSSimon Schubert break; 13745796c8dcSSimon Schubert case tp_array: 13755796c8dcSSimon Schubert array_size = pop_type_int (); 13765796c8dcSSimon Schubert /* FIXME-type-allocation: need a way to free this type when we are 13775796c8dcSSimon Schubert done with it. */ 13785796c8dcSSimon Schubert follow_type = 13795796c8dcSSimon Schubert lookup_array_range_type (follow_type, 13805796c8dcSSimon Schubert 0, array_size >= 0 ? array_size - 1 : 0); 13815796c8dcSSimon Schubert if (array_size < 0) 13825796c8dcSSimon Schubert TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (follow_type) = 1; 13835796c8dcSSimon Schubert break; 13845796c8dcSSimon Schubert case tp_function: 13855796c8dcSSimon Schubert /* FIXME-type-allocation: need a way to free this type when we are 13865796c8dcSSimon Schubert done with it. */ 13875796c8dcSSimon Schubert follow_type = lookup_function_type (follow_type); 13885796c8dcSSimon Schubert break; 13895796c8dcSSimon Schubert } 13905796c8dcSSimon Schubert return follow_type; 13915796c8dcSSimon Schubert } 13925796c8dcSSimon Schubert 13935796c8dcSSimon Schubert /* This function avoids direct calls to fprintf 13945796c8dcSSimon Schubert in the parser generated debug code. */ 13955796c8dcSSimon Schubert void 13965796c8dcSSimon Schubert parser_fprintf (FILE *x, const char *y, ...) 13975796c8dcSSimon Schubert { 13985796c8dcSSimon Schubert va_list args; 1399*cf7f2e2dSJohn Marino 14005796c8dcSSimon Schubert va_start (args, y); 14015796c8dcSSimon Schubert if (x == stderr) 14025796c8dcSSimon Schubert vfprintf_unfiltered (gdb_stderr, y, args); 14035796c8dcSSimon Schubert else 14045796c8dcSSimon Schubert { 14055796c8dcSSimon Schubert fprintf_unfiltered (gdb_stderr, " Unknown FILE used.\n"); 14065796c8dcSSimon Schubert vfprintf_unfiltered (gdb_stderr, y, args); 14075796c8dcSSimon Schubert } 14085796c8dcSSimon Schubert va_end (args); 14095796c8dcSSimon Schubert } 14105796c8dcSSimon Schubert 1411*cf7f2e2dSJohn Marino /* Implementation of the exp_descriptor method operator_check. */ 1412*cf7f2e2dSJohn Marino 1413*cf7f2e2dSJohn Marino int 1414*cf7f2e2dSJohn Marino operator_check_standard (struct expression *exp, int pos, 1415*cf7f2e2dSJohn Marino int (*objfile_func) (struct objfile *objfile, 1416*cf7f2e2dSJohn Marino void *data), 1417*cf7f2e2dSJohn Marino void *data) 1418*cf7f2e2dSJohn Marino { 1419*cf7f2e2dSJohn Marino const union exp_element *const elts = exp->elts; 1420*cf7f2e2dSJohn Marino struct type *type = NULL; 1421*cf7f2e2dSJohn Marino struct objfile *objfile = NULL; 1422*cf7f2e2dSJohn Marino 1423*cf7f2e2dSJohn Marino /* Extended operators should have been already handled by exp_descriptor 1424*cf7f2e2dSJohn Marino iterate method of its specific language. */ 1425*cf7f2e2dSJohn Marino gdb_assert (elts[pos].opcode < OP_EXTENDED0); 1426*cf7f2e2dSJohn Marino 1427*cf7f2e2dSJohn Marino /* Track the callers of write_exp_elt_type for this table. */ 1428*cf7f2e2dSJohn Marino 1429*cf7f2e2dSJohn Marino switch (elts[pos].opcode) 1430*cf7f2e2dSJohn Marino { 1431*cf7f2e2dSJohn Marino case BINOP_VAL: 1432*cf7f2e2dSJohn Marino case OP_COMPLEX: 1433*cf7f2e2dSJohn Marino case OP_DECFLOAT: 1434*cf7f2e2dSJohn Marino case OP_DOUBLE: 1435*cf7f2e2dSJohn Marino case OP_LONG: 1436*cf7f2e2dSJohn Marino case OP_SCOPE: 1437*cf7f2e2dSJohn Marino case OP_TYPE: 1438*cf7f2e2dSJohn Marino case UNOP_CAST: 1439*cf7f2e2dSJohn Marino case UNOP_DYNAMIC_CAST: 1440*cf7f2e2dSJohn Marino case UNOP_REINTERPRET_CAST: 1441*cf7f2e2dSJohn Marino case UNOP_MAX: 1442*cf7f2e2dSJohn Marino case UNOP_MEMVAL: 1443*cf7f2e2dSJohn Marino case UNOP_MIN: 1444*cf7f2e2dSJohn Marino type = elts[pos + 1].type; 1445*cf7f2e2dSJohn Marino break; 1446*cf7f2e2dSJohn Marino 1447*cf7f2e2dSJohn Marino case TYPE_INSTANCE: 1448*cf7f2e2dSJohn Marino { 1449*cf7f2e2dSJohn Marino LONGEST arg, nargs = elts[pos + 1].longconst; 1450*cf7f2e2dSJohn Marino 1451*cf7f2e2dSJohn Marino for (arg = 0; arg < nargs; arg++) 1452*cf7f2e2dSJohn Marino { 1453*cf7f2e2dSJohn Marino struct type *type = elts[pos + 2 + arg].type; 1454*cf7f2e2dSJohn Marino struct objfile *objfile = TYPE_OBJFILE (type); 1455*cf7f2e2dSJohn Marino 1456*cf7f2e2dSJohn Marino if (objfile && (*objfile_func) (objfile, data)) 1457*cf7f2e2dSJohn Marino return 1; 1458*cf7f2e2dSJohn Marino } 1459*cf7f2e2dSJohn Marino } 1460*cf7f2e2dSJohn Marino break; 1461*cf7f2e2dSJohn Marino 1462*cf7f2e2dSJohn Marino case UNOP_MEMVAL_TLS: 1463*cf7f2e2dSJohn Marino objfile = elts[pos + 1].objfile; 1464*cf7f2e2dSJohn Marino type = elts[pos + 2].type; 1465*cf7f2e2dSJohn Marino break; 1466*cf7f2e2dSJohn Marino 1467*cf7f2e2dSJohn Marino case OP_VAR_VALUE: 1468*cf7f2e2dSJohn Marino { 1469*cf7f2e2dSJohn Marino const struct block *const block = elts[pos + 1].block; 1470*cf7f2e2dSJohn Marino const struct symbol *const symbol = elts[pos + 2].symbol; 1471*cf7f2e2dSJohn Marino 1472*cf7f2e2dSJohn Marino /* Check objfile where the variable itself is placed. 1473*cf7f2e2dSJohn Marino SYMBOL_OBJ_SECTION (symbol) may be NULL. */ 1474*cf7f2e2dSJohn Marino if ((*objfile_func) (SYMBOL_SYMTAB (symbol)->objfile, data)) 1475*cf7f2e2dSJohn Marino return 1; 1476*cf7f2e2dSJohn Marino 1477*cf7f2e2dSJohn Marino /* Check objfile where is placed the code touching the variable. */ 1478*cf7f2e2dSJohn Marino objfile = lookup_objfile_from_block (block); 1479*cf7f2e2dSJohn Marino 1480*cf7f2e2dSJohn Marino type = SYMBOL_TYPE (symbol); 1481*cf7f2e2dSJohn Marino } 1482*cf7f2e2dSJohn Marino break; 1483*cf7f2e2dSJohn Marino } 1484*cf7f2e2dSJohn Marino 1485*cf7f2e2dSJohn Marino /* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL. */ 1486*cf7f2e2dSJohn Marino 1487*cf7f2e2dSJohn Marino if (type && TYPE_OBJFILE (type) 1488*cf7f2e2dSJohn Marino && (*objfile_func) (TYPE_OBJFILE (type), data)) 1489*cf7f2e2dSJohn Marino return 1; 1490*cf7f2e2dSJohn Marino if (objfile && (*objfile_func) (objfile, data)) 1491*cf7f2e2dSJohn Marino return 1; 1492*cf7f2e2dSJohn Marino 1493*cf7f2e2dSJohn Marino return 0; 1494*cf7f2e2dSJohn Marino } 1495*cf7f2e2dSJohn Marino 1496*cf7f2e2dSJohn Marino /* Call OBJFILE_FUNC for any TYPE and OBJFILE found being referenced by EXP. 1497*cf7f2e2dSJohn Marino The functions are never called with NULL OBJFILE. Functions get passed an 1498*cf7f2e2dSJohn Marino arbitrary caller supplied DATA pointer. If any of the functions returns 1499*cf7f2e2dSJohn Marino non-zero value then (any other) non-zero value is immediately returned to 1500*cf7f2e2dSJohn Marino the caller. Otherwise zero is returned after iterating through whole EXP. 1501*cf7f2e2dSJohn Marino */ 1502*cf7f2e2dSJohn Marino 1503*cf7f2e2dSJohn Marino static int 1504*cf7f2e2dSJohn Marino exp_iterate (struct expression *exp, 1505*cf7f2e2dSJohn Marino int (*objfile_func) (struct objfile *objfile, void *data), 1506*cf7f2e2dSJohn Marino void *data) 1507*cf7f2e2dSJohn Marino { 1508*cf7f2e2dSJohn Marino int endpos; 1509*cf7f2e2dSJohn Marino 1510*cf7f2e2dSJohn Marino for (endpos = exp->nelts; endpos > 0; ) 1511*cf7f2e2dSJohn Marino { 1512*cf7f2e2dSJohn Marino int pos, args, oplen = 0; 1513*cf7f2e2dSJohn Marino 1514*cf7f2e2dSJohn Marino operator_length (exp, endpos, &oplen, &args); 1515*cf7f2e2dSJohn Marino gdb_assert (oplen > 0); 1516*cf7f2e2dSJohn Marino 1517*cf7f2e2dSJohn Marino pos = endpos - oplen; 1518*cf7f2e2dSJohn Marino if (exp->language_defn->la_exp_desc->operator_check (exp, pos, 1519*cf7f2e2dSJohn Marino objfile_func, data)) 1520*cf7f2e2dSJohn Marino return 1; 1521*cf7f2e2dSJohn Marino 1522*cf7f2e2dSJohn Marino endpos = pos; 1523*cf7f2e2dSJohn Marino } 1524*cf7f2e2dSJohn Marino 1525*cf7f2e2dSJohn Marino return 0; 1526*cf7f2e2dSJohn Marino } 1527*cf7f2e2dSJohn Marino 1528*cf7f2e2dSJohn Marino /* Helper for exp_uses_objfile. */ 1529*cf7f2e2dSJohn Marino 1530*cf7f2e2dSJohn Marino static int 1531*cf7f2e2dSJohn Marino exp_uses_objfile_iter (struct objfile *exp_objfile, void *objfile_voidp) 1532*cf7f2e2dSJohn Marino { 1533*cf7f2e2dSJohn Marino struct objfile *objfile = objfile_voidp; 1534*cf7f2e2dSJohn Marino 1535*cf7f2e2dSJohn Marino if (exp_objfile->separate_debug_objfile_backlink) 1536*cf7f2e2dSJohn Marino exp_objfile = exp_objfile->separate_debug_objfile_backlink; 1537*cf7f2e2dSJohn Marino 1538*cf7f2e2dSJohn Marino return exp_objfile == objfile; 1539*cf7f2e2dSJohn Marino } 1540*cf7f2e2dSJohn Marino 1541*cf7f2e2dSJohn Marino /* Return 1 if EXP uses OBJFILE (and will become dangling when OBJFILE 1542*cf7f2e2dSJohn Marino is unloaded), otherwise return 0. OBJFILE must not be a separate debug info 1543*cf7f2e2dSJohn Marino file. */ 1544*cf7f2e2dSJohn Marino 1545*cf7f2e2dSJohn Marino int 1546*cf7f2e2dSJohn Marino exp_uses_objfile (struct expression *exp, struct objfile *objfile) 1547*cf7f2e2dSJohn Marino { 1548*cf7f2e2dSJohn Marino gdb_assert (objfile->separate_debug_objfile_backlink == NULL); 1549*cf7f2e2dSJohn Marino 1550*cf7f2e2dSJohn Marino return exp_iterate (exp, exp_uses_objfile_iter, objfile); 1551*cf7f2e2dSJohn Marino } 1552*cf7f2e2dSJohn Marino 15535796c8dcSSimon Schubert void 15545796c8dcSSimon Schubert _initialize_parse (void) 15555796c8dcSSimon Schubert { 15565796c8dcSSimon Schubert type_stack_size = 80; 15575796c8dcSSimon Schubert type_stack_depth = 0; 15585796c8dcSSimon Schubert type_stack = (union type_stack_elt *) 15595796c8dcSSimon Schubert xmalloc (type_stack_size * sizeof (*type_stack)); 15605796c8dcSSimon Schubert 15615796c8dcSSimon Schubert add_setshow_zinteger_cmd ("expression", class_maintenance, 15625796c8dcSSimon Schubert &expressiondebug, _("\ 15635796c8dcSSimon Schubert Set expression debugging."), _("\ 15645796c8dcSSimon Schubert Show expression debugging."), _("\ 15655796c8dcSSimon Schubert When non-zero, the internal representation of expressions will be printed."), 15665796c8dcSSimon Schubert NULL, 15675796c8dcSSimon Schubert show_expressiondebug, 15685796c8dcSSimon Schubert &setdebuglist, &showdebuglist); 1569*cf7f2e2dSJohn Marino add_setshow_boolean_cmd ("parser", class_maintenance, 1570*cf7f2e2dSJohn Marino &parser_debug, _("\ 1571*cf7f2e2dSJohn Marino Set parser debugging."), _("\ 1572*cf7f2e2dSJohn Marino Show parser debugging."), _("\ 1573*cf7f2e2dSJohn Marino When non-zero, expression parser tracing will be enabled."), 1574*cf7f2e2dSJohn Marino NULL, 1575*cf7f2e2dSJohn Marino show_parserdebug, 1576*cf7f2e2dSJohn Marino &setdebuglist, &showdebuglist); 15775796c8dcSSimon Schubert } 1578