]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Replace header_files global by per-objfile field.
authorPer Bothner <per@bothner.com>
Mon, 7 Oct 1996 17:45:29 +0000 (17:45 +0000)
committerPer Bothner <per@bothner.com>
Mon, 7 Oct 1996 17:45:29 +0000 (17:45 +0000)
* gdb-stabs.h (struct dbx_symfile_info):  Add fields header_files,
n_header_files, n_allocated_header_files.
* stabsread.h (header_files, n_header_files, n_allocated_header_files):
Replace externs by macros HEADER_FILES, N_HEADER_FILES, and
N_ALLOCATED_HEADER_FILES.
* dbxread.c (dbx_symfile_finish):  Free HEADER_FILES.
(free_header_files, init_header-files):  Don't free/init headerfiles.
(various functions):  Use macros instead of header_files globals.
* stabsread.c (various functions):  Likewise.

gdb/ChangeLog
gdb/dbxread.c
gdb/gdb-stabs.h
gdb/stabsread.c
gdb/stabsread.h

index 5f1275978a3dbb9dfc979e86ead41d846a0b2f69..0a8cf3f328ea864454ad40263f16da3c5b748cc7 100644 (file)
@@ -1,3 +1,16 @@
+Mon Oct  7 10:42:32 1996  Per Bothner  <bothner@deneb.cygnus.com>
+
+       Replace header_files global by per-objfile field.
+       * gdb-stabs.h (struct dbx_symfile_info):  Add fields header_files,
+       n_header_files, n_allocated_header_files.
+       * stabsread.h (header_files, n_header_files, n_allocated_header_files):
+       Replace externs by macros HEADER_FILES, N_HEADER_FILES, and
+       N_ALLOCATED_HEADER_FILES.
+       * dbxread.c (dbx_symfile_finish):  Free HEADER_FILES.
+       (free_header_files, init_header-files):  Don't free/init headerfiles.
+       (various functions):  Use macros instead of header_files globals.
+       * stabsread.c (various functions):  Likewise.
+
 Sun Oct  6 22:43:06 1996  Jason Merrill  <jason@yorick.cygnus.com>
 
        * dwarf2read.c (read_tag_reference_type): New fn.
index 5b0e5cc2bcb660d8c73d49d6e20142e905711584..35884bb8cf3d196737e60334e1c0368b3d0543b4 100644 (file)
@@ -41,10 +41,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #endif
 
 #include "obstack.h"
-#include <sys/param.h>
-#ifndef        NO_SYS_FILE
-#include <sys/file.h>
-#endif
 #include "gdb_stat.h"
 #include <ctype.h>
 #include "symtab.h"
@@ -279,24 +275,11 @@ add_this_object_header_file PARAMS ((int));
 static void
 free_header_files ()
 {
-  register int i;
-
-  if (header_files != NULL)
-    {
-      for (i = 0; i < n_header_files; i++)
-       {
-         free (header_files[i].name);
-       }
-      free ((PTR)header_files);
-      header_files = NULL;
-      n_header_files = 0;
-    }
   if (this_object_header_files)
     {
       free ((PTR)this_object_header_files);
       this_object_header_files = NULL;
     }
-  n_allocated_header_files = 0;
   n_allocated_this_object_header_files = 0;
 }
 
@@ -305,11 +288,6 @@ free_header_files ()
 static void
 init_header_files ()
 {
-  n_header_files = 0;
-  n_allocated_header_files = 10;
-  header_files = (struct header_file *)
-    xmalloc (10 * sizeof (struct header_file));
-
   n_allocated_this_object_header_files = 10;
   this_object_header_files = (int *) xmalloc (10 * sizeof (int));
 }
