diff options
author | Sergio Durigan Junior <sergiodj@redhat.com> | 2012-01-18 12:47:35 +0000 |
---|---|---|
committer | Sergio Durigan Junior <sergiodj@redhat.com> | 2012-01-18 12:47:35 +0000 |
commit | 2dbca4d632a80b36f1da836d366c28c9e1d71e20 (patch) | |
tree | ccadc94b8a6661b2b6ac6878b3e80e9ffca2ef87 /gdb | |
parent | 0695b514b3e19fe0d444b6815727fe0ceeab713e (diff) | |
download | gdb-2dbca4d632a80b36f1da836d366c28c9e1d71e20.zip gdb-2dbca4d632a80b36f1da836d366c28c9e1d71e20.tar.gz gdb-2dbca4d632a80b36f1da836d366c28c9e1d71e20.tar.bz2 |
2012-01-18 Sergio Durigan Junior <sergiodj@redhat.com>
* parse.c (initialize_expout): New function.
(reallocate_expout): Likewise.
(parse_exp_in_context): Use `initialize_expout' and
`reallocate_expout' when appropriate.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 7 | ||||
-rw-r--r-- | gdb/parse.c | 51 |
2 files changed, 44 insertions, 14 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index dbfa524..00b0f06 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2012-01-18 Sergio Durigan Junior <sergiodj@redhat.com> + + * parse.c (initialize_expout): New function. + (reallocate_expout): Likewise. + (parse_exp_in_context): Use `initialize_expout' and + `reallocate_expout' when appropriate. + 2012-01-18 Pedro Alves <palves@redhat.com> * record.c (struct record_breakpoint, record_breakpoint_p) diff --git a/gdb/parse.c b/gdb/parse.c index f405dc5..32a3bd6 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -182,6 +182,41 @@ free_funcalls (void *ignore) /* This page contains the functions for adding data to the struct expression being constructed. */ +/* Helper function to initialize the expout, expout_size, expout_ptr + trio before it is used to store expression elements created during + the parsing of an expression. INITIAL_SIZE is the initial size of + the expout array. LANG is the language used to parse the expression. + And GDBARCH is the gdbarch to use during parsing. */ + +static void +initialize_expout (int initial_size, const struct language_defn *lang, + struct gdbarch *gdbarch) +{ + expout_size = initial_size; + expout_ptr = 0; + expout = xmalloc (sizeof (struct expression) + + EXP_ELEM_TO_BYTES (expout_size)); + expout->language_defn = lang; + expout->gdbarch = gdbarch; +} + +/* Helper function that frees any unsed space in the expout array. + It is generally used when the parser has just been parsed and + created. */ + +static void +reallocate_expout (void) +{ + /* Record the actual number of expression elements, and then + reallocate the expression memory so that we free up any + excess elements. */ + + expout->nelts = expout_ptr; + expout = xrealloc ((char *) expout, + sizeof (struct expression) + + EXP_ELEM_TO_BYTES (expout_ptr)); +} + /* Add one element to the end of the expression. */ /* To avoid a bug in the Sun 4 compiler, we pass things that can fit into @@ -1156,12 +1191,7 @@ parse_exp_in_context (char **stringptr, struct block *block, int comma, else lang = current_language; - expout_size = 10; - expout_ptr = 0; - expout = (struct expression *) - xmalloc (sizeof (struct expression) + EXP_ELEM_TO_BYTES (expout_size)); - expout->language_defn = lang; - expout->gdbarch = get_current_arch (); + initialize_expout (10, lang, get_current_arch ()); TRY_CATCH (except, RETURN_MASK_ALL) { @@ -1179,14 +1209,7 @@ parse_exp_in_context (char **stringptr, struct block *block, int comma, discard_cleanups (old_chain); - /* Record the actual number of expression elements, and then - reallocate the expression memory so that we free up any - excess elements. */ - - expout->nelts = expout_ptr; - expout = (struct expression *) - xrealloc ((char *) expout, - sizeof (struct expression) + EXP_ELEM_TO_BYTES (expout_ptr)); + reallocate_expout (); /* Convert expression from postfix form as generated by yacc parser, to a prefix form. */ |