From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29234 invoked by alias); 6 Dec 2002 00:19:49 -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 29227 invoked from network); 6 Dec 2002 00:19:48 -0000 Received: from unknown (HELO jackfruit.Stanford.EDU) (171.64.38.136) by sources.redhat.com with SMTP; 6 Dec 2002 00:19:48 -0000 Received: (from carlton@localhost) by jackfruit.Stanford.EDU (8.11.6/8.11.6) id gB60JlJ27965; Thu, 5 Dec 2002 16:19:47 -0800 X-Authentication-Warning: jackfruit.Stanford.EDU: carlton set sender to carlton@math.stanford.edu using -f To: gdb-patches@sources.redhat.com Subject: [rfa] linespec.c, part 6 Cc: Elena Zannoni From: David Carlton Date: Thu, 05 Dec 2002 16:26:00 -0000 Message-ID: User-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Common Lisp) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2002-12/txt/msg00214.txt.bz2 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. 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; +} +