This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[RFA]: Remove linear search for C++
- To: gdb-patches at sources dot redhat dot com
- Subject: [RFA]: Remove linear search for C++
- From: Daniel Berlin <dberlin at redhat dot com>
- Date: 11 Oct 2000 00:05:06 -0400
- Cc: Elena Zannoni <ezannoni at cygnus dot com>
Once again, I don't have a changelog handy to paste from.
It hasn't changed anyway, unless i'm misremembering.
I have an exam tomorrow, so it's quite possible i *am* misremembering,
and someone did request changelog modifications to the previous patch.
Elena, this includes the suggested modifications to lookup_symbol, so
that needstofreename gets initialized to 0, reducing the amount of
code. I have an odd feeling I missed something when changing that
code, so i'd appreciate it if you'd double check it for me.
It's probably just my stress level, but ....
Index: symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.18
diff -c -3 -p -r1.18 symfile.c
*** symfile.c 2000/09/02 00:09:06 1.18
--- symfile.c 2000/10/11 03:55:07
*************** compare_symbols (const PTR s1p, const PT
*** 212,219 ****
s1 = (struct symbol **) s1p;
s2 = (struct symbol **) s2p;
!
! return (STRCMP (SYMBOL_NAME (*s1), SYMBOL_NAME (*s2)));
}
/*
--- 212,218 ----
s1 = (struct symbol **) s1p;
s2 = (struct symbol **) s2p;
! return (STRCMP (SYMBOL_SOURCE_NAME (*s1), SYMBOL_SOURCE_NAME (*s2)));
}
/*
*************** compare_symbols (const PTR s1p, const PT
*** 241,248 ****
static int
compare_psymbols (const PTR s1p, const PTR s2p)
{
! register char *st1 = SYMBOL_NAME (*(struct partial_symbol **) s1p);
! register char *st2 = SYMBOL_NAME (*(struct partial_symbol **) s2p);
if ((st1[0] - st2[0]) || !st1[0])
{
--- 240,253 ----
static int
compare_psymbols (const PTR s1p, const PTR s2p)
{
! register struct partial_symbol **s1, **s2;
! register char *st1, *st2;
!
! s1 = (struct partial_symbol **) s1p;
! s2 = (struct partial_symbol **) s2p;
! st1 = SYMBOL_SOURCE_NAME (*s1);
! st2 = SYMBOL_SOURCE_NAME (*s2);
!
if ((st1[0] - st2[0]) || !st1[0])
{
Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.15
diff -c -3 -p -r1.15 symtab.c
*** symtab.c 2000/09/04 08:29:25 1.15
--- symtab.c 2000/10/11 03:55:08
*************** static struct partial_symbol *lookup_par
*** 83,88 ****
--- 83,95 ----
static struct symtab *lookup_symtab_1 (char *);
+ static struct symbol *lookup_symbol_aux (const char *name, const
+ struct block *block, const
+ namespace_enum namespace, int
+ *is_a_field_of_this, struct
+ symtab **symtab);
+
+
static void cplusplus_hint (char *);
static struct symbol *find_active_alias (struct symbol *sym, CORE_ADDR addr);
*************** fixup_psymbol_section (struct partial_sy
*** 572,588 ****
can probably assume it will never hit the C++ code). */
struct symbol *
! lookup_symbol (const char *name, register const struct block *block,
const namespace_enum namespace, int *is_a_field_of_this,
struct symtab **symtab)
{
! register struct symbol *sym;
! register struct symtab *s = NULL;
! register struct partial_symtab *ps;
! struct blockvector *bv;
! register struct objfile *objfile = NULL;
! register struct block *b;
! register struct minimal_symbol *msymbol;
if (case_sensitivity == case_sensitive_off)
{
--- 565,578 ----
can probably assume it will never hit the C++ code). */
struct symbol *
! lookup_symbol (const char *name, const struct block *block,
const namespace_enum namespace, int *is_a_field_of_this,
struct symtab **symtab)
{
! char *modified_name = NULL;
! char *modified_name2 = NULL;
! int needtofreename=0;
! struct symbol *returnval;
if (case_sensitivity == case_sensitive_off)
{
*************** lookup_symbol (const char *name, registe
*** 594,601 ****
for (i= 0; i < len; i++)
copy[i] = tolower (name[i]);
copy[len] = 0;
! name = copy;
}
/* Search specified block and its superiors. */
--- 584,630 ----
for (i= 0; i < len; i++)
copy[i] = tolower (name[i]);
copy[len] = 0;
! modified_name = copy;
}
+ else
+ {
+ modified_name = (char *)name;
+ }
+ modified_name2 = modified_name;
+ /* If we are using C++ language, demangle the name before doing a lookup, so
+ we can always binary search. */
+ if (current_language->la_language == language_cplus)
+ {
+ modified_name2 = cplus_demangle (modified_name, DMGL_ANSI |
+ DMGL_PARAMS);
+ needtofreename=1;
+ }
+
+ if (!modified_name2)
+ {
+ modified_name2 = modified_name;
+ }
+ returnval = lookup_symbol_aux (modified_name2, block, namespace,
+ is_a_field_of_this, symtab);
+ if (needtofreename)
+ free(modified_name2);
+
+ return returnval;
+ }
+
+ static struct symbol *
+ lookup_symbol_aux (const char *name, const struct block *block,
+ const namespace_enum namespace, int *is_a_field_of_this,
+ struct symtab **symtab)
+ {
+ register struct symbol *sym;
+ register struct symtab *s = NULL;
+ register struct partial_symtab *ps;
+ register struct blockvector *bv;
+ register struct objfile *objfile = NULL;
+ register struct block *b;
+ register struct minimal_symbol *msymbol;
+
/* Search specified block and its superiors. */
*************** lookup_partial_symbol (struct partial_sy
*** 987,993 ****
{
do_linear_search = 1;
}
! if (STRCMP (SYMBOL_NAME (*center), name) >= 0)
{
top = center;
}
--- 1017,1023 ----
{
do_linear_search = 1;
}
! if (STRCMP (SYMBOL_SOURCE_NAME (*center), name) >= 0)
{
top = center;
}
*************** lookup_block_symbol (register const stru
*** 1190,1198 ****
{
/* Reset the linear search flag so if the binary search fails, we
won't do the linear search once unless we find some reason to
! do so, such as finding a C++ symbol during the binary search.
! Note that for C++ modules, ALL the symbols in a block should
! end up marked as C++ symbols. */
do_linear_search = 0;
top = BLOCK_NSYMS (block);
--- 1220,1226 ----
{
/* Reset the linear search flag so if the binary search fails, we
won't do the linear search once unless we find some reason to
! do so */
do_linear_search = 0;
top = BLOCK_NSYMS (block);
*************** lookup_block_symbol (register const stru
*** 1210,1231 ****
}
inc = (inc >> 1) + bot;
sym = BLOCK_SYM (block, inc);
! if (!do_linear_search
! && (SYMBOL_LANGUAGE (sym) == language_cplus
! || SYMBOL_LANGUAGE (sym) == language_java
! ))
{
do_linear_search = 1;
}
! if (SYMBOL_NAME (sym)[0] < name[0])
{
bot = inc;
}
! else if (SYMBOL_NAME (sym)[0] > name[0])
{
top = inc;
}
! else if (STRCMP (SYMBOL_NAME (sym), name) < 0)
{
bot = inc;
}
--- 1238,1256 ----
}
inc = (inc >> 1) + bot;
sym = BLOCK_SYM (block, inc);
! if (!do_linear_search && (SYMBOL_LANGUAGE (sym) == language_java))
{
do_linear_search = 1;
}
! if (SYMBOL_SOURCE_NAME (sym)[0] < name[0])
{
bot = inc;
}
! else if (SYMBOL_SOURCE_NAME (sym)[0] > name[0])
{
top = inc;
}
! else if (STRCMP (SYMBOL_SOURCE_NAME (sym), name) < 0)
{
bot = inc;
}
*************** lookup_block_symbol (register const stru
*** 1247,1265 ****
while (bot < top)
{
sym = BLOCK_SYM (block, bot);
! inc = SYMBOL_NAME (sym)[0] - name[0];
! if (inc == 0)
! {
! inc = STRCMP (SYMBOL_NAME (sym), name);
! }
! if (inc == 0 && SYMBOL_NAMESPACE (sym) == namespace)
! {
! return (sym);
! }
! if (inc > 0)
! {
! break;
! }
bot++;
}
}
--- 1272,1279 ----
while (bot < top)
{
sym = BLOCK_SYM (block, bot);
! if (SYMBOL_MATCHES_NAME (sym, name))
! return sym;
bot++;
}
}