This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [RFA]: Fix partial symbol lookups


Jim Blandy <jimb@cygnus.com> writes:

> Let me make sure I've got this straight:
> 
> - In the current sources, globals in partial symbol tables are sorted
>   by demangled name, and lookup_partial_symbol looks up demangled
>   names only.

No, partial symbol tables have no demangled names, and all partial
symbol lookups attempt to be done by demangled name.
Thus, all partial symbol lookups on demangled names, which is like 90%
of  partial symbol lookups, fail. The exception is routines calling
lookup_partial_symbol directly, rather than through
lookup_symbol. Some of these routines are using mangled names, which
is the correct way.


> 
> - Your patch reverts this to the way it used to be: globals in partial
>   symbol tables are sorted by mangled name, and lookup_partial_symbol
>   looks up mangled names only.

The partial symbol table only ever had mangled names since 1994, but i
never realized it because nothing says this explicitly, and the
lookup_partial_symbol code implied this wasn't true, but it indeed is.
If you grep the changelogs from 94, for demangled, you'll see the
changes made that remove demangled names from partial symbols, by
default, for speed/space reasons.

> 
> - Your patch changes changes lookup_symbol to pass the original name through 
>   to lookup_symbol_aux, which will then use that when it needs to
>   search the partial symbol tables.
Correct

> 
> Thus, if lookup_symbol is given a mangled name, we'll search for the
> mangled name in the psymtabs, and find it if it's there.

Yup.
> 
> However, if lookup_symbol is given a demangled name, we'll still never
> find it in the psymtabs.  Is that right?

Correct.
But this never worked since 1994 anyway, since psymbols have no
demangled name in them.
:)


I also corrected lookup_partial_symbol to binary search the global
table, regardless of language, since this is the part that had led me
to believe it had demangled names in it in the first place.  Since we
only have a sorted list of mangled names in the global list, there is
no reason to linear search it, ever.
Statics still aren't sorted, so we linear search those.


