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]
Other format: [Raw text]

Re: [rfa] clean up lookup_symbol_aux


David Carlton writes:
 > Here's a slightly different version of my lookup_symbol_aux cleanup
 > patch.  It's basically the same patch, except that it tries to mimic
 > the current flow of control of lookup_symbol_aux even more closely.
 > Specifically, it no longer moves the psymtab search before the minsym
 > search (I no longer am convinced that that's a particularly good
 > idea), and it follows the flow of control from within the minsym
 > search more closely (the flow of control would seem to be somewhat
 > bizarre, but that's an issue for a subsequent patch).  Other than
 > that, my comments from that earlier message still hold, so I'll repeat
 > them here:
 > 
 > On 02 Oct 2002 14:50:34 -0700, David Carlton
 > <carlton@math.Stanford.EDU> said:
 > 
 > > When trying to understand lookup_symbol_aux, I found that it helped
 > > to pull chunks of the code into separate functions (e.g. the code to
 > > look up a symbol in all the global symtabs); this way, I could
 > > separate questions like "in what order do we look up symbols in
 > > various data structures?" from questions like "what exactly do we do
 > > when we look for a symbol in the partial symbol tables?".  And, once
 > > I'd done that, I found that some of the resulting functions could be
 > > combined (e.g. the code to look up a symbol in all the global
 > > symtabs is essentially the same as the code to look up a symbol in
 > > all the static symtabs).
 > 
 > > I think that the result is enough clearer than the original that I'm
 > > probably not the only person who would find it useful.  And
 > > combining similar chunks of code should help maintenance: e.g. the
 > > non-HPUXHPPA and HPUXHPPA cases are now combined (i.e. they're both
 > > calls to lookup_symbol_aux_minsyms, albeit in different places), so
 > > you don't have to remember to update them both.  (Some people seem
 > > to have forgotten that in the past: see below.)
 > 
 > > The resulting patch isn't easy to read: to be honest, to understand
 > > what it's doing, you'll probably want to apply it to a copy of
 > > symtab.c and compare the results, rather than try to read the patch
 > > directly.  Here are the Cliff's Notes for reading it:
 > 
 > > Changes that shouldn't affect the functioning of GDB at all:
 > 
 > > * The part of lookup_symbol_aux that never gets run and that is
 > >   prefaced by 17 lines of comments being bemused at its existence
 > >   has been deleted.

Could it be if deffed 0 for a bit, to see if we get some weird behaviors?
We can delete it later. Make sure you add a comment with a date.

 > 
 > > * Other long, coherent chunks of lookup_symbol_aux have been moved
 > >   into separate functions.
 > 

Yes

 > > * When two of the new functions were essentially identical, those
 > >   functions have been merged.  To be specific, there's a single
 > >   function lookup_symbol_aux_symtabs that can either search global
 > >   symbols or static symbols, and similarly with psymtab search.
 > 

