*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / coffread.c
index 1a923ebff6600d755967cbb27d778f59d063421e..c781a34f18fc6dab0aaeba29749f6a6fa3e08fa8 100644 (file)
@@ -43,7 +43,7 @@
 #include "complaints.h"
 #include "target.h"
 
-extern void _initialize_coffread PARAMS ((void));
+extern void _initialize_coffread (void);
 
 struct coff_symfile_info
   {
@@ -176,77 +176,78 @@ struct coff_symbol
     unsigned int c_type;
   };
 
-static struct type *coff_read_struct_type PARAMS ((int, int, int));
+extern void stabsread_clear_cache (void);
 
-static struct type *decode_base_type PARAMS ((struct coff_symbol *,
-                                             unsigned int,
-                                             union internal_auxent *));
+static struct type *coff_read_struct_type (int, int, int);
 
-static struct type *decode_type PARAMS ((struct coff_symbol *, unsigned int,
-                                        union internal_auxent *));
+static struct type *decode_base_type (struct coff_symbol *,
+                                     unsigned int, union internal_auxent *);
 
-static struct type *decode_function_type PARAMS ((struct coff_symbol *,
-                                                 unsigned int,
-                                                 union internal_auxent *));
+static struct type *decode_type (struct coff_symbol *, unsigned int,
+                                union internal_auxent *);
 
-static struct type *coff_read_enum_type PARAMS ((int, int, int));
+static struct type *decode_function_type (struct coff_symbol *,
+                                         unsigned int,
+                                         union internal_auxent *);
 
-static struct symbol *process_coff_symbol PARAMS ((struct coff_symbol *,
-                                                  union internal_auxent *,
-                                                  struct section_offsets *,
-                                                  struct objfile *));
+static struct type *coff_read_enum_type (int, int, int);
 
-static void patch_opaque_types PARAMS ((struct symtab *));
+static struct symbol *process_coff_symbol (struct coff_symbol *,
+                                          union internal_auxent *,
+                                          struct objfile *);
 
-static void patch_type PARAMS ((struct type *, struct type *));
+static void patch_opaque_types (struct symtab *);
 
-static void enter_linenos PARAMS ((long, int, int, struct section_offsets *));
+static void patch_type (struct type *, struct type *);
 
-static void free_linetab PARAMS ((void));
+static void enter_linenos (long, int, int, struct objfile *);
 
-static int init_lineno PARAMS ((bfd *, long, int));
+static void free_linetab (void);
 
-static char *getsymname PARAMS ((struct internal_syment *));
+static void free_linetab_cleanup (void *ignore);
 
-static char *coff_getfilename PARAMS ((union internal_auxent *));
+static int init_lineno (bfd *, long, int);
 
-static void free_stringtab PARAMS ((void));
+static char *getsymname (struct internal_syment *);
 
-static int init_stringtab PARAMS ((bfd *, long));
+static char *coff_getfilename (union internal_auxent *);
 
-static void read_one_sym PARAMS ((struct coff_symbol *,
-                                 struct internal_syment *,
-                                 union internal_auxent *));
+static void free_stringtab (void);
 
-static void coff_symtab_read PARAMS ((long, int, struct section_offsets *,
-                                     struct objfile *));
+static void free_stringtab_cleanup (void *ignore);
 
-static void find_linenos PARAMS ((bfd *, sec_ptr, PTR));
+static int init_stringtab (bfd *, long);
 
-static void coff_symfile_init PARAMS ((struct objfile *));
+static void read_one_sym (struct coff_symbol *,
+                         struct internal_syment *, union internal_auxent *);
 
-static void coff_new_init PARAMS ((struct objfile *));
+static void coff_symtab_read (long, unsigned int, struct objfile *);
 
-static void coff_symfile_read PARAMS ((struct objfile *,
-                                      struct section_offsets *, int));
+static void find_linenos (bfd *, sec_ptr, PTR);
 
-static void coff_symfile_finish PARAMS ((struct objfile *));
+static void coff_symfile_init (struct objfile *);
 
-static void record_minimal_symbol PARAMS ((char *, CORE_ADDR,
-                                          enum minimal_symbol_type,
-                                          struct objfile *));
+static void coff_new_init (struct objfile *);
 
-static void coff_end_symtab PARAMS ((struct objfile *));
+static void coff_symfile_read (struct objfile *, int);
 