> 
> Daniel Berlin <dberlin@redhat.com> writes:
> 
> > 
> > This patch should fix partial symbol lookups, which are currently
> > broken for C++.
> > 
> > Jim, this needs your approval.
> > 
> > --Dan
> > 
> > Changelog entry:
> > 2000-11-14  Daniel Berlin  <dberlin@redhat.com> 
> >  
> >         * symfile.c (compare_psymbols): Use SYMBOL_NAME rather than 
> >         SYMBOL_SOURCE_NAME.  
> >  
> >         * symtab.c (lookup_symbol_aux): Also take mangled name, and 
> >         then pass it as the name to use for lookup for partial symbols.  
> >         (lookup_symbol): Pass mangled name to lookup_symbol_aux. 
> >         (lookup_partial_symbol): No need for SYMBOL_SOURCE_NAME. 
> >         (top level): Change lookup_symbol_aux prototype to take mangled name as
> >         last argument. 
> >  
> > Patch:
> > Index: symtab.c
> > ===================================================================
> > RCS file: /cvs/src/src/gdb/symtab.c,v
> > retrieving revision 1.22
> > diff -c -3 -p -r1.22 symtab.c
> > *** symtab.c	2000/11/10 23:02:56	1.22
> > --- symtab.c	2000/11/14 16:55:26
> > *************** static struct symbol *lookup_symbol_aux 
> > *** 81,87 ****
> >   					 struct block *block, const
> >   					 namespace_enum namespace, int
> >   					 *is_a_field_of_this, struct
> > ! 					 symtab **symtab);
> >   
> >   
> >   static struct symbol *find_active_alias (struct symbol *sym, CORE_ADDR addr);
> > --- 81,87 ----
> >   					 struct block *block, const
> >   					 namespace_enum namespace, int
> >   					 *is_a_field_of_this, struct
> > ! 					 symtab **symtab, const char *mangled_name);
> >   
> >   
> >   static struct symbol *find_active_alias (struct symbol *sym, CORE_ADDR addr);
> > *************** lookup_symbol (const char *name, const s
> > *** 594,600 ****
> >       }
> >   
> >     returnval = lookup_symbol_aux (modified_name, block, namespace,
> > ! 				 is_a_field_of_this, symtab);
> >     if (needtofreename)
> >       free (modified_name2);
> >   
> > --- 594,600 ----
> >       }
> >   
> >     returnval = lookup_symbol_aux (modified_name, block, namespace,
> > ! 				 is_a_field_of_this, symtab, name);
> >     if (needtofreename)
> >       free (modified_name2);
> >   
> > *************** lookup_symbol (const char *name, const s
> > *** 604,610 ****
> >   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;
> > --- 604,610 ----
> >   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, const char *mangled_name)
> >   {
> >     register struct symbol *sym;
> >     register struct symtab *s = NULL;
> > *************** lookup_symbol_aux (const char *name, con
> > *** 785,791 ****
> >   
> >     ALL_PSYMTABS (objfile, ps)
> >     {
> > !     if (!ps->readin && lookup_partial_symbol (ps, name, 1, namespace))
> >         {
> >   	s = PSYMTAB_TO_SYMTAB (ps);
> >   	bv = BLOCKVECTOR (s);
> > --- 785,791 ----
> >   
> >     ALL_PSYMTABS (objfile, ps)
> >     {
> > !     if (!ps->readin && lookup_partial_symbol (ps, mangled_name, 1, namespace))
> >         {
> >   	s = PSYMTAB_TO_SYMTAB (ps);
> >   	bv = BLOCKVECTOR (s);
> > *************** lookup_symbol_aux (const char *name, con
> > *** 835,841 ****
> >   
> >     ALL_PSYMTABS (objfile, ps)
> >     {
> > !     if (!ps->readin && lookup_partial_symbol (ps, name, 0, namespace))
> >         {
> >   	s = PSYMTAB_TO_SYMTAB (ps);
> >   	bv = BLOCKVECTOR (s);
> > --- 835,841 ----
> >   
> >     ALL_PSYMTABS (objfile, ps)
> >     {
> > !     if (!ps->readin && lookup_partial_symbol (ps, mangled_name, 0, namespace))
> >         {
> >   	s = PSYMTAB_TO_SYMTAB (ps);
> >   	bv = BLOCKVECTOR (s);
> > *************** lookup_symbol_aux (const char *name, con
> > *** 964,970 ****
> >   }
> >   								
> >   /* Look, in partial_symtab PST, for symbol NAME.  Check the global
> > !    symbols if GLOBAL, the static symbols if not */
> >   
> >   static struct partial_symbol *
> >   lookup_partial_symbol (struct partial_symtab *pst, const char *name, int global,
> > --- 964,975 ----
> >   }
> >   								
> >   /* Look, in partial_symtab PST, for symbol NAME.  Check the global
> > !    symbols if GLOBAL, the static symbols if not. 
> > ! 
> > !    Be aware that minimal symbols have no demangled names. So we need to lookup
> > !    by mangled name. However, this also means we can always binary search them, 
> > !    since they are a sorted list. If you change the way partial symbols work, 
> > !    you'll need to change this routine.  */
> >   
> >   static struct partial_symbol *
> >   lookup_partial_symbol (struct partial_symtab *pst, const char *name, int global,
> > *************** lookup_partial_symbol (struct partial_sy
> > *** 1000,1011 ****
> >   	  center = bottom + (top - bottom) / 2;
> >   	  if (!(center < top))
> >   	    abort ();
> > ! 	  if (!do_linear_search
> > ! 	      && (SYMBOL_LANGUAGE (*center) == language_java))
> > ! 	    {
> > ! 	      do_linear_search = 1;
> > ! 	    }
> > ! 	  if (STRCMP (SYMBOL_SOURCE_NAME (*center), name) >= 0)
> >   	    {
> >   	      top = center;
> >   	    }
> > --- 1005,1012 ----
> >   	  center = bottom + (top - bottom) / 2;
> >   	  if (!(center < top))
> >   	    abort ();
> > ! 
> > ! 	  if (STRCMP (SYMBOL_NAME (*center), name) >= 0)
> >   	    {
> >   	      top = center;
> >   	    }
> > Index: symfile.c
> > ===================================================================
> > RCS file: /cvs/src/src/gdb/symfile.c,v
> > retrieving revision 1.20
> > diff -c -3 -p -r1.20 symfile.c
> > *** symfile.c	2000/10/27 15:02:42	1.20
> > --- symfile.c	2000/11/14 16:55:27
> > *************** compare_psymbols (const PTR s1p, const P
> > *** 245,252 ****
> >   
> >     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])
> > --- 245,252 ----
> >   
> >     s1 = (struct partial_symbol **) s1p;
> >     s2 = (struct partial_symbol **) s2p;
> > !   st1 = SYMBOL_NAME (*s1);
> > !   st2 = SYMBOL_NAME (*s2);
> >   
> >   
> >     if ((st1[0] - st2[0]) || !st1[0])
> > 
> > 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]