From patchwork Thu Mar 5 00:42:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 38416 Received: (qmail 65008 invoked by alias); 5 Mar 2020 00:43:40 -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 64961 invoked by uid 89); 5 Mar 2020 00:43:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=pushes X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (205.139.110.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 05 Mar 2020 00:43:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583369016; 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=8Di/f9d7+Jf/om7OEsvR/pc8bT6wzD6kvzvFhLz11Uo=; b=Q3qUL5YmwPoRhQUDBtxz21eMRGtp8SB0f3k47ZM5lfys38qlgSZjwYww5KbW1QqM1d11y6 gLXoBjeg7XhB6wRU6WJtYb15kotRu1o5PtyeoKuTz1rQNkOkumPke8kVR5tGGV/QlmJJEA nk/Zv2zldeayn7qODiAZQUYEIFSlcDM= 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-152-lReWsiJyPkKTSTYQQgt1lw-1; Wed, 04 Mar 2020 19:43:35 -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 6D8578014CA 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 37833272A1; Thu, 5 Mar 2020 00:43:34 +0000 (UTC) From: Kevin Buettner To: gdb-patches@sourceware.org Cc: Kevin Buettner Subject: [PATCH 2/4] Add function for partitioning/splitting a section table Date: Wed, 4 Mar 2020 17:42:41 -0700 Message-Id: <20200305004243.334607-3-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 gdb/ChangeLog: * exec.h, exec.c (split_section_table): New function. Change-Id: I8909174aed892727bdd6d704cfe43763ee8969c3 --- gdb/exec.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ gdb/exec.h | 13 +++++++++++++ 2 files changed, 68 insertions(+) diff --git a/gdb/exec.c b/gdb/exec.c index 68bca1be17..e8cd471f5f 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -604,6 +604,61 @@ resize_section_table (struct target_section_table *table, int adjustment) return old_count; } +/* See exec.h. */ + +void +split_section_table (struct target_section_table *orig, + struct target_section_table *splits, + bool (*criterion) (struct target_section *)) +{ + int count = 0; + + for (struct target_section *sect = orig->sections; + sect < orig->sections_end; + sect++) + { + if (criterion (sect)) + count++; + } + + /* Handle the case of an empty SPLITS table. */ + if (count == 0) + { + splits->sections = nullptr; + splits->sections_end = nullptr; + return; + } + + /* Handle case of an empty ORIG table. */ + if (count == orig->sections_end - orig->sections) + { + splits = orig; + orig->sections = nullptr; + orig->sections_end = nullptr; + return; + } + + /* Okay, we actually have something to do. Allocate a new table for + SPLITS. We'll resize ORIG after copying. */ + + splits->sections = XNEWVEC (struct target_section, count); + splits->sections_end = splits->sections + count; + + for (struct target_section *sect = orig->sections, + *osect = sect, + *ssect = splits->sections; + sect < orig->sections_end; + sect++) + { + if (criterion (sect)) + *ssect++ = *sect; + else + *osect++ = *sect; + } + + resize_section_table (orig, -count); +} + /* Builds a section table, given args BFD, SECTABLE_PTR, SECEND_PTR. Returns 0 if OK, 1 on error. */ diff --git a/gdb/exec.h b/gdb/exec.h index 54e6ff4d9b..fc45e11898 100644 --- a/gdb/exec.h +++ b/gdb/exec.h @@ -44,6 +44,19 @@ extern int build_section_table (struct bfd *, struct target_section **, extern void clear_section_table (struct target_section_table *table); +/* Split a target section table ORIG into two parts. Sections meeting + CRITERION will be placed into SPLITS. The original table ORIG will + be adjusted and resized as necessary, removing those sections which + were placed into SPLITS. If no sections in ORIG satisfy CRITERION, + sections and sections_end in SPLITS will be set to nullptr, + representing an empty table. Likewise, if all sections in ORIG + satisfy CRITERION, ORIG will be set to an empty table and SPLITS + end up with all of the sections originally in ORIG. */ + +extern void split_section_table (struct target_section_table *orig, + struct target_section_table *splits, + bool (*criterion) (struct target_section *)); + /* The current inferior is a child vforked and its program space is shared with its parent. This pushes the exec target on the current/child inferior's target stack if there are sections in the