[RFA/hpux] Implement file_matches_executable_p
Joel Brobecker
brobecker@adacore.com
Fri Nov 18 00:47:00 GMT 2005
> Very simple: you grep for file_matches_executable_p :-) If anyone
> didn't give theirs the obvious name, well, too bad for them.
Oh no :-). This is the answer I didn't want to hear. Is this OK if
I do this in a separate patch? I'm working on it right now, but
this breaks down a bit the size of the overall change.
> You can just do this instead:
> #define hpux_core_file_matches_executable_p generic_core_file_matches_executable_p
Clever. Implemented as suggested.
One bad point for me, I knew that libbfd.h was generated. For some
reason I forgot to include libbfd-in.h in the patch.
I also implemented AlanM's suggestion of losing a macro and expanding
it manually.
2005-11-17 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.
Now, on to the other maches_executable_p function bodies...
--
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 18 Nov 2005 00:33:36 -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-in.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd-in.h,v
retrieving revision 1.59
diff -u -p -r1.59 libbfd-in.h
--- libbfd-in.h 3 Nov 2005 16:06:11 -0000 1.59
+++ libbfd-in.h 18 Nov 2005 00:34:00 -0000
@@ -247,6 +247,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: 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 18 Nov 2005 00:34:00 -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 18 Nov 2005 00:33:59 -0000
@@ -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_UN
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_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 +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 */
-}
/* 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