[v12,14/32] Provide new gdb_bfd_open_from_target

Message ID 20150821212209.6673.966.stgit@host1.jankratochvil.net
State New, archived
Headers

Commit Message

Jan Kratochvil Aug. 21, 2015, 9:22 p.m. UTC
  Hi,

later code needs to call the gdb_bfd_openr_iovec part of gdb_bfd_open with more
special parameters.  So it is refactored out first (and extended later in the
next patches).

Jan


gdb/ChangeLog
2015-08-18  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb_bfd.c (gdb_bfd_open_from_target): New function from ...
	(gdb_bfd_open): ... here.  Call it.
	* gdb_bfd.h (gdb_bfd_open_from_target): New prototype.
---
 0 files changed
  

Patch

diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c
index 64712da..10031f8 100644
--- a/gdb/gdb_bfd.c
+++ b/gdb/gdb_bfd.c
@@ -353,6 +353,25 @@  gdb_bfd_iovec_fileio_fstat (struct bfd *abfd, void *stream,
   return result;
 }
 
+/* Open a read-only (FOPEN_RB) BFD using target fileio operations given
+   arguments like bfd_fopen.  Return value matches that of
+   gdb_bfd_openr_iovec.  */
+
+struct bfd *
+gdb_bfd_open_from_target (const char *name, const char *target, int fd)
+{
+  gdb_assert (is_target_filename (name));
+  gdb_assert (!target_filesystem_is_local ());
+  gdb_assert (fd == -1);
+
+  return gdb_bfd_openr_iovec (name, target,
+			      gdb_bfd_iovec_fileio_open,
+			      current_inferior (),
+			      gdb_bfd_iovec_fileio_pread,
+			      gdb_bfd_iovec_fileio_close,
+			      gdb_bfd_iovec_fileio_fstat);
+}
+
 /* See gdb_bfd.h.  */
 
 struct bfd *
@@ -367,16 +386,7 @@  gdb_bfd_open (const char *name, const char *target, int fd)
   if (is_target_filename (name))
     {
       if (!target_filesystem_is_local ())
-	{
-	  gdb_assert (fd == -1);
-
-	  return gdb_bfd_openr_iovec (name, target,
-				      gdb_bfd_iovec_fileio_open,
-				      current_inferior (),
-				      gdb_bfd_iovec_fileio_pread,
-				      gdb_bfd_iovec_fileio_close,
-				      gdb_bfd_iovec_fileio_fstat);
-	}
+	return gdb_bfd_open_from_target (name, target, fd);
 
       name += strlen (TARGET_SYSROOT_PREFIX);
     }
diff --git a/gdb/gdb_bfd.h b/gdb/gdb_bfd.h
index 8fbdf36..0e38d62 100644
--- a/gdb/gdb_bfd.h
+++ b/gdb/gdb_bfd.h
@@ -53,6 +53,9 @@  int gdb_bfd_has_target_filename (struct bfd *abfd);
 
 struct bfd *gdb_bfd_open (const char *name, const char *target, int fd);
 
+struct bfd *gdb_bfd_open_from_target (const char *name, const char *target,
+				      int fd);
+
 /* Increment the reference count of ABFD.  It is fine for ABFD to be
    NULL; in this case the function does nothing.  */