use remote-utils facilities for baud_rate
[deliverable/binutils-gdb.git] / gdb / paread.c
index 46a6e3d2537001495251391fa7a8bbcdcb6c6be8..1ea889105090235f6e2236069b7553c2977d5980 100644 (file)
@@ -20,18 +20,24 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include "defs.h"
 #include "bfd.h"
+#include <time.h> /* For time_t in libbfd.h.  */
 #include "libbfd.h"
-#include "libhppa.h"
+#include "som.h"
 #include <syms.h>
 #include "symtab.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "buildsym.h"
+#include "stabsread.h"
 #include "gdb-stabs.h"
 #include "complaints.h"
 #include <string.h>
 #include "demangle.h"
 #include <sys/file.h>
+
+/* Size of n_value and n_strx fields in a stab symbol.  */
+#define BYTES_IN_WORD 4
+
 #include "aout/aout64.h"
 
 /* Various things we might complain about... */
@@ -105,7 +111,8 @@ pa_symtab_read (abfd, addr, objfile)
   unsigned int i;
   int val;
   char *stringtab;
-  struct symbol_dictionary_record *buf, *bufp;
+  struct symbol_dictionary_record *buf, *bufp, *endbufp;
+  char *symname;
   CONST int symsize = sizeof (struct symbol_dictionary_record);
 
   number_of_symbols = bfd_get_symcount (abfd);
@@ -121,41 +128,96 @@ pa_symtab_read (abfd, addr, objfile)
   val = bfd_read (stringtab, obj_stringtab_size (abfd), 1, abfd);
   if (val != obj_stringtab_size (abfd))
     error ("Can't read in HP string table.");
-  
-  for (i = 0, bufp = buf; i < number_of_symbols; i++, bufp++)
+
+  endbufp = buf + number_of_symbols;
+  for (bufp = buf; bufp < endbufp; ++bufp)
     {
       enum minimal_symbol_type ms_type;
 
       QUIT;
 
-      if (bufp->symbol_scope != SS_UNIVERSAL)
-       continue;
-
-      switch (bufp->symbol_type)
-        {
-        case ST_SYM_EXT:
-        case ST_ARG_EXT:
-          continue;
-        case ST_CODE:
-        case ST_PRI_PROG:
-        case ST_SEC_PROG:
-        case ST_ENTRY:
-        case ST_MILLICODE:
-          ms_type = mst_text;
-          bufp->symbol_value &= ~0x3; /* clear out permission bits */
-          break;
-        case ST_DATA:
-          ms_type = mst_data;
-          break;
-        default:
-          continue;
-        }
+      switch (bufp->symbol_scope)
+       {
+       case SS_UNIVERSAL:
+         switch (bufp->symbol_type)
+           {
+           case ST_SYM_EXT:
+           case ST_ARG_EXT:
+             continue;
+
+           case ST_CODE:
+           case ST_PRI_PROG:
+           case ST_SEC_PROG:
+           case ST_ENTRY:
+           case ST_MILLICODE:
+             symname = bufp->name.n_strx + stringtab;
+             ms_type = mst_text;
+             bufp->symbol_value &= ~0x3; /* clear out permission bits */
+             break;
+           case ST_DATA:
+             symname = bufp->name.n_strx + stringtab;
+             ms_type = mst_data;
+             break;
+           default:
+             continue;
+           }
+         break;
+
+#if 0
+         /* SS_GLOBAL and SS_LOCAL are two names for the same thing (!).  */
+       case SS_GLOBAL:
+#endif
+       case SS_LOCAL:
+         switch (bufp->symbol_type)
+           {
+           case ST_SYM_EXT:
+           case ST_ARG_EXT:
+             continue;
+
+           case ST_CODE:
+             symname = bufp->name.n_strx + stringtab;
+             ms_type = mst_file_text;
+             bufp->symbol_value &= ~0x3; /* clear out permission bits */
+
+           check_strange_names:
+             /* GAS leaves symbols with the prefixes "LS$", "LBB$",
+                and "LBE$" in .o files after assembling.  And thus
+                they appear in the final executable.  This can
+                cause problems if these special symbols have the
+                same value as real symbols.  So ignore them.  Also "LC$".  */
+             if (*symname == 'L'
+                 && (symname[2] == '$' || symname[3] == '$'))
+               continue;
+             break;
+
+           case ST_PRI_PROG:
+           case ST_SEC_PROG:
+           case ST_ENTRY:
+           case ST_MILLICODE:
+             symname = bufp->name.n_strx + stringtab;
+             ms_type = mst_file_text;
+             bufp->symbol_value &= ~0x3; /* clear out permission bits */
+             break;
+
+           case ST_DATA:
+             symname = bufp->name.n_strx + stringtab;
+             ms_type = mst_file_data;
+             goto check_strange_names;
+
+           default:
+             continue;
+           }
+         break;
+
+       default:
+         continue;
+       }
 
       if (bufp->name.n_strx > obj_stringtab_size (abfd))
        error ("Invalid symbol data; bad HP string table offset: %d",
               bufp->name.n_strx);
 
-      record_minimal_symbol (bufp->name.n_strx + stringtab,
+      record_minimal_symbol (symname,
                             bufp->symbol_value, ms_type, 
                             objfile);
     }
@@ -360,6 +422,9 @@ pa_symfile_init (objfile)
   if (!DBX_TEXT_SECT (objfile))
     error ("Can't find .text section in symbol file");
 
+  /* FIXME: I suspect this should be external_nlist.  The size of host
+     types like long and bfd_vma should not affect how we read the
+     file.  */
   DBX_SYMBOL_SIZE (objfile) = sizeof (struct internal_nlist);
   DBX_SYMCOUNT (objfile) = bfd_section_size (sym_bfd, stabsect)
     / DBX_SYMBOL_SIZE (objfile);
@@ -399,8 +464,14 @@ pa_symfile_init (objfile)
     perror_with_name (name);
   val = bfd_read (DBX_STRINGTAB (objfile), DBX_STRINGTAB_SIZE (objfile), 1,
                  sym_bfd);
-  if (val != DBX_STRINGTAB_SIZE (objfile))
+  if (val == 0)
+    error ("End of file reading string table");
+  else if (val < 0)
+    /* It's possible bfd_read should be setting bfd_error, and we should be
+       checking that.  But currently it doesn't set bfd_error.  */
     perror_with_name (name);
+  else if (val != DBX_STRINGTAB_SIZE (objfile))
+    error ("Short read reading string table");
 }
 
 /* PA specific parsing routine for section offsets.
This page took 0.025088 seconds and 4 git commands to generate.