/* Handle SunOS and SVR4 shared libraries for GDB, the GNU Debugger.
- Copyright 1990, 91, 92, 93, 94, 95, 96, 98, 1999
+ Copyright 1990, 91, 92, 93, 94, 95, 96, 98, 1999, 2000
Free Software Foundation, Inc.
This file is part of GDB.
Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-
+#define _SYSCALL32 /* for Sparc64 cross Sparc32 */
#include "defs.h"
/* This file is only compilable if link.h is available. */
NULL
};
-/* local data declarations */
-
-/* Macro to extract an address from a solib structure.
+/* Function 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. */
+ to get the right address when accessing the core file BFD.
+
+ We'll use the BFD itself to determine the number of significant bits.
+ MVS, June 2000 */
+
+static CORE_ADDR
+solib_extract_address (void *memberp)
+{
+ return extract_address (memberp,
+ bfd_get_arch_size (exec_bfd) / 8);
+}
-#define SOLIB_EXTRACT_ADDRESS(member) \
- extract_address (&member, sizeof (member))
+#define SOLIB_EXTRACT_ADDRESS(MEMBER) \
+ solib_extract_address (&MEMBER)
+
+/* local data declarations */
#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)
+/* NOTE: converted the macros LM_ADDR, LM_NEXT, LM_NAME and
+ IGNORE_FIRST_LINK_MAP_ENTRY into functions (see below).
+ MVS, June 2000 */
+
static struct link_dynamic dynamic_copy;
static struct link_dynamic_2 ld_2_copy;
static struct ld_debug debug_copy;
#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;
+#if defined (HAVE_STRUCT_LINK_MAP32)
+static struct r_debug32 debug32_copy; /* Sparc64 cross Sparc32 */
+#endif
+
char shadow_contents[BREAKPOINT_MAX]; /* Stash old bkpt addr contents */
#endif /* !SVR4_SHARED_LIBS */
struct so_list *next; /* next structure in linked list */
struct link_map lm; /* copy of link map from inferior */
+#if defined (HAVE_STRUCT_LINK_MAP32)
+ struct link_map32 lm32; /* copy of link map from 32-bit inferior */
+#endif
CORE_ADDR lmaddr; /* addr in inferior lm was read from */
/* Shared object file name, exactly as it appears in the
};
static struct so_list *so_list_head; /* List of known shared objects */
+
+/* link map access functions */
+
+#ifndef SVR4_SHARED_LIBS
+
+static CORE_ADDR
+LM_ADDR (so)
+ struct so_list *so;
+{
+#if defined (HAVE_STRUCT_LINK_MAP32)
+ if (bfd_get_arch_size (exec_bfd) == 32)
+ return extract_address (&so->lm32.lm_addr, sizeof (so->lm32.lm_addr));
+ else
+#endif
+ return extract_address (&so->lm.lm_addr, sizeof (so->lm.lm_addr));
+}
+
+static CORE_ADDR
+LM_NEXT (so)
+ struct so_list *so;
+{
+#if defined (HAVE_STRUCT_LINK_MAP32)
+ if (bfd_get_arch_size (exec_bfd) == 32)
+ return extract_address (&so->lm32.lm_next, sizeof (so->lm32.lm_next));
+ else
+#endif
+ return extract_address (&so->lm.lm_next, sizeof (so->lm.lm_next));
+}
+
+static CORE_ADDR
+LM_NAME (so)
+ struct so_list *so;
+{
+#if defined (HAVE_STRUCT_LINK_MAP32)
+ if (bfd_get_arch_size (exec_bfd) == 32)
+ return extract_address (&so->lm32.lm_name, sizeof (so->lm32.lm_name));
+ else
+#endif
+ return extract_address (&so->lm.lm_name, sizeof (so->lm.lm_name));
+}
+
+static int
+IGNORE_FIRST_LINK_MAP_ENTRY (so)
+ struct so_list *so;
+{
+ return 0;
+}
+
+#else /* SVR4_SHARED_LIBS */
+
+static CORE_ADDR
+LM_ADDR (so)
+ struct so_list *so;
+{
+#if defined (HAVE_STRUCT_LINK_MAP32)
+ if (bfd_get_arch_size (exec_bfd) == 32)
+ return extract_address (&so->lm32.l_addr, sizeof (so->lm32.l_addr));
+ else
+#endif
+ return extract_address (&so->lm.l_addr, sizeof (so->lm.l_addr));
+}
+
+static CORE_ADDR
+LM_NEXT (so)
+ struct so_list *so;
+{
+#if defined (HAVE_STRUCT_LINK_MAP32)
+ if (bfd_get_arch_size (exec_bfd) == 32)
+ return extract_address (&so->lm32.l_next, sizeof (so->lm32.l_next));
+ else
+#endif
+ return extract_address (&so->lm.l_next, sizeof (so->lm.l_next));
+}
+
+static CORE_ADDR
+LM_NAME (so)
+ struct so_list *so;
+{
+#if defined (HAVE_STRUCT_LINK_MAP32)
+ if (bfd_get_arch_size (exec_bfd) == 32)
+ return extract_address (&so->lm32.l_name, sizeof (so->lm32.l_name));
+ else
+#endif
+ return extract_address (&so->lm.l_name, sizeof (so->lm.l_name));
+}
+
+static int
+IGNORE_FIRST_LINK_MAP_ENTRY (so)
+ struct so_list *so;
+{
+#if defined (HAVE_STRUCT_LINK_MAP32)
+ if (bfd_get_arch_size (exec_bfd) == 32)
+ return (solib_extract_address (&(so) -> lm32.l_prev) == 0);
+ else
+#endif
+ return (solib_extract_address (&(so) -> lm.l_prev) == 0);
+}
+
+#endif /* !SVR4_SHARED_LIBS */
+
+
static CORE_ADDR debug_base; /* Base of dynamic linker structures */
static CORE_ADDR breakpoint_addr; /* Address where end bkpt is set */
static int solib_cleanup_queued = 0; /* make_run_cleanup called */
-extern int
-fdmatch PARAMS ((int, int)); /* In libiberty */
+extern int fdmatch (int, int); /* In libiberty */
/* Local function prototypes */
-static void
-do_clear_solib PARAMS ((PTR));
+static void do_clear_solib (PTR);
-static int
-match_main PARAMS ((char *));
+static int match_main (char *);
-static void
-special_symbol_handling PARAMS ((void));
+static void special_symbol_handling (void);
-static void
-sharedlibrary_command PARAMS ((char *, int));
+static void sharedlibrary_command (char *, int);
-static int
-enable_break PARAMS ((void));
+static int enable_break (void);
-static void
-info_sharedlibrary_command PARAMS ((char *, int));
+static void info_sharedlibrary_command (char *, int);
-static int symbol_add_stub PARAMS ((PTR));
+static int symbol_add_stub (PTR);
-static CORE_ADDR
- first_link_map_member PARAMS ((void));
+static CORE_ADDR first_link_map_member (void);
-static CORE_ADDR
- locate_base PARAMS ((void));
+static CORE_ADDR locate_base (void);
-static int solib_map_sections PARAMS ((PTR));
+static int solib_map_sections (PTR);
#ifdef SVR4_SHARED_LIBS
-static CORE_ADDR
- elf_locate_base PARAMS ((void));
+static CORE_ADDR elf_locate_base (void);
#else
static struct so_list *current_sos (void);
static void free_so (struct so_list *node);
-static int
-disable_break PARAMS ((void));
+static int disable_break (void);
-static void
-allocate_rt_common_objfile PARAMS ((void));
+static void allocate_rt_common_objfile (void);
static void
solib_add_common_symbols (CORE_ADDR);
#endif
-void _initialize_solib PARAMS ((void));
+void _initialize_solib (void);
/* If non-zero, this is a prefix that will be added to the front of the name
shared libraries with an absolute filename for loading. */
*/
static int
-solib_map_sections (arg)
- PTR arg;
+solib_map_sections (PTR arg)
{
struct so_list *so = (struct so_list *) arg; /* catch_errors bogon */
char *filename;
/* Allocate the runtime common object file. */
static void
-allocate_rt_common_objfile ()
+allocate_rt_common_objfile (void)
{
struct objfile *objfile;
struct objfile *last_one;
objfile. */
static void
-solib_add_common_symbols (rtc_symp)
- CORE_ADDR rtc_symp;
+solib_add_common_symbols (CORE_ADDR rtc_symp)
{
struct rtc_symb inferior_rtc_symb;
struct nlist inferior_rtc_nlist;
#ifdef SVR4_SHARED_LIBS
-static CORE_ADDR
- bfd_lookup_symbol PARAMS ((bfd *, char *));
+static CORE_ADDR bfd_lookup_symbol (bfd *, char *);
/*
*/
static CORE_ADDR
-bfd_lookup_symbol (abfd, symname)
- bfd *abfd;
- char *symname;
+bfd_lookup_symbol (bfd *abfd, char *symname)
{
unsigned int storage_needed;
asymbol *sym;
}
do_cleanups (back_to);
}
- return (symaddr);
+
+ if (symaddr)
+ return symaddr;
+
+ /* On FreeBSD, the dynamic linker is stripped by default. So we'll
+ have to check the dynamic string table too. */
+
+ storage_needed = bfd_get_dynamic_symtab_upper_bound (abfd);
+
+ if (storage_needed > 0)
+ {
+ symbol_table = (asymbol **) xmalloc (storage_needed);
+ back_to = make_cleanup (free, (PTR) symbol_table);
+ number_of_symbols = bfd_canonicalize_dynamic_symtab (abfd, symbol_table);
+
+ for (i = 0; i < number_of_symbols; i++)
+ {
+ sym = *symbol_table++;
+ if (STREQ (sym->name, symname))
+ {
+ /* Bfd symbols are section relative. */
+ symaddr = sym->value + sym->section->vma;
+ break;
+ }
+ }
+ do_cleanups (back_to);
+ }
+
+ return symaddr;
}
#ifdef HANDLE_SVR4_EXEC_EMULATORS
NULL
};
-static int
-look_for_base PARAMS ((int, CORE_ADDR));
+static int look_for_base (int, CORE_ADDR);
/*
*/
static int
-look_for_base (fd, baseaddr)
- int fd;
- CORE_ADDR baseaddr;
+look_for_base (int fd, CORE_ADDR baseaddr)
{
bfd *interp_bfd;
CORE_ADDR address = 0;
*/
static CORE_ADDR
-elf_locate_base ()
+elf_locate_base (void)
{
sec_ptr dyninfo_sect;
int dyninfo_sect_size;
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);
+ arch_size = bfd_get_arch_size (exec_bfd);
if (arch_size == -1) /* failure */
return 0;
#ifdef DT_MIPS_RLD_MAP
else if (dyn_tag == DT_MIPS_RLD_MAP)
{
- char pbuf[TARGET_PTR_BIT / HOST_CHAR_BIT];
+ char *pbuf;
+ pbuf = alloca (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,
*/
static CORE_ADDR
-locate_base ()
+locate_base (void)
{
#ifndef SVR4_SHARED_LIBS
does the reading. */
static CORE_ADDR
-first_link_map_member ()
+first_link_map_member (void)
{
CORE_ADDR lm = 0;
}
#else /* SVR4_SHARED_LIBS */
-
- read_memory (debug_base, (char *) &debug_copy, sizeof (struct r_debug));
+#if defined (HAVE_STRUCT_LINK_MAP32)
+ if (bfd_get_arch_size (exec_bfd) == 32)
+ {
+ read_memory (debug_base, (char *) &debug32_copy,
+ sizeof (struct r_debug32));
+ lm = SOLIB_EXTRACT_ADDRESS (debug32_copy.r_map);
+ }
+ else
+#endif
+ {
+ read_memory (debug_base, (char *) &debug_copy,
+ sizeof (struct r_debug));
+ lm = SOLIB_EXTRACT_ADDRESS (debug_copy.r_map);
+ }
/* 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 */
int *from_ttyp; /* sneak past catch_errors */
{
CORE_ADDR lm;
- struct link_map lmcopy;
char *filename;
int errcode;
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 defined (HAVE_STRUCT_LINK_MAP32)
+ if (bfd_get_arch_size (exec_bfd) == 32)
+ {
+ struct link_map32 lmcopy;
+ /* Read from target memory to GDB. */
+ read_memory (lm, (void *) &lmcopy, sizeof (lmcopy));
- if (lmcopy.l_name == 0)
- return 0; /* no filename. */
+ 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);
+ }
+ else
+#endif /* HAVE_STRUCT_LINK_MAP32 */
+ {
+ struct link_map lmcopy;
+ /* 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);
+ }
- /* Now fetch the filename from target memory. */
- target_read_string (SOLIB_EXTRACT_ADDRESS (lmcopy.l_name), &filename,
- MAX_PATH_SIZE - 1, &errcode);
if (errcode)
{
warning ("failed to read exec filename from attached file: %s",
return 0;
}
- make_cleanup ((make_cleanup_func) free, (void *) filename);
+ make_cleanup (free, filename);
/* Have a pathname: read the symbol file. */
symbol_file_command (filename, *from_ttyp);
non-zero iff SONAME matches one of the known main executable names. */
static int
-match_main (soname)
- char *soname;
+match_main (char *soname)
{
char **mainp;
we provide values for. */
static struct so_list *
-current_sos ()
+current_sos (void)
{
CORE_ADDR lm;
struct so_list *head = 0;
memset (new, 0, sizeof (*new));
new->lmaddr = lm;
- read_memory (lm, (char *) &(new->lm), sizeof (struct link_map));
+
+#if defined (HAVE_STRUCT_LINK_MAP32)
+ if (bfd_get_arch_size (exec_bfd) == 32)
+ read_memory (lm, (char *) &(new->lm32), sizeof (struct link_map32));
+ else
+#endif
+ read_memory (lm, (char *) &(new->lm), sizeof (struct link_map));
lm = LM_NEXT (new);
/* A small stub to get us past the arg-passing pinhole of catch_errors. */
static int
-symbol_add_stub (arg)
- PTR arg;
+symbol_add_stub (PTR arg)
{
register struct so_list *so = (struct so_list *) arg; /* catch_errs bogon */
struct section_addr_info *sap;
*/
static void
-info_sharedlibrary_command (ignore, from_tty)
- char *ignore;
- int from_tty;
+info_sharedlibrary_command (char *ignore, int from_tty)
{
register struct so_list *so = NULL; /* link map state variable */
int header_done = 0;
return;
}
- arch_size = bfd_elf_get_arch_size (exec_bfd);
+ arch_size = bfd_get_arch_size (exec_bfd);
/* Default to 32-bit in case of failure (non-elf). */
if (arch_size == 32 || arch_size == -1)
{
*/
char *
-solib_address (address)
- CORE_ADDR address;
+solib_address (CORE_ADDR address)
{
register struct so_list *so = 0; /* link map state variable */
/* Called by free_all_symtabs */
void
-clear_solib ()
+clear_solib (void)
{
/* This function is expected to handle ELF shared libraries. It is
also used on Solaris, which can run either ELF or a.out binaries
}
static void
-do_clear_solib (dummy)
- PTR dummy;
+do_clear_solib (PTR dummy)
{
solib_cleanup_queued = 0;
clear_solib ();
static CORE_ADDR interp_plt_sect_high;
int
-in_svr4_dynsym_resolve_code (pc)
- CORE_ADDR pc;
+in_svr4_dynsym_resolve_code (CORE_ADDR pc)
{
return ((pc >= interp_text_sect_low && pc < interp_text_sect_high)
|| (pc >= interp_plt_sect_low && pc < interp_plt_sect_high)
#ifndef SVR4_SHARED_LIBS
static int
-disable_break ()
+disable_break (void)
{
int status = 1;
*/
static int
-enable_break ()
+enable_break (void)
{
int success = 0;
*/
void
-solib_create_inferior_hook ()
+solib_create_inferior_hook (void)
{
/* If we are using the BKPT_AT_SYMBOL code, then we don't need the base
yet. In fact, in the case of a SunOS4 executable being run on
*/
static void
-special_symbol_handling ()
+special_symbol_handling (void)
{
#ifndef SVR4_SHARED_LIBS
int j;
*/
static void
-sharedlibrary_command (args, from_tty)
- char *args;
- int from_tty;
+sharedlibrary_command (char *args, int from_tty)
{
dont_repeat ();
solib_add (args, from_tty, (struct target_ops *) 0);
#endif /* HAVE_LINK_H */
void
-_initialize_solib ()
+_initialize_solib (void)
{
#ifdef HAVE_LINK_H