[RFA/hpux] Implement file_matches_executable_p

Joel Brobecker brobecker@adacore.com
Thu Nov 17 01:14:00 GMT 2005


> 
> Yes; more generally (a) you can define the relevant method directly to
> the generic function, no need to wrap it, and (b) might as well call it
> from every currently stubbed out implementation of this function and
> get them all at once.

The attached patch should be better. The only part I wasn't sure about
is regarding the stubbed out implementations. How to I find them?

2005-11-16  Joel Brobecker  <brobecker@adacore.com>

        * corefile.c (generic_core_file_matches_executable_p): New function.
        * libbfd.h (generic_core_file_matches_executable_p): Add declaration.
        * hpux-core.c: ANSIfy function declarations and prototypes.
        (thread_section_p): Add comment.
        (hpux_core_core_file_matches_executable_p): Delete.
        (hpux_core_vec): Change the matches_executable_p method to
        use generic_core_file_matches_executable_p.

OK to apply?

Thanks,
-- 
Joel
-------------- next part --------------
Index: corefile.c
===================================================================
RCS file: /cvs/src/src/bfd/corefile.c,v
retrieving revision 1.10
diff -u -p -r1.10 corefile.c
--- corefile.c	5 Oct 2005 21:24:23 -0000	1.10
+++ corefile.c	17 Nov 2005 01:04:30 -0000
@@ -107,3 +107,32 @@ core_file_matches_executable_p (bfd *cor
   return BFD_SEND (core_bfd, _core_file_matches_executable_p,
 		   (core_bfd, exec_bfd));
 }
+
+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;
+
+  exec = bfd_get_filename (exec_bfd);
+  last_slash = strrchr (exec, '/');
+  if (last_slash != NULL)
+    exec = last_slash + 1;
+  
+  /* 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);
+  last_slash = strrchr (core, '/');
+  if (last_slash != NULL)
+    core = last_slash + 1;
+
+  return (strcmp(exec, core) == 0);
+}
+
Index: libbfd.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd.h,v
retrieving revision 1.164
diff -u -p -r1.164 libbfd.h
--- libbfd.h	8 Nov 2005 11:15:11 -0000	1.164
+++ libbfd.h	17 Nov 2005 01:04:55 -0000
@@ -252,6 +252,12 @@ extern int _bfd_nocore_core_file_failing
 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: hpux-core.c
===================================================================
RCS file: /cvs/src/src/bfd/hpux-core.c,v
retrieving revision 1.18
diff -u -p -r1.18 hpux-core.c
--- hpux-core.c	29 Oct 2005 23:00:12 -0000	1.18
+++ hpux-core.c	17 Nov 2005 01:04:54 -0000
@@ -102,28 +102,17 @@ struct hpux_core_struct
 #define core_kernel_thread_id(bfd) (core_hdr(bfd)->lwpid)
 #define core_user_thread_id(bfd) (core_hdr(bfd)->user_tid)
 
-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,6 +144,10 @@ thread_section_p (bfd *abfd ATTRIBUTE_UN
                   asection *sect,
                   void *obj ATTRIBUTE_UNUSED)
 {
+  /* The ATTRIBUTE_UNUSED for parameter ABFD is at first sight surprising,
+     since it appears to be used in the call to bfd_section_name.  However,
+     bfd_section_name is a macro that doesn't use the first parameter,
+     so the attribute above is perfectly justified.  */
   return (strncmp (bfd_section_name (abfd, sect), ".reg/", 5) == 0);
 }
 
@@ -168,8 +161,7 @@ thread_section_p (bfd *abfd ATTRIBUTE_UN
    (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 +353,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 */
-}
 
 /* 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 */
 }
@@ -433,7 +416,9 @@ const bfd_target hpux_core_vec =
 
     BFD_JUMP_TABLE_GENERIC (_bfd_generic),
     BFD_JUMP_TABLE_COPY (_bfd_generic),
-    BFD_JUMP_TABLE_CORE (hpux_core),
+    hpux_core_core_file_failing_command,
+    hpux_core_core_file_failing_signal,
+    generic_core_file_matches_executable_p,
     BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
     BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
     BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),


More information about the Binutils mailing list