yes

 > > Changes that might theoretically affect the function of GDB:
 > 
 > > * The two cases for searching minimal symbols (i.e. whether or not
 > >   you're in HPUXHPPA) turned out to be slightly different.  I went
 > >   through those differences and picked whichever variant seemed to
 > >   me to be better; as far as I can tell, there's no reason for the
 > >   code to differ in the two cases.  I also threw in a bug fix:
 > >   fixup_symbol_section had the wrong second argument in the variant
 > >   where it was present.
 > 

This one I am a bit worried about.  For the bugfix, I would prefer
that a separate patch is submitted, I cannot spot the fix in the patch.

I would check in the functions except the minsyms one, ifdeffing
the code that was deleted. Separately submit a patch for the bugfix,
and one just for the minsyms changes so that it can be tested independentely.

 > > I've tested this, and didn't turn up any new regressions.  It would
 > > be nice if somebody could give it a spin on an HP machine to make
 > > sure I didn't screw up that variant of the function.
 > 

Maybe Joel can test the hppa patch?

 > Once this patch is accepted, I'll probably submit more patches which
 > could actually change the behavior of lookup_symbol_aux, but it seemed
 > like a good idea to start with a patch that tries to preserve the
 > current behavior while reducing code duplication.  (And while making
 > it clear just what that current behavior is...)
 > 

Yes, mechanical changes should be separated from more functional ones.

Elena


 > David Carlton
 > carlton@math.stanford.edu
 > 
 > 2002-10-30  David Carlton  <carlton@math.stanford.edu>
 > 
 > 	* symtab.c (lookup_symbol_aux): Move chunks of code into separate
 > 	functions.
 > 	(lookup_symbol_aux_local): New function.
 > 	(lookup_symbol_aux_symtabs): New function.
 > 	(lookup_symbol_aux_psymtabs): New function.
 > 	(lookup_symbol_aux_minsyms): New function.
 > 
 > Index: symtab.c
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/symtab.c,v
 > retrieving revision 1.75
 > diff -u -p -r1.75 symtab.c
 > --- symtab.c	28 Oct 2002 17:05:56 -0000	1.75
 > +++ symtab.c	30 Oct 2002 22:52:55 -0000
 > @@ -83,6 +83,32 @@ static struct symbol *lookup_symbol_aux 
 >  					 int *is_a_field_of_this,
 >  					 struct symtab **symtab);
 >  
 > +static struct symbol *lookup_symbol_aux_local (const char *name,
 > +					       const char *mangled_name,
 > +					       const struct block *block,
 > +					       const namespace_enum namespace,
 > +					       struct symtab **symtab);
 > +
 > +static
 > +struct symbol *lookup_symbol_aux_symtabs (int block_index,
 > +					  const char *name,
 > +					  const char *mangled_name,
 > +					  const namespace_enum namespace,
 > +					  struct symtab **symtab);
 > +
 > +static
 > +struct symbol *lookup_symbol_aux_psymtabs (int block_index,
 > +					   const char *name,
 > +					   const char *mangled_name,
 > +					   const namespace_enum namespace,
 > +					   struct symtab **symtab);
 > +static
 > +struct symbol *lookup_symbol_aux_minsyms (const char *name,
 > +					  const char *mangled_name,
 > +					  const namespace_enum namespace,
 > +					  int *is_a_field_of_this,
 > +					  struct symtab **symtab,
 > +					  int *force_return);
 >  
 >  static struct symbol *find_active_alias (struct symbol *sym, CORE_ADDR addr);
 >  
 > @@ -766,84 +792,23 @@ lookup_symbol_aux (const char *name, con
 >  		   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;
 > +  struct symbol *sym;
 >  
 > +  /* FIXME: carlton/2002-10-30: This variable is here so that
 > +     lookup_symbol_aux will sometimes return NULL after receiving a
 > +     NULL return value from lookup_symbol_aux_minsyms, without
 > +     proceeding on to the partial symtab and static variable tests.  I
 > +     don't yet have an informed opinion as to the circumstances in
 > +     which that's a good idea (if ever).  */
 > +  
 > +  int force_return;
 >  
 >    /* Search specified block and its superiors.  */
 >  
 > -  while (block != 0)
 > -    {
 > -      sym = lookup_block_symbol (block, name, mangled_name, namespace);
 > -      if (sym)
 > -	{
 > -	  block_found = block;
 > -	  if (symtab != NULL)
 > -	    {
 > -	      /* Search the list of symtabs for one which contains the
 > -	         address of the start of this block.  */
 > -	      ALL_SYMTABS (objfile, s)
 > -	      {
 > -		bv = BLOCKVECTOR (s);
 > -		b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
 > -		if (BLOCK_START (b) <= BLOCK_START (block)
 > -		    && BLOCK_END (b) > BLOCK_START (block))
 > -		  goto found;
 > -	      }
 > -	    found:
 > -	      *symtab = s;
 > -	    }
 > -
 > -	  return fixup_symbol_section (sym, objfile);
 > -	}
 > -      block = BLOCK_SUPERBLOCK (block);
 > -    }
 > -
 > -  /* FIXME: this code is never executed--block is always NULL at this
 > -     point.  What is it trying to do, anyway?  We already should have
 > -     checked the STATIC_BLOCK above (it is the superblock of top-level
 > -     blocks).  Why is VAR_NAMESPACE special-cased?  */
 > -  /* Don't need to mess with the psymtabs; if we have a block,
 > -     that file is read in.  If we don't, then we deal later with
 > -     all the psymtab stuff that needs checking.  */
 > -  /* Note (RT): The following never-executed code looks unnecessary to me also.
 > -   * If we change the code to use the original (passed-in)
 > -   * value of 'block', we could cause it to execute, but then what
 > -   * would it do? The STATIC_BLOCK of the symtab containing the passed-in
 > -   * 'block' was already searched by the above code. And the STATIC_BLOCK's
 > -   * of *other* symtabs (those files not containing 'block' lexically)
 > -   * should not contain 'block' address-wise. So we wouldn't expect this
 > -   * code to find any 'sym''s that were not found above. I vote for 
 > -   * deleting the following paragraph of code.
 > -   */
 > -  if (namespace == VAR_NAMESPACE && block != NULL)
 > -    {
 > -      struct block *b;
 > -      /* Find the right symtab.  */
 > -      ALL_SYMTABS (objfile, s)
 > -      {
 > -	bv = BLOCKVECTOR (s);
 > -	b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
 > -	if (BLOCK_START (b) <= BLOCK_START (block)
 > -	    && BLOCK_END (b) > BLOCK_START (block))
 > -	  {
 > -	    sym = lookup_block_symbol (b, name, mangled_name, VAR_NAMESPACE);
 > -	    if (sym)
 > -	      {
 > -		block_found = b;
 > -		if (symtab != NULL)
 > -		  *symtab = s;
 > -		return fixup_symbol_section (sym, objfile);
 > -	      }
 > -	  }
 > -      }
 > -    }
 > -
 > +  sym = lookup_symbol_aux_local (name, mangled_name, block, namespace,
 > +				 symtab);
 > +  if (sym != NULL)
 > +    return sym;
 >  
 >    /* C++: If requested to do so by the caller, 
 >       check to see if NAME is a field of `this'. */
 > @@ -866,128 +831,151 @@ lookup_symbol_aux (const char *name, con
 >       of the desired name as a global, then do psymtab-to-symtab
 >       conversion on the fly and return the found symbol. */
 >  
 > -  ALL_SYMTABS (objfile, s)
 > -  {
 > -    bv = BLOCKVECTOR (s);
 > -    block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
 > -    sym = lookup_block_symbol (block, name, mangled_name, namespace);
 > -    if (sym)
 > -      {
 > -	block_found = block;
 > -	if (symtab != NULL)
 > -	  *symtab = s;
 > -	return fixup_symbol_section (sym, objfile);
 > -      }
 > -  }
 > +  sym = lookup_symbol_aux_symtabs (GLOBAL_BLOCK, name, mangled_name,
 > +				   namespace, symtab);
 > +  if (sym != NULL)
 > +    return sym;
 >  
 >  #ifndef HPUXHPPA
 >  
 > -  /* Check for the possibility of the symbol being a function or
 > -     a mangled variable that is stored in one of the minimal symbol tables.
 > -     Eventually, all global symbols might be resolved in this way.  */
 > +  /* Check for the possibility of the symbol being a function or a
 > +     mangled variable that is stored in one of the minimal symbol
 > +     tables.  Eventually, all global symbols might be resolved in this
 > +     way.  */
 > +
 > +  force_return = 0;
 > +
 > +  sym = lookup_symbol_aux_minsyms (name, mangled_name,
 > +				   namespace, is_a_field_of_this,
 > +				   symtab, &force_return);
 > +  
 > +  if (sym != NULL || force_return == 1)
 > +    return sym;
 >  
 > -  if (namespace == VAR_NAMESPACE)
 > -    {
 > -      msymbol = lookup_minimal_symbol (name, NULL, NULL);
 > -      if (msymbol != NULL)
 > -	{
 > -	  s = find_pc_sect_symtab (SYMBOL_VALUE_ADDRESS (msymbol),
 > -				   SYMBOL_BFD_SECTION (msymbol));
 > -	  if (s != NULL)
 > -	    {
 > -	      /* This is a function which has a symtab for its address.  */
 > -	      bv = BLOCKVECTOR (s);
 > -	      block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
 > +#endif
 >  
 > -              /* This call used to pass `SYMBOL_NAME (msymbol)' as the
 > -                 `name' argument to lookup_block_symbol.  But the name
 > -                 of a minimal symbol is always mangled, so that seems
 > -                 to be clearly the wrong thing to pass as the
 > -                 unmangled name.  */
 > -	      sym = lookup_block_symbol (block, name, mangled_name, namespace);
 > -	      /* We kept static functions in minimal symbol table as well as
 > -	         in static scope. We want to find them in the symbol table. */
 > -	      if (!sym)
 > -		{
 > -		  block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
 > -		  sym = lookup_block_symbol (block, name,
 > -                                             mangled_name, namespace);
 > -		}
 > +  sym = lookup_symbol_aux_psymtabs (GLOBAL_BLOCK, name, mangled_name,
 > +				    namespace, symtab);
 > +  if (sym != NULL)
 > +    return sym;
 >  
 > -	      /* sym == 0 if symbol was found in the minimal symbol table
 > -	         but not in the symtab.
 > -	         Return 0 to use the msymbol definition of "foo_".
 > +  /* Now search all static file-level symbols.  Not strictly correct,
 > +     but more useful than an error.  Do the symtabs first, then check
 > +     the psymtabs.  If a psymtab indicates the existence of the
 > +     desired name as a file-level static, then do psymtab-to-symtab
 > +     conversion on the fly and return the found symbol. */
 >  
 > -	         This happens for Fortran  "foo_" symbols,
 > -	         which are "foo" in the symtab.
 > +  sym = lookup_symbol_aux_symtabs (STATIC_BLOCK, name, mangled_name,
 > +				   namespace, symtab);
 > +  if (sym != NULL)
 > +    return sym;
 > +  
 > +  sym = lookup_symbol_aux_psymtabs (STATIC_BLOCK, name, mangled_name,
 > +				    namespace, symtab);
 > +  if (sym != NULL)
 > +    return sym;
 >  
 > -	         This can also happen if "asm" is used to make a
 > -	         regular symbol but not a debugging symbol, e.g.
 > -	         asm(".globl _main");
 > -	         asm("_main:");
 > -	       */
 >  
 > -	      if (symtab != NULL)
 > -		*symtab = s;
 > -	      return fixup_symbol_section (sym, objfile);
 > -	    }
 > -	  else if (MSYMBOL_TYPE (msymbol) != mst_text
 > -		   && MSYMBOL_TYPE (msymbol) != mst_file_text
 > -		   && !STREQ (name, SYMBOL_NAME (msymbol)))
 > +#ifdef HPUXHPPA
 > +
 > +  /* Check for the possibility of the symbol being a function or a
 > +     global variable that is stored in one of the minimal symbol
 > +     tables.  The "minimal symbol table" is built from linker-supplied
 > +     info.
 > +
 > +     RT: I moved this check to last, after the complete search of the
 > +     global (p)symtab's and static (p)symtab's. For HP-generated
 > +     symbol tables, this check was causing a premature exit from
 > +     lookup_symbol with NULL return, and thus messing up symbol
 > +     lookups of things like "c::f". It seems to me a check of the
 > +     minimal symbol table ought to be a last resort in any case. I'm
 > +     vaguely worried about the comment within
 > +     lookup_symbol_aux_minsyms which talks about FORTRAN routines
 > +     "foo_" though... is it saying we need to do the "minsym" check
 > +     before the static check in this case?  */
 > +
 > +  force_return = 0;
 > +
 > +  sym = lookup_symbol_aux_minsyms (name, mangled_name,
 > +				   namespace, is_a_field_of_this,
 > +				   symtab, &force_return);
 > +  
 > +  if (sym != NULL || force_return == 1)
 > +    return sym;
 > +
 > +#endif
 > +
 > +  if (symtab != NULL)
 > +    *symtab = NULL;
 > +  return NULL;
 > +}
 > +
 > +/* Check to see if the symbol is defined in BLOCK or its
 > +   superiors.  */
 > +
 > +static struct symbol *
 > +lookup_symbol_aux_local (const char *name, const char *mangled_name,
 > +			 const struct block *block,
 > +			 const namespace_enum namespace,
 > +			 struct symtab **symtab)
 > +{
 > +  struct symbol *sym;
 > +  struct objfile *objfile = NULL;
 > +  struct blockvector *bv;
 > +  struct block *b;
 > +  struct symtab *s = NULL;
 > +  
 > +  while (block != 0)
 > +    {
 > +      sym = lookup_block_symbol (block, name, mangled_name, namespace);
 > +      if (sym)
 > +	{
 > +	  block_found = block;
 > +	  if (symtab != NULL)
 >  	    {
 > -	      /* This is a mangled variable, look it up by its
 > -	         mangled name.  */
 > -	      return lookup_symbol_aux (SYMBOL_NAME (msymbol), mangled_name, block,
 > -					namespace, is_a_field_of_this, symtab);
 > +	      /* Search the list of symtabs for one which contains the
 > +	         address of the start of this block.  */
 > +	      ALL_SYMTABS (objfile, s)
 > +	      {
 > +		bv = BLOCKVECTOR (s);
 > +		b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
 > +		if (BLOCK_START (b) <= BLOCK_START (block)
 > +		    && BLOCK_END (b) > BLOCK_START (block))
 > +		  goto found;
 > +	      }
 > +	    found:
 > +	      *symtab = s;
 >  	    }
 > -	  /* There are no debug symbols for this file, or we are looking
 > -	     for an unmangled variable.
 > -	     Try to find a matching static symbol below. */
 > +
 > +	  return fixup_symbol_section (sym, objfile);
 >  	}
 > +      block = BLOCK_SUPERBLOCK (block);
 >      }
 >  
 > -#endif
 > +  return NULL;
 > +}
 >  
 > -  ALL_PSYMTABS (objfile, ps)
 > -  {
 > -    if (!ps->readin && lookup_partial_symbol (ps, name, 1, namespace))
 > -      {
 > -	s = PSYMTAB_TO_SYMTAB (ps);
 > -	bv = BLOCKVECTOR (s);
 > -	block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
 > -	sym = lookup_block_symbol (block, name, mangled_name, namespace);
 > -	if (!sym)
 > -	  {
 > -	    /* This shouldn't be necessary, but as a last resort
 > -	     * try looking in the statics even though the psymtab
 > -	     * claimed the symbol was global. It's possible that
 > -	     * the psymtab gets it wrong in some cases.
 > -	     */
 > -	    block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
 > -	    sym = lookup_block_symbol (block, name, mangled_name, namespace);
 > -	    if (!sym)
 > -	      error ("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
 > -%s may be an inlined function, or may be a template function\n\
 > -(if a template, try specifying an instantiation: %s<type>).",
 > -		     name, ps->filename, name, name);
 > -	  }
 > -	if (symtab != NULL)
 > -	  *symtab = s;
 > -	return fixup_symbol_section (sym, objfile);
 > -      }
 > -  }
 > +/* Check to see if the symbol is defined in one of the symtabs.
 > +   BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK,
 > +   depending on whether or not we want to search global symbols or
 > +   static symbols.  */
 >  
 > -  /* Now search all static file-level symbols.
 > -     Not strictly correct, but more useful than an error.
 > -     Do the symtabs first, then check the psymtabs.
 > -     If a psymtab indicates the existence
 > -     of the desired name as a file-level static, then do psymtab-to-symtab
 > -     conversion on the fly and return the found symbol. */
 > +static struct symbol *
 > +lookup_symbol_aux_symtabs (int block_index,
 > +			   const char *name, const char *mangled_name,
 > +			   const namespace_enum namespace,
 > +			   struct symtab **symtab)
 > +{
 > +  struct symbol *sym;
 > +  struct objfile *objfile;
 > +  struct blockvector *bv;
 > +  const struct block *block;
 > +  struct symtab *s;
 >  
 >    ALL_SYMTABS (objfile, s)
 >    {
 >      bv = BLOCKVECTOR (s);
 > -    block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
 > +    block = BLOCKVECTOR_BLOCK (bv, block_index);
 >      sym = lookup_block_symbol (block, name, mangled_name, namespace);
 >      if (sym)
 >        {
 > @@ -998,27 +986,57 @@ lookup_symbol_aux (const char *name, con
 >        }
 >    }
 >  
 > +  return NULL;
 > +}
 > +
 > +/* Check to see if the symbol is defined in one of the partial
 > +   symtabs.  BLOCK_INDEX should be either GLOBAL_BLOCK or
 > +   STATIC_BLOCK, depending on whether or not we want to search global
 > +   symbols or static symbols.  */
 > +
 > +static struct symbol *
 > +lookup_symbol_aux_psymtabs (int block_index, const char *name,
 > +			    const char *mangled_name,
 > +			    const namespace_enum namespace,
 > +			    struct symtab **symtab)
 > +{
 > +  struct symbol *sym;
 > +  struct objfile *objfile;
 > +  struct blockvector *bv;
 > +  const struct block *block;
 > +  struct partial_symtab *ps;
 > +  struct symtab *s;
 > +  const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
 > +
 >    ALL_PSYMTABS (objfile, ps)
 >    {
 > -    if (!ps->readin && lookup_partial_symbol (ps, name, 0, namespace))
 > +    if (!ps->readin
 > +	&& lookup_partial_symbol (ps, name, psymtab_index, namespace))
 >        {
 >  	s = PSYMTAB_TO_SYMTAB (ps);
 >  	bv = BLOCKVECTOR (s);
 > -	block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
 > +	block = BLOCKVECTOR_BLOCK (bv, block_index);
 >  	sym = lookup_block_symbol (block, name, mangled_name, namespace);
 >  	if (!sym)
 >  	  {
 > -	    /* This shouldn't be necessary, but as a last resort
 > -	     * try looking in the globals even though the psymtab
 > -	     * claimed the symbol was static. It's possible that
 > -	     * the psymtab gets it wrong in some cases.
 > -	     */
 > -	    block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
 > +	    /* This shouldn't be necessary, but as a last resort try
 > +	       looking in the statics even though the psymtab claimed
 > +	       the symbol was global, or vice-versa. It's possible
 > +	       that the psymtab gets it wrong in some cases.  */
 > +
 > +	    /* FIXME: carlton/2002-09-30: Should we really do that?
 > +	       If that happens, isn't it likely to be a GDB error, in
 > +	       which case we should fix the GDB error rather than
 > +	       silently dealing with it here?  So I'd vote for
 > +	       removing the check for the symbol in the other
 > +	       block.  */
 > +	    block = BLOCKVECTOR_BLOCK (bv,
 > +				       block_index == GLOBAL_BLOCK ?
 > +				       STATIC_BLOCK : GLOBAL_BLOCK);
 >  	    sym = lookup_block_symbol (block, name, mangled_name, namespace);
 >  	    if (!sym)
 > -	      error ("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
 > -%s may be an inlined function, or may be a template function\n\
 > -(if a template, try specifying an instantiation: %s<type>).",
 > +	      error ("Internal: %s symbol `%s' found in %s psymtab but not in symtab.\n%s may be an inlined function, or may be a template function\n(if a template, try specifying an instantiation: %s<type>).",
 > +		     block_index == GLOBAL_BLOCK ? "global" : "static",
 >  		     name, ps->filename, name, name);
 >  	  }
 >  	if (symtab != NULL)
 > @@ -1027,79 +1045,75 @@ lookup_symbol_aux (const char *name, con
 >        }
 >    }
 >  
 > -#ifdef HPUXHPPA
 > +  return NULL;
 > +}
 >  
 > -  /* Check for the possibility of the symbol being a function or
 > -     a global variable that is stored in one of the minimal symbol tables.
 > -     The "minimal symbol table" is built from linker-supplied info.
 > +/* Check for the possibility of the symbol being a function or a
 > +   mangled variable that is stored in one of the minimal symbol
 > +   tables.  Eventually, all global symbols might be resolved in this
 > +   way.  */
 >  
 > -     RT: I moved this check to last, after the complete search of
 > -     the global (p)symtab's and static (p)symtab's. For HP-generated
 > -     symbol tables, this check was causing a premature exit from
 > -     lookup_symbol with NULL return, and thus messing up symbol lookups
 > -     of things like "c::f". It seems to me a check of the minimal
 > -     symbol table ought to be a last resort in any case. I'm vaguely
 > -     worried about the comment below which talks about FORTRAN routines "foo_"
 > -     though... is it saying we need to do the "minsym" check before
 > -     the static check in this case? 
 > -   */
 > +static struct symbol *
 > +lookup_symbol_aux_minsyms (const char *name,
 > +			   const char *mangled_name,
 > +			   const namespace_enum namespace,
 > +			   int *is_a_field_of_this,
 > +			   struct symtab **symtab,
 > +			   int *force_return)
 > +{
 > +  struct symbol *sym;
 > +  struct blockvector *bv;
 > +  const struct block *block;
 > +  struct minimal_symbol *msymbol;
 > +  struct symtab *s;
 >  
 >    if (namespace == VAR_NAMESPACE)
 >      {
 >        msymbol = lookup_minimal_symbol (name, NULL, NULL);
 > +
 >        if (msymbol != NULL)
 >  	{
 > -	  /* OK, we found a minimal symbol in spite of not
 > -	   * finding any symbol. There are various possible
 > -	   * explanations for this. One possibility is the symbol
 > -	   * exists in code not compiled -g. Another possibility
 > -	   * is that the 'psymtab' isn't doing its job.
 > -	   * A third possibility, related to #2, is that we were confused 
 > -	   * by name-mangling. For instance, maybe the psymtab isn't
 > -	   * doing its job because it only know about demangled
 > -	   * names, but we were given a mangled name...
 > -	   */
 > -
 > -	  /* We first use the address in the msymbol to try to
 > -	   * locate the appropriate symtab. Note that find_pc_symtab()
 > -	   * has a side-effect of doing psymtab-to-symtab expansion,
 > -	   * for the found symtab.
 > -	   */
 > -	  s = find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol));
 > +	  /* OK, we found a minimal symbol in spite of not finding any
 > +	     symbol. There are various possible explanations for
 > +	     this. One possibility is the symbol exists in code not
 > +	     compiled -g. Another possibility is that the 'psymtab'
 > +	     isn't doing its job.  A third possibility, related to #2,
 > +	     is that we were confused by name-mangling. For instance,
 > +	     maybe the psymtab isn't doing its job because it only
 > +	     know about demangled names, but we were given a mangled
 > +	     name...  */
 > +
 > +	  /* We first use the address in the msymbol to try to locate
 > +	     the appropriate symtab. Note that find_pc_sect_symtab()
 > +	     has a side-effect of doing psymtab-to-symtab expansion,
 > +	     for the found symtab.  */
 > +	  s = find_pc_sect_symtab (SYMBOL_VALUE_ADDRESS (msymbol),
 > +				   SYMBOL_BFD_SECTION (msymbol));
 >  	  if (s != NULL)
 >  	    {
 > +	      /* This is a function which has a symtab for its address.  */
 >  	      bv = BLOCKVECTOR (s);
 >  	      block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
 > -              /* This call used to pass `SYMBOL_NAME (msymbol)' as the
 > -                 `name' argument to lookup_block_symbol.  But the name
 > -                 of a minimal symbol is always mangled, so that seems
 > -                 to be clearly the wrong thing to pass as the
 > -                 unmangled name.  */
 > -	      sym = lookup_block_symbol (block, name, mangled_name, namespace);
 > +
 > +	      /* This call used to pass `SYMBOL_NAME (msymbol)' as the
 > +	         `name' argument to lookup_block_symbol.  But the name
 > +	         of a minimal symbol is always mangled, so that seems
 > +	         to be clearly the wrong thing to pass as the
 > +	         unmangled name.  */
 > +	      sym =
 > +		lookup_block_symbol (block, name, mangled_name, namespace);
 >  	      /* We kept static functions in minimal symbol table as well as
 >  	         in static scope. We want to find them in the symbol table. */
 >  	      if (!sym)
 >  		{
 >  		  block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
 >  		  sym = lookup_block_symbol (block, name,
 > -                                             mangled_name, namespace);
 > -		}
 > -	      /* If we found one, return it */
 > -	      if (sym)
 > -		{
 > -		  if (symtab != NULL)
 > -		    *symtab = s;
 > -		  return sym;
 > +					     mangled_name, namespace);
 >  		}
 >  
 > -	      /* If we get here with sym == 0, the symbol was 
 > -	         found in the minimal symbol table
 > +	      /* sym == 0 if symbol was found in the minimal symbol table
 >  	         but not in the symtab.
 > -	         Fall through and return 0 to use the msymbol 
 > -	         definition of "foo_".
 > -	         (Note that outer code generally follows up a call
 > -	         to this routine with a call to lookup_minimal_symbol(),
 > -	         so a 0 return means we'll just flow into that other routine).
 > +	         Return 0 to use the msymbol definition of "foo_".
 >  
 >  	         This happens for Fortran  "foo_" symbols,
 >  	         which are "foo" in the symtab.
 > @@ -1109,28 +1123,27 @@ lookup_symbol_aux (const char *name, con
 >  	         asm(".globl _main");
 >  	         asm("_main:");
 >  	       */
 > -	    }
 >  
 > -	  /* If the lookup-by-address fails, try repeating the
 > -	   * entire lookup process with the symbol name from
 > -	   * the msymbol (if different from the original symbol name).
 > -	   */
 > +	      if (symtab != NULL)
 > +		*symtab = s;
 > +	      *force_return = 1;
 > +	      return fixup_symbol_section (sym, s->objfile);
 > +	    }
 >  	  else if (MSYMBOL_TYPE (msymbol) != mst_text
 >  		   && MSYMBOL_TYPE (msymbol) != mst_file_text
 >  		   && !STREQ (name, SYMBOL_NAME (msymbol)))
 >  	    {
 > +	      /* This is a mangled variable, look it up by its
 > +	         mangled name.  */
 > +	      *force_return = 1;
 >  	      return lookup_symbol_aux (SYMBOL_NAME (msymbol), mangled_name,
 > -					block, namespace, is_a_field_of_this,
 > +					NULL, namespace, is_a_field_of_this,
 >  					symtab);
 >  	    }
 >  	}
 >      }
 >  
 > -#endif
 > -
 > -  if (symtab != NULL)
 > -    *symtab = NULL;
 > -  return 0;
 > +  return NULL;
 >  }
 >  								
 >  /* Look, in partial_symtab PST, for symbol NAME.  Check the global


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