* hppa.h (pa_opcodes): Add popbts, new forms of bb, havg,
[deliverable/binutils-gdb.git] / bfd / syms.c
index 0feacbc3e03656577665cca57a879c617c8dcab6..108e3eac27ba7faf338806dbceeebd02526c2c71 100644 (file)
@@ -1,5 +1,5 @@
 /* Generic symbol-table support for the BFD library.
-   Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97, 1998
+   Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97, 98, 1999
    Free Software Foundation, Inc.
    Written by Cygnus Support.
 
@@ -698,10 +698,10 @@ _bfd_generic_read_minisymbols (abfd, dynamic, minisymsp, sizep)
 /*ARGSUSED*/
 asymbol *
 _bfd_generic_minisymbol_to_symbol (abfd, dynamic, minisym, sym)
-     bfd *abfd;
-     boolean dynamic;
+     bfd *abfd ATTRIBUTE_UNUSED;
+     boolean dynamic ATTRIBUTE_UNUSED;
      const PTR minisym;
-     asymbol *sym;
+     asymbol *sym ATTRIBUTE_UNUSED;
 {
   return *(asymbol **) minisym;
 }
@@ -728,9 +728,9 @@ struct indexentry
   bfd_vma val;
   bfd_byte *stab;
   bfd_byte *str;
-  bfd_byte *directory_name;
-  bfd_byte *file_name;
-  bfd_byte *function_name;
+  char *directory_name;
+  char *file_name;
+  char *function_name;
 };
 
 /* Compare two indexentry structures.  This is called via qsort.  */
@@ -774,7 +774,7 @@ struct stab_find_info
   struct indexentry *cached_indexentry;
   bfd_vma cached_offset;
   bfd_byte *cached_stab;
-  bfd_byte *cached_file_name;
+  char *cached_file_name;
 #endif
 
   /* Saved ptr to malloc'ed filename.  */
@@ -797,9 +797,11 @@ _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset, pfound,
   struct stab_find_info *info;
   bfd_size_type stabsize, strsize;
   bfd_byte *stab, *str;
+  bfd_byte *last_stab = NULL;
   bfd_size_type stroff;
   struct indexentry *indexentry;
   char *directory_name, *file_name;
+  int saw_fun;
 
   *pfound = false;
   *pfilename = bfd_get_filename (abfd);
@@ -842,7 +844,6 @@ _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset, pfound,
     {
       long reloc_size, reloc_count;
       arelent **reloc_vector;
-      bfd_vma val;
       int i;
       char *name;
       char *file_name;
@@ -944,12 +945,38 @@ _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset, pfound,
         table.  */
 
       info->indextablesize = 0;
+      saw_fun = 1;
       for (stab = info->stabs; stab < info->stabs + stabsize; stab += STABSIZE)
        {
-         if (stab[TYPEOFF] == N_FUN)
-           ++info->indextablesize;
+         if (stab[TYPEOFF] == N_SO)
+           {
+             /* N_SO with null name indicates EOF */
+             if (bfd_get_32 (abfd, stab + STRDXOFF) == 0)
+               continue;
+
+             /* if we did not see a function def, leave space for one. */
+             if (saw_fun == 0)
+               ++info->indextablesize;
+
+             saw_fun = 0;
+
+             /* two N_SO's in a row is a filename and directory. Skip */
+             if (stab + STABSIZE < info->stabs + stabsize
+                 && *(stab + STABSIZE + TYPEOFF) == N_SO)
+               {
+                 stab += STABSIZE;
+               }
+           }
+         else if (stab[TYPEOFF] == N_FUN)
+           {
+             saw_fun = 1;
+             ++info->indextablesize;
+           }
        }
 
+      if (saw_fun == 0)
+       ++info->indextablesize;
+      
       if (info->indextablesize == 0)
        return true;
       ++info->indextablesize;
@@ -963,6 +990,7 @@ _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset, pfound,
 
       file_name = NULL;
       directory_name = NULL;
+      saw_fun = 1;
 
       for (i = 0, stroff = 0, stab = info->stabs, str = info->strs;
           i < info->indextablesize && stab < info->stabs + stabsize;
@@ -981,26 +1009,47 @@ _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset, pfound,
            case N_SO:
              /* The main file name.  */
 
+             /* The following code creates a new indextable entry with
+                a NULL function name if there were no N_FUNs in a file.
+                Note that a N_SO without a file name is an EOF and
+                there could be 2 N_SO following it with the new filename 
+                and directory. */
+             if (saw_fun == 0)
+               {
+                 info->indextable[i].val = bfd_get_32 (abfd, last_stab + VALOFF);
+                 info->indextable[i].stab = last_stab;
+                 info->indextable[i].str = str;
+                 info->indextable[i].directory_name = directory_name;
+                 info->indextable[i].file_name = file_name;
+                 info->indextable[i].function_name = NULL;
+                 ++i;
+               }
+             saw_fun = 0;
+             
              file_name = (char *) str + bfd_get_32 (abfd, stab + STRDXOFF);
-
              if (*file_name == '\0')
                {
                  directory_name = NULL;
                  file_name = NULL;
-               }
-             else if (stab + STABSIZE >= info->stabs + stabsize
-                      || *(stab + STABSIZE + TYPEOFF) != N_SO)
-               {
-                 directory_name = NULL;
+                 saw_fun = 1;
                }
              else
                {
-                 /* Two consecutive N_SOs are a directory and a file
-                     name.  */
-                 stab += STABSIZE;
-                 directory_name = file_name;
-                 file_name = ((char *) str
-                              + bfd_get_32 (abfd, stab + STRDXOFF));
+                 last_stab = stab;
+                 if (stab + STABSIZE >= info->stabs + stabsize
+                     || *(stab + STABSIZE + TYPEOFF) != N_SO)
+                   {
+                     directory_name = NULL;
+                   }
+                 else
+                   {
+                     /* Two consecutive N_SOs are a directory and a
+                        file name.  */
+                     stab += STABSIZE;
+                     directory_name = file_name;
+                     file_name = ((char *) str
+                                  + bfd_get_32 (abfd, stab + STRDXOFF));
+                   }
                }
              break;
 
@@ -1011,7 +1060,7 @@ _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset, pfound,
 
            case N_FUN:
              /* A function name.  */
-
+             saw_fun = 1;
              name = (char *) str + bfd_get_32 (abfd, stab + STRDXOFF);
 
              if (*name == '\0')
@@ -1022,20 +1071,28 @@ _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset, pfound,
              if (name == NULL)
                continue;
 
-             val = bfd_get_32 (abfd, stab + VALOFF);
-
-             info->indextable[i].val = val;
+             info->indextable[i].val = bfd_get_32 (abfd, stab + VALOFF);
              info->indextable[i].stab = stab;
              info->indextable[i].str = str;
              info->indextable[i].directory_name = directory_name;
              info->indextable[i].file_name = file_name;
              info->indextable[i].function_name = function_name;
-
              ++i;
              break;
            }
        }
 
+      if (saw_fun == 0)
+       {
+         info->indextable[i].val = bfd_get_32 (abfd, last_stab + VALOFF);
+         info->indextable[i].stab = last_stab;
+         info->indextable[i].str = str;
+         info->indextable[i].directory_name = directory_name;
+         info->indextable[i].file_name = file_name;
+         info->indextable[i].function_name = NULL;
+         ++i;
+       }
+
       info->indextable[i].val = (bfd_vma) -1;
       info->indextable[i].stab = info->stabs + stabsize;
       info->indextable[i].str = str;
@@ -1045,7 +1102,6 @@ _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset, pfound,
       ++i;
 
       info->indextablesize = i;
-
       qsort (info->indextable, i, sizeof (struct indexentry), cmpindexentry);
 
       *pinfo = (PTR) info;
This page took 0.02541 seconds and 4 git commands to generate.