This is the mail archive of the gdb-patches@sourceware.cygnus.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]

RFA: solib.c: Clean fix to get rid of severe Solaris 2.7 sparc regressions


> > I think there must be a better solution than the one that Peter
> > proposes.  However, I don't know what it is either.
> 
> Something like "extract_address (&lm->field, sizeof (lm->field))" I
> think.  I didn't suggest that at first because I thought it would
> require massive solib.c changes to use separate internal and external
> structures like in BFD.  But I guess that isn't true, I guess you can
> just change the cast to a call to extract_address.

Good idea, thanks. Here is a revised patch which gets rid of all
CORE_ADDR pointer casts in solib.c.

Once again the rationale for the patch:

This change:

2000-02-25  Alexandre Oliva  <oliva@lsd.ic.unicamp.br>

        * config.bfd: Enable 64 bit support for GNU/Linux/sparc.

        * config.bfd: Enable 64 bit support for Solaris7+/sparc.

causes a severe regression in corefile.exp on Solaris 2.7 sparc, which
should definitely be fixed before the 5.0 release.

Due to the BFD change, a CORE_ADDR is now an unsigned long long with 64 Bits.
When casting 32 bit pointers to a CORE_ADDR in solib.c, the sign bit of the
pointer gets extended, resulting in a very large adress. This is not a
problem when accessing the inferior via procfs (because the address gets
truncated back to 32 bits in the procfs interface), but it causes failures
when trying to retrieve the shared library info from corefile BFDs.


2000-03-09  Peter Schauer  <pes@regent.e-technik.tu-muenchen.de>

	* solib.c (SOLIB_EXTRACT_ADDRESS):  New macro to extract addresses
	from solib structures. Use it throughout solib.c, get rid of all
	CORE_ADDR casts.
	(struct so_list):  Change type of lmaddr to CORE_ADDR.
	(first_link_map_member):  Change return value type to CORE_ADDR,
	update callers.
	(solib_add_common_symbols):  Change parameter type to CORE_ADDR,
	update callers.
	(open_symbol_file_object, find_solib):  Change type of lm variable
	to CORE_ADDR.

*** gdb/solib.c.orig	Wed Nov 17 03:30:28 1999
--- gdb/solib.c	Wed Mar  8 14:06:40 2000
***************
*** 109,121 ****
  
  /* local data declarations */
  
  #ifndef SVR4_SHARED_LIBS
  
! #define LM_ADDR(so) ((so) -> lm.lm_addr)
! #define LM_NEXT(so) ((so) -> lm.lm_next)
! #define LM_NAME(so) ((so) -> lm.lm_name)
  /* Test for first link map entry; first entry is a shared library. */
! #define IGNORE_FIRST_LINK_MAP_ENTRY(x) (0)
  static struct link_dynamic dynamic_copy;
  static struct link_dynamic_2 ld_2_copy;
  static struct ld_debug debug_copy;
--- 109,130 ----
  
  /* local data declarations */
  
+ /* Macro to extract an address from a solib structure.
+    When GDB is configured for some 32-bit targets (e.g. Solaris 2.7
+    sparc), BFD is configured to handle 64-bit targets, so CORE_ADDR is
+    64 bits.  We have to extract only the significant bits of addresses
+    to get the right address when accessing the core file BFD.  */
+ 
+ #define SOLIB_EXTRACT_ADDRESS(member) \
+   extract_address (&member, sizeof (member))
+ 
  #ifndef SVR4_SHARED_LIBS
  
! #define LM_ADDR(so) (SOLIB_EXTRACT_ADDRESS ((so) -> lm.lm_addr))
! #define LM_NEXT(so) (SOLIB_EXTRACT_ADDRESS ((so) -> lm.lm_next))
! #define LM_NAME(so) (SOLIB_EXTRACT_ADDRESS ((so) -> lm.lm_name))
  /* Test for first link map entry; first entry is a shared library. */
! #define IGNORE_FIRST_LINK_MAP_ENTRY(so) (0)
  static struct link_dynamic dynamic_copy;
  static struct link_dynamic_2 ld_2_copy;
  static struct ld_debug debug_copy;
***************
*** 124,134 ****
  
  #else /* SVR4_SHARED_LIBS */
  
! #define LM_ADDR(so) ((so) -> lm.l_addr)
! #define LM_NEXT(so) ((so) -> lm.l_next)
! #define LM_NAME(so) ((so) -> lm.l_name)
  /* Test for first link map entry; first entry is the exec-file. */
