daily update
[external/binutils.git] / gprof / corefile.c
index 5c6fe6b..e25d19b 100644 (file)
@@ -1,7 +1,7 @@
 /* corefile.c
 
-   Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
-   Free Software Foundation, Inc.
+   Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009,
+   2010, 2011  Free Software Foundation, Inc.
 
    This file is part of GNU Binutils.
 
@@ -22,6 +22,7 @@
 \f
 #include "gprof.h"
 #include "libiberty.h"
+#include "filenames.h"
 #include "search_list.h"
 #include "source.h"
 #include "symtab.h"
@@ -140,7 +141,7 @@ read_function_mappings (const char *filename)
        }
 
       /* dummy has the filename, go ahead and copy it.  */
-      symbol_map[count].file_name = xmalloc (strlen (dummy) + 1);
+      symbol_map[count].file_name = (char *) xmalloc (strlen (dummy) + 1);
       strcpy (symbol_map[count].file_name, dummy);
 
       /* Now we need the function name.  */
@@ -148,7 +149,7 @@ read_function_mappings (const char *filename)
       if (!matches)
        parse_error (filename);
       tmp = strrchr (dummy, ' ') + 1;
-      symbol_map[count].function_name = xmalloc (strlen (tmp) + 1);
+      symbol_map[count].function_name = (char *) xmalloc (strlen (tmp) + 1);
       strcpy (symbol_map[count].function_name, tmp);
       count++;
     }
@@ -157,7 +158,8 @@ read_function_mappings (const char *filename)
   symbol_map_count = count;
 
   for (i = 0; i < symbol_map_count; ++i)
-    if (i == 0 || strcmp (symbol_map[i].file_name, symbol_map[i - 1].file_name))
+    if (i == 0
+        || filename_cmp (symbol_map[i].file_name, symbol_map[i - 1].file_name))
       symbol_map[i].is_first = 1;
 
   qsort (symbol_map, symbol_map_count, sizeof (struct function_map), cmp_symbol_map);
@@ -227,7 +229,7 @@ core_init (const char * aout_name)
       long i;
 
       new_size = (core_num_syms + synth_count + 1) * sizeof (*core_syms);
-      core_syms = xrealloc (core_syms, new_size);
+      core_syms = (asymbol **) xrealloc (core_syms, new_size);
       symp = core_syms + core_num_syms;
       core_num_syms += synth_count;
       for (i = 0; i < synth_count; i++)
@@ -385,12 +387,28 @@ core_sym_class (asymbol *sym)
       if (*name == '$')
         return 0;
 
-      /* Do not discard nested subprograms (those
-        which end with .NNN, where N are digits).  */
-      if (*name == '.')
-       for (name++; *name; name++)
-         if (! ISDIGIT (*name))
-           return 0;
+      while (*name == '.')
+       {
+         /* Allow both nested subprograms (which end with ".NNN", where N is
+            a digit) and GCC cloned functions (which contain ".clone").
+            Allow for multiple iterations of both - apparently GCC can clone
+            clones and subprograms.  */
+         int digit_seen = 0;
+#define CLONE_NAME      ".clone."
+#define CLONE_NAME_LEN  strlen (CLONE_NAME)
+             
+         if (strlen (name) > CLONE_NAME_LEN
+             && strncmp (name, CLONE_NAME, CLONE_NAME_LEN) == 0)
+           name += CLONE_NAME_LEN - 1;
+
+         for (name++; *name; name++)
+           if (digit_seen && *name == '.')
+             break;
+           else if (ISDIGIT (*name))
+             digit_seen = 1;
+           else
+             return 0;
+       }
     }
 
   /* On systems where the C compiler adds an underscore to all
@@ -517,7 +535,7 @@ core_create_syms_from (const char * sym_table_file)
       done (1);
     }
 
-  while (!feof (f) && fgets (buf, sizeof (buf), f))
+  while (!feof (f) && fgets (buf, BUFSIZE - 1, f))
     {
       if (sscanf (buf, "%s %c %s", address, &type, name) == 3)
         if (type != 't' && type != 'T')
@@ -565,6 +583,20 @@ core_create_function_syms (void)
   int cxxclass;
   long i;
   struct function_map * found;
+  int core_has_func_syms = 0;
+
+  switch (core_bfd->xvec->flavour)
+    {
+    default:
+      break;
+    case bfd_target_coff_flavour:
+    case bfd_target_ecoff_flavour:
+    case bfd_target_xcoff_flavour:
+    case bfd_target_elf_flavour:
+    case bfd_target_nlm_flavour:
+    case bfd_target_som_flavour:
+      core_has_func_syms = 1;
+    }
 
   /* Pass 1 - determine upper bound on number of function names.  */
   symtab.len = 0;
@@ -577,8 +609,10 @@ core_create_function_syms (void)
       /* Don't create a symtab entry for a function that has
         a mapping to a file, unless it's the first function
         in the file.  */
-      found = bsearch (core_syms[i]->name, symbol_map, symbol_map_count,
-                      sizeof (struct function_map), search_mapped_symbol);
+      found = (struct function_map *) bsearch (core_syms[i]->name, symbol_map,
+                                               symbol_map_count,
+                                               sizeof (struct function_map),
+                                               search_mapped_symbol);
       if (found == NULL || found->is_first)
        ++symtab.len;
     }
@@ -609,7 +643,8 @@ core_create_function_syms (void)
          continue;
        }
 
-      found = bsearch (core_syms[i]->name, symbol_map, symbol_map_count,
+      found = (struct function_map *) bsearch (core_syms[i]->name, symbol_map,
+                                               symbol_map_count,
                       sizeof (struct function_map), search_mapped_symbol);
       if (found && ! found->is_first)
        continue;
@@ -667,7 +702,8 @@ core_create_function_syms (void)
          }
       }
 
-      symtab.limit->is_func = (core_syms[i]->flags & BSF_FUNCTION) != 0; 
+      symtab.limit->is_func = (!core_has_func_syms
+                              || (core_syms[i]->flags & BSF_FUNCTION) != 0);
       symtab.limit->is_bb_head = TRUE;
 
       if (cxxclass == 't')
@@ -726,8 +762,8 @@ core_create_line_syms (void)
      BFD would provide an iterator for enumerating all line infos.  */
   prev_name_len = PATH_MAX;
   prev_filename_len = PATH_MAX;
-  prev_name = xmalloc (prev_name_len);
-  prev_filename = xmalloc (prev_filename_len);
+  prev_name = (char *) xmalloc (prev_name_len);
+  prev_filename = (char *) xmalloc (prev_filename_len);
   ltab.len = 0;
   prev_line_num = 0;
 
@@ -740,7 +776,7 @@ core_create_line_syms (void)
          || (prev_line_num == dummy.line_num
              && prev_name != NULL
              && strcmp (prev_name, dummy.name) == 0
-             && strcmp (prev_filename, filename) == 0))
+             && filename_cmp (prev_filename, filename) == 0))
        continue;
 
       ++ltab.len;
@@ -751,7 +787,7 @@ core_create_line_syms (void)
        {
          prev_name_len = len + 1024;
          free (prev_name);
-         prev_name = xmalloc (prev_name_len);
+         prev_name = (char *) xmalloc (prev_name_len);
        }
 
       strcpy (prev_name, dummy.name);
@@ -761,7 +797,7 @@ core_create_line_syms (void)
        {
          prev_filename_len = len + 1024;
          free (prev_filename);
-         prev_filename = xmalloc (prev_filename_len);
+         prev_filename = (char *) xmalloc (prev_filename_len);
        }
 
       strcpy (prev_filename, filename);
@@ -805,7 +841,7 @@ core_create_line_syms (void)
       if (!get_src_info (vma, &filename, &ltab.limit->name, &ltab.limit->line_num)
          || (prev && prev->line_num == ltab.limit->line_num
              && strcmp (prev->name, ltab.limit->name) == 0
-             && strcmp (prev->file->name, filename) == 0))
+             && filename_cmp (prev->file->name, filename) == 0))
        continue;
 
       /* Make name pointer a malloc'ed string.  */