This is the mail archive of the
gdb-patches@sourceware.cygnus.com
mailing list for the GDB project.
Re: [PATCH]: Make solib.c more multi-archable
- To: Andrew Cagney <ac131313 at cygnus dot com>
- Subject: Re: [PATCH]: Make solib.c more multi-archable
- From: Michael Snyder <msnyder at cygnus dot com>
- Date: Thu, 04 May 2000 15:25:31 -0700
- CC: gdb-patches at sourceware dot cygnus dot com, jimb at cygnus dot com
- Organization: Cygnus Solutions
- References: <200005040017.RAA15336@seadog.cygnus.com> <3910CDE6.1D5770EB@cygnus.com>
- Reply-To: msnyder at cygnus dot com
Andrew Cagney wrote:
>
> msnyder@cygnus.com wrote:
> >
> > Hello,
> >
> > This patch will allow solib.c to use the bfd to determine whether
> > it is ELF32 or ELF64, rather than using a compile-time macro.
> >
> > This gets us closer to allowing a single GDB to debug both types
> > of solibs.
> >
> > 2000-05-03 Michael Snyder <msnyder@seadog.cygnus.com>
> >
> > * solib.c (elf_locate_base, info_sharedlibrary_command):
> > Look at the bfd to determine if it is elf32 or elf64, rather
> > than using an ifdef. This makes it runtime teststable and
> > multi-arch.
>
> My only thought is to make:
>
> (get_elf_backend_data (exec_bfd))->s->arch_size == 32)
>
> a function.
OK, how about this (same ChangeLog entry):
From - Thu May 04 15:24:41 2000
Received: from seadog.cygnus.com (seadog.cygnus.com [205.180.231.191])
by runyon.cygnus.com (8.8.7-cygnus/8.8.7) with ESMTP id PAA08606
for <msnyder@mailhost>; Thu, 4 May 2000 15:09:01 -0700 (PDT)
Received: by seadog.cygnus.com (8.9.3+Sun/SMI-SVR4)
id PAA23153; Thu, 4 May 2000 15:08:59 -0700 (PDT)
Date: Thu, 4 May 2000 15:08:59 -0700 (PDT)
Message-Id: <200005042208.PAA23153@seadog.cygnus.com>
From: msnyder@cygnus.com
To: msnyder@cygnus.com
Subject: solib.diff
X-UIDL: b2560af98009731769dec2b6f261c825
X-Mozilla-Status: 0001
Content-Length: 5208
Index: solib.c
===================================================================
RCS file: /cvs/src/src/gdb/solib.c,v
retrieving revision 1.11
diff -c -r1.11 solib.c
*** solib.c 2000/04/17 16:09:04 1.11
--- solib.c 2000/05/04 21:19:05
***************
*** 710,715 ****
--- 710,716 ----
CORE_ADDR dyninfo_addr;
char *buf;
char *bufend;
+ int arch_size;
/* Find the start address of the .dynamic section. */
dyninfo_sect = bfd_get_section_by_name (exec_bfd, ".dynamic");
***************
*** 726,781 ****
/* Find the DT_DEBUG entry in the the .dynamic section.
For mips elf we look for DT_MIPS_RLD_MAP, mips elf apparently has
no DT_DEBUG entries. */
! #ifndef TARGET_ELF64
! for (bufend = buf + dyninfo_sect_size;
! buf < bufend;
! buf += sizeof (Elf32_External_Dyn))
! {
! Elf32_External_Dyn *x_dynp = (Elf32_External_Dyn *) buf;
! long dyn_tag;
! CORE_ADDR dyn_ptr;
!
! dyn_tag = bfd_h_get_32 (exec_bfd, (bfd_byte *) x_dynp->d_tag);
! if (dyn_tag == DT_NULL)
! break;
! else if (dyn_tag == DT_DEBUG)
! {
! dyn_ptr = bfd_h_get_32 (exec_bfd, (bfd_byte *) x_dynp->d_un.d_ptr);
! return dyn_ptr;
! }
#ifdef DT_MIPS_RLD_MAP
! else if (dyn_tag == DT_MIPS_RLD_MAP)
! {
! char pbuf[TARGET_PTR_BIT / HOST_CHAR_BIT];
! /* DT_MIPS_RLD_MAP contains a pointer to the address
! of the dynamic link structure. */
! dyn_ptr = bfd_h_get_32 (exec_bfd, (bfd_byte *) x_dynp->d_un.d_ptr);
! if (target_read_memory (dyn_ptr, pbuf, sizeof (pbuf)))
! return 0;
! return extract_unsigned_integer (pbuf, sizeof (pbuf));
! }
#endif
}
! #else /* ELF64 */
! for (bufend = buf + dyninfo_sect_size;
! buf < bufend;
! buf += sizeof (Elf64_External_Dyn))
! {
! Elf64_External_Dyn *x_dynp = (Elf64_External_Dyn *) buf;
! long dyn_tag;
! CORE_ADDR dyn_ptr;
!
! dyn_tag = bfd_h_get_64 (exec_bfd, (bfd_byte *) x_dynp->d_tag);
! if (dyn_tag == DT_NULL)
! break;
! else if (dyn_tag == DT_DEBUG)
! {
! dyn_ptr = bfd_h_get_64 (exec_bfd, (bfd_byte *) x_dynp->d_un.d_ptr);
! return dyn_ptr;
}
}
- #endif
/* DT_DEBUG entry not found. */
return 0;
--- 727,793 ----
/* Find the DT_DEBUG entry in the the .dynamic section.
For mips elf we look for DT_MIPS_RLD_MAP, mips elf apparently has
no DT_DEBUG entries. */
!
! arch_size = bfd_elf_get_arch_size (exec_bfd);
! if (arch_size == -1) /* failure */
! return 0;
!
! if (arch_size == 32)
! { /* 32-bit elf */
! for (bufend = buf + dyninfo_sect_size;
! buf < bufend;
! buf += sizeof (Elf32_External_Dyn))
! {
! Elf32_External_Dyn *x_dynp = (Elf32_External_Dyn *) buf;
! long dyn_tag;
! CORE_ADDR dyn_ptr;
!
! dyn_tag = bfd_h_get_32 (exec_bfd, (bfd_byte *) x_dynp->d_tag);
! if (dyn_tag == DT_NULL)
! break;
! else if (dyn_tag == DT_DEBUG)
! {
! dyn_ptr = bfd_h_get_32 (exec_bfd,
! (bfd_byte *) x_dynp->d_un.d_ptr);
! return dyn_ptr;
! }
#ifdef DT_MIPS_RLD_MAP
! else if (dyn_tag == DT_MIPS_RLD_MAP)
! {
! char pbuf[TARGET_PTR_BIT / HOST_CHAR_BIT];
! /* DT_MIPS_RLD_MAP contains a pointer to the address
! of the dynamic link structure. */
! dyn_ptr = bfd_h_get_32 (exec_bfd,
! (bfd_byte *) x_dynp->d_un.d_ptr);
! if (target_read_memory (dyn_ptr, pbuf, sizeof (pbuf)))
! return 0;
! return extract_unsigned_integer (pbuf, sizeof (pbuf));
! }
#endif
+ }
}
! else /* 64-bit elf */
! {
! for (bufend = buf + dyninfo_sect_size;
! buf < bufend;
! buf += sizeof (Elf64_External_Dyn))
! {
! Elf64_External_Dyn *x_dynp = (Elf64_External_Dyn *) buf;
! long dyn_tag;
! CORE_ADDR dyn_ptr;
!
! dyn_tag = bfd_h_get_64 (exec_bfd, (bfd_byte *) x_dynp->d_tag);
! if (dyn_tag == DT_NULL)
! break;
! else if (dyn_tag == DT_DEBUG)
! {
! dyn_ptr = bfd_h_get_64 (exec_bfd,
! (bfd_byte *) x_dynp->d_un.d_ptr);
! return dyn_ptr;
! }
}
}
/* DT_DEBUG entry not found. */
return 0;
***************
*** 1484,1489 ****
--- 1496,1502 ----
int header_done = 0;
int addr_width;
char *addr_fmt;
+ int arch_size;
if (exec_bfd == NULL)
{
***************
*** 1491,1503 ****
return;
}
! #ifndef TARGET_ELF64
! addr_width = 8 + 4;
! addr_fmt = "08l";
! #else
! addr_width = 16 + 4;
! addr_fmt = "016l";
! #endif
update_solib_list (from_tty, 0);
--- 1504,1521 ----
return;
}
! arch_size = bfd_elf_get_arch_size (exec_bfd);
! if (arch_size == 32 ||
! arch_size == -1) /* default to 32-bit in case of failure (non-elf) */
! {
! addr_width = 8 + 4;
! addr_fmt = "08l";
! }
! else if (arch_size == 64)
! {
! addr_width = 16 + 4;
! addr_fmt = "016l";
! }
update_solib_list (from_tty, 0);