@@ -342,10 +320,10 @@ add_old_header_file (name, instance)
      char *name;
      int instance;
 {
-  register struct header_file *p = header_files;
+  register struct header_file *p = HEADER_FILES (current_objfile);
   register int i;
 
-  for (i = 0; i < n_header_files; i++)
+  for (i = 0; i < N_HEADER_FILES (current_objfile); i++)
     if (STREQ (p[i].name, name) && instance == p[i].instance)
       {
        add_this_object_header_file (i);
@@ -371,26 +349,40 @@ add_new_header_file (name, instance)
      int instance;
 {
   register int i;
+  register struct header_file *hfile;
 
   /* Make sure there is room for one more header file.  */
 
-  if (n_header_files == n_allocated_header_files)
+  i = N_ALLOCATED_HEADER_FILES (current_objfile);
+
+  if (N_HEADER_FILES (current_objfile) == i)
     {
-      n_allocated_header_files *= 2;
-      header_files = (struct header_file *)
-       xrealloc ((char *) header_files,
-                 (n_allocated_header_files * sizeof (struct header_file)));
+      if (i == 0)
+       {
+         N_ALLOCATED_HEADER_FILES (current_objfile) = 10;
+         HEADER_FILES (current_objfile) = (struct header_file *)
+           xmalloc (10 * sizeof (struct header_file));
+       }
+      else
+       {
+         i *= 2;
+         N_ALLOCATED_HEADER_FILES (current_objfile) = i;
+         HEADER_FILES (current_objfile) = (struct header_file *)
+           xrealloc ((char *) HEADER_FILES (current_objfile),
+                     (i * sizeof (struct header_file)));
+       }
     }
 
   /* Create an entry for this header file.  */
 
-  i = n_header_files++;
-  header_files[i].name = savestring (name, strlen(name));
-  header_files[i].instance = instance;
-  header_files[i].length = 10;
-  header_files[i].vector
+  i = N_HEADER_FILES (current_objfile)++;
+  hfile = HEADER_FILES (current_objfile) + i;
+  hfile->name = savestring (name, strlen(name));
+  hfile->instance = instance;
+  hfile->length = 10;
+  hfile->vector
     = (struct type **) xmalloc (10 * sizeof (struct type *));
-  memset (header_files[i].vector, 0, 10 * sizeof (struct type *));
+  memset (hfile->vector, 0, 10 * sizeof (struct type *));
 
   add_this_object_header_file (i);
 }
@@ -400,7 +392,7 @@ static struct type **
 explicit_lookup_type (real_filenum, index)
      int real_filenum, index;
 {
-  register struct header_file *f = &header_files[real_filenum];
+  register struct header_file *f = &HEADER_FILES (current_objfile)[real_filenum];
 
   if (index >= f->length)
     {
@@ -522,29 +514,26 @@ dbx_symfile_read (objfile, section_offsets, mainline)
 
   val = strlen (objfile->name);
 
+  sym_bfd = objfile->obfd;
+
   /* .o and .nlm files are relocatables with text, data and bss segs based at
      0.  This flag disables special (Solaris stabs-in-elf only) fixups for
-     symbols with a value of 0.  XXX - This is a Krock.  Solaris stabs-in-elf
-     should be fixed to determine pst->textlow without using this text seg of
-     0 fixup crap. */
+     symbols with a value of 0.  */
 
-  if (strcmp (&objfile->name[val-2], ".o") == 0
-      || strcmp (&objfile->name[val-4], ".nlm") == 0)
-    symfile_relocatable = 1;
+  symfile_relocatable = bfd_get_file_flags (sym_bfd) & HAS_RELOC;
 
   /* This is true for Solaris (and all other systems which put stabs
      in sections, hopefully, since it would be silly to do things
      differently from Solaris), and false for SunOS4 and other a.out
      file formats.  */
   block_address_function_relative =
-    ((0 == strncmp (bfd_get_target (objfile->obfd), "elf", 3))
-     || (0 == strncmp (bfd_get_target (objfile->obfd), "som", 3))
-     || (0 == strncmp (bfd_get_target (objfile->obfd), "coff", 4))
-     || (0 == strncmp (bfd_get_target (objfile->obfd), "pe", 2))
-     || (0 == strncmp (bfd_get_target (objfile->obfd), "nlm", 3)));
+    ((0 == strncmp (bfd_get_target (sym_bfd), "elf", 3))
+     || (0 == strncmp (bfd_get_target (sym_bfd), "som", 3))
+     || (0 == strncmp (bfd_get_target (sym_bfd), "coff", 4))
+     || (0 == strncmp (bfd_get_target (sym_bfd), "pe", 2))
+     || (0 == strncmp (bfd_get_target (sym_bfd), "nlm", 3)));
 
-  sym_bfd = objfile->obfd;
-  val = bfd_seek (objfile->obfd, DBX_SYMTAB_OFFSET (objfile), SEEK_SET);
+  val = bfd_seek (sym_bfd, DBX_SYMTAB_OFFSET (objfile), SEEK_SET);
   if (val < 0)
     perror_with_name (objfile->name);
 
@@ -730,6 +719,17 @@ dbx_symfile_finish (objfile)
 {
   if (objfile->sym_stab_info != NULL)
     {
+      if (HEADER_FILES (objfile) != NULL)
+       {
+         register int i = N_HEADER_FILES (objfile);
+         register struct header_file *hfiles = HEADER_FILES (objfile);
+
+         while (--i >= 0)
+           {
+             free (hfiles [i].name);
+           }
+         free ((PTR) hfiles);
+       }
       mfree (objfile -> md, objfile->sym_stab_info);
     }
   free_header_files ();
index cb7b6215da2285da618f68a404c51b48be8448bb..fabe17c2fe8b95ee891ed3e0e719fa6eb9d464bd 100644 (file)
@@ -64,6 +64,11 @@ struct dbx_symfile_info {
   int symbol_size;             /* Bytes in a single symbol */
   struct stab_section_info *stab_section_info;         /* section starting points
                                   of the original .o files before linking. */
+
+  /* See stabsread.h for the use of the following. */
+  struct header_file *header_files;
+  int n_header_files;
+  int n_allocated_header_files;
 };
 
 #define DBX_SYMFILE_INFO(o)    ((struct dbx_symfile_info *)((o)->sym_stab_info))
index 8c03a6f7de764dc1f55f946964a02710f3376641..adc0a3640b18031ab6d225a59b0ce288353c6454 100644 (file)
@@ -344,7 +344,7 @@ Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
     {
       real_filenum = this_object_header_files[filenum];
 
-      if (real_filenum >= n_header_files)
+      if (real_filenum >= N_HEADER_FILES (current_objfile))
        {
          struct type *temp_type;
          struct type **temp_type_p;
@@ -358,7 +358,7 @@ Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
          return temp_type_p;
        }
 
-      f = &header_files[real_filenum];
+      f = HEADER_FILES (current_objfile) + real_filenum;
 
       f_orig_length = f->length;
       if (index >= f_orig_length)
index 0a1d1650761461c130f350e3673ca6928feb83e6..c08635f711b9d56af3ce9e5a1c4ed4bd870dc10b 100644 (file)
@@ -106,11 +106,15 @@ struct header_file
 
 };
 
-EXTERN struct header_file *header_files;
+/* The table of header_files of this OBJFILE. */
+#define HEADER_FILES(OBJFILE) (DBX_SYMFILE_INFO (OBJFILE)->header_files)
 
-EXTERN int n_header_files;
+/* The actual length of HEADER_FILES. */
+#define N_HEADER_FILES(OBJFILE) (DBX_SYMFILE_INFO (OBJFILE)->n_header_files)
 
-EXTERN int n_allocated_header_files;
+/* The allocated lengh of HEADER_FILES. */
+#define N_ALLOCATED_HEADER_FILES(OBJFILE) \
+  (DBX_SYMFILE_INFO (OBJFILE)->n_allocated_header_files)
 
 /* Within each object file, various header files are assigned numbers.
    A type is defined or referred to with a pair of numbers
@@ -118,7 +122,7 @@ EXTERN int n_allocated_header_files;
    and TYPENUM is the number within that header file.
    TYPENUM is the index within the vector of types for that header file.
 
-   FILENUM == 1 is special; it refers to the main source of the object file,
+   FILENUM == 0 is special; it refers to the main source of the object file,
    and not to any header file.  FILENUM != 1 is interpreted by looking it up
    in the following table, which contains indices in header_files.  */