* 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 075895e330c447f8d4ac8cf4fe15e44bb9db9849..a7efbca08be9f2eaac8ad955bec4e8b6ed6e3e17 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 3f0a27dccd48c2dd14922c6b8a71922026dcddd0..17a0290e3544a420d78a3797ac48dfe041ade66b 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 6b588ba3e6146a2e0c401267d8a3b3af5083b713..ff58bf38def0762185067168698b233f3a93f558 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 56129e9664ff5f074955692f6203e607414e9804..b7f735b59deeab674988b83e82b84fb4d6aacffd 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 adc5b4ac88ee859bc66b3195773ea974a88070b3..aaf888bcec479e9b0e4db3f5ec9a2e70cf00b9ce 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 894d244bbc3cd4e71783d8fc4d9b8e23086d9eaa..67627e7a66648ac46c26bfb0427ee53c30ff7542 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 9a97531eb93433c9a4f3d82062155ad925d41828..08adcd3a1e6d24df37d51d29e19b940c6057b171 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 954d553cbe270d8e96361a7556a7995375cdaea9..e6331454c4459a6eef8eaf92c7741fcfbc3d422c 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 e3468c1a9950cf391a13f0b32bef59cda76177f7..c838d9021a4300305239adb6a08bc92ade58ebc5 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 5a8c2167b003f9594eac3ee32f345b3f13363117..48a8b9b51b1f8fa68c5815778b1563bc94edb643 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 470cb506467c13045a014003f84dfc8e2905f466..ef243fbef19547176db4c4dcedbea1efe4e53b13 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 6991612f07cffee1edb7fad041b201daca526418..03a714495bb398bf482c43415cec200967137f30 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 948423d2b5def128393b049b66655ef6512a17f2..e9111a98501041923014c8d30a43881e3374e837 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 35aa82df43ee1b889e12339896bf0e0315615468..cc6c4dccd00298df11fc6bc391c23cad9a5c3207 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 4ddd54ca8c11e6ed5a82b2abde6f2a138f2e1bb1..4ac28aa1dece59ff7f0a2632d6902f71b3211b78 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 d10dbfa9d3da8e743fcfb5c8e67da9467de53482..9a06b8839f54464bf7a90d51a05bc03c3fe718a6 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 2f8c9f9ca5f80d8954a1df8e908331404b8492f9..cb4111fb9418c59e1d5024d19c82a7fef7d8ad5f 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