From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17231 invoked by alias); 9 Dec 2002 18:22:30 -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 17200 invoked from network); 9 Dec 2002 18:22:29 -0000 Received: from unknown (HELO mx1.redhat.com) (66.187.233.31) by sources.redhat.com with SMTP; 9 Dec 2002 18:22:29 -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 gB9GnxP25220 for ; Mon, 9 Dec 2002 11:49:59 -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 gB9HFRD21632 for ; Mon, 9 Dec 2002 12:15:27 -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 gB9HFPu06877; Mon, 9 Dec 2002 12:15:25 -0500 Received: by localhost.redhat.com (Postfix, from userid 469) id 53A23FF79; Mon, 9 Dec 2002 12:11:05 -0500 (EST) From: Elena Zannoni MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15860.52905.66816.48498@localhost.redhat.com> Date: Mon, 09 Dec 2002 10:26:00 -0000 To: David Carlton Cc: gdb-patches@sources.redhat.com, Elena Zannoni Subject: Re: [rfa] linespec.c, part 6 In-Reply-To: References: X-SW-Source: 2002-12/txt/msg00282.txt.bz2 David Carlton writes: > Here's the next part of the exciting linespec series of patches. This > one factors out the code dealing with filenames into a function > symtab_from_filename. (And it gets rid of a few register > declarations, but never mind that.) > > I didn't change the code when I extracted it, so the only thing to be > careful about is uses of variables. The code that I extracted does > modify 'p', but 'p' isn't referenced again in decode_line_1 until the > code following the comment starting with "Arg token is not digits"; > and every branch of the conditional following that comment resets 'p' > from scratch. Similarly, the code that I extracted modifies 'copy', > but one can easily check that the value of 'copy' is reset later. > Ok. Elena > David Carlton > carlton@math.stanford.edu > > 2002-12-05 David Carlton > > * linespec.c (symtab_from_filename): New function. > (decode_line_1): Move code into symtab_from_filename. > > Index: linespec.c > =================================================================== > RCS file: /cvs/src/src/gdb/linespec.c,v > retrieving revision 1.30 > diff -u -p -r1.30 linespec.c > --- linespec.c 5 Dec 2002 22:25:49 -0000 1.30 > +++ linespec.c 6 Dec 2002 00:15:06 -0000 > @@ -70,6 +70,9 @@ static char *find_toplevel_char (char *s > static struct symtabs_and_lines decode_line_2 (struct symbol *[], > int, int, char ***); > > +static struct symtab *symtab_from_filename (char **argptr, > + char *p, int is_quote_enclosed); > + > static struct > symtabs_and_lines symbol_found (int funfirstline, > char ***canonical, > @@ -539,15 +542,15 @@ decode_line_1 (char **argptr, int funfir > { > struct symtabs_and_lines values; > struct symtab_and_line val; > - register char *p, *p1; > + char *p; > char *q; > - register struct symtab *s = NULL; > + struct symtab *s = NULL; > > - register struct symbol *sym; > + struct symbol *sym; > /* The symtab that SYM was found in. */ > struct symtab *sym_symtab; > > - register struct minimal_symbol *msymbol; > + struct minimal_symbol *msymbol; > char *copy; > /* This is NULL if there are no parens in *ARGPTR, or a pointer to > the closing parenthesis if there are parens. */ > @@ -591,40 +594,17 @@ decode_line_1 (char **argptr, int funfir > { > if (is_quoted) > *argptr = *argptr + 1; > + > + /* Is it a C++ or Java compound data structure? */ > + > if (p[0] == '.' || p[1] == ':') > - /* C++ */ > - /* ... or Java */ > return decode_compound (argptr, funfirstline, canonical, > saved_arg, p); > > - /* Extract the file name. */ > - p1 = p; > - while (p != *argptr && p[-1] == ' ') > - --p; > - if ((*p == '"') && is_quote_enclosed) > - --p; > - copy = (char *) alloca (p - *argptr + 1); > - memcpy (copy, *argptr, p - *argptr); > - /* It may have the ending quote right after the file name */ > - if (is_quote_enclosed && copy[p - *argptr - 1] == '"') > - copy[p - *argptr - 1] = 0; > - else > - copy[p - *argptr] = 0; > - > - /* Find that file's data. */ > - s = lookup_symtab (copy); > - if (s == 0) > - { > - if (!have_full_symbols () && !have_partial_symbols ()) > - error ("No symbol table is loaded. Use the \"file\" command."); > - error ("No source file named %s.", copy); > - } > + /* No, the first part is a filename; set s to be that file's > + symtab. Also, move argptr past the filename. */ > > - /* Discard the file name from the arg. */ > - p = p1 + 1; > - while (*p == ' ' || *p == '\t') > - p++; > - *argptr = p; > + s = symtab_from_filename (argptr, p, is_quote_enclosed); > } > #if 0 > /* No one really seems to know why this was added. It certainly > @@ -1317,6 +1297,50 @@ decode_compound (char **argptr, int funf > "Can't find member of namespace, class, struct, or union named \"%s\"\n", > copy); > } > + > + > + > +/* Return the symtab associated to the filename given by the substring > + of *ARGPTR ending at P, and advance ARGPTR past that filename. */ > + > +static struct symtab * > +symtab_from_filename (char **argptr, char *p, int is_quote_enclosed) > +{ > + char *p1; > + char *copy; > + struct symtab *s; > + > + p1 = p; > + while (p != *argptr && p[-1] == ' ') > + --p; > + if ((*p == '"') && is_quote_enclosed) > + --p; > + copy = (char *) alloca (p - *argptr + 1); > + memcpy (copy, *argptr, p - *argptr); > + /* It may have the ending quote right after the file name */ > + if (is_quote_enclosed && copy[p - *argptr - 1] == '"') > + copy[p - *argptr - 1] = 0; > + else > + copy[p - *argptr] = 0; > + > + /* Find that file's data. */ > + s = lookup_symtab (copy); > + if (s == 0) > + { > + if (!have_full_symbols () && !have_partial_symbols ()) > + error ("No symbol table is loaded. Use the \"file\" command."); > + error ("No source file named %s.", copy); > + } > + > + /* Discard the file name from the arg. */ > + p = p1 + 1; > + while (*p == ' ' || *p == '\t') > + p++; > + *argptr = p; > + > + return s; > +} > + > > >