! #define IGNORE_FIRST_LINK_MAP_ENTRY(x) ((x).l_prev == NULL)
  static struct r_debug debug_copy;
  char shadow_contents[BREAKPOINT_MAX];	/* Stash old bkpt addr contents */
  
--- 133,144 ----
  
  #else /* SVR4_SHARED_LIBS */
  
! #define LM_ADDR(so) (SOLIB_EXTRACT_ADDRESS ((so) -> lm.l_addr))
! #define LM_NEXT(so) (SOLIB_EXTRACT_ADDRESS ((so) -> lm.l_next))
! #define LM_NAME(so) (SOLIB_EXTRACT_ADDRESS ((so) -> lm.l_name))
  /* Test for first link map entry; first entry is the exec-file. */
! #define IGNORE_FIRST_LINK_MAP_ENTRY(so) \
!   (SOLIB_EXTRACT_ADDRESS ((so) -> lm.l_prev) == 0)
  static struct r_debug debug_copy;
  char shadow_contents[BREAKPOINT_MAX];	/* Stash old bkpt addr contents */
  
***************
*** 138,144 ****
    {
      struct so_list *next;	/* next structure in linked list */
      struct link_map lm;		/* copy of link map from inferior */
!     struct link_map *lmaddr;	/* addr in inferior lm was read from */
      CORE_ADDR lmend;		/* upper addr bound of mapped object */
      char so_name[MAX_PATH_SIZE];	/* shared object lib name (FIXME) */
      char symbols_loaded;	/* flag: symbols read in yet? */
--- 148,154 ----
    {
      struct so_list *next;	/* next structure in linked list */
      struct link_map lm;		/* copy of link map from inferior */
!     CORE_ADDR lmaddr;		/* addr in inferior lm was read from */
      CORE_ADDR lmend;		/* upper addr bound of mapped object */
      char so_name[MAX_PATH_SIZE];	/* shared object lib name (FIXME) */
      char symbols_loaded;	/* flag: symbols read in yet? */
***************
*** 184,190 ****
  static struct so_list *
    find_solib PARAMS ((struct so_list *));
  
! static struct link_map *
    first_link_map_member PARAMS ((void));
  
  static CORE_ADDR
--- 194,200 ----
  static struct so_list *
    find_solib PARAMS ((struct so_list *));
  
! static CORE_ADDR
    first_link_map_member PARAMS ((void));
  
  static CORE_ADDR
***************
*** 206,212 ****
  allocate_rt_common_objfile PARAMS ((void));
  
  static void
! solib_add_common_symbols PARAMS ((struct rtc_symb *));
  
  #endif
  
--- 216,222 ----
  allocate_rt_common_objfile PARAMS ((void));
  
  static void
! solib_add_common_symbols PARAMS ((CORE_ADDR));
  
  #endif
  
***************
*** 338,346 ****
        /* Relocate the section binding addresses as recorded in the shared
           object's file by the base address to which the object was actually
           mapped. */
!       p->addr += (CORE_ADDR) LM_ADDR (so);
!       p->endaddr += (CORE_ADDR) LM_ADDR (so);
!       so->lmend = (CORE_ADDR) max (p->endaddr, so->lmend);
        if (STREQ (p->the_bfd_section->name, ".text"))
  	{
  	  so->textsection = p;
--- 348,356 ----
        /* Relocate the section binding addresses as recorded in the shared
           object's file by the base address to which the object was actually
           mapped. */
!       p->addr += LM_ADDR (so);
!       p->endaddr += LM_ADDR (so);
!       so->lmend = max (p->endaddr, so->lmend);
        if (STREQ (p->the_bfd_section->name, ".text"))
  	{
  	  so->textsection = p;
***************
*** 398,404 ****
  
  static void
  solib_add_common_symbols (rtc_symp)
!      struct rtc_symb *rtc_symp;
  {
    struct rtc_symb inferior_rtc_symb;
    struct nlist inferior_rtc_nlist;
--- 408,414 ----
  
  static void
  solib_add_common_symbols (rtc_symp)
!      CORE_ADDR rtc_symp;
  {
    struct rtc_symb inferior_rtc_symb;
    struct nlist inferior_rtc_nlist;
***************
*** 421,430 ****
  
    while (rtc_symp)
      {
!       read_memory ((CORE_ADDR) rtc_symp,
  		   (char *) &inferior_rtc_symb,
  		   sizeof (inferior_rtc_symb));
!       read_memory ((CORE_ADDR) inferior_rtc_symb.rtc_sp,
  		   (char *) &inferior_rtc_nlist,
  		   sizeof (inferior_rtc_nlist));
        if (inferior_rtc_nlist.n_type == N_COMM)
--- 431,440 ----
  
    while (rtc_symp)
      {
!       read_memory (rtc_symp,
  		   (char *) &inferior_rtc_symb,
  		   sizeof (inferior_rtc_symb));
!       read_memory (SOLIB_EXTRACT_ADDRESS (inferior_rtc_symb.rtc_sp),
  		   (char *) &inferior_rtc_nlist,
  		   sizeof (inferior_rtc_nlist));
        if (inferior_rtc_nlist.n_type == N_COMM)
***************
*** 435,441 ****
  	  len = inferior_rtc_nlist.n_value - inferior_rtc_nlist.n_un.n_strx;
  
  	  name = xmalloc (len);
! 	  read_memory ((CORE_ADDR) inferior_rtc_nlist.n_un.n_name, name, len);
  
  	  /* Allocate the runtime common objfile if necessary. */
  	  if (rt_common_objfile == NULL)
--- 445,452 ----
  	  len = inferior_rtc_nlist.n_value - inferior_rtc_nlist.n_un.n_strx;
  
  	  name = xmalloc (len);
! 	  read_memory (SOLIB_EXTRACT_ADDRESS (inferior_rtc_nlist.n_un.n_name),
! 		       name, len);
  
  	  /* Allocate the runtime common objfile if necessary. */
  	  if (rt_common_objfile == NULL)
***************
*** 445,451 ****
  				      mst_bss, rt_common_objfile);
  	  free (name);
  	}
!       rtc_symp = inferior_rtc_symb.rtc_next;
      }
  
    /* Install any minimal symbols that have been collected as the current
--- 456,462 ----
  				      mst_bss, rt_common_objfile);
  	  free (name);
  	}
!       rtc_symp = SOLIB_EXTRACT_ADDRESS (inferior_rtc_symb.rtc_next);
      }
  
    /* Install any minimal symbols that have been collected as the current
***************
*** 857,866 ****
     a pointer to the copy in our address space.
   */
  
! static struct link_map *
  first_link_map_member ()
  {
!   struct link_map *lm = NULL;
  
  #ifndef SVR4_SHARED_LIBS
  
--- 868,877 ----
     a pointer to the copy in our address space.
   */
  
! static CORE_ADDR
  first_link_map_member ()
  {
!   CORE_ADDR lm = 0;
  
  #ifndef SVR4_SHARED_LIBS
  
***************
*** 869,877 ****
      {
        /* It is a version that we can deal with, so read in the secondary
           structure and find the address of the link map list from it. */
!       read_memory ((CORE_ADDR) dynamic_copy.ld_un.ld_2, (char *) &ld_2_copy,
  		   sizeof (struct link_dynamic_2));
!       lm = ld_2_copy.ld_loaded;
      }
  
  #else /* SVR4_SHARED_LIBS */
--- 880,889 ----
      {
        /* It is a version that we can deal with, so read in the secondary
           structure and find the address of the link map list from it. */
!       read_memory (SOLIB_EXTRACT_ADDRESS (dynamic_copy.ld_un.ld_2),
! 		   (char *) &ld_2_copy,
  		   sizeof (struct link_dynamic_2));
!       lm = SOLIB_EXTRACT_ADDRESS (ld_2_copy.ld_loaded);
      }
  
  #else /* SVR4_SHARED_LIBS */
***************
*** 880,886 ****
    /* FIXME:  Perhaps we should validate the info somehow, perhaps by
       checking r_version for a known version number, or r_state for
       RT_CONSISTENT. */
!   lm = debug_copy.r_map;
  
  #endif /* !SVR4_SHARED_LIBS */
  
--- 892,898 ----
    /* FIXME:  Perhaps we should validate the info somehow, perhaps by
       checking r_version for a known version number, or r_state for
       RT_CONSISTENT. */
!   lm = SOLIB_EXTRACT_ADDRESS (debug_copy.r_map);
  
  #endif /* !SVR4_SHARED_LIBS */
  
***************
*** 912,918 ****
       PTR arg;
  {
    int from_tty = (int) arg;	/* sneak past catch_errors */
!   struct link_map *lm, lmcopy;
    char *filename;
    int errcode;
  
--- 924,931 ----
       PTR arg;
  {
    int from_tty = (int) arg;	/* sneak past catch_errors */
!   CORE_ADDR lm;
!   struct link_map lmcopy;
    char *filename;
    int errcode;
  
***************
*** 924,940 ****
      return 0;	/* failed somehow... */
  
    /* First link map member should be the executable.  */
!   if ((lm = first_link_map_member ()) == NULL)
      return 0;	/* failed somehow... */
  
    /* Read from target memory to GDB.  */
!   read_memory ((CORE_ADDR) lm, (void *) &lmcopy, sizeof (lmcopy));
  
    if (lmcopy.l_name == 0)
      return 0;	/* no filename.  */
  
    /* Now fetch the filename from target memory.  */
!   target_read_string ((CORE_ADDR) lmcopy.l_name, &filename, 
  		      MAX_PATH_SIZE - 1, &errcode);
    if (errcode)
      {
--- 937,953 ----
      return 0;	/* failed somehow... */
  
    /* First link map member should be the executable.  */
!   if ((lm = first_link_map_member ()) == 0)
      return 0;	/* failed somehow... */
  
    /* Read from target memory to GDB.  */
!   read_memory (lm, (void *) &lmcopy, sizeof (lmcopy));
  
    if (lmcopy.l_name == 0)
      return 0;	/* no filename.  */
  
    /* Now fetch the filename from target memory.  */
!   target_read_string (SOLIB_EXTRACT_ADDRESS (lmcopy.l_name), &filename, 
  		      MAX_PATH_SIZE - 1, &errcode);
    if (errcode)
      {
***************
*** 979,985 ****
       struct so_list *so_list_ptr;	/* Last lm or NULL for first one */
  {
    struct so_list *so_list_next = NULL;
!   struct link_map *lm = NULL;
    struct so_list *new;
  
    if (so_list_ptr == NULL)
--- 992,998 ----
       struct so_list *so_list_ptr;	/* Last lm or NULL for first one */
  {
    struct so_list *so_list_next = NULL;
!   CORE_ADDR lm = 0;
    struct so_list *new;
  
    if (so_list_ptr == NULL)
***************
*** 1002,1012 ****
      {
        /* We have been called before, and are in the process of walking
           the shared library list.  Advance to the next shared object. */
!       if ((lm = LM_NEXT (so_list_ptr)) == NULL)
  	{
  	  /* We have hit the end of the list, so check to see if any were
  	     added, but be quiet if we can't read from the target any more. */
! 	  int status = target_read_memory ((CORE_ADDR) so_list_ptr->lmaddr,
  					   (char *) &(so_list_ptr->lm),
  					   sizeof (struct link_map));
  	  if (status == 0)
--- 1015,1025 ----
      {
        /* We have been called before, and are in the process of walking
           the shared library list.  Advance to the next shared object. */
!       if ((lm = LM_NEXT (so_list_ptr)) == 0)
  	{
  	  /* We have hit the end of the list, so check to see if any were
  	     added, but be quiet if we can't read from the target any more. */
! 	  int status = target_read_memory (so_list_ptr->lmaddr,
  					   (char *) &(so_list_ptr->lm),
  					   sizeof (struct link_map));
  	  if (status == 0)
***************
*** 1015,1026 ****
  	    }
  	  else
  	    {
! 	      lm = NULL;
  	    }
  	}
        so_list_next = so_list_ptr->next;
      }
!   if ((so_list_next == NULL) && (lm != NULL))
      {
        /* Get next link map structure from inferior image and build a local
           abbreviated load_map structure */
--- 1028,1039 ----
  	    }
  	  else
  	    {
! 	      lm = 0;
  	    }
  	}
        so_list_next = so_list_ptr->next;
      }
!   if ((so_list_next == NULL) && (lm != 0))
      {
        /* Get next link map structure from inferior image and build a local
           abbreviated load_map structure */
***************
*** 1045,1063 ****
  
  	}
        so_list_next = new;
!       read_memory ((CORE_ADDR) lm, (char *) &(new->lm),
! 		   sizeof (struct link_map));
        /* For SVR4 versions, the first entry in the link map is for the
           inferior executable, so we must ignore it.  For some versions of
           SVR4, it has no name.  For others (Solaris 2.3 for example), it
           does have a name, so we can no longer use a missing name to
           decide when to ignore it. */
!       if (!IGNORE_FIRST_LINK_MAP_ENTRY (new->lm))
  	{
  	  int errcode;
  	  char *buffer;
! 	  target_read_string ((CORE_ADDR) LM_NAME (new), &buffer,
! 			      MAX_PATH_SIZE - 1, &errcode);
  	  if (errcode != 0)
  	    {
  	      warning ("find_solib: Can't read pathname for load map: %s\n",
--- 1058,1075 ----
  
  	}
        so_list_next = new;
!       read_memory (lm, (char *) &(new->lm), sizeof (struct link_map));
        /* For SVR4 versions, the first entry in the link map is for the
           inferior executable, so we must ignore it.  For some versions of
           SVR4, it has no name.  For others (Solaris 2.3 for example), it
           does have a name, so we can no longer use a missing name to
           decide when to ignore it. */
!       if (!IGNORE_FIRST_LINK_MAP_ENTRY (new))
  	{
  	  int errcode;
  	  char *buffer;
! 	  target_read_string (LM_NAME (new),
! 			      &buffer, MAX_PATH_SIZE - 1, &errcode);
  	  if (errcode != 0)
  	    {
  	      warning ("find_solib: Can't read pathname for load map: %s\n",
***************
*** 1101,1107 ****
  			       (PTR) &lowest_sect);
        if (lowest_sect)
  	text_addr = bfd_section_vma (so->abfd, lowest_sect)
! 	  + (CORE_ADDR) LM_ADDR (so);
      }
  
    ALL_OBJFILES (so->objfile)
--- 1113,1119 ----
  			       (PTR) &lowest_sect);
        if (lowest_sect)
  	text_addr = bfd_section_vma (so->abfd, lowest_sect)
! 	  + LM_ADDR (so);
      }
  
    ALL_OBJFILES (so->objfile)
***************
*** 1351,1358 ****
      {
        if (so->so_name[0])
  	{
! 	  if ((address >= (CORE_ADDR) LM_ADDR (so)) &&
! 	      (address < (CORE_ADDR) so->lmend))
  	    return (so->so_name);
  	}
      }
--- 1363,1369 ----
      {
        if (so->so_name[0])
  	{
! 	  if ((address >= LM_ADDR (so)) && (address < so->lmend))
  	    return (so->so_name);
  	}
      }
***************
*** 1484,1490 ****
  
    write_memory (flag_addr, (char *) &in_debugger, sizeof (in_debugger));
  
!   breakpoint_addr = (CORE_ADDR) debug_copy.ldd_bp_addr;
    write_memory (breakpoint_addr, (char *) &debug_copy.ldd_bp_inst,
  		sizeof (debug_copy.ldd_bp_inst));
  
--- 1495,1501 ----
  
    write_memory (flag_addr, (char *) &in_debugger, sizeof (in_debugger));
  
!   breakpoint_addr = SOLIB_EXTRACT_ADDRESS (debug_copy.ldd_bp_addr);
    write_memory (breakpoint_addr, (char *) &debug_copy.ldd_bp_inst,
  		sizeof (debug_copy.ldd_bp_inst));
  
***************
*** 1579,1585 ****
  
    /* Calc address of debugger interface structure */
  
!   debug_addr = (CORE_ADDR) dynamic_copy.ldd;
  
    /* Calc address of `in_debugger' member of debugger interface structure */
  
--- 1590,1596 ----
  
    /* Calc address of debugger interface structure */
  
!   debug_addr = SOLIB_EXTRACT_ADDRESS (dynamic_copy.ldd);
  
    /* Calc address of `in_debugger' member of debugger interface structure */
  
***************
*** 1881,1887 ****
        /* FIXME, this needs work for cross-debugging of core files
           (byteorder, size, alignment, etc).  */
  
!       debug_addr = (CORE_ADDR) dynamic_copy.ldd;
      }
  
    /* Read the debugger structure from the inferior, just to make sure
--- 1892,1898 ----
        /* FIXME, this needs work for cross-debugging of core files
           (byteorder, size, alignment, etc).  */
  
!       debug_addr = SOLIB_EXTRACT_ADDRESS (dynamic_copy.ldd);
      }
  
    /* Read the debugger structure from the inferior, just to make sure
***************
*** 1896,1902 ****
  
    if (debug_copy.ldd_cp)
      {
!       solib_add_common_symbols (debug_copy.ldd_cp);
      }
  
  #endif /* !SVR4_SHARED_LIBS */
--- 1907,1913 ----
  
    if (debug_copy.ldd_cp)
      {
!       solib_add_common_symbols (SOLIB_EXTRACT_ADDRESS (debug_copy.ldd_cp));
      }
  
  #endif /* !SVR4_SHARED_LIBS */

-- 
Peter Schauer			pes@regent.e-technik.tu-muenchen.de

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