Blame SOURCES/gdb-rhbz1842691-corefile-mem-access-6of15.patch

7d6eda
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
7d6eda
From: Keith Seitz <keiths@redhat.com>
7d6eda
Date: Mon, 27 Jul 2020 17:32:50 -0400
7d6eda
Subject: gdb-rhbz1842691-corefile-mem-access-6of15.patch
7d6eda
7d6eda
;; Update binary_get_section_contents to seek using section's file position
7d6eda
;; Kevin Buettner, RH BZ 1842961
7d6eda
7d6eda
   Author: Kevin Buettner <kevinb@redhat.com>
7d6eda
   Date:   Thu Jun 11 18:58:49 2020 -0700
7d6eda
7d6eda
    Update binary_get_section_contents to seek using section's file position
7d6eda
7d6eda
    I have a patch for GDB which opens and reads from BFDs using the
7d6eda
    "binary" target.  However, for it to work, we need to be able to get a
7d6eda
    section's contents based from the file position of that section.
7d6eda
7d6eda
    At the moment, reading a section's contents will always read from the
7d6eda
    start of the file regardless of where that section is located.  While
7d6eda
    this was fine for the original use of the "binary" target, it won't
7d6eda
    work for my use case.  This change shouldn't impact any existing
7d6eda
    callers due to the fact that the single .data section is initialized
7d6eda
    with a filepos of 0.
7d6eda
7d6eda
    bfd/ChangeLog:
7d6eda
7d6eda
    	* binary.c (binary_get_section_contents): Seek using offset
7d6eda
    	from section's file position.
7d6eda
7d6eda
diff --git a/bfd/binary.c b/bfd/binary.c
7d6eda
--- a/bfd/binary.c
7d6eda
+++ b/bfd/binary.c
7d6eda
@@ -19,10 +19,10 @@
7d6eda
    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
7d6eda
    MA 02110-1301, USA.  */
7d6eda
 
7d6eda
-/* This is a BFD backend which may be used to write binary objects.
7d6eda
-   It may only be used for output, not input.  The intention is that
7d6eda
-   this may be used as an output format for objcopy in order to
7d6eda
-   generate raw binary data.
7d6eda
+/* This is a BFD backend which may be used to read or write binary
7d6eda
+   objects.  Historically, it was used as an output format for objcopy
7d6eda
+   in order to generate raw binary data, but is now used for other
7d6eda
+   purposes as well.
7d6eda
 
7d6eda
    This is very simple.  The only complication is that the real data
7d6eda
    will start at some address X, and in some cases we will not want to
7d6eda
@@ -97,12 +97,12 @@ binary_object_p (bfd *abfd)
7d6eda
 
7d6eda
 static bfd_boolean
7d6eda
 binary_get_section_contents (bfd *abfd,
7d6eda
-			     asection *section ATTRIBUTE_UNUSED,
7d6eda
+			     asection *section,
7d6eda
 			     void * location,
7d6eda
 			     file_ptr offset,
7d6eda
 			     bfd_size_type count)
7d6eda
 {
7d6eda
-  if (bfd_seek (abfd, offset, SEEK_SET) != 0
7d6eda
+  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0
7d6eda
       || bfd_bread (location, count, abfd) != count)
7d6eda
     return FALSE;
7d6eda
   return TRUE;