From patchwork Thu Mar 5 00:42:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 38417 Received: (qmail 65248 invoked by alias); 5 Mar 2020 00:43:41 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 65197 invoked by uid 89); 5 Mar 2020 00:43:41 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-2.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (205.139.110.61) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 05 Mar 2020 00:43:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583369018; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GzTF4qvOBGeK0WKgkkWrUtNgdmfcec5x5FOe2T5oY/U=; b=VrEaJvf7YFzjltqY7iQCgnQsEdMKDXP7GPiVe9Xj9UU2UUgM2mpaXqNxU7yXIR1b4G/+mx eS59gyx1JdYaswZASIIn7HH9Tw0VYWPDts2FLRoAB6ax8bNBI3vYtQBlPG1oDbtKxbrTBJ n3x13V9YGZpXtK+mCCUZt15IO5IjxMI= 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-208-O99yQPkUNnOOoAvR40vUJA-1; Wed, 04 Mar 2020 19:43:34 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 25CCC185734D for ; Thu, 5 Mar 2020 00:43:34 +0000 (UTC) Received: from f31-1.lan (ovpn-116-156.phx2.redhat.com [10.3.116.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id E54AB272A1; Thu, 5 Mar 2020 00:43:32 +0000 (UTC) From: Kevin Buettner To: gdb-patches@sourceware.org Cc: Kevin Buettner Subject: [PATCH 1/4] Remove hack for GDB which sets the section size to 0 Date: Wed, 4 Mar 2020 17:42:40 -0700 Message-Id: <20200305004243.334607-2-kevinb@redhat.com> In-Reply-To: <20200305004243.334607-1-kevinb@redhat.com> References: <20200305004243.334607-1-kevinb@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-IsSubscribed: yes [Note: This patch will require approval from binutils maintainers. I'll send this patch to that list separately, but include it in this series for completeness.] This commit removes a hack for GDB which was introduced in 2007. See: https://sourceware.org/ml/binutils/2007-08/msg00044.html That hack mostly allowed GDB's handling of core files to continue to work without any changes to GDB. The problem with setting the section size to zero is that GDB won't know how big that section is/was. Often, this doesn't matter because the data in question are found in the exec file. But it can happen that the section describes memory that had been allocated, but never written to. In this instance, the contents of that memory region are not written to the core file. Also, since the region in question was dynamically allocated, it won't appear in the exec file. We don't want these regions to appear as inaccessible to GDB (since they *were* accessible when the process was live), so it's important that GDB know the size of the region. I've made changes to GDB which correctly handles this case. When attempting to access memory, GDB will first consider core file data for which both SEC_ALLOC and SEC_HAS_CONTENTS is set. Next, if that fails, GDB will attempt to find the data in the exec file. Finally, if that also fails, GDB will attempt to access memory in the sections which are flagged as SEC_ALLOC, but not SEC_HAS_CONTENTS. bfd/ChangeLog: * elf.c (_bfd_elf_make_section_from_phdr): Remove hack for GDB. Change-Id: I7cce707aa3c217addbc27589730a77620199843f --- bfd/elf.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/bfd/elf.c b/bfd/elf.c index c4d6718aaa..89c61acc40 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -3007,14 +3007,6 @@ _bfd_elf_make_section_from_phdr (bfd *abfd, newsect->alignment_power = bfd_log2 (align); if (hdr->p_type == PT_LOAD) { - /* Hack for gdb. Segments that have not been modified do - not have their contents written to a core file, on the - assumption that a debugger can find the contents in the - executable. We flag this case by setting the fake - section size to zero. Note that "real" bss sections will - always have their contents dumped to the core file. */ - if (bfd_get_format (abfd) == bfd_core) - newsect->size = 0; newsect->flags |= SEC_ALLOC; if (hdr->p_flags & PF_X) newsect->flags |= SEC_CODE;