Add forgotten ChangeLog snippet for last elf64-x86-64.c patch.
[deliverable/binutils-gdb.git] / gdb / symfile.c
index 62f96798b6e87b636940c36197af1ee6f045466c..839a7bc366ed45aaa0001fcd9010889b60d83a48 100644 (file)
@@ -210,55 +210,20 @@ compare_symbols (const void *s1p, const void *s2p)
 
   s1 = (struct symbol **) s1p;
   s2 = (struct symbol **) s2p;
-  return (strcmp (SYMBOL_SOURCE_NAME (*s1), SYMBOL_SOURCE_NAME (*s2)));
+  return (strcmp (SYMBOL_NATURAL_NAME (*s1), SYMBOL_NATURAL_NAME (*s2)));
 }
 
-/*
-
-   LOCAL FUNCTION
-
-   compare_psymbols -- compare two partial symbols by name
-
-   DESCRIPTION
-
-   Given pointers to pointers to two partial symbol table entries,
-   compare them by name and return -N, 0, or +N (ala strcmp).
-   Typically used by sorting routines like qsort().
-
-   NOTES
-
-   Does direct compare of first two characters before punting
-   and passing to strcmp for longer compares.  Note that the
-   original version had a bug whereby two null strings or two
-   identically named one character strings would return the
-   comparison of memory following the null byte.
-
- */
+/* This compares two partial symbols by names, using strcmp_iw_ordered
+   for the comparison.  */
 
 static int
 compare_psymbols (const void *s1p, const void *s2p)
 {
-  register struct partial_symbol **s1, **s2;
-  register char *st1, *st2;
-
-  s1 = (struct partial_symbol **) s1p;
-  s2 = (struct partial_symbol **) s2p;
-  st1 = SYMBOL_SOURCE_NAME (*s1);
-  st2 = SYMBOL_SOURCE_NAME (*s2);
-
+  struct partial_symbol *const *s1 = s1p;
+  struct partial_symbol *const *s2 = s2p;
 
-  if ((st1[0] - st2[0]) || !st1[0])
-    {
-      return (st1[0] - st2[0]);
-    }
-  else if ((st1[1] - st2[1]) || !st1[1])
-    {
-      return (st1[1] - st2[1]);
-    }
-  else
-    {
-      return (strcmp (st1, st2));
-    }
+  return strcmp_iw_ordered (SYMBOL_NATURAL_NAME (*s1),
+                           SYMBOL_NATURAL_NAME (*s2));
 }
 
 void
@@ -271,38 +236,6 @@ sort_pst_symbols (struct partial_symtab *pst)
         compare_psymbols);
 }
 
-/* Call sort_block_syms to sort alphabetically the symbols of one block.  */
-
-void
-sort_block_syms (register struct block *b)
-{
-  qsort (&BLOCK_SYM (b, 0), BLOCK_NSYMS (b),
-        sizeof (struct symbol *), compare_symbols);
-}
-
-/* Call sort_symtab_syms to sort alphabetically
-   the symbols of each block of one symtab.  */
-
-void
-sort_symtab_syms (register struct symtab *s)
-{
-  register struct blockvector *bv;
-  int nbl;
-  int i;
-  register struct block *b;
-
-  if (s == 0)
-    return;
-  bv = BLOCKVECTOR (s);
-  nbl = BLOCKVECTOR_NBLOCKS (bv);
-  for (i = 0; i < nbl; i++)
-    {
-      b = BLOCKVECTOR_BLOCK (bv, i);
-      if (BLOCK_SHOULD_SORT (b))
-       sort_block_syms (b);
-    }
-}
-
 /* Make a null terminated copy of the string at PTR with SIZE characters in
    the obstack pointed to by OBSTACKP .  Returns the address of the copy.
    Note that the string at PTR does not have to be null terminated, I.E. it
@@ -436,6 +369,22 @@ find_lowest_section (bfd *abfd, asection *sect, void *obj)
     *lowest = sect;
 }
 
+/* Create a new section_addr_info, with room for NUM_SECTIONS.  */
+
+struct section_addr_info *
+alloc_section_addr_info (size_t num_sections)
+{
+  struct section_addr_info *sap;
+  size_t size;
+
+  size = (sizeof (struct section_addr_info)
+         +  sizeof (struct other_sections) * (num_sections - 1));
+  sap = (struct section_addr_info *) xmalloc (size);
+  memset (sap, 0, size);
+  sap->num_sections = num_sections;
+
+  return sap;
+}
 
 /* Build (allocate and populate) a section_addr_info struct from
    an existing section table. */
@@ -448,14 +397,13 @@ build_section_addr_info_from_section_table (const struct section_table *start,
   const struct section_table *stp;
   int oidx;
 
-  sap = xmalloc (sizeof (struct section_addr_info));
-  memset (sap, 0, sizeof (struct section_addr_info));
+  sap = alloc_section_addr_info (end - start);
 
   for (stp = start, oidx = 0; stp != end; stp++)
     {
       if (bfd_get_section_flags (stp->bfd, 
                                 stp->the_bfd_section) & (SEC_ALLOC | SEC_LOAD)
-         && oidx < MAX_SECTIONS)
+         && oidx < end - start)
        {
          sap->other[oidx].addr = stp->addr;
          sap->other[oidx].name 
@@ -476,7 +424,7 @@ free_section_addr_info (struct section_addr_info *sap)
 {
   int idx;
 
-  for (idx = 0; idx < MAX_SECTIONS; idx++)
+  for (idx = 0; idx < sap->num_sections; idx++)
     if (sap->other[idx].name)
       xfree (sap->other[idx].name);
   xfree (sap);
@@ -549,14 +497,16 @@ default_symfile_offsets (struct objfile *objfile,
 {
   int i;
 
-  objfile->num_sections = SECT_OFF_MAX;
+  objfile->num_sections = bfd_count_sections (objfile->obfd);
   objfile->section_offsets = (struct section_offsets *)
-    obstack_alloc (&objfile->psymbol_obstack, SIZEOF_SECTION_OFFSETS);
-  memset (objfile->section_offsets, 0, SIZEOF_SECTION_OFFSETS);
+    obstack_alloc (&objfile->psymbol_obstack, 
+                  SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
+  memset (objfile->section_offsets, 0, 
+         SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
 
   /* Now calculate offsets for section that were specified by the
      caller. */
-  for (i = 0; i < MAX_SECTIONS && addrs->other[i].name; i++)
+  for (i = 0; i < addrs->num_sections && addrs->other[i].name; i++)
     {
       struct other_sections *osp ;
 
@@ -616,26 +566,11 @@ syms_from_objfile (struct objfile *objfile,
                   int mainline,
                    int verbo)
 {
-  asection *lower_sect;
-  asection *sect;
-  CORE_ADDR lower_offset;
-  struct section_addr_info local_addr;
+  struct section_addr_info *local_addr = NULL;
   struct cleanup *old_chain;
-  int i;
 
   gdb_assert (! (addrs && offsets));
 
-  /* If ADDRS and OFFSETS are both NULL, put together a dummy address
-     list.  We now establish the convention that an addr of zero means
-     no load address was specified. */
-  if (! addrs && ! offsets)
-    {
-      memset (&local_addr, 0, sizeof (local_addr));
-      addrs = &local_addr;
-    }
-
-  /* Now either addrs or offsets is non-zero.  */
-
   init_entry_point_info (objfile);
   find_sym_fns (objfile);
 
@@ -646,6 +581,19 @@ syms_from_objfile (struct objfile *objfile,
      if an error occurs during symbol reading.  */
   old_chain = make_cleanup_free_objfile (objfile);
 
+  /* If ADDRS and OFFSETS are both NULL, put together a dummy address
+     list.  We now establish the convention that an addr of zero means
+     no load address was specified. */
+  if (! addrs && ! offsets)
+    {
+      local_addr 
+       = alloc_section_addr_info (bfd_count_sections (objfile->obfd));
+      make_cleanup (xfree, local_addr);
+      addrs = local_addr;
+    }
+
+  /* Now either addrs or offsets is non-zero.  */
+
   if (mainline)
     {
       /* We will modify the main symbol table, make sure that all its users
@@ -674,8 +622,13 @@ syms_from_objfile (struct objfile *objfile,
 
      We no longer warn if the lowest section is not a text segment (as
      happens for the PA64 port.  */
-  if (!mainline)
+  if (!mainline && addrs && addrs->other[0].name)
     {
+      asection *lower_sect;
+      asection *sect;
+      CORE_ADDR lower_offset;
+      int i;
+
       /* Find lowest loadable section to be used as starting point for 
          continguous sections. FIXME!! won't work without call to find
         .text first, but this assumes text is lowest section. */
@@ -707,9 +660,7 @@ syms_from_objfile (struct objfile *objfile,
         (the loadable section directly below it in memory).
         this_offset = lower_offset = lower_addr - lower_orig_addr */
 
-      /* Calculate offsets for sections. */
-      if (addrs)
-        for (i=0 ; i < MAX_SECTIONS && addrs->other[i].name; i++)
+        for (i = 0; i < addrs->num_sections && addrs->other[i].name; i++)
           {
             if (addrs->other[i].addr != 0)
               {
@@ -793,7 +744,7 @@ syms_from_objfile (struct objfile *objfile,
          int i;
 
            for (i = 0; 
-                !s_addr && i < MAX_SECTIONS && addrs->other[i].name;
+                !s_addr && i < addrs->num_sections && addrs->other[i].name;
                 i++)
              if (strcmp (bfd_section_name (s->objfile->obfd, 
                                            s->the_bfd_section), 
@@ -827,13 +778,6 @@ syms_from_objfile (struct objfile *objfile,
   /* Discard cleanups as symbol reading was successful.  */
 
   discard_cleanups (old_chain);
-
-  /* Call this after reading in a new symbol table to give target
-     dependent code a crack at the new symbols.  For instance, this
-     could be used to update the values of target-specific symbols GDB
-     needs to keep track of (such as _sigtramp, or whatever).  */
-
-  TARGET_SYMFILE_POSTREAD (objfile);
 }
 
 /* Perform required actions after either reading in the initial
@@ -891,10 +835,8 @@ symbol_file_add_with_addrs_or_offsets (char *name, int from_tty,
   struct partial_symtab *psymtab;
   char *debugfile;
   bfd *abfd;
-  struct section_addr_info orig_addrs;
-  
-  if (addrs)
-    orig_addrs = *addrs;
+  struct section_addr_info *orig_addrs;
+  struct cleanup *my_cleanups;
 
   /* Open a bfd for the file, and give user a chance to burp if we'd be
      interactively wiping out any existing symbols.  */
@@ -909,6 +851,11 @@ symbol_file_add_with_addrs_or_offsets (char *name, int from_tty,
 
   objfile = allocate_objfile (abfd, flags);
 
+  orig_addrs = alloc_section_addr_info (bfd_count_sections (abfd));
+  my_cleanups = make_cleanup (xfree, orig_addrs);
+  if (addrs)
+    *orig_addrs = *addrs;
+
   /* If the objfile uses a mapped symbol file, and we have a psymtab for
      it, then skip reading any symbols at this time. */
 
@@ -975,7 +922,7 @@ symbol_file_add_with_addrs_or_offsets (char *name, int from_tty,
       if (addrs != NULL)
        {
          objfile->separate_debug_objfile
-            = symbol_file_add (debugfile, from_tty, &orig_addrs, 0, flags);
+            = symbol_file_add (debugfile, from_tty, orig_addrs, 0, flags);
        }
       else
        {
@@ -1014,6 +961,8 @@ symbol_file_add_with_addrs_or_offsets (char *name, int from_tty,
      time.  */
   gdb_flush (gdb_stdout);
 
+  do_cleanups (my_cleanups);
+
   if (objfile->sf == NULL)
     return objfile;    /* No symbols. */
 
@@ -1731,15 +1680,21 @@ add_symbol_file_command (char *args, int from_tty)
   int expecting_sec_name = 0;
   int expecting_sec_addr = 0;
 
-  struct
+  struct sect_opt
   {
     char *name;
     char *value;
-  } sect_opts[SECT_OFF_MAX];
+  };
 
-  struct section_addr_info section_addrs;
+  struct section_addr_info *section_addrs;
+  struct sect_opt *sect_opts = NULL;
+  size_t num_sect_opts = 0;
   struct cleanup *my_cleanups = make_cleanup (null_cleanup, NULL);
 
+  num_sect_opts = 16;
+  sect_opts = (struct sect_opt *) xmalloc (num_sect_opts 
+                                          * sizeof (struct sect_opt));
+
   dont_repeat ();
 
   if (args == NULL)
@@ -1748,9 +1703,6 @@ add_symbol_file_command (char *args, int from_tty)
   /* Make a copy of the string that we can safely write into. */
   args = xstrdup (args);
 
-  /* Ensure section_addrs is initialized */
-  memset (&section_addrs, 0, sizeof (section_addrs));
-
   while (*args != '\000')
     {
       /* Any leading spaces? */
@@ -1783,7 +1735,14 @@ add_symbol_file_command (char *args, int from_tty)
                to load the program. */
            sect_opts[section_index].name = ".text";
            sect_opts[section_index].value = arg;
-           section_index++;              
+           if (++section_index > num_sect_opts) 
+             {
+               num_sect_opts *= 2;
+               sect_opts = ((struct sect_opt *) 
+                            xrealloc (sect_opts,
+                                      num_sect_opts 
+                                      * sizeof (struct sect_opt)));
+             }
          }
        else
          {
@@ -1800,8 +1759,6 @@ add_symbol_file_command (char *args, int from_tty)
                  else 
                    if (strcmp (arg, "-s") == 0)
                      {
-                       if (section_index >= SECT_OFF_MAX)
-                         error ("Too many sections specified.");
                        expecting_sec_name = 1;
                        expecting_sec_addr = 1;
                      }
@@ -1818,7 +1775,14 @@ add_symbol_file_command (char *args, int from_tty)
                    {
                      sect_opts[section_index].value = arg;
                      expecting_sec_addr = 0;
-                     section_index++;            
+                     if (++section_index > num_sect_opts) 
+                       {
+                         num_sect_opts *= 2;
+                         sect_opts = ((struct sect_opt *) 
+                                      xrealloc (sect_opts,
+                                                num_sect_opts 
+                                                * sizeof (struct sect_opt)));
+                       }
                    }
                  else
                    error ("USAGE: add-symbol-file <filename> <textaddress> [-mapped] [-readnow] [-s <secname> <addr>]*");
@@ -1834,22 +1798,20 @@ add_symbol_file_command (char *args, int from_tty)
      string. */
  
   printf_filtered ("add symbol table from file \"%s\" at\n", filename);
+  section_addrs = alloc_section_addr_info (section_index);
+  make_cleanup (xfree, section_addrs);
   for (i = 0; i < section_index; i++)
     {
       CORE_ADDR addr;
       char *val = sect_opts[i].value;
       char *sec = sect_opts[i].name;
  
-      val = sect_opts[i].value;
-      if (val[0] == '0' && val[1] == 'x')
-       addr = strtoul (val+2, NULL, 16);
-      else
-       addr = strtoul (val, NULL, 10);
+      addr = parse_and_eval_address (val);
 
       /* Here we store the section offsets in the order they were
          entered on the command line. */
-      section_addrs.other[sec_num].name = sec;
-      section_addrs.other[sec_num].addr = addr;
+      section_addrs->other[sec_num].name = sec;
+      section_addrs->other[sec_num].addr = addr;
       printf_filtered ("\t%s_addr = %s\n",
                       sec, 
                       local_hex_string ((unsigned long)addr));
@@ -1865,7 +1827,7 @@ add_symbol_file_command (char *args, int from_tty)
   if (from_tty && (!query ("%s", "")))
     error ("Not confirmed.");
 
-  symbol_file_add (filename, from_tty, &section_addrs, 0, flags);
+  symbol_file_add (filename, from_tty, section_addrs, 0, flags);
 
   /* Getting new symbols may change our opinion about what is
      frameless.  */
@@ -1962,8 +1924,10 @@ reread_symbols (void)
              /* Save the offsets, we will nuke them with the rest of the
                 psymbol_obstack.  */
              num_offsets = objfile->num_sections;
-             offsets = (struct section_offsets *) alloca (SIZEOF_SECTION_OFFSETS);
-             memcpy (offsets, objfile->section_offsets, SIZEOF_SECTION_OFFSETS);
+             offsets = ((struct section_offsets *) 
+                        alloca (SIZEOF_N_SECTION_OFFSETS (num_offsets)));
+             memcpy (offsets, objfile->section_offsets, 
+                     SIZEOF_N_SECTION_OFFSETS (num_offsets));
 
              /* Nuke all the state that we will re-read.  Much of the following
                 code which sets things to NULL really is necessary to tell
@@ -1998,6 +1962,7 @@ reread_symbols (void)
              objfile->psymtabs = NULL;
              objfile->free_psymtabs = NULL;
              objfile->msymbols = NULL;
+             objfile->sym_private = NULL;
              objfile->minimal_symbol_count = 0;
              memset (&objfile->msymbol_hash, 0,
                      sizeof (objfile->msymbol_hash));
@@ -2031,8 +1996,10 @@ reread_symbols (void)
              /* We use the same section offsets as from last time.  I'm not
                 sure whether that is always correct for shared libraries.  */
              objfile->section_offsets = (struct section_offsets *)
-               obstack_alloc (&objfile->psymbol_obstack, SIZEOF_SECTION_OFFSETS);
-             memcpy (objfile->section_offsets, offsets, SIZEOF_SECTION_OFFSETS);
+               obstack_alloc (&objfile->psymbol_obstack, 
+                              SIZEOF_N_SECTION_OFFSETS (num_offsets));
+             memcpy (objfile->section_offsets, offsets, 
+                     SIZEOF_N_SECTION_OFFSETS (num_offsets));
              objfile->num_sections = num_offsets;
 
              /* What the hell is sym_new_init for, anyway?  The concept of
@@ -2076,14 +2043,6 @@ reread_symbols (void)
                 again now.  */
              objfile->mtime = new_modtime;
              reread_one = 1;
-
-             /* Call this after reading in a new symbol table to give target
-                dependent code a crack at the new symbols.  For instance, this
-                could be used to update the values of target-specific symbols GDB
-                needs to keep track of (such as _sigtramp, or whatever).  */
-
-             TARGET_SYMFILE_POSTREAD (objfile);
-
               reread_separate_symbols (objfile);
            }
        }
@@ -2675,7 +2634,7 @@ start_psymtab_common (struct objfile *objfile,
    Since one arg is a struct, we pass in a ptr and deref it (sigh).  */
 
 void
-add_psymbol_to_list (char *name, int namelength, namespace_enum namespace,
+add_psymbol_to_list (char *name, int namelength, domain_enum domain,
                     enum address_class class,
                     struct psymbol_allocation_list *list, long val,    /* Value as a long */
                     CORE_ADDR coreaddr,        /* Value as a CORE_ADDR */
@@ -2702,7 +2661,7 @@ add_psymbol_to_list (char *name, int namelength, namespace_enum namespace,
     }
   SYMBOL_SECTION (&psymbol) = 0;
   SYMBOL_LANGUAGE (&psymbol) = language;
-  PSYMBOL_NAMESPACE (&psymbol) = namespace;
+  PSYMBOL_DOMAIN (&psymbol) = domain;
   PSYMBOL_CLASS (&psymbol) = class;
 
   SYMBOL_SET_NAMES (&psymbol, buf, namelength, objfile);
@@ -2725,7 +2684,7 @@ add_psymbol_to_list (char *name, int namelength, namespace_enum namespace,
 
 void
 add_psymbol_with_dem_name_to_list (char *name, int namelength, char *dem_name,
-                                  int dem_namelength, namespace_enum namespace,
+                                  int dem_namelength, domain_enum domain,
                                   enum address_class class,
                                   struct psymbol_allocation_list *list, long val,      /* Value as a long */
                                   CORE_ADDR coreaddr,  /* Value as a CORE_ADDR */
@@ -2743,7 +2702,7 @@ add_psymbol_with_dem_name_to_list (char *name, int namelength, char *dem_name,
 
   memcpy (buf, name, namelength);
   buf[namelength] = '\0';
-  SYMBOL_NAME (&psymbol) = bcache (buf, namelength + 1, objfile->psymbol_cache);
+  DEPRECATED_SYMBOL_NAME (&psymbol) = bcache (buf, namelength + 1, objfile->psymbol_cache);
 
   buf = alloca (dem_namelength + 1);
   memcpy (buf, dem_name, dem_namelength);
@@ -2770,7 +2729,7 @@ add_psymbol_with_dem_name_to_list (char *name, int namelength, char *dem_name,
     }
   SYMBOL_SECTION (&psymbol) = 0;
   SYMBOL_LANGUAGE (&psymbol) = language;
-  PSYMBOL_NAMESPACE (&psymbol) = namespace;
+  PSYMBOL_DOMAIN (&psymbol) = domain;
   PSYMBOL_CLASS (&psymbol) = class;
   SYMBOL_INIT_LANGUAGE_SPECIFIC (&psymbol, language);
 
@@ -3015,7 +2974,7 @@ pc_in_mapped_range (CORE_ADDR pc, asection *section)
 
 /* Return true if the mapped ranges of sections A and B overlap, false
    otherwise.  */
-int
+static int
 sections_overlap (asection *a, asection *b)
 {
   /* FIXME: need bfd *, so we can use bfd_section_vma methods. */
@@ -3608,7 +3567,7 @@ symfile_relocate_debug_section (bfd *abfd, asection *sectp, bfd_byte *buf)
      all sections begin at 0.  */
   bfd_map_over_sections (abfd, symfile_dummy_outputs, NULL);
 
-  return bfd_simple_get_relocated_section_contents (abfd, sectp, buf);
+  return bfd_simple_get_relocated_section_contents (abfd, sectp, buf, NULL);
 }
 
 void
This page took 0.038904 seconds and 4 git commands to generate.