[PATCH]: Make solib.c more multi-archable
Jim Blandy
jimb@zwingli.cygnus.com
Thu May 4 17:25:00 GMT 2000
If you implement Andrew's suggestion of wrapping it up in a function,
then I approve of this patch.
msnyder@cygnus.com writes:
>
> 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.
>
> Index: solib.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/solib.c,v
> retrieving revision 1.11
> diff -p -r1.11 solib.c
> *** solib.c 2000/04/17 16:09:04 1.11
> --- solib.c 2000/05/04 00:15:08
> ***************
> *** 43,48 ****
> --- 43,51 ----
>
> #include "symtab.h"
> #include "bfd.h"
> + #define _ELF_COMMON_H /* Kludge: prevent inclusion of elf/common.h.
> + Defines conflict with /usr/include/sys/elf.h */
> + #include "elf-bfd.h"
> #include "symfile.h"
> #include "objfiles.h"
> #include "gdbcore.h"
> *************** elf_locate_base ()
> *** 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;
> --- 729,790 ----
> /* 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. */
> ! if ((get_elf_backend_data (exec_bfd))->s->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;
> *************** info_sharedlibrary_command (ignore, from
> *** 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);
>
> --- 1500,1515 ----
> return;
> }
>
> ! if ((get_elf_backend_data (exec_bfd))->s->arch_size == 32)
> ! { /* 32-bit elf */
> ! addr_width = 8 + 4;
> ! addr_fmt = "08l";
> ! }
> ! else /* 64-bit elf */
> ! {
> ! addr_width = 16 + 4;
> ! addr_fmt = "016l";
> ! }
>
> update_solib_list (from_tty, 0);
>
>
More information about the Gdb-patches
mailing list