This is the mail archive of the gdb-prs@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]

pending/991: [rfa] ALL_OBJFILE_MSYMBOLS


>Number:         991
>Category:       pending
>Synopsis:       [rfa] ALL_OBJFILE_MSYMBOLS
>Confidential:   yes
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          change-request
>Submitter-Id:   unknown
>Arrival-Date:   Fri Jan 31 05:28:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     
>Release:        
>Organization:
>Environment:
>Description:
 When playing around with anonymous objfiles on a branch, I noticed
 another problem with them: the macro ALL_OBJFILE_MSYMBOLS assumes that
 objfile->msymbols is always non-NULL, which isn't the case if you have
 an artificial objfile floating around.
 
 Looking further, I noticed that the macro ALL_MSYMBOLS already has an
 explicit test that objfile->msymbols is non-NULL; it seems to me that
 the easiest thing to do is is to require users of ALL_OBJFILE_MSYMBOLS
 to first check that objfile->msymbols is non-NULL.
 
 Here's a patch that does that, along with adding some comments to
 objfiles.h explaining the situation.  It turns out that
 ALL_OBJFILE_MSYMBOLS is only used in two places; in two of those
 places, it's immediately within ALL_OBJFILES, so the intended effect
 is to look at all the msymbols; I thus replaced those two occurrences
 by uses of ALL_MSYMBOLS.  The third occurrence isn't surrounded by a
 use of ALL_OBJFILES, so I just enclosed it in a test that
 objfile->msymbols is non-NULL.
 
 Like my earlier allocate_objfile(NULL, 0) patch, I don't know of any
 concrete bugs that this fixes on mainline GDB, though I could imagine
 that Java code could run into this problem since Java does allocate an
 anonymous objfile.  But the patch is so straightforward that I don't
 see how applying it could hurt.  (It looks a little more complicated
 than it is because it changes the indentation levels.)
 
 Tested on i686-pc-linux-gnu/GCC3.1/DWARF-2; I also verified that 'make
 arm-linux-tdep.o' compiles without errors, though I haven't run that
 code directly.  (The code in question in arm-linux-tdep.c is
 essentially identical to the code in i386-linux-tdep.c.)
 
 David Carlton
 carlton@math.stanford.edu
 
 2003-01-27  David Carlton  <carlton@math.stanford.edu>
 
 	* objfiles.h: Add comments about objfile->msymbols being NULL.
 	* objfiles.c (objfile_relocate): Enclose ALL_OBJFILE_MSYMBOLS in
 	guard.
 	* i386-linux-tdep.c (find_minsym_and_objfile): Call ALL_MSYMBOLS
 	instead of ALL_OBJFILES and ALL_OBJFILE_MSYMBOLS.
 	* arm-linux-tdep.c (find_minsym_and_objfile): Ditto.
 
 Index: objfiles.h
 ===================================================================
 RCS file: /cvs/src/src/gdb/objfiles.h,v
 retrieving revision 1.17
 diff -u -p -r1.17 objfiles.h
 --- objfiles.h	23 Jan 2003 23:03:31 -0000	1.17
 +++ objfiles.h	28 Jan 2003 22:09:15 -0000
 @@ -300,6 +300,12 @@ struct objfile
         null symbol.  The array itself, as well as all the data that it points
         to, should be allocated on the symbol_obstack for this file. */
  
 +    /* NOTE: carlton/2003-01-27: For a newly-created objfile, msymbols
 +       is set to NULL, rather than a one-element array ending in a
 +       null symbol.  ALL_MSYMBOLS already guarded against that case,
 +       so that seems to be a valid possibility; it can be useful if
 +       you like to create artificial objfiles.  */
 +
      struct minimal_symbol *msymbols;
      int minimal_symbol_count;
  
 @@ -574,6 +580,10 @@ extern int is_in_import_list (char *, st
      for ((p) = (objfile) -> psymtabs; (p) != NULL; (p) = (p) -> next)
  
  /* Traverse all minimal symbols in one objfile.  */
 +
 +/* NOTE: carlton/2003-01-27: Don't call this macro unless
 +   objfile->msymbols is non-NULL.  See NOTE above in the declaration
 +   of 'struct objfile'.  */
  
  #define	ALL_OBJFILE_MSYMBOLS(objfile, m) \
      for ((m) = (objfile) -> msymbols; SYMBOL_NAME(m) != NULL; (m)++)
 Index: objfiles.c
 ===================================================================
 RCS file: /cvs/src/src/gdb/objfiles.c,v
 retrieving revision 1.24
 diff -u -p -r1.24 objfiles.c
 --- objfiles.c	23 Jan 2003 23:03:31 -0000	1.24
 +++ objfiles.c	28 Jan 2003 22:08:14 -0000
 @@ -674,12 +674,15 @@ objfile_relocate (struct objfile *objfil
        }
    }
  
 -  {
 -    struct minimal_symbol *msym;
 -    ALL_OBJFILE_MSYMBOLS (objfile, msym)
 -      if (SYMBOL_SECTION (msym) >= 0)
 -      SYMBOL_VALUE_ADDRESS (msym) += ANOFFSET (delta, SYMBOL_SECTION (msym));
 -  }
 +  if (objfile->msymbols != NULL)
 +    {
 +      struct minimal_symbol *msym;
 +      ALL_OBJFILE_MSYMBOLS (objfile, msym)
 +	if (SYMBOL_SECTION (msym) >= 0)
 +	  SYMBOL_VALUE_ADDRESS (msym)
 +	    += ANOFFSET (delta, SYMBOL_SECTION (msym));
 +    }
 +
    /* Relocating different sections by different amounts may cause the symbols
       to be out of order.  */
    msymbols_sort (objfile);
 Index: i386-linux-tdep.c
 ===================================================================
 RCS file: /cvs/src/src/gdb/i386-linux-tdep.c,v
 retrieving revision 1.22
 diff -u -p -r1.22 i386-linux-tdep.c
 --- i386-linux-tdep.c	8 Jan 2003 22:47:46 -0000	1.22
 +++ i386-linux-tdep.c	28 Jan 2003 22:07:08 -0000
 @@ -325,19 +325,15 @@ static struct minimal_symbol *
  find_minsym_and_objfile (char *name, struct objfile **objfile_p)
  {
    struct objfile *objfile;
 +  struct minimal_symbol *msym;
  
 -  ALL_OBJFILES (objfile)
 +  ALL_MSYMBOLS (objfile, msym)
      {
 -      struct minimal_symbol *msym;
 -
 -      ALL_OBJFILE_MSYMBOLS (objfile, msym)
 +      if (SYMBOL_NAME (msym)
 +	  && STREQ (SYMBOL_NAME (msym), name))
  	{
 -	  if (SYMBOL_NAME (msym)
 -	      && STREQ (SYMBOL_NAME (msym), name))
 -	    {
 -	      *objfile_p = objfile;
 -	      return msym;
 -	    }
 +	  *objfile_p = objfile;
 +	  return msym;
  	}
      }
  
 Index: arm-linux-tdep.c
 ===================================================================
 RCS file: /cvs/src/src/gdb/arm-linux-tdep.c,v
 retrieving revision 1.25
 diff -u -p -r1.25 arm-linux-tdep.c
 --- arm-linux-tdep.c	4 Jan 2003 23:38:44 -0000	1.25
 +++ arm-linux-tdep.c	28 Jan 2003 22:06:25 -0000
 @@ -356,19 +356,15 @@ static struct minimal_symbol *
  find_minsym_and_objfile (char *name, struct objfile **objfile_p)
  {
    struct objfile *objfile;
 +  struct minimal_symbol *msym;
  
 -  ALL_OBJFILES (objfile)
 +  ALL_MSYMBOLS (objfile, msym)
      {
 -      struct minimal_symbol *msym;
 -
 -      ALL_OBJFILE_MSYMBOLS (objfile, msym)
 +      if (SYMBOL_NAME (msym)
 +	  && strcmp (SYMBOL_NAME (msym), name) == 0)
  	{
 -	  if (SYMBOL_NAME (msym)
 -	      && strcmp (SYMBOL_NAME (msym), name) == 0)
 -	    {
 -	      *objfile_p = objfile;
 -	      return msym;
 -	    }
 +	  *objfile_p = objfile;
 +	  return msym;
  	}
      }
  
 
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:


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