Clarify texinfo/
[deliverable/binutils-gdb.git] / gdb / solib.c
index fe3265e0930a6dfc7dad9f695dab6911d47b1dec..d5afd5a951c6df934750b502f027bdd4ab89ab5a 100644 (file)
@@ -184,61 +184,49 @@ 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.  */
@@ -445,7 +433,7 @@ solib_add_common_symbols (rtc_symp)
     }
 
   init_minimal_symbol_collection ();
-  make_cleanup ((make_cleanup_func) discard_minimal_symbols, 0);
+  make_cleanup_discard_minimal_symbols ();
 
   while (rtc_symp)
     {
@@ -488,8 +476,7 @@ solib_add_common_symbols (rtc_symp)
 
 #ifdef SVR4_SHARED_LIBS
 
-static CORE_ADDR
-  bfd_lookup_symbol PARAMS ((bfd *, char *));
+static CORE_ADDR bfd_lookup_symbol (bfd *, char *);
 
 /*
 
@@ -574,8 +561,7 @@ static char *debug_base_symbols[] =
   NULL
 };
 
-static int
-look_for_base PARAMS ((int, CORE_ADDR));
+static int look_for_base (int, CORE_ADDR);
 
 /*
 
@@ -710,6 +696,7 @@ elf_locate_base ()
   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,56 +713,67 @@ elf_locate_base ()
   /* 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)
+
+  arch_size = bfd_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))
        {
-         dyn_ptr = bfd_h_get_32 (exec_bfd, (bfd_byte *) x_dynp->d_un.d_ptr);
-         return dyn_ptr;
-       }
+         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));
-       }
+         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))
+  else /* 64-bit elf */
     {
-      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)
+      for (bufend = buf + dyninfo_sect_size;
+          buf < bufend;
+          buf += sizeof (Elf64_External_Dyn))
        {
-         dyn_ptr = bfd_h_get_64 (exec_bfd, (bfd_byte *) x_dynp->d_un.d_ptr);
-         return dyn_ptr;
+         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;
@@ -972,7 +970,7 @@ open_symbol_file_object (from_ttyp)
       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);
 
@@ -1153,10 +1151,10 @@ symbol_add_stub (arg)
      PTR arg;
 {
   register struct so_list *so = (struct so_list *) arg;  /* catch_errs bogon */
-  CORE_ADDR text_addr = 0;
   struct section_addr_info *sap;
-  int i;
-  asection *text_section;
+  CORE_ADDR lowest_addr = 0;
+  int lowest_index;
+  asection *lowest_sect = NULL;
 
   /* Have we already loaded this shared object?  */
   ALL_OBJFILES (so->objfile)
@@ -1167,32 +1165,33 @@ symbol_add_stub (arg)
 
   /* Find the shared object's text segment.  */
   if (so->textsection)
-    text_addr = so->textsection->addr;
+    {
+      lowest_addr = so->textsection->addr;
+      lowest_sect = bfd_get_section_by_name (so->abfd, ".text");
+      lowest_index = lowest_sect->index;
+    }
   else if (so->abfd != NULL)
     {
-      asection *lowest_sect;
-
-      /* If we didn't find a mapped non zero sized .text section, set up
-         text_addr so that the relocation in symbol_file_add does no harm.  */
+      /* If we didn't find a mapped non zero sized .text section, set
+         up lowest_addr so that the relocation in symbol_file_add does
+         no harm.  */
       lowest_sect = bfd_get_section_by_name (so->abfd, ".text");
       if (lowest_sect == NULL)
        bfd_map_over_sections (so->abfd, find_lowest_section,
                               (PTR) &lowest_sect);
       if (lowest_sect)
-       text_addr = bfd_section_vma (so->abfd, lowest_sect)
-         + LM_ADDR (so);
+       {
+         lowest_addr = bfd_section_vma (so->abfd, lowest_sect)
+           + LM_ADDR (so);
+         lowest_index = lowest_sect->index;
+       }
     }
 
   sap = build_section_addr_info_from_section_table (so->sections,
                                                     so->sections_end);
 
-  /* Look for the index for the .text section in the sap structure. */
-  text_section = bfd_get_section_by_name (so->abfd, ".text");
-  for (i = 0; i < MAX_SECTIONS && sap->other[i].name; i++)
-    if (sap->other[i].sectindex == text_section->index)
-      break;
-  
-  sap->other[i].addr = text_addr;
+  sap->other[lowest_index].addr = lowest_addr;
+
   so->objfile = symbol_file_add (so->so_name, so->from_tty,
                                 sap, 0, OBJF_SHARED);
   free_section_addr_info (sap);
@@ -1484,6 +1483,7 @@ info_sharedlibrary_command (ignore, from_tty)
   int header_done = 0;
   int addr_width;
   char *addr_fmt;
+  int arch_size;
 
   if (exec_bfd == NULL)
     {
@@ -1491,13 +1491,18 @@ info_sharedlibrary_command (ignore, from_tty)
       return;
     }
 
-#ifndef TARGET_ELF64
-  addr_width = 8 + 4;
-  addr_fmt = "08l";
-#else
-  addr_width = 16 + 4;
-  addr_fmt = "016l";
-#endif
+  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)
+    {
+      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);
 
This page took 0.028399 seconds and 4 git commands to generate.