From patchwork Mon Apr 8 21:11:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 88204 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 44E16384646C for ; Mon, 8 Apr 2024 21:12:57 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta034.useast.a.cloudfilter.net (omta034.useast.a.cloudfilter.net [44.202.169.33]) by sourceware.org (Postfix) with ESMTPS id DC84A3858408 for ; Mon, 8 Apr 2024 21:11:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DC84A3858408 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DC84A3858408 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712610704; cv=none; b=iChmrkBRIwcrdtT5ALO5aSyYjUflalGJUW7SkoEtj0YnCqhyUdLlY5DCaaL67FrCa/XUTtNiC4JMwz+qHoJKPUXdXw89kqdrPYe6DjvlrPP9lPS8vU7Gqkauhc4nh6V+NgqDGSqoPpIo3m2QdFV2QYGd/aFK2ZA6ZrDboKxJwJs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712610704; c=relaxed/simple; bh=ocXt6XkxBRJVDtsnn4FmvvaWTL7JUy6zdCjPIUKTR9I=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=tWic0jCfGLDU03sQElKcCMw/tLLpxsR8r1PXetzJ8sU++e3iDvUr/diEp3bYftl714D2GMemD5oUAu1uJNaydGvMiMEiXlA18u6kybduUAC3StH2jzqzkRIn4pGYcHW2r69Jb21KdMlXfY/7hN+kQ/0r6/ktQEtLDGTI2IJxipE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5003a.ext.cloudfilter.net ([10.0.29.159]) by cmsmtp with ESMTPS id trADriY6Ts4yTtwHGr7OE4; Mon, 08 Apr 2024 21:11:42 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id twHFrqYLssT9BtwHFr9SXn; Mon, 08 Apr 2024 21:11:42 +0000 X-Authority-Analysis: v=2.4 cv=LIutQ4W9 c=1 sm=1 tr=0 ts=66145d8e a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=raytVjVEu-sA:10 a=Qbun_eYptAEA:10 a=rxEfz5amTwgwtFEVBNsA:9 a=QEXdDO2ut3YA:10 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Kb/XCMxHFNuknDnYx65GjK8JnjZSen0Tji2nHWjH9H4=; b=T8g6y9tBZnEcwwBIqKbnaGNhdR hai5XVjwTjjFSKAA9lhfOpJegaiBsloMRgbKN1/jlLsCu2RM8TtBpP2NxrQMZiNgAdtWLAg3HcjKE TcdKjnbks3x5LER1eFD7Z2htW; Received: from 97-122-82-115.hlrn.qwest.net ([97.122.82.115]:54230 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1rtwHF-001uXf-19 for gdb-patches@sourceware.org; Mon, 08 Apr 2024 15:11:41 -0600 From: Tom Tromey Date: Mon, 08 Apr 2024 15:11:39 -0600 Subject: [PATCH v2 3/7] Add move operators for addrmap MIME-Version: 1.0 Message-Id: <20240408-die-map-madness-v2-3-6741626d544d@tromey.com> References: <20240408-die-map-madness-v2-0-6741626d544d@tromey.com> In-Reply-To: <20240408-die-map-madness-v2-0-6741626d544d@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.82.115 X-Source-L: No X-Exim-ID: 1rtwHF-001uXf-19 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-82-115.hlrn.qwest.net ([192.168.0.21]) [97.122.82.115]:54230 X-Source-Auth: tom+tromey.com X-Email-Count: 6 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfDgF/WoRjQVsYhwWCvNZekJEZadzQiikhHgCn1y6yQUYKy5BL39qY2uYbSS3ubgVfS9a2owlbtIJja/xG2FNsABQHYznhkt5klZ1dPuUc8lAYOokJlPL yTmkYUX6qZdVSB5ctgaWwG1Qat57lUbAW0NqDybemSpNNbu5JChwb/RZopNalKUUc9q1ZdVnrWbFcyHiZwhBYkfWATxqhuSkilo= X-Spam-Status: No, score=-3021.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org A subsequent patch needs to move an addrmap. This patch adds the necessary support. It also changes addrmap_fixed to take a 'const' addrmap_mutable. This is fine according to the contract of addrmap_mutable; but it did require a compensating const_cast in the implementation. --- gdb/addrmap.c | 12 +++++++----- gdb/addrmap.h | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/gdb/addrmap.c b/gdb/addrmap.c index 0c60c0c2ceb..c6e037330ec 100644 --- a/gdb/addrmap.c +++ b/gdb/addrmap.c @@ -250,12 +250,13 @@ addrmap_mutable::do_find (CORE_ADDR addr) const } -addrmap_fixed::addrmap_fixed (struct obstack *obstack, addrmap_mutable *mut) +addrmap_fixed::addrmap_fixed (struct obstack *obstack, + const addrmap_mutable *mut) { size_t transition_count = 0; /* Count the number of transitions in the tree. */ - mut->foreach ([&] (CORE_ADDR start, void *obj) + mut->foreach ([&] (CORE_ADDR start, const void *obj) { ++transition_count; return 0; @@ -273,10 +274,10 @@ addrmap_fixed::addrmap_fixed (struct obstack *obstack, addrmap_mutable *mut) /* Copy all entries from the splay tree to the array, in order of increasing address. */ - mut->foreach ([&] (CORE_ADDR start, void *obj) + mut->foreach ([&] (CORE_ADDR start, const void *obj) { transitions[num_transitions].addr = start; - transitions[num_transitions].value = obj; + transitions[num_transitions].value = const_cast (obj); ++num_transitions; return 0; }); @@ -344,7 +345,8 @@ addrmap_mutable::addrmap_mutable () addrmap_mutable::~addrmap_mutable () { - splay_tree_delete (tree); + if (tree != nullptr) + splay_tree_delete (tree); } diff --git a/gdb/addrmap.h b/gdb/addrmap.h index ed52e3cd990..5378b753760 100644 --- a/gdb/addrmap.h +++ b/gdb/addrmap.h @@ -85,9 +85,14 @@ struct addrmap_fixed final : public addrmap, { public: - addrmap_fixed (struct obstack *obstack, addrmap_mutable *mut); + addrmap_fixed (struct obstack *obstack, const addrmap_mutable *mut); DISABLE_COPY_AND_ASSIGN (addrmap_fixed); + /* It's fine to use the default move operators, because this addrmap + does not own the storage for the elements. */ + addrmap_fixed (addrmap_fixed &&other) = default; + addrmap_fixed &operator= (addrmap_fixed &&) = default; + void relocate (CORE_ADDR offset) override; private: @@ -124,6 +129,18 @@ struct addrmap_mutable final : public addrmap ~addrmap_mutable (); DISABLE_COPY_AND_ASSIGN (addrmap_mutable); + addrmap_mutable (addrmap_mutable &&other) + : tree (other.tree) + { + other.tree = nullptr; + } + + addrmap_mutable &operator= (addrmap_mutable &&other) + { + std::swap (tree, other.tree); + return *this; + } + /* In the mutable address map MAP, associate the addresses from START to END_INCLUSIVE that are currently associated with NULL with OBJ instead. Addresses mapped to an object other than NULL are left