* config/tc-sh.c (sh_force_relocation): Make sure TLS relocs get
[deliverable/binutils-gdb.git] / binutils / rddbg.c
index d42d04863eda71df2a0af18501c852993368edd0..3430c02862867da69d417a139bcb579c1b700e55 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.
@@ -54,8 +54,6 @@ read_debugging_info (abfd, syms, symcount)
   if (dhandle == NULL)
     return NULL;
 
-  /* All we know about right now is stabs.  */
-
   if (! read_section_stabs_debugging_info (abfd, syms, symcount, dhandle,
                                           &found))
     return NULL;
@@ -73,10 +71,21 @@ read_debugging_info (abfd, syms, symcount)
        return NULL;
     }
 
+  /* Try reading the COFF symbols if we didn't find any stabs in COFF
+     sections.  */
+  if (! found
+      && bfd_get_flavour (abfd) == bfd_target_coff_flavour
+      && symcount > 0)
+    {
+      if (! parse_coff (abfd, syms, symcount, dhandle))
+       return NULL;
+      found = true;
+    }
+
   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;
     }
 
@@ -150,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;
@@ -176,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;
@@ -261,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)
            {
@@ -287,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))
@@ -378,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;
@@ -417,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.025001 seconds and 4 git commands to generate.