From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by sourceware.org (Postfix) with ESMTP id DEC973857026 for ; Sun, 5 Jul 2020 22:59:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DEC973857026 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-481-UAzbHmVKNxqhiP6fteLlcg-1; Sun, 05 Jul 2020 18:59:10 -0400 X-MC-Unique: UAzbHmVKNxqhiP6fteLlcg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D150310059AA for ; Sun, 5 Jul 2020 22:59:09 +0000 (UTC) Received: from f32-1.lan (ovpn-112-21.phx2.redhat.com [10.3.112.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id A011660BEC; Sun, 5 Jul 2020 22:59:09 +0000 (UTC) From: Kevin Buettner To: gdb-patches@sourceware.org Subject: [PATCH v4 06/14] Update binary_get_section_contents to seek using section's file position Date: Sun, 5 Jul 2020 15:57:59 -0700 Message-Id: <20200705225807.2264705-7-kevinb@redhat.com> In-Reply-To: <20200705225807.2264705-1-kevinb@redhat.com> References: <20200705225807.2264705-1-kevinb@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Jul 2020 22:59:14 -0000 I have a patch for GDB which opens and reads from BFDs using the "binary" target. However, for it to work, we need to be able to get a section's contents based from the file position of that section. At the moment, reading a section's contents will always read from the start of the file regardless of where that section is located. While this was fine for the original use of the "binary" target, it won't work for my use case. This change shouldn't impact any existing callers due to the fact that the single .data section is initialized with a filepos of 0. bfd/ChangeLog: * binary.c (binary_get_section_contents): Seek using offset from section's file position. --- bfd/binary.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bfd/binary.c b/bfd/binary.c index 999de0d8c4..e872924a2d 100644 --- a/bfd/binary.c +++ b/bfd/binary.c @@ -19,10 +19,10 @@ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -/* This is a BFD backend which may be used to write binary objects. - It may only be used for output, not input. The intention is that - this may be used as an output format for objcopy in order to - generate raw binary data. +/* This is a BFD backend which may be used to read or write binary + objects. Historically, it was used as an output format for objcopy + in order to generate raw binary data, but is now used for other + purposes as well. This is very simple. The only complication is that the real data will start at some address X, and in some cases we will not want to @@ -97,12 +97,12 @@ binary_object_p (bfd *abfd) static bfd_boolean binary_get_section_contents (bfd *abfd, - asection *section ATTRIBUTE_UNUSED, + asection *section, void * location, file_ptr offset, bfd_size_type count) { - if (bfd_seek (abfd, offset, SEEK_SET) != 0 + if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0 || bfd_bread (location, count, abfd) != count) return FALSE; return TRUE; -- 2.26.2