-static void complete_symtab PARAMS ((char *, CORE_ADDR, unsigned int));
+static void coff_symfile_finish (struct objfile *);
 
-static void coff_start_symtab PARAMS ((char *));
+static void record_minimal_symbol (char *, CORE_ADDR,
+                                  enum minimal_symbol_type,
+                                  struct objfile *);
 
-static struct type *coff_alloc_type PARAMS ((int));
+static void coff_end_symtab (struct objfile *);
 
-static struct type **coff_lookup_type PARAMS ((int));
+static void complete_symtab (char *, CORE_ADDR, unsigned int);
 
-static void coff_locate_sections PARAMS ((bfd *, asection *, PTR));
+static void coff_start_symtab (char *);
+
+static struct type *coff_alloc_type (int);
+
+static struct type **coff_lookup_type (int);
+
+static void coff_locate_sections (bfd *, asection *, PTR);
 \f
 /* We are called once per section from coff_symfile_read.  We
    need to examine each section we are passed, check to see
@@ -312,7 +313,7 @@ coff_locate_sections (abfd, sectp, csip)
 }
 
 /* Return the section_offsets* that CS points to.  */
-static int cs_to_section PARAMS ((struct coff_symbol *, struct objfile *));
+static int cs_to_section (struct coff_symbol *, struct objfile *);
 
 struct find_targ_sec_arg
   {
@@ -320,7 +321,7 @@ struct find_targ_sec_arg
     asection **resultp;
   };
 
-static void find_targ_sec PARAMS ((bfd *, asection *, void *));
+static void find_targ_sec (bfd *, asection *, void *);
 
 static void
 find_targ_sec (abfd, sect, obj)
@@ -341,7 +342,7 @@ cs_to_section (cs, objfile)
 {
   asection *sect = NULL;
   struct find_targ_sec_arg args;
-  int off = SECT_OFF_TEXT;
+  int off = SECT_OFF_TEXT (objfile);
 
   args.targ_index = cs->c_secnum;
   args.resultp = §
@@ -350,18 +351,18 @@ cs_to_section (cs, objfile)
     {
       /* This is the section.  Figure out what SECT_OFF_* code it is.  */
       if (bfd_get_section_flags (abfd, sect) & SEC_CODE)
-       off = SECT_OFF_TEXT;
+       off = SECT_OFF_TEXT (objfile);
       else if (bfd_get_section_flags (abfd, sect) & SEC_LOAD)
-       off = SECT_OFF_DATA;
+       off = SECT_OFF_DATA (objfile);
       else
-       off = SECT_OFF_BSS;
+       off = SECT_OFF_BSS (objfile);
     }
   return off;
 }
 
 /* Return the address of the section of a COFF symbol.  */
 
-static CORE_ADDR cs_section_address PARAMS ((struct coff_symbol *, bfd *));
+static CORE_ADDR cs_section_address (struct coff_symbol *, bfd *);
 
 static CORE_ADDR
 cs_section_address (cs, abfd)
@@ -596,9 +597,8 @@ static bfd *symfile_bfd;
 
 /* ARGSUSED */
 static void
-coff_symfile_read (objfile, section_offsets, mainline)
+coff_symfile_read (objfile, mainline)
      struct objfile *objfile;
-     struct section_offsets *section_offsets;
      int mainline;
 {
   struct coff_symfile_info *info;
@@ -607,12 +607,14 @@ coff_symfile_read (objfile, section_offsets, mainline)
   coff_data_type *cdata = coff_data (abfd);
   char *name = bfd_get_filename (abfd);
   register int val;
-  int num_symbols;
+  unsigned int num_symbols;
   int symtab_offset;
   int stringtab_offset;
   struct cleanup *back_to;
   int stabstrsize;
-
+  int len;
+  char * target;
+  
   info = (struct coff_symfile_info *) objfile->sym_private;
   dbxinfo = objfile->sym_stab_info;
   symfile_bfd = abfd;          /* Kludge for swap routines */
@@ -638,14 +640,16 @@ coff_symfile_read (objfile, section_offsets, mainline)
   temp_sym = (char *) xmalloc
     (cdata->local_symesz + cdata->local_auxesz);
   temp_aux = temp_sym + cdata->local_symesz;
-  back_to = make_cleanup ((make_cleanup_func) free_current_contents, &temp_sym);
+  back_to = make_cleanup (free_current_contents, &temp_sym);
 
   /* We need to know whether this is a PE file, because in PE files,
      unlike standard COFF files, symbol values are stored as offsets
      from the section address, rather than as absolute addresses.
      FIXME: We should use BFD to read the symbol table, and thus avoid
      this problem.  */
-  pe_file = strncmp (bfd_get_target (objfile->obfd), "pe", 2) == 0;
+  pe_file =
+    strncmp (bfd_get_target (objfile->obfd), "pe", 2) == 0
+    || strncmp (bfd_get_target (objfile->obfd), "epoc-pe", 7) == 0;
 
 /* End of warning */
 
@@ -654,7 +658,7 @@ coff_symfile_read (objfile, section_offsets, mainline)
   info->max_lineno_offset = 0;
   bfd_map_over_sections (abfd, find_linenos, (PTR) info);
 
-  make_cleanup ((make_cleanup_func) free_linetab, 0);
+  make_cleanup (free_linetab_cleanup, 0 /*ignore*/);
   val = init_lineno (abfd, info->min_lineno_offset,
                     info->max_lineno_offset - info->min_lineno_offset);
   if (val < 0)
@@ -662,19 +666,18 @@ coff_symfile_read (objfile, section_offsets, mainline)
 
   /* Now read the string table, all at once.  */
 
-  make_cleanup ((make_cleanup_func) free_stringtab, 0);
+  make_cleanup (free_stringtab_cleanup, 0 /*ignore*/);
   val = init_stringtab (abfd, stringtab_offset);
   if (val < 0)
     error ("\"%s\": can't get string table", name);
 
   init_minimal_symbol_collection ();
-  make_cleanup ((make_cleanup_func) discard_minimal_symbols, 0);
+  make_cleanup_discard_minimal_symbols ();
 
   /* Now that the executable file is positioned at symbol table,
      process it and define symbols accordingly.  */
 
-  coff_symtab_read ((long) symtab_offset, num_symbols, section_offsets,
-                   objfile);
+  coff_symtab_read ((long) symtab_offset, num_symbols, objfile);
 
   /* Sort symbols alphabetically within each block.  */
 
@@ -712,7 +715,6 @@ coff_symfile_read (objfile, section_offsets, mainline)
       stabstrsize = bfd_section_size (abfd, info->stabstrsect);
 
       coffstab_build_psymtabs (objfile,
-                              section_offsets,
                               mainline,
                               info->textaddr, info->textsize,
                               info->stabsects,
@@ -741,6 +743,9 @@ coff_symfile_finish (objfile)
     {
       mfree (objfile->md, objfile->sym_private);
     }
+
+  /* Let stabs reader clean up */
+  stabsread_clear_cache ();
 }
 \f
 
@@ -750,10 +755,9 @@ coff_symfile_finish (objfile)
    We read them one at a time using read_one_sym ().  */
 
 static void
-coff_symtab_read (symtab_offset, nsyms, section_offsets, objfile)
+coff_symtab_read (symtab_offset, nsyms, objfile)
      long symtab_offset;
-     int nsyms;
-     struct section_offsets *section_offsets;
+     unsigned int nsyms;
      struct objfile *objfile;
 {
   register struct context_stack *new;
@@ -841,7 +845,7 @@ coff_symtab_read (symtab_offset, nsyms, section_offsets, objfile)
       if (ISFCN (cs->c_type) && cs->c_sclass != C_TPDEF)
        {
          /* Record all functions -- external and static -- in minsyms. */
-         tmpaddr = cs->c_value + ANOFFSET (section_offsets, SECT_OFF_TEXT);
+         tmpaddr = cs->c_value + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
          record_minimal_symbol (cs->c_name, tmpaddr, mst_text, objfile);
 
          fcn_line_ptr = main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr;
@@ -906,7 +910,7 @@ coff_symtab_read (symtab_offset, nsyms, section_offsets, objfile)
                     followed by a later file with no symbols.  */
                  if (in_source_file)
                    complete_symtab (filestring,
-                   cs->c_value + ANOFFSET (section_offsets, SECT_OFF_TEXT),
+                   cs->c_value + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)),
                                     main_aux.x_scn.x_scnlen);
                  in_source_file = 0;
                }
@@ -965,12 +969,10 @@ coff_symtab_read (symtab_offset, nsyms, section_offsets, objfile)
                tmpaddr = cs->c_value;
                if (cs->c_sclass == C_EXT || cs->c_sclass == C_THUMBEXTFUNC
                    || cs->c_sclass == C_THUMBEXT)
-                 tmpaddr += ANOFFSET (section_offsets, sec);
+                 tmpaddr += ANOFFSET (objfile->section_offsets, sec);
 
-               switch (sec)
+               if (sec == SECT_OFF_TEXT (objfile))
                  {
-                 case SECT_OFF_TEXT:
-                 case SECT_OFF_RODATA:
                    ms_type =
                      cs->c_sclass == C_EXT || cs->c_sclass == C_THUMBEXTFUNC
                      || cs->c_sclass == C_THUMBEXT ?
@@ -979,21 +981,21 @@ coff_symtab_read (symtab_offset, nsyms, section_offsets, objfile)
                    if (tmpaddr & 1)    /* FIXME: delete this line */
                      SMASH_TEXT_ADDRESS (tmpaddr);
 #endif
-                   break;
-                 case SECT_OFF_DATA:
+                 }
+               else if (sec == SECT_OFF_DATA (objfile))
+                 {
                    ms_type =
                      cs->c_sclass == C_EXT || cs->c_sclass == C_THUMBEXT ?
                      mst_data : mst_file_data;
-                   break;
-                 case SECT_OFF_BSS:
+                 }
+               else if (sec == SECT_OFF_BSS (objfile))
+                 {
                    ms_type =
                      cs->c_sclass == C_EXT || cs->c_sclass == C_THUMBEXT ?
                      mst_data : mst_file_data;
-                   break;
-                 default:
-                   ms_type = mst_unknown;
-                   break;
                  }
+               else
+                 ms_type = mst_unknown;
              }
 
            if (cs->c_name[0] != '@' /* Skip tdesc symbols */ )
@@ -1012,7 +1014,7 @@ coff_symtab_read (symtab_offset, nsyms, section_offsets, objfile)
              {
                struct symbol *sym;
                sym = process_coff_symbol
-                 (cs, &main_aux, section_offsets, objfile);
+                 (cs, &main_aux, objfile);
                SYMBOL_VALUE (sym) = tmpaddr;
                SYMBOL_SECTION (sym) = sec;
              }
@@ -1039,8 +1041,7 @@ coff_symtab_read (symtab_offset, nsyms, section_offsets, objfile)
              new = push_context (depth, fcn_start_addr);
              fcn_cs_saved.c_name = getsymname (&fcn_sym_saved);
              new->name =
-               process_coff_symbol (&fcn_cs_saved, &fcn_aux_saved,
-                                    section_offsets, objfile);
+               process_coff_symbol (&fcn_cs_saved, &fcn_aux_saved, objfile);
            }
          else if (STREQ (cs->c_name, ".ef"))
            {
@@ -1084,7 +1085,7 @@ coff_symtab_read (symtab_offset, nsyms, section_offsets, objfile)
                             fcn_first_line_addr);
              else
                enter_linenos (fcn_line_ptr, fcn_first_line, fcn_last_line,
-                              section_offsets);
+                              objfile);
 
              finish_block (new->name, &local_symbols, new->old_blocks,
                            new->start_addr,
@@ -1098,11 +1099,11 @@ coff_symtab_read (symtab_offset, nsyms, section_offsets, objfile)
                 of the epilogue.  */
                            cs->c_value
                            + FUNCTION_EPILOGUE_SIZE
-                           + ANOFFSET (section_offsets, SECT_OFF_TEXT),
+                           + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)),
 #else
                            fcn_cs_saved.c_value
                            + fcn_aux_saved.x_sym.x_misc.x_fsize
-                           + ANOFFSET (section_offsets, SECT_OFF_TEXT),
+                           + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)),
 #endif
                            objfile
                );
@@ -1114,7 +1115,7 @@ coff_symtab_read (symtab_offset, nsyms, section_offsets, objfile)
          if (STREQ (cs->c_name, ".bb"))
            {
              tmpaddr = cs->c_value;
-             tmpaddr += ANOFFSET (section_offsets, SECT_OFF_TEXT);
+             tmpaddr += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
              push_context (++depth, tmpaddr);
            }
          else if (STREQ (cs->c_name, ".eb"))
@@ -1134,7 +1135,7 @@ coff_symtab_read (symtab_offset, nsyms, section_offsets, objfile)
              if (local_symbols && context_stack_depth > 0)
                {
                  tmpaddr =
-                   cs->c_value + ANOFFSET (section_offsets, SECT_OFF_TEXT);
+                   cs->c_value + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
                  /* Make a block for the local symbols within.  */
                  finish_block (0, &local_symbols, new->old_blocks,
                                new->start_addr, tmpaddr, objfile);
@@ -1145,7 +1146,7 @@ coff_symtab_read (symtab_offset, nsyms, section_offsets, objfile)
          break;
 
        default:
-         process_coff_symbol (cs, &main_aux, section_offsets, objfile);
+         process_coff_symbol (cs, &main_aux, objfile);
          break;
        }
     }
@@ -1286,6 +1287,12 @@ free_stringtab ()
   stringtab = NULL;
 }
 
+static void
+free_stringtab_cleanup (void *ignore)
+{
+  free_stringtab ();
+}
+
 static char *
 getsymname (symbol_entry)
      struct internal_syment *symbol_entry;
@@ -1387,16 +1394,22 @@ free_linetab ()
   linetab = NULL;
 }
 
+static void
+free_linetab_cleanup (void *ignore)
+{
+  free_linetab ();
+}
+
 #if !defined (L_LNNO32)
 #define L_LNNO32(lp) ((lp)->l_lnno)
 #endif
 
 static void
-enter_linenos (file_offset, first_line, last_line, section_offsets)
+enter_linenos (file_offset, first_line, last_line, objfile)
      long file_offset;
      register int first_line;
      register int last_line;
-     struct section_offsets *section_offsets;
+     struct objfile *objfile;
 {
   register char *rawptr;
   struct internal_lineno lptr;
@@ -1426,7 +1439,7 @@ enter_linenos (file_offset, first_line, last_line, section_offsets)
       if (L_LNNO32 (&lptr) && L_LNNO32 (&lptr) <= last_line)
        record_line (current_subfile, first_line + L_LNNO32 (&lptr),
                     lptr.l_addr.l_paddr
-                    + ANOFFSET (section_offsets, SECT_OFF_TEXT));
+                    + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)));
       else
        break;
     }
@@ -1521,10 +1534,9 @@ patch_opaque_types (s)
 }
 \f
 static struct symbol *
-process_coff_symbol (cs, aux, section_offsets, objfile)
+process_coff_symbol (cs, aux, objfile)
      register struct coff_symbol *cs;
      register union internal_auxent *aux;
-     struct section_offsets *section_offsets;
      struct objfile *objfile;
 {
   register struct symbol *sym
@@ -1547,7 +1559,7 @@ process_coff_symbol (cs, aux, section_offsets, objfile)
 
   if (ISFCN (cs->c_type))
     {
-      SYMBOL_VALUE (sym) += ANOFFSET (section_offsets, SECT_OFF_TEXT);
+      SYMBOL_VALUE (sym) += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
       SYMBOL_TYPE (sym) =
        lookup_function_type (decode_function_type (cs, cs->c_type, aux));
 
@@ -1577,7 +1589,7 @@ process_coff_symbol (cs, aux, section_offsets, objfile)
        case C_EXT:
          SYMBOL_CLASS (sym) = LOC_STATIC;
          SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value;
-         SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (section_offsets, SECT_OFF_TEXT);
+         SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
          add_symbol_to_list (sym, &global_symbols);
          break;
 
@@ -1586,7 +1598,7 @@ process_coff_symbol (cs, aux, section_offsets, objfile)
        case C_STAT:
          SYMBOL_CLASS (sym) = LOC_STATIC;
          SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value;
-         SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (section_offsets, SECT_OFF_TEXT);
+         SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
          if (within_function)
            {
              /* Static symbol of local scope */
@@ -2211,8 +2223,7 @@ static struct sym_fns coff_sym_fns =
   coff_symfile_init,           /* sym_init: read initial info, setup for sym_read() */
   coff_symfile_read,           /* sym_read: read a symbol file into symtab */
   coff_symfile_finish,         /* sym_finish: finished with file, cleanup */
-  default_symfile_offsets,
-                       /* sym_offsets:  xlate external to internal form */
+  default_symfile_offsets,     /* sym_offsets:  xlate external to internal form */
   NULL                         /* next: pointer to next struct sym_fns */
 };
 
This page took 0.068424 seconds and 4 git commands to generate.