This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[rfa] linespec.c: lookup_prefix_sym
- From: David Carlton <carlton at math dot stanford dot edu>
- To: gdb-patches at sources dot redhat dot com
- Cc: Elena Zannoni <ezannoni at redhat dot com>
- Date: 15 Jan 2003 14:26:43 -0800
- Subject: [rfa] linespec.c: lookup_prefix_sym
Now I'm starting to decompose decode_compound into pieces. Here's the
first one: this creates a new function lookup_prefix_sym.
It's pretty straightforward: it doesn't change the code at all. The
only delicate issue is to make sure that decode_compound doesn't need
the values of 'p' and 'copy' after the call, since lookup_prefix_sym
changes them. The other uses of both variables lie in two situations:
if the big "if (sym_class && ...)" branch is taken, and if it isn't.
If the branch is taken, then p is reset immediately (to either
skip_quoted (*argptr) or *argptr). And 'copy' is reset right after
that, in the code that follows the commented-out bit. (Despite the
presence of braces, that code is commented out: those braces are there
because it was originally the else clause of a commented-out
conditional.)
And if the branch isn't taken, then p is reset immediately as well.
And the only use of copy outside the branch is right at the end of the
function, and copy is reset there as well.
Tested on i686-pc-linux-gnu/GCC3.1/DWARF-2; OK to commit?
David Carlton
carlton@math.stanford.edu
2003-01-15 David Carlton <carlton@math.stanford.edu>
* linespec.c (decode_compound): Extract code into
lookup_prefix_sym.
(lookup_prefix_sym): New function.
Index: linespec.c
===================================================================
RCS file: /cvs/src/src/gdb/linespec.c,v
retrieving revision 1.38
diff -u -p -r1.38 linespec.c
--- linespec.c 14 Jan 2003 20:48:50 -0000 1.38
+++ linespec.c 15 Jan 2003 22:16:07 -0000
@@ -54,6 +54,8 @@ static struct symtabs_and_lines decode_c
char *saved_arg,
char *p);
+static struct symbol *lookup_prefix_sym (char **argptr, char *p);
+
static NORETURN void cplusplus_error (const char *name,
const char *fmt, ...)
ATTR_NORETURN ATTR_FORMAT (printf, 2, 3);
@@ -930,7 +932,7 @@ decode_compound (char **argptr, int funf
char *saved_arg, char *p)
{
struct symtabs_and_lines values;
- char *p1, *p2;
+ char *p2;
#if 0
char *q, *q1;
#endif
@@ -975,22 +977,7 @@ decode_compound (char **argptr, int funf
p2 = p; /* Save for restart. */
while (1)
{
- /* Extract the class name. */
- p1 = p;
- while (p != *argptr && p[-1] == ' ')
- --p;
- copy = (char *) alloca (p - *argptr + 1);
- memcpy (copy, *argptr, p - *argptr);
- copy[p - *argptr] = 0;
-
- /* Discard the class name from the arg. */
- p = p1 + (p1[0] == ':' ? 2 : 1);
- while (*p == ' ' || *p == '\t')
- p++;
- *argptr = p;
-
- sym_class = lookup_symbol (copy, 0, STRUCT_NAMESPACE, 0,
- (struct symtab **) NULL);
+ sym_class = lookup_prefix_sym (argptr, p);
if (sym_class &&
(t = check_typedef (SYMBOL_TYPE (sym_class)),
@@ -1166,6 +1153,37 @@ decode_compound (char **argptr, int funf
cplusplus_error (saved_arg,
"Can't find member of namespace, class, struct, or union named \"%s\"\n",
copy);
+}
+
+/* Next come some helper functions for decode_compound. */
+
+/* Return the symbol corresponding to the substring of *ARGPTR ending
+ at P, allowing whitespace. Also, advance *ARGPTR past the symbol
+ name in question, the compound object separator ("::" or "."), and
+ whitespace. */
+
+static struct symbol *
+lookup_prefix_sym (char **argptr, char *p)
+{
+ char *p1;
+ char *copy;
+
+ /* Extract the class name. */
+ p1 = p;
+ while (p != *argptr && p[-1] == ' ')
+ --p;
+ copy = (char *) alloca (p - *argptr + 1);
+ memcpy (copy, *argptr, p - *argptr);
+ copy[p - *argptr] = 0;
+
+ /* Discard the class name from the arg. */
+ p = p1 + (p1[0] == ':' ? 2 : 1);
+ while (*p == ' ' || *p == '\t')
+ p++;
+ *argptr = p;
+
+ return lookup_symbol (copy, 0, STRUCT_NAMESPACE, 0,
+ (struct symtab **) NULL);
}