From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1030 invoked by alias); 7 Jan 2003 14:55:33 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 1021 invoked from network); 7 Jan 2003 14:55:32 -0000 Received: from unknown (HELO mx1.redhat.com) (66.187.233.31) by 209.249.29.67 with SMTP; 7 Jan 2003 14:55:32 -0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.11.6/8.11.6) with ESMTP id h07ERhB32466 for ; Tue, 7 Jan 2003 09:27:43 -0500 Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [172.16.52.156]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id h07EtKa15167 for ; Tue, 7 Jan 2003 09:55:20 -0500 Received: from localhost.redhat.com (romulus-int.sfbay.redhat.com [172.16.27.46]) by pobox.corp.redhat.com (8.11.6/8.11.6) with ESMTP id h07EtIn06351; Tue, 7 Jan 2003 09:55:19 -0500 Received: by localhost.redhat.com (Postfix, from userid 469) id BD231FF79; Tue, 7 Jan 2003 09:59:41 -0500 (EST) From: Elena Zannoni MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15898.60253.630749.735372@localhost.redhat.com> Date: Tue, 07 Jan 2003 14:55:00 -0000 To: David Carlton Cc: gdb-patches@sources.redhat.com, Elena Zannoni Subject: Re: [rfa] linespec.c: decode_dollar In-Reply-To: References: X-SW-Source: 2003-01/txt/msg00274.txt.bz2 David Carlton writes: > This patch extracts some code in decode_line_1 into a new function > decode_dollar. It doesn't change the extracted code at all. It also > deletes a call to 'init_sal(&val)' and the 'return values;' from > decode_line_1(), since 'val' and 'values' are no longer used (though > the call to init_sal gets moved inside decode_dollar). > > The code before the call to decode_dollar in decode_line_1 is messy; > I'll deal with that eventually, but that issue is a little more > delicate, so I'm postponing that to a later date. > > Tested on i686-pc-linux-gnu/GCC 3.1/DWARF 2; no regressions. > Ok, thanks Elena > David Carlton > carlton@math.stanford.edu > > 2003-01-06 David Carlton > > * linespec.c (decode_line_1): Move code into decode_dollar. > (decode_dollar): New function. > > Index: linespec.c > =================================================================== > RCS file: /cvs/src/src/gdb/linespec.c,v > retrieving revision 1.32 > diff -u -p -r1.32 linespec.c > --- linespec.c 19 Dec 2002 18:56:14 -0000 1.32 > +++ linespec.c 7 Jan 2003 00:30:35 -0000 > @@ -81,6 +81,12 @@ symtabs_and_lines decode_all_digits (cha > struct symtab *s, > char *q); > > +static struct symtabs_and_lines decode_dollar (char *copy, > + int funfirstline, > + struct symtab *default_symtab, > + char ***canonical, > + struct symtab *s); > + > static struct > symtabs_and_lines symbol_found (int funfirstline, > char ***canonical, > @@ -548,8 +554,6 @@ struct symtabs_and_lines > decode_line_1 (char **argptr, int funfirstline, struct symtab *default_symtab, > int default_line, char ***canonical) > { > - struct symtabs_and_lines values; > - struct symtab_and_line val; > char *p; > char *q; > struct symtab *s = NULL; > @@ -570,8 +574,6 @@ decode_line_1 (char **argptr, int funfir > int is_quote_enclosed; > char *saved_arg = *argptr; > > - init_sal (&val); /* initialize to zeroes */ > - > /* Defaults have defaults. */ > > initialize_defaults (&default_symtab, &default_line); > @@ -705,64 +707,8 @@ decode_line_1 (char **argptr, int funfir > be history value, or it may be a convenience variable */ > > if (*copy == '$') > - { > - struct value *valx; > - int index = 0; > - int need_canonical = 0; > - > - p = (copy[1] == '$') ? copy + 2 : copy + 1; > - while (*p >= '0' && *p <= '9') > - p++; > - if (!*p) /* reached end of token without hitting non-digit */ > - { > - /* We have a value history reference */ > - sscanf ((copy[1] == '$') ? copy + 2 : copy + 1, "%d", &index); > - valx = access_value_history ((copy[1] == '$') ? -index : index); > - if (TYPE_CODE (VALUE_TYPE (valx)) != TYPE_CODE_INT) > - error ("History values used in line specs must have integer values."); > - } > - else > - { > - /* Not all digits -- may be user variable/function or a > - convenience variable */ > - > - /* Look up entire name as a symbol first */ > - sym = lookup_symbol (copy, 0, VAR_NAMESPACE, 0, &sym_symtab); > - s = (struct symtab *) 0; > - need_canonical = 1; > - /* Symbol was found --> jump to normal symbol processing. */ > - if (sym) > - return symbol_found (funfirstline, canonical, copy, sym, > - NULL, sym_symtab); > - > - /* If symbol was not found, look in minimal symbol tables */ > - msymbol = lookup_minimal_symbol (copy, NULL, NULL); > - /* Min symbol was found --> jump to minsym processing. */ > - if (msymbol) > - return minsym_found (funfirstline, msymbol); > - > - /* Not a user variable or function -- must be convenience variable */ > - need_canonical = (s == 0) ? 1 : 0; > - valx = value_of_internalvar (lookup_internalvar (copy + 1)); > - if (TYPE_CODE (VALUE_TYPE (valx)) != TYPE_CODE_INT) > - error ("Convenience variables used in line specs must have integer values."); > - } > - > - /* Either history value or convenience value from above, in valx */ > - val.symtab = s ? s : default_symtab; > - val.line = value_as_long (valx); > - val.pc = 0; > - > - values.sals = (struct symtab_and_line *) xmalloc (sizeof val); > - values.sals[0] = val; > - values.nelts = 1; > - > - if (need_canonical) > - build_canonical_line_spec (values.sals, NULL, canonical); > - > - return values; > - } > - > + return decode_dollar (copy, funfirstline, default_symtab, > + canonical, s); > > /* Look up that token as a variable. > If file specified, use that file's per-file block to start with. */ > @@ -785,7 +731,6 @@ decode_line_1 (char **argptr, int funfir > error ("No symbol table is loaded. Use the \"file\" command."); > > error ("Function \"%s\" not defined.", copy); > - return values; /* for lint */ > } > > > @@ -1365,6 +1310,80 @@ decode_all_digits (char **argptr, struct > values.nelts = 1; > if (need_canonical) > build_canonical_line_spec (values.sals, NULL, canonical); > + return values; > +} > + > + > + > +/* Decode a linespec starting with a dollar sign. */ > + > +static struct symtabs_and_lines > +decode_dollar (char *copy, int funfirstline, struct symtab *default_symtab, > + char ***canonical, struct symtab *s) > +{ > + struct value *valx; > + int index = 0; > + int need_canonical = 0; > + struct symtabs_and_lines values; > + struct symtab_and_line val; > + char *p; > + struct symbol *sym; > + /* The symtab that SYM was found in. */ > + struct symtab *sym_symtab; > + struct minimal_symbol *msymbol; > + > + p = (copy[1] == '$') ? copy + 2 : copy + 1; > + while (*p >= '0' && *p <= '9') > + p++; > + if (!*p) /* reached end of token without hitting non-digit */ > + { > + /* We have a value history reference */ > + sscanf ((copy[1] == '$') ? copy + 2 : copy + 1, "%d", &index); > + valx = access_value_history ((copy[1] == '$') ? -index : index); > + if (TYPE_CODE (VALUE_TYPE (valx)) != TYPE_CODE_INT) > + error ("History values used in line specs must have integer values."); > + } > + else > + { > + /* Not all digits -- may be user variable/function or a > + convenience variable */ > + > + /* Look up entire name as a symbol first */ > + sym = lookup_symbol (copy, 0, VAR_NAMESPACE, 0, &sym_symtab); > + s = (struct symtab *) 0; > + need_canonical = 1; > + /* Symbol was found --> jump to normal symbol processing. */ > + if (sym) > + return symbol_found (funfirstline, canonical, copy, sym, > + NULL, sym_symtab); > + > + /* If symbol was not found, look in minimal symbol tables */ > + msymbol = lookup_minimal_symbol (copy, NULL, NULL); > + /* Min symbol was found --> jump to minsym processing. */ > + if (msymbol) > + return minsym_found (funfirstline, msymbol); > + > + /* Not a user variable or function -- must be convenience variable */ > + need_canonical = (s == 0) ? 1 : 0; > + valx = value_of_internalvar (lookup_internalvar (copy + 1)); > + if (TYPE_CODE (VALUE_TYPE (valx)) != TYPE_CODE_INT) > + error ("Convenience variables used in line specs must have integer values."); > + } > + > + init_sal (&val); > + > + /* Either history value or convenience value from above, in valx */ > + val.symtab = s ? s : default_symtab; > + val.line = value_as_long (valx); > + val.pc = 0; > + > + values.sals = (struct symtab_and_line *) xmalloc (sizeof val); > + values.sals[0] = val; > + values.nelts = 1; > + > + if (need_canonical) > + build_canonical_line_spec (values.sals, NULL, canonical); > + > return values; > } >