* readelf.c: Add missing prototypes.
[deliverable/binutils-gdb.git] / binutils / rddbg.c
index b2602af4c6e98dd30e8a08367d77da47deb3d24c..e6ace7755775054c9ea1f2e4916afbfc4e1a9bed 100644 (file)
@@ -1,5 +1,5 @@
 /* rddbg.c -- Read debugging information into a generic form.
-   Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+   Copyright 1995, 1996, 1997, 2000 Free Software Foundation, Inc.
    Written by Ian Lance Taylor <ian@cygnus.com>.
 
    This file is part of GNU Binutils.
@@ -84,8 +84,8 @@ read_debugging_info (abfd, syms, symcount)
 
   if (! found)
     {
-      fprintf (stderr, "%s: no recognized debugging information\n",
-              bfd_get_filename (abfd));
+      non_fatal (_("%s: no recognized debugging information"),
+                bfd_get_filename (abfd));
       return NULL;
     }
 
@@ -159,7 +159,7 @@ read_section_stabs_debugging_info (abfd, syms, symcount, dhandle, pfound)
          next_stroff = 0;
          for (stab = stabs; stab < stabs + stabsize; stab += 12)
            {
-             bfd_size_type strx;
+             unsigned int strx;
              int type;
              int other;
              int desc;
@@ -185,17 +185,36 @@ read_section_stabs_debugging_info (abfd, syms, symcount, dhandle, pfound)
                  char *f, *s;
 
                  f = NULL;
+                 
+                 if (stroff + strx > strsize)
+                   {
+                     fprintf (stderr, "%s: %s: stab entry %d is corrupt, strx = 0x%x, type = %d\n",
+                              bfd_get_filename (abfd), names[i].secname,
+                              (stab - stabs) / 12, strx, type);
+                     continue;
+                   }
+                 
                  s = (char *) strings + stroff + strx;
+                 
                  while (s[strlen (s) - 1] == '\\'
                         && stab + 12 < stabs + stabsize)
                    {
+                     char *p;
+
                      stab += 12;
-                     s[strlen (s) - 1] = '\0';
+                     p = s + strlen (s) - 1;
+                     *p = '\0';
                      s = concat (s,
                                  ((char *) strings
                                   + stroff
                                   + bfd_get_32 (abfd, stab)),
                                  (const char *) NULL);
+
+                     /* We have to restore the backslash, because, if
+                         the linker is hashing stabs strings, we may
+                         see the same string more than once.  */
+                     *p = '\\';
+
                      if (f != NULL)
                        free (f);
                      f = s;
@@ -270,6 +289,7 @@ read_symbol_stabs_debugging_info (abfd, syms, symcount, dhandle, pfound)
          *pfound = true;
 
          s = i.name;
+         f = NULL;
          while (s[strlen (s) - 1] == '\\'
                 && ps + 1 < symend)
            {
@@ -296,14 +316,14 @@ read_symbol_stabs_debugging_info (abfd, syms, symcount, dhandle, pfound)
              return false;
            }
 
-         free_saved_stabs ();
-
          /* Don't free f, since I think the stabs code expects
             strings to hang around.  This should be straightened out.
             FIXME.  */
        }
     }
 
+  free_saved_stabs ();
+
   if (shandle != NULL)
     {
       if (! finish_stab (dhandle, shandle))
@@ -387,7 +407,7 @@ stab_context ()
 {
   int i;
 
-  fprintf (stderr, "Last stabs entries before error:\n");
+  fprintf (stderr, _("Last stabs entries before error:\n"));
   fprintf (stderr, "n_type n_desc n_value  string\n");
 
   i = saved_stabs_index;
@@ -426,7 +446,13 @@ free_saved_stabs ()
   int i;
 
   for (i = 0; i < SAVE_STABS_COUNT; i++)
-    if (saved_stabs[i].string != NULL)
-      free (saved_stabs[i].string);
+    {
+      if (saved_stabs[i].string != NULL)
+       {
+         free (saved_stabs[i].string);
+         saved_stabs[i].string = NULL;
+       }
+    }
+
   saved_stabs_index = 0;
 }
This page took 0.024959 seconds and 4 git commands to generate.