[RFA/hpux] Implement file_matches_executable_p

Joel Brobecker brobecker@adacore.com
Sun Nov 13 18:33:00 GMT 2005


Hello,

The attached patch implements file_matches_executable_p for HP/UX.
The intent is to have GDB print a little warning when core file and
executable name do not match, as it already does on x86-linux.

While at it, I saw that the file could use a bit of ansification,
and a touch of cleanup, plus some comment addition.

        * hpux-core.c: ANSIfy function declarations and prototypes.
        (thread_section_p): Add comment.
        (hpux_core_core_file_matches_executable_p): Add full implementation.

Tested on pa-hpux using GDB. No warning before the modification, the
warning appears after.

OK to apply?

Thanks,
-- 
Joel
-------------- next part --------------
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	12 Nov 2005 01:59:25 -0000
@@ -102,28 +102,18 @@ 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 bfd_boolean hpux_core_core_file_matches_executable_p (bfd *, 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 +145,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 +162,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 +354,48 @@ 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;
+hpux_core_core_file_matches_executable_p (bfd *core_bfd, bfd *exec_bfd)
 {
-  return TRUE;			/* FIXME, We have no way of telling at this point */
+  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);
 }
 
 /* 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 */
 }


More information about the Binutils mailing list