* [rfa] linespec.c, part 6
@ 2002-12-05 16:26 David Carlton
2002-12-09 10:26 ` Elena Zannoni
0 siblings, 1 reply; 3+ messages in thread
From: David Carlton @ 2002-12-05 16:26 UTC (permalink / raw)
To: gdb-patches; +Cc: Elena Zannoni
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 <carlton@math.stanford.edu>
* 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);
}
+
+\f
+
+/* 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;
+}
+
\f
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [rfa] linespec.c, part 6
2002-12-05 16:26 [rfa] linespec.c, part 6 David Carlton
@ 2002-12-09 10:26 ` Elena Zannoni
2002-12-09 11:59 ` David Carlton
0 siblings, 1 reply; 3+ messages in thread
From: Elena Zannoni @ 2002-12-09 10:26 UTC (permalink / raw)
To: David Carlton; +Cc: gdb-patches, Elena Zannoni
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 <carlton@math.stanford.edu>
>
> * 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);
> }
> +
> +\f
> +
> +/* 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;
> +}
> +
>
> \f
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [rfa] linespec.c, part 6
2002-12-09 10:26 ` Elena Zannoni
@ 2002-12-09 11:59 ` David Carlton
0 siblings, 0 replies; 3+ messages in thread
From: David Carlton @ 2002-12-09 11:59 UTC (permalink / raw)
To: Elena Zannoni; +Cc: gdb-patches
On Mon, 9 Dec 2002 12:11:05 -0500, Elena Zannoni <ezannoni@redhat.com> said:
> David Carlton writes:
>> Here's the next part of the exciting linespec series of patches.
> Ok.
Thanks, committed.
David Carlton
carlton@math.stanford.edu
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-12-09 19:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-05 16:26 [rfa] linespec.c, part 6 David Carlton
2002-12-09 10:26 ` Elena Zannoni
2002-12-09 11:59 ` David Carlton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox