* gdb.threads/Makefile.in (docdir): Removed.
[deliverable/binutils-gdb.git] / gdb / symfile.c
index 98b25df5d370734e58d1b2500743d3801174171d..e95d1db000778bd3272e1349d636cda01ea2dbbc 100644 (file)
@@ -43,6 +43,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "gdb_string.h"
 #include "gdb_stat.h"
 #include <ctype.h>
+#include <time.h>
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
@@ -66,34 +67,28 @@ struct complaint empty_symtab_complaint = {
 
 extern int info_verbose;
 
+extern void report_transfer_performance PARAMS ((unsigned long,
+                                                time_t, time_t));
+
 /* Functions this file defines */
 
-static void
-set_initial_language PARAMS ((void));
+static void set_initial_language PARAMS ((void));
 
-static void
-load_command PARAMS ((char *, int));
+static void load_command PARAMS ((char *, int));
 
-static void
-add_symbol_file_command PARAMS ((char *, int));
+static void add_symbol_file_command PARAMS ((char *, int));
 
-static void
-add_shared_symbol_files_command PARAMS ((char *, int));
+static void add_shared_symbol_files_command PARAMS ((char *, int));
 
-static void
-cashier_psymtab PARAMS ((struct partial_symtab *));
+static void cashier_psymtab PARAMS ((struct partial_symtab *));
 
-static int
-compare_psymbols PARAMS ((const void *, const void *));
+static int compare_psymbols PARAMS ((const void *, const void *));
 
-static int
-compare_symbols PARAMS ((const void *, const void *));
+static int compare_symbols PARAMS ((const void *, const void *));
 
-static bfd *
-symfile_bfd_open PARAMS ((char *));
+static bfd *symfile_bfd_open PARAMS ((char *));
 
-static void
-find_sym_fns PARAMS ((struct objfile *));
+static void find_sym_fns PARAMS ((struct objfile *));
 
 /* List of all available sym_fns.  On gdb startup, each object file reader
    calls add_symtab_fns() to register information on each format it is
@@ -148,9 +143,9 @@ LOCAL FUNCTION
 
 DESCRIPTION
 
-       Given pointer 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().
+       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
 
@@ -167,8 +162,8 @@ compare_psymbols (s1p, s2p)
      const PTR s1p;
      const PTR s2p;
 {
-  register char *st1 = SYMBOL_NAME ((struct partial_symbol *) s1p);
-  register char *st2 = SYMBOL_NAME ((struct partial_symbol *) s2p);
+  register char *st1 = SYMBOL_NAME (*(struct partial_symbol **) s1p);
+  register char *st2 = SYMBOL_NAME (*(struct partial_symbol **) s2p);
 
   if ((st1[0] - st2[0]) || !st1[0])
     {
@@ -191,7 +186,7 @@ sort_pst_symbols (pst)
   /* Sort the global list; don't sort the static list */
 
   qsort (pst -> objfile -> global_psymbols.list + pst -> globals_offset,
-        pst -> n_global_syms, sizeof (struct partial_symbol),
+        pst -> n_global_syms, sizeof (struct partial_symbol *),
         compare_psymbols);
 }
 
@@ -273,7 +268,7 @@ obconcat (obstackp, s1, s2, s3)
 
 int currently_reading_symtab = 0;
 
-static int
+static void
 decrement_reading_symtab (dummy)
      void *dummy;
 {
@@ -350,7 +345,7 @@ entry_point_address()
    If the vmas and sizes are equal, the last section is considered the
    lowest-addressed loadable section.  */
 
-static void
+void
 find_lowest_section (abfd, sect, obj)
      bfd *abfd;
      asection *sect;
@@ -923,6 +918,8 @@ generic_load (filename, from_tty)
   struct cleanup *old_cleanups;
   asection *s;
   bfd *loadfile_bfd;
+  time_t start_time, end_time; /* Start and end times of download */
+  unsigned long data_count = 0;        /* Number of bytes transferred to memory */
 
   loadfile_bfd = bfd_openr (filename, gnutarget);
   if (loadfile_bfd == NULL)
@@ -941,6 +938,8 @@ generic_load (filename, from_tty)
             bfd_errmsg (bfd_get_error ()));
     }
   
+  start_time = time (NULL);
+
   for (s = loadfile_bfd->sections; s; s = s->next) 
     {
       if (s->flags & SEC_LOAD) 
@@ -954,6 +953,8 @@ generic_load (filename, from_tty)
              struct cleanup *old_chain;
              bfd_vma vma;
 
+             data_count += size;
+
              buffer = xmalloc (size);
              old_chain = make_cleanup (free, buffer);
 
@@ -976,6 +977,8 @@ generic_load (filename, from_tty)
        }
     }
 
+  end_time = time (NULL);
+
   /* We were doing this in remote-mips.c, I suspect it is right
      for other targets too.  */
   write_pc (loadfile_bfd->start_address);
@@ -986,9 +989,27 @@ generic_load (filename, from_tty)
      loaded in.  remote-nindy.c had no call to symbol_file_add, but remote-vx.c
      does.  */
 
+  report_transfer_performance (data_count, start_time, end_time);
+
   do_cleanups (old_cleanups);
 }
 
+/* Report how fast the transfer went. */
+
+void
+report_transfer_performance (data_count, start_time, end_time)
+unsigned long data_count;
+time_t start_time, end_time;
+{
+  printf_filtered ("Transfer rate: ");
+  if (end_time != start_time)
+    printf_filtered ("%d bits/sec",
+                    (data_count * 8) / (end_time - start_time));
+  else
+    printf_filtered ("%d bits in <1 sec", (data_count * 8));
+  printf_filtered (".\n");
+}
+
 /* This function allows the addition of incrementally linked object files.
    It does not modify any state in the target, only in the debugger.  */
 
@@ -1182,16 +1203,17 @@ reread_symbols ()
             enough?  */
          if (objfile->global_psymbols.list)
            mfree (objfile->md, objfile->global_psymbols.list);
-         objfile->global_psymbols.list = NULL;
-         objfile->global_psymbols.next = NULL;
-         objfile->global_psymbols.size = 0;
+         memset (&objfile -> global_psymbols, 0,
+                 sizeof (objfile -> global_psymbols));
          if (objfile->static_psymbols.list)
            mfree (objfile->md, objfile->static_psymbols.list);
-         objfile->static_psymbols.list = NULL;
-         objfile->static_psymbols.next = NULL;
-         objfile->static_psymbols.size = 0;
+         memset (&objfile -> static_psymbols, 0,
+                 sizeof (objfile -> static_psymbols));
 
          /* Free the obstacks for non-reusable objfiles */
+         obstack_free (&objfile -> psymbol_cache.cache, 0);
+         memset (&objfile -> psymbol_cache, 0,
+                 sizeof (objfile -> psymbol_cache));
          obstack_free (&objfile -> psymbol_obstack, 0);
          obstack_free (&objfile -> symbol_obstack, 0);
          obstack_free (&objfile -> type_obstack, 0);
@@ -1211,6 +1233,8 @@ reread_symbols ()
          objfile -> md = NULL;
          /* obstack_specify_allocation also initializes the obstack so
             it is empty.  */
+         obstack_specify_allocation (&objfile -> psymbol_cache.cache, 0, 0,
+                                     xmalloc, free);
          obstack_specify_allocation (&objfile -> psymbol_obstack, 0, 0,
                                      xmalloc, free);
          obstack_specify_allocation (&objfile -> symbol_obstack, 0, 0,
@@ -1616,8 +1640,8 @@ start_psymtab_common (objfile, section_offsets,
      struct section_offsets *section_offsets;
      char *filename;
      CORE_ADDR textlow;
-     struct partial_symbol *global_syms;
-     struct partial_symbol *static_syms;
+     struct partial_symbol **global_syms;
+     struct partial_symbol **static_syms;
 {
   struct partial_symtab *psymtab;
 
@@ -1651,24 +1675,29 @@ add_psymbol_to_list (name, namelength, namespace, class, list, val, language,
      struct objfile *objfile;
 {
   register struct partial_symbol *psym;
-  register char *demangled_name;
-
+  char *buf = alloca (namelength + 1);
+  struct partial_symbol psymbol;
+
+  /* Create local copy of the partial symbol */
+  memcpy (buf, name, namelength);
+  buf[namelength] = '\0';
+  SYMBOL_NAME (&psymbol) = bcache (buf, namelength + 1, &objfile->psymbol_cache);
+  SYMBOL_VALUE (&psymbol) = val;
+  SYMBOL_SECTION (&psymbol) = 0;
+  SYMBOL_LANGUAGE (&psymbol) = language;
+  PSYMBOL_NAMESPACE (&psymbol) = namespace;
+  PSYMBOL_CLASS (&psymbol) = class;
+  SYMBOL_INIT_LANGUAGE_SPECIFIC (&psymbol, language);
+
+  /* Stash the partial symbol away in the cache */
+  psym = bcache (&psymbol, sizeof (struct partial_symbol), &objfile->psymbol_cache);
+
+  /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
   if (list->next >= list->list + list->size)
     {
-      extend_psymbol_list (list,objfile);
+      extend_psymbol_list (list, objfile);
     }
-  psym = list->next++;
-  
-  SYMBOL_NAME (psym) =
-    (char *) obstack_alloc (&objfile->psymbol_obstack, namelength + 1);
-  memcpy (SYMBOL_NAME (psym), name, namelength);
-  SYMBOL_NAME (psym)[namelength] = '\0';
-  SYMBOL_VALUE (psym) = val;
-  SYMBOL_SECTION (psym) = 0;
-  SYMBOL_LANGUAGE (psym) = language;
-  PSYMBOL_NAMESPACE (psym) = namespace;
-  PSYMBOL_CLASS (psym) = class;
-  SYMBOL_INIT_LANGUAGE_SPECIFIC (psym, language);
+  *list->next++ = psym;
   OBJSTAT (objfile, n_psyms++);
 }
 
@@ -1687,24 +1716,29 @@ add_psymbol_addr_to_list (name, namelength, namespace, class, list, val,
      struct objfile *objfile;
 {
   register struct partial_symbol *psym;
-  register char *demangled_name;
-
+  char *buf = alloca (namelength + 1);
+  struct partial_symbol psymbol;
+
+  /* Create local copy of the partial symbol */
+  memcpy (buf, name, namelength);
+  buf[namelength] = '\0';
+  SYMBOL_NAME (&psymbol) = bcache (buf, namelength + 1, &objfile->psymbol_cache);
+  SYMBOL_VALUE_ADDRESS (&psymbol) = val;
+  SYMBOL_SECTION (&psymbol) = 0;
+  SYMBOL_LANGUAGE (&psymbol) = language;
+  PSYMBOL_NAMESPACE (&psymbol) = namespace;
+  PSYMBOL_CLASS (&psymbol) = class;
+  SYMBOL_INIT_LANGUAGE_SPECIFIC (&psymbol, language);
+
+  /* Stash the partial symbol away in the cache */
+  psym = bcache (&psymbol, sizeof (struct partial_symbol), &objfile->psymbol_cache);
+
+  /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
   if (list->next >= list->list + list->size)
     {
-      extend_psymbol_list (list,objfile);
+      extend_psymbol_list (list, objfile);
     }
-  psym = list->next++;
-  
-  SYMBOL_NAME (psym) =
-    (char *) obstack_alloc (&objfile->psymbol_obstack, namelength + 1);
-  memcpy (SYMBOL_NAME (psym), name, namelength);
-  SYMBOL_NAME (psym)[namelength] = '\0';
-  SYMBOL_VALUE_ADDRESS (psym) = val;
-  SYMBOL_SECTION (psym) = 0;
-  SYMBOL_LANGUAGE (psym) = language;
-  PSYMBOL_NAMESPACE (psym) = namespace;
-  PSYMBOL_CLASS (psym) = class;
-  SYMBOL_INIT_LANGUAGE_SPECIFIC (psym, language);
+  *list->next++ = psym;
   OBJSTAT (objfile, n_psyms++);
 }
 
@@ -1735,13 +1769,13 @@ init_psymbol_list (objfile, total_symbols)
   objfile -> global_psymbols.size = total_symbols / 10;
   objfile -> static_psymbols.size = total_symbols / 10;
   objfile -> global_psymbols.next =
-    objfile -> global_psymbols.list = (struct partial_symbol *)
+    objfile -> global_psymbols.list = (struct partial_symbol **)
       xmmalloc (objfile -> md, objfile -> global_psymbols.size
-                            * sizeof (struct partial_symbol));
+                            * sizeof (struct partial_symbol *));
   objfile -> static_psymbols.next =
-    objfile -> static_psymbols.list = (struct partial_symbol *)
+    objfile -> static_psymbols.list = (struct partial_symbol **)
       xmmalloc (objfile -> md, objfile -> static_psymbols.size
-                            * sizeof (struct partial_symbol));
+                            * sizeof (struct partial_symbol *));
 }
 \f
 void
This page took 0.027147 seconds and 4 git commands to generate.