* corefile.c (generic_core_file_matches_executable_p): New function.
authorJoel Brobecker <brobecker@gnat.com>
Fri, 23 Dec 2005 10:19:40 +0000 (10:19 +0000)
committerJoel Brobecker <brobecker@gnat.com>
Fri, 23 Dec 2005 10:19:40 +0000 (10:19 +0000)
        * libbfd-in.h (generic_core_file_matches_executable_p): Add
        declaration.
        * libbfd.h: Regenerate.
        * hpux-core.c: ANSIfy function declarations and prototypes.
        (thread_section_p): Manually expand bfd_section_name macro
        to make it clear that parameter ABFD is not used.
        (hpux_core_core_file_matches_executable_p): Delete, replaced
        by macro pointing to generic_core_file_matches_executable_p.

        * aix386-core.c: Replace core_file_matches_executable_p null
        implementation by generic_core_file_matches_executable_p by
        using a macro.
        * aix5ppc-core.c: Likewise.
        * cisco-core.c: Likewise.
        * hppabsd-core.c: Likewise.
        * irix-core.c: Likewise.
        * lynx-core.c: Likewise.
        * mach-o.c: Likewise.
        * netbsd-core.c: Likewise.
        * osf-core.c: Likewise.
        * ptrace-core.c: Likewise.
        * sco5-core.c: Likewise.
        * trad-core.c: Likewise.

17 files changed:
bfd/ChangeLog
bfd/aix386-core.c
bfd/aix5ppc-core.c
bfd/cisco-core.c
bfd/corefile.c
bfd/hppabsd-core.c
bfd/hpux-core.c
bfd/irix-core.c
bfd/libbfd-in.h
bfd/libbfd.h
bfd/lynx-core.c
bfd/mach-o.c
bfd/netbsd-core.c
bfd/osf-core.c
bfd/ptrace-core.c
bfd/sco5-core.c
bfd/trad-core.c

index 075895e..a7efbca 100644 (file)
@@ -1,3 +1,30 @@
+2005-12-23  Joel Brobecker  <brobecker@adacore.com>
+
+       * corefile.c (generic_core_file_matches_executable_p): New function.
+       * libbfd-in.h (generic_core_file_matches_executable_p): Add
+       declaration.
+       * libbfd.h: Regenerate.
+       * hpux-core.c: ANSIfy function declarations and prototypes.
+       (thread_section_p): Manually expand bfd_section_name macro
+       to make it clear that parameter ABFD is not used.
+       (hpux_core_core_file_matches_executable_p): Delete, replaced
+       by macro pointing to generic_core_file_matches_executable_p.
+       
+       * aix386-core.c: Replace core_file_matches_executable_p null
+       implementation by generic_core_file_matches_executable_p by
+       using a macro.
+       * aix5ppc-core.c: Likewise.
+       * cisco-core.c: Likewise.
+       * hppabsd-core.c: Likewise.
+       * irix-core.c: Likewise.
+       * lynx-core.c: Likewise.
+       * mach-o.c: Likewise.
+       * netbsd-core.c: Likewise.
+       * osf-core.c: Likewise.
+       * ptrace-core.c: Likewise.
+       * sco5-core.c: Likewise.
+       * trad-core.c: Likewise.
+
 2005-12-19  David Heine  <dlheine@tensilica.com>
 
        * elf32-xtensa.c (action_list_count, xlate_map_entry, xlate_map,
index 3f0a27d..17a0290 100644 (file)
@@ -204,14 +204,7 @@ aix386_core_file_failing_signal (abfd)
   return core_hdr (abfd)->cd_cursig;
 }
 
-static bfd_boolean
-aix386_core_file_matches_executable_p (core_bfd, exec_bfd)
-     bfd *core_bfd;
-     bfd *exec_bfd;
-{
-  /* FIXME: We have no way of telling at this point.  */
-  return TRUE;
-}
+#define aix386_core_file_matches_executable_p generic_core_file_matches_executable_p
 
 /* If somebody calls any byte-swapping routines, shoot them.  */
 
index 6b588ba..ff58bf3 100644 (file)
@@ -319,7 +319,7 @@ xcoff64_core_file_failing_signal (bfd *abfd)
 #else /* AIX_5_CORE */
 
 const bfd_target *xcoff64_core_p  (bfd *);
-bfd_boolean xcoff64_core_file_matches_executable_p (bfd *, bfd *);
+#define xcoff64_core_file_matches_executable_p generic_core_file_matches_executable_p
 char *xcoff64_core_file_failing_command (bfd *);
 int xcoff64_core_file_failing_signal (bfd *);
 
@@ -330,13 +330,6 @@ xcoff64_core_p (bfd *abfd ATTRIBUTE_UNUSED)
   return 0;
 }
 
-bfd_boolean
-xcoff64_core_file_matches_executable_p (bfd *core_bfd ATTRIBUTE_UNUSED,
-                                       bfd *exec_bfd ATTRIBUTE_UNUSED)
-{
-  return FALSE;
-}
-
 char *
 xcoff64_core_file_failing_command (bfd *abfd ATTRIBUTE_UNUSED)
 {
index 56129e9..b7f735b 100644 (file)
@@ -75,7 +75,7 @@ static const bfd_target *cisco_core_file_validate PARAMS ((bfd *, int));
 static const bfd_target *cisco_core_file_p PARAMS ((bfd *));
 char *cisco_core_file_failing_command PARAMS ((bfd *));
 int cisco_core_file_failing_signal PARAMS ((bfd *));
-bfd_boolean cisco_core_file_matches_executable_p PARAMS ((bfd *, bfd *));
+#define cisco_core_file_matches_executable_p generic_core_file_matches_executable_p
 \f
 /* Examine the file for a crash info struct at the offset given by
    CRASH_INFO_LOC.  */
@@ -317,14 +317,6 @@ cisco_core_file_failing_signal (abfd)
 {
   return abfd->tdata.cisco_core_data->sig;
 }
-
-bfd_boolean
-cisco_core_file_matches_executable_p (core_bfd, exec_bfd)
-     bfd *core_bfd ATTRIBUTE_UNUSED;
-     bfd *exec_bfd ATTRIBUTE_UNUSED;
-{
-  return TRUE;
-}
 \f
 extern const bfd_target cisco_core_little_vec;
 
index adc5b4a..aaf888b 100644 (file)
@@ -107,3 +107,59 @@ core_file_matches_executable_p (bfd *core_bfd, bfd *exec_bfd)
   return BFD_SEND (core_bfd, _core_file_matches_executable_p,
                   (core_bfd, exec_bfd));
 }
+
+/*
+FUNCTION
+        generic_core_file_matches_executable_p
+
+SYNOPSIS
+        bfd_boolean generic_core_file_matches_executable_p
+          (bfd *core_bfd, bfd *exec_bfd)
+
+DESCRIPTION
+        Return TRUE if the core file attached to @var{core_bfd}
+        was generated by a run of the executable file attached
+        to @var{exec_bfd}.  The match is based on executable
+        basenames only.
+
+        Note: When not able to determine the core file failing
+        command or the executable name, we still return TRUE even
+        though we're not sure that core file and executable match.
+        This is to avoid generating a false warning in situations
+        where we really don't know whether they match or not.
+*/
+
+bfd_boolean
+generic_core_file_matches_executable_p (bfd *core_bfd, bfd *exec_bfd)
+{
+  char *exec;
+  char *core;
+  char *last_slash;
+
+  if (exec_bfd == NULL || core_bfd == NULL)
+    return TRUE;
+
+  /* The cast below is to avoid a compiler warning due to the assignment
+     of the const char * returned by bfd_core_file_failing_command to a
+     non-const char *.  In this case, the assignement does not lead to
+     breaking the const, as we're only reading the string.  */
+     
+  core = (char *) bfd_core_file_failing_command (core_bfd);
+  if (core == NULL)
+    return TRUE;
+
+  exec = bfd_get_filename (exec_bfd);
+  if (exec == NULL)
+    return TRUE;
+
+  last_slash = strrchr (core, '/');
+  if (last_slash != NULL)
+    core = last_slash + 1;
+
+  last_slash = strrchr (exec, '/');
+  if (last_slash != NULL)
+    exec = last_slash + 1;
+  
+  return strcmp (exec, core) == 0;
+}
+
index 894d244..67627e7 100644 (file)
@@ -57,8 +57,7 @@ static char *hppabsd_core_core_file_failing_command
   PARAMS ((bfd *));
 static int hppabsd_core_core_file_failing_signal
   PARAMS ((bfd *));
-static bfd_boolean hppabsd_core_core_file_matches_executable_p
-  PARAMS ((bfd *, bfd *));
+#define hppabsd_core_core_file_matches_executable_p generic_core_file_matches_executable_p
 static void swap_abort
   PARAMS ((void));
 
@@ -217,14 +216,6 @@ hppabsd_core_core_file_failing_signal (abfd)
 {
   return core_signal (abfd);
 }
-
-static bfd_boolean
-hppabsd_core_core_file_matches_executable_p (core_bfd, exec_bfd)
-     bfd *core_bfd, *exec_bfd;
-{
-  /* There's no way to know this...  */
-  return TRUE;
-}
 \f
 /* If somebody calls any byte-swapping routines, shoot them.  */
 static void
index 9a97531..08adcd3 100644 (file)
@@ -101,29 +101,19 @@ struct hpux_core_struct
 #define core_command(bfd) (core_hdr(bfd)->cmd)
 #define core_kernel_thread_id(bfd) (core_hdr(bfd)->lwpid)
 #define core_user_thread_id(bfd) (core_hdr(bfd)->user_tid)
+#define hpux_core_core_file_matches_executable_p generic_core_file_matches_executable_p
 
-static asection *make_bfd_asection
-  PARAMS ((bfd *, const char *, flagword, bfd_size_type, bfd_vma,
-          unsigned int));
-static const bfd_target *hpux_core_core_file_p
-  PARAMS ((bfd *));
-static char *hpux_core_core_file_failing_command
-  PARAMS ((bfd *));
-static int hpux_core_core_file_failing_signal
-  PARAMS ((bfd *));
-static bfd_boolean hpux_core_core_file_matches_executable_p
-  PARAMS ((bfd *, bfd *));
-static void swap_abort
-  PARAMS ((void));
+static asection *make_bfd_asection (bfd *, const char *, flagword,
+                                    bfd_size_type, bfd_vma, unsigned int);
+static const bfd_target *hpux_core_core_file_p (bfd *);
+static char *hpux_core_core_file_failing_command (bfd *);
+static int hpux_core_core_file_failing_signal (bfd *);
+static void swap_abort (void);
 
 static asection *
-make_bfd_asection (abfd, name, flags, size, vma, alignment_power)
-     bfd *abfd;
-     const char *name;
-     flagword flags;
-     bfd_size_type size;
-     bfd_vma vma;
-     unsigned int alignment_power;
+make_bfd_asection (bfd *abfd, const char *name, flagword flags,
+                   bfd_size_type size, bfd_vma vma,
+                   unsigned int alignment_power)
 {
   asection *asect;
   char *newname;
@@ -155,7 +145,7 @@ thread_section_p (bfd *abfd ATTRIBUTE_UNUSED,
                   asection *sect,
                   void *obj ATTRIBUTE_UNUSED)
 {
-  return (strncmp (bfd_section_name (abfd, sect), ".reg/", 5) == 0);
+  return (strncmp (sect->name, ".reg/", 5) == 0);
 }
 
 /* this function builds a bfd target if the file is a corefile.
@@ -168,8 +158,7 @@ thread_section_p (bfd *abfd ATTRIBUTE_UNUSED,
    (I am just guessing here!)
 */
 static const bfd_target *
-hpux_core_core_file_p (abfd)
-     bfd *abfd;
+hpux_core_core_file_p (bfd *abfd)
 {
   int  good_sections = 0;
   int  unknown_sections = 0;
@@ -361,30 +350,21 @@ hpux_core_core_file_p (abfd)
 }
 
 static char *
-hpux_core_core_file_failing_command (abfd)
-     bfd *abfd;
+hpux_core_core_file_failing_command (bfd *abfd)
 {
   return core_command (abfd);
 }
 
 static int
-hpux_core_core_file_failing_signal (abfd)
-     bfd *abfd;
+hpux_core_core_file_failing_signal (bfd *abfd)
 {
   return core_signal (abfd);
 }
 
-static bfd_boolean
-hpux_core_core_file_matches_executable_p (core_bfd, exec_bfd)
-     bfd *core_bfd ATTRIBUTE_UNUSED;
-     bfd *exec_bfd ATTRIBUTE_UNUSED;
-{
-  return TRUE;                 /* FIXME, We have no way of telling at this point */
-}
 \f
 /* If somebody calls any byte-swapping routines, shoot them.  */
 static void
-swap_abort ()
+swap_abort (void)
 {
   abort(); /* This way doesn't require any declaration for ANSI to fuck up */
 }
index 954d553..e633145 100644 (file)
@@ -41,6 +41,8 @@ struct sgi_core_struct
 #define core_signal(bfd) (core_hdr(bfd)->sig)
 #define core_command(bfd) (core_hdr(bfd)->cmd)
 
+#define irix_core_core_file_matches_executable_p generic_core_file_matches_executable_p
+
 static asection *make_bfd_asection
   (bfd *, const char *, flagword, bfd_size_type, bfd_vma, file_ptr);
 
@@ -262,13 +264,6 @@ irix_core_core_file_failing_signal (bfd *abfd)
   return core_signal (abfd);
 }
 
-static bfd_boolean
-irix_core_core_file_matches_executable_p (bfd *core_bfd ATTRIBUTE_UNUSED,
-                                          bfd *exec_bfd ATTRIBUTE_UNUSED)
-{
-  return TRUE;                 /* XXX - FIXME */
-}
-
 /* If somebody calls any byte-swapping routines, shoot them.  */
 static void
 swap_abort(void)
index e3468c1..c838d90 100644 (file)
@@ -247,6 +247,12 @@ extern int _bfd_nocore_core_file_failing_signal
 extern bfd_boolean _bfd_nocore_core_file_matches_executable_p
   (bfd *, bfd *);
 
+/* A generic implementation of CORE_FILE_MATCHES_EXECUTABLE_P that
+   is independent of the target.  */
+
+extern bfd_boolean generic_core_file_matches_executable_p
+  (bfd *core_bfd, bfd *exec_bfd);
+
 /* Routines to use for BFD_JUMP_TABLE_ARCHIVE when there is no archive
    file support.  Use BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive).  */
 
index 5a8c216..48a8b9b 100644 (file)
@@ -252,6 +252,12 @@ extern int _bfd_nocore_core_file_failing_signal
 extern bfd_boolean _bfd_nocore_core_file_matches_executable_p
   (bfd *, bfd *);
 
+/* A generic implementation of CORE_FILE_MATCHES_EXECUTABLE_P that
+   is independent of the target.  */
+
+extern bfd_boolean generic_core_file_matches_executable_p
+  (bfd *core_bfd, bfd *exec_bfd);
+
 /* Routines to use for BFD_JUMP_TABLE_ARCHIVE when there is no archive
    file support.  Use BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive).  */
 
index 470cb50..ef243fb 100644 (file)
@@ -51,6 +51,8 @@ struct lynx_core_struct
 #define core_signal(bfd) (core_hdr(bfd)->sig)
 #define core_command(bfd) (core_hdr(bfd)->cmd)
 
+#define lynx_core_file_matches_executable_p generic_core_file_matches_executable_p
+
 /* Handle Lynx core dump file.  */
 
 static asection *
@@ -225,11 +227,4 @@ lynx_core_file_failing_signal (abfd)
   return core_signal (abfd);
 }
 
-bfd_boolean
-lynx_core_file_matches_executable_p  (core_bfd, exec_bfd)
-     bfd *core_bfd, *exec_bfd;
-{
-  return TRUE;         /* FIXME, We have no way of telling at this point */
-}
-
 #endif /* LYNX_CORE */
index 6991612..03a7144 100644 (file)
@@ -75,6 +75,7 @@
 #define bfd_mach_o_bfd_discard_group                  bfd_generic_discard_group
 #define bfd_mach_o_section_already_linked             _bfd_generic_section_already_linked
 #define bfd_mach_o_bfd_copy_private_header_data       _bfd_generic_bfd_copy_private_header_data
+#define bfd_mach_o_core_file_matches_executable_p     generic_core_file_matches_executable_p
 
 
 /* The flags field of a section structure is separated into two parts a section
@@ -1993,13 +1994,6 @@ bfd_mach_o_core_file_failing_signal (bfd *abfd ATTRIBUTE_UNUSED)
   return 0;
 }
 
-bfd_boolean
-bfd_mach_o_core_file_matches_executable_p (bfd *core_bfd ATTRIBUTE_UNUSED,
-                                          bfd *exec_bfd ATTRIBUTE_UNUSED)
-{
-  return TRUE;
-}
-
 #define TARGET_NAME            mach_o_be_vec
 #define TARGET_STRING          "mach-o-be"
 #define TARGET_BIG_ENDIAN      1
index 948423d..e9111a9 100644 (file)
@@ -42,6 +42,8 @@
    OpenBSD/sparc64.  */
 #define SPARC64_WCOOKIE_OFFSET 832
 
+#define netbsd_core_file_matches_executable_p generic_core_file_matches_executable_p
+
 struct netbsd_core_struct
 {
   struct core core;
@@ -246,14 +248,6 @@ netbsd_core_file_failing_signal (bfd *abfd)
   /*return core_signal (abfd);*/
   return abfd->tdata.netbsd_core_data->core.c_signo;
 }
-
-static bfd_boolean
-netbsd_core_file_matches_executable_p  (bfd *core_bfd ATTRIBUTE_UNUSED,
-                                       bfd *exec_bfd ATTRIBUTE_UNUSED)
-{
-  /* FIXME, We have no way of telling at this point.  */
-  return TRUE;
-}
 \f
 /* If somebody calls any byte-swapping routines, shoot them.  */
 
index 35aa82d..cc6c4dc 100644 (file)
@@ -40,8 +40,7 @@ static char *osf_core_core_file_failing_command
   PARAMS ((bfd *));
 static int osf_core_core_file_failing_signal
   PARAMS ((bfd *));
-static bfd_boolean osf_core_core_file_matches_executable_p
-  PARAMS ((bfd *, bfd *));
+#define osf_core_core_file_matches_executable_p generic_core_file_matches_executable_p
 static void swap_abort
   PARAMS ((void));
 
@@ -172,14 +171,6 @@ osf_core_core_file_failing_signal (abfd)
 {
   return core_signal (abfd);
 }
-
-static bfd_boolean
-osf_core_core_file_matches_executable_p (core_bfd, exec_bfd)
-     bfd *core_bfd ATTRIBUTE_UNUSED;
-     bfd *exec_bfd ATTRIBUTE_UNUSED;
-{
-  return TRUE;         /* FIXME, We have no way of telling at this point */
-}
 \f
 /* If somebody calls any byte-swapping routines, shoot them.  */
 static void
index 4ddd54c..4ac28aa 100644 (file)
@@ -51,8 +51,7 @@ struct trad_core_struct
 const bfd_target *ptrace_unix_core_file_p PARAMS ((bfd *abfd));
 char * ptrace_unix_core_file_failing_command PARAMS ((bfd *abfd));
 int ptrace_unix_core_file_failing_signal PARAMS ((bfd *abfd));
-bfd_boolean ptrace_unix_core_file_matches_executable_p
-  PARAMS ((bfd *core_bfd, bfd *exec_bfd));
+#define ptrace_unix_core_file_matches_executable_p generic_core_file_matches_executable_p
 static void swap_abort PARAMS ((void));
 
 const bfd_target *
@@ -151,15 +150,6 @@ ptrace_unix_core_file_failing_signal (abfd)
 {
   return abfd->tdata.trad_core_data->u.pt_sigframe.sig_num;
 }
-
-bfd_boolean
-ptrace_unix_core_file_matches_executable_p  (core_bfd, exec_bfd)
-     bfd *core_bfd, *exec_bfd;
-{
-  /* FIXME: Use pt_timdat field of the ptrace_user structure to match
-     the date of the executable */
-  return TRUE;
-}
 \f
 /* If somebody calls any byte-swapping routines, shoot them.  */
 static void
index d10dbfa..9a06b88 100644 (file)
@@ -49,8 +49,7 @@ static struct user *read_uarea PARAMS ((bfd *, int));
 const bfd_target *sco5_core_file_p PARAMS ((bfd *abfd));
 char *sco5_core_file_failing_command PARAMS ((bfd *abfd));
 int sco5_core_file_failing_signal PARAMS ((bfd *abfd));
-bfd_boolean sco5_core_file_matches_executable_p
-  PARAMS ((bfd *core_bfd, bfd *exec_bfd));
+#define sco5_core_file_matches_executable_p generic_core_file_matches_executable_p
 static void swap_abort PARAMS ((void));
 
 static asection *
@@ -345,14 +344,6 @@ sco5_core_file_failing_signal (ignore_abfd)
          : -1);
 }
 
-bfd_boolean
-sco5_core_file_matches_executable_p  (core_bfd, exec_bfd)
-     bfd *core_bfd ATTRIBUTE_UNUSED;
-     bfd *exec_bfd ATTRIBUTE_UNUSED;
-{
-  return TRUE;         /* FIXME, We have no way of telling at this point */
-}
-
 /* If somebody calls any byte-swapping routines, shoot them.  */
 static void
 swap_abort ()
index 2f8c9f9..cb4111f 100644 (file)
@@ -65,8 +65,7 @@ struct trad_core_struct
 const bfd_target *trad_unix_core_file_p PARAMS ((bfd *abfd));
 char * trad_unix_core_file_failing_command PARAMS ((bfd *abfd));
 int trad_unix_core_file_failing_signal PARAMS ((bfd *abfd));
-bfd_boolean trad_unix_core_file_matches_executable_p
-  PARAMS ((bfd *core_bfd, bfd *exec_bfd));
+#define trad_unix_core_file_matches_executable_p generic_core_file_matches_executable_p
 static void swap_abort PARAMS ((void));
 
 /* Handle 4.2-style (and perhaps also sysV-style) core dump file.  */
@@ -253,14 +252,6 @@ trad_unix_core_file_failing_signal (ignore_abfd)
   return -1;           /* FIXME, where is it? */
 #endif
 }
-
-bfd_boolean
-trad_unix_core_file_matches_executable_p  (core_bfd, exec_bfd)
-     bfd *core_bfd ATTRIBUTE_UNUSED;
-     bfd *exec_bfd ATTRIBUTE_UNUSED;
-{
-  return TRUE;         /* FIXME, We have no way of telling at this point */
-}
 \f
 /* If somebody calls any byte-swapping routines, shoot them.  */
 static void