Various fixed triggered by trying to do the right thing wrt
authorPer Bothner <per@bothner.com>
Thu, 30 Jan 1992 03:56:32 +0000 (03:56 +0000)
committerPer Bothner <per@bothner.com>
Thu, 30 Jan 1992 03:56:32 +0000 (03:56 +0000)
to external symbols in mips ecoff binaries.  See ChangeLog.

gdb/ChangeLog
gdb/mipsread.c
gdb/symfile.c

index 49290ee..cf50941 100644 (file)
@@ -1,3 +1,24 @@
+Wed Jan 29 19:24:34 1992  Per Bothner  (bothner at cygnus.com)
+
+       * mipsread.c (parse_partial_symbols):  Make sure partial
+       symbols are created for external symbols (as used to be
+       the case).  This is a bit of a pain with the mips-coff.
+       It uses a table which points to all of the external
+       symbols belonging to a particular FDR or psymtab.
+       Once we've generated this table, we might as well save
+       it, and then use it in psymtab_to_symtab_1 to find
+       the symbols to pass to parse_external().
+       * symfile.c,  symfile.c:  New function start_psymtab_common
+       to share the common parts of allocating a new psymtab
+       for dbxread, mipsread (and later dwarfread).  Its code
+       was pulled out from start_psymtab in dbxread.c.
+       * dbxread.c (start_psymtab):  Use start_psymtab_common().
+
+       * valprint.c (val_print):  If there is an error when trying
+       to print a string, check to see if there really is a problem
+       by reading just one character.  If that works, assume
+       things are ok.
+
 Wed Jan 29 18:58:43 1992  Stu Grossman  (grossman at cygnus.com)
 
        * sparc-pinsn.c (compare_opcodes):  Make it prefer v6, v7,
index 4bd8786..27601e1 100644 (file)
@@ -60,9 +60,9 @@ struct coff_exec {
        struct external_aouthdr a;
 };
 
-/* These must match the corresponding definition in mips-tfile.c.
-   At some point, these should probably go into an include file,
-   but currently gcc does use/need the ../include directory. */
+/* These must match the corresponding definition in gcc/config/xm-mips.h.
+   At some point, these should probably go into a shared include file,
+   but currently gcc and gdb do not share any directories. */
 
 #define CODE_MASK 0x8F300
 #define MIPS_IS_STAB(sym) (((sym)->index & 0xFFF00) == CODE_MASK)
@@ -78,12 +78,15 @@ struct coff_exec {
    represents and a pointer to the symbol table header HDRR from the symbol
    file that the psymtab was created from.  */
 
-#define FDR_IDX(p) (((struct symloc *)((p)->read_symtab_private))->fdr_idx)
-#define CUR_HDR(p) (((struct symloc *)((p)->read_symtab_private))->cur_hdr)
+#define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
+#define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
+#define CUR_HDR(p) (PST_PRIVATE(p)->cur_hdr)
 
 struct symloc {
   int fdr_idx;
   HDRR *cur_hdr;
+  EXTR **extern_tab; /* Pointer to external symbols for this file. */
+  int extern_count; /* Size of extern_tab. */
 };
 
 /* Things we import explicitly from other modules */
@@ -589,9 +592,11 @@ read_mips_symtab (objfile, desc)
 
 /* Map of FDR indexes to partial symtabs */
 
-static struct pst_map {
-       struct partial_symtab *pst;     /* the psymtab proper */
-} * fdr_to_pst;
+struct pst_map {
+    struct partial_symtab *pst;        /* the psymtab proper */
+    int n_globals; /* exported globals (external symbols) */
+    int globals_offset;  /* cumulative */
+};
 
 
 /* Utility stack, used to nest procedures and blocks properly.
@@ -1662,74 +1667,95 @@ parse_lines(fh, lt)
 
 static
 parse_partial_symbols(end_of_text_seg, objfile)
-       int end_of_text_seg;
-       struct objfile *objfile;
+     int end_of_text_seg;
+     struct objfile *objfile;
 {
-       int             f_idx, s_idx;
+    int             f_idx, s_idx;
 /*     int  stat_idx, h_max;*/
-       HDRR            *hdr;
-       /* Running pointers */
-       FDR             *fh;
-       RFDT            *rh;
-       register EXTR   *esh;
-       register SYMR   *sh;
-       struct partial_symtab *pst;
-
-  int past_first_source_file = 0;
-
-  /* List of current psymtab's include files */
-  char **psymtab_include_list;
-  int includes_allocated;
-  int includes_used;
-
-  /* Index within current psymtab dependency list */
-  struct partial_symtab **dependency_list;
-  int dependencies_used, dependencies_allocated;
-
-  includes_allocated = 30;
-  includes_used = 0;
-  psymtab_include_list = (char **) alloca (includes_allocated *
-                                          sizeof (char *));
-  next_symbol_text_func = mips_next_symbol_text;
-
-  dependencies_allocated = 30;
-  dependencies_used = 0;
-  dependency_list =
-    (struct partial_symtab **) alloca (dependencies_allocated *
-                                      sizeof (struct partial_symtab *));
-
-  last_source_file = 0;
-
-       /*
-        * Big plan: 
-        *
-        * Only parse the Local and External symbols, and the Relative FDR.
-        * Fixup enough of the loader symtab to be able to use it.
-        * Allocate space only for the file's portions we need to
-        * look at. (XXX)
-        */
-
-       hdr = cur_hdr;
-       max_gdbinfo = 0;
-       max_glevel = MIN_GLEVEL;
-
-       /* Allocate the map FDR -> PST.
-          Minor hack: -O3 images might claim some global data belongs
-          to FDR -1. We`ll go along with that */
-       fdr_to_pst = (struct pst_map *)xzalloc((hdr->ifdMax+1) * sizeof *fdr_to_pst);
-       fdr_to_pst++;
-       {
-               struct partial_symtab * pst = new_psymtab("", objfile);
-               fdr_to_pst[-1].pst = pst;
-               FDR_IDX(pst) = -1;
-       }
+    HDRR               *hdr = cur_hdr;
+    /* Running pointers */
+    FDR                *fh;
+    RFDT               *rh;
+    register EXTR      *esh;
+    register SYMR      *sh;
+    struct partial_symtab *pst;
+    
+    int past_first_source_file = 0;
+    
+    /* List of current psymtab's include files */
+    char **psymtab_include_list;
+    int includes_allocated;
+    int includes_used;
+    EXTR **extern_tab;
+    struct pst_map * fdr_to_pst;
+    /* Index within current psymtab dependency list */
+    struct partial_symtab **dependency_list;
+    int dependencies_used, dependencies_allocated;
+    struct cleanup *old_chain;
+    
+    extern_tab = (EXTR**)obstack_alloc (psymbol_obstack,
+                                       sizeof(EXTR *) * hdr->iextMax);
+   
+    includes_allocated = 30;
+    includes_used = 0;
+    psymtab_include_list = (char **) alloca (includes_allocated *
+                                            sizeof (char *));
+    next_symbol_text_func = mips_next_symbol_text;
+    
+    dependencies_allocated = 30;
+    dependencies_used = 0;
+    dependency_list =
+       (struct partial_symtab **) alloca (dependencies_allocated *
+                                          sizeof (struct partial_symtab *));
+    
+    last_source_file = 0;
+
+    /*
+     * Big plan: 
+     *
+     * Only parse the Local and External symbols, and the Relative FDR.
+     * Fixup enough of the loader symtab to be able to use it.
+     * Allocate space only for the file's portions we need to
+     * look at. (XXX)
+     */
+    
+    max_gdbinfo = 0;
+    max_glevel = MIN_GLEVEL;
+    
+    /* Allocate the map FDR -> PST.
+       Minor hack: -O3 images might claim some global data belongs
+       to FDR -1. We`ll go along with that */
+    fdr_to_pst = (struct pst_map *)xzalloc((hdr->ifdMax+1) * sizeof *fdr_to_pst);
+    old_chain = make_cleanup (free, fdr_to_pst);
+    fdr_to_pst++;
+    {
+       struct partial_symtab * pst = new_psymtab("", objfile);
+       fdr_to_pst[-1].pst = pst;
+       FDR_IDX(pst) = -1;
+    }
+    
+    /* Pass 1 over external syms: Presize and partition the list */
+    for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
+       esh = (EXTR *) (hdr->cbExtOffset) + s_idx;
+       fdr_to_pst[esh->ifd].n_globals++;
+    }
+    
+    /* Pass 1.5 over files:  partition out global symbol space */
+    s_idx = 0;
+    for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++) {
+       fdr_to_pst[f_idx].globals_offset = s_idx;
+       s_idx += fdr_to_pst[f_idx].n_globals;
+       fdr_to_pst[f_idx].n_globals = 0;
+    }
 
-       /* Pass 2 over external syms: fill in external symbols */
+/* Pass 2 over external syms: fill in external symbols */
        for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
-               register struct partial_symbol *p;
                enum misc_function_type misc_type = mf_text;
                esh = (EXTR *) (hdr->cbExtOffset) + s_idx;
 
+               extern_tab[fdr_to_pst[esh->ifd].globals_offset
+                          + fdr_to_pst[esh->ifd].n_globals++] = esh;
+
                if (esh->asym.sc == scUndefined || esh->asym.sc == scNil)
                        continue;
 
@@ -1743,7 +1769,8 @@ parse_partial_symbols(end_of_text_seg, objfile)
                        break;
                default:
                        misc_type = mf_unknown;
-                       complain (&unknown_ext_complaint, SYMBOL_NAME(p));
+                       complain (&unknown_ext_complaint,
+                                 (char *)(esh->asym.iss));
                }
                prim_record_misc_function ((char *)(esh->asym.iss),
                                           esh->asym.value,
@@ -1753,18 +1780,20 @@ parse_partial_symbols(end_of_text_seg, objfile)
        /* Pass 3 over files, over local syms: fill in static symbols */
        for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
            struct partial_symtab *save_pst;
-           
+           EXTR **ext_ptr;
            cur_fdr = fh = f_idx + (FDR *)(cur_hdr->cbFdOffset);
 
            if (fh->csym == 0) {
                fdr_to_pst[f_idx].pst = NULL;
                continue;
            }
-           pst = start_psymtab (objfile, 0, (char*)fh->rss,
-                                fh->cpd ? fh->adr : 0,
-                                -1,
-                                global_psymbols.next,
-                                static_psymbols.next);
+           pst = start_psymtab_common (objfile, 0, (char*)fh->rss,
+                                       fh->cpd ? fh->adr : 0,
+                                       global_psymbols.next,
+                                       static_psymbols.next);
+           pst->read_symtab_private = (char *)
+               obstack_alloc (psymbol_obstack, sizeof (struct symloc));
+
            save_pst = pst;
            /* Make everything point to everything. */
            FDR_IDX(pst) = f_idx;
@@ -1824,6 +1853,7 @@ parse_partial_symbols(end_of_text_seg, objfile)
                }
            }
            else {
+               register struct partial_symbol *psym;
                for (cur_sdx = 0; cur_sdx < fh->csym; ) {
                    register struct partial_symbol *p;
                    char *name;
@@ -1898,7 +1928,41 @@ parse_partial_symbols(end_of_text_seg, objfile)
                  skip:
                    cur_sdx++;          /* Go to next file symbol */
                }
+
+               /* Now do enter the external symbols. */
+               ext_ptr = &extern_tab[fdr_to_pst[f_idx].globals_offset];
+               cur_sdx = fdr_to_pst[f_idx].n_globals;
+               PST_PRIVATE(save_pst)->extern_count = cur_sdx;
+               PST_PRIVATE(save_pst)->extern_tab = ext_ptr;
+               for (; --cur_sdx >= 0; ext_ptr++) {
+                   enum address_class class;
+                   if ((*ext_ptr)->ifd != f_idx)
+                       abort();
+                   sh = &(*ext_ptr)->asym;
+                   switch (sh->st) {
+                     case stProc:
+                       class = LOC_BLOCK;
+                       break;
+                     case stLabel:
+                       class = LOC_LABEL;
+                       break;
+                     default:
+                       complain (&unknown_ext_complaint, sh->iss);
+                     case stGlobal:
+                       class = LOC_STATIC;
+                       break;
+                   }
+                   if (global_psymbols.next >=
+                       global_psymbols.list + global_psymbols.size)
+                       extend_psymbol_list (&global_psymbols);
+                   psym = global_psymbols.next++;
+                   SYMBOL_NAME (psym) = (char*)sh->iss;
+                   SYMBOL_NAMESPACE (psym) = VAR_NAMESPACE;
+                   SYMBOL_CLASS (psym) = class;
+                   SYMBOL_VALUE_ADDRESS (psym) = (CORE_ADDR)sh->value;
+               }
            }
+
            end_psymtab (save_pst, psymtab_include_list, includes_used,
                         -1, save_pst->texthigh,
                         dependency_list, dependencies_used,
@@ -1913,11 +1977,11 @@ parse_partial_symbols(end_of_text_seg, objfile)
        /* Mark the last code address, and remember it for later */
        hdr->cbDnOffset = end_of_text_seg;
 
-       free(&fdr_to_pst[-1]);
-       fdr_to_pst = 0;
+       do_cleanups (old_chain);
 }
 
 
+#if 0
 /* Do the initial analisys of the F_IDX-th file descriptor.
    Allocates a partial symtab for it, and builds the list
    of dependent files by recursion. LEV says at which level
@@ -1986,6 +2050,7 @@ parse_fdr(f_idx, lev, objfile)
 
        return pst;
 }
+#endif
 
 static char*
 mips_next_symbol_text ()
@@ -2149,6 +2214,7 @@ psymtab_to_symtab_1(pst, filename)
 
     }
     if (!have_stabs) {
+       EXTR **ext_ptr;
        LINETABLE(st) = lines;
     
        /* .. and our share of externals.
@@ -2159,11 +2225,9 @@ psymtab_to_symtab_1(pst, filename)
        top_stack->maxsyms =
            cur_hdr->isymMax + cur_hdr->ipdMax + cur_hdr->iextMax;
 
-       for (i = 0; i < cur_hdr->iextMax; i++) {
-           register EXTR *esh = (EXTR *) (cur_hdr->cbExtOffset) + i;
-           if (esh->ifd == cur_fd)
-               parse_external(esh, 1);
-       }
+       ext_ptr = PST_PRIVATE(pst)->extern_tab;
+       for (i = PST_PRIVATE(pst)->extern_count; --i >= 0; ext_ptr++)
+           parse_external(*ext_ptr, 1);
     
        /* If there are undefined, tell the user */
        if (n_undef_symbols) {
index 8f5b5b3..8745796 100644 (file)
@@ -602,7 +602,7 @@ symbol_file_add (name, from_tty, addr, mainline)
       && !query ("Load new symbol table from \"%s\"? ", name))
     error ("Not confirmed.");
 
-  if (from_tty)
+  if (from_tty || info_verbose)
     {
       printf_filtered ("Reading symbols from %s...", name);
       wrap_here ("");
@@ -611,7 +611,7 @@ symbol_file_add (name, from_tty, addr, mainline)
 
   syms_from_objfile (objfile, addr, mainline, from_tty);
 
-  if (from_tty)
+  if (from_tty || info_verbose)
     {
       printf_filtered ("done.\n");
       fflush (stdout);
@@ -875,7 +875,6 @@ reread_symbols ()
 
   for (objfile = object_files; objfile; objfile = objfile->next) {
     if (objfile->obfd) {
-      objfile->obfd->mtime_set = false;                /* Force it to reread. */
       new_modtime = bfd_get_mtime (objfile->obfd);
       if (new_modtime != objfile->mtime) {
        printf_filtered ("`%s' has changed; re-reading symbols.\n",
@@ -1255,6 +1254,53 @@ again2:
   return blewit;
 }
 \f
+/* Allocate and partially fill a partial symtab.  It will be
+   completely filled at the end of the symbol list.
+
+   SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
+   is the address relative to which its symbols are (incremental) or 0
+   (normal). */
+
+
+struct partial_symtab *
+start_psymtab_common (objfile, addr,
+                     filename, textlow, global_syms, static_syms)
+     struct objfile *objfile;
+     CORE_ADDR addr;
+     char *filename;
+     CORE_ADDR textlow;
+     struct partial_symbol *global_syms;
+     struct partial_symbol *static_syms;
+{
+  int filename_length = strlen (filename) + 1;
+  struct partial_symtab *result =
+    (struct partial_symtab *) obstack_alloc (psymbol_obstack,
+                                            sizeof (struct partial_symtab));
+
+  result->addr = addr;
+
+  result->filename = (char *) obstack_alloc (psymbol_obstack, filename_length);
+  memcpy (result->filename, filename, filename_length);
+
+  result->textlow = textlow;
+
+  result->readin = 0;
+  result->symtab = NULL;
+
+  result->globals_offset = global_syms - global_psymbols.list;
+  result->statics_offset = static_syms - static_psymbols.list;
+
+  result->n_global_syms = 0;
+  result->n_static_syms = 0;
+
+  /* Chain it to the list owned by the current object file.  */
+  result->objfile = objfile;
+  result->objfile_chain = objfile->psymtabs;
+  objfile->psymtabs = result;
+
+  return result;
+}
+
 /*
  * Free all partial_symtab storage.
  */