From patchwork Wed Jan 17 18:58:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 84290 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 01AFD385841D for ; Wed, 17 Jan 2024 18:59:42 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta038.useast.a.cloudfilter.net (omta038.useast.a.cloudfilter.net [44.202.169.37]) by sourceware.org (Postfix) with ESMTPS id 983203858C52 for ; Wed, 17 Jan 2024 18:59:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 983203858C52 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 983203858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.37 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705517945; cv=none; b=LBtjnbzjYV5xpO2d5nfOf+lLjb/aQII4YXZ3Sod891mo7/baxHKwcBTpJUgny9xXmPLpx0iiYFhMaylo1vELdGxgxhJ3pRbUSWbBpyPrgm6esXw4ImWfnouxxSooDeZasCH7INodbVLF6wvYStQEIecH/QCyO2MjR1H5ZU2ldXA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705517945; c=relaxed/simple; bh=a05in9nH/WOoE1RVpGvB4snBinC+pI+VTRM7PGCWT4o=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=G+8xhtQTeIG6Edw4dMSiWtvjvcfvzD7rQfNex88Vopw3WrssDUnZEwLUVYfOs9Pv8NGU1dNXeHZ2s/99P+8Y2i9vmonoIb3Kjopw3PmEnu8kxHCyLKbHg1KGkl1/7l0SSkiPA5mSgYbCEK1BwePtEdHKyEDktAPoHnUk+WdlsFg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5007a.ext.cloudfilter.net ([10.0.29.141]) by cmsmtp with ESMTPS id Q9GlrJ7b89gG6QB7urT1sS; Wed, 17 Jan 2024 18:59:02 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id QB7trAxqhPwzWQB7trSkYR; Wed, 17 Jan 2024 18:59:01 +0000 X-Authority-Analysis: v=2.4 cv=T8yf8tGQ c=1 sm=1 tr=0 ts=65a82375 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10 a=dEuoMetlWLkA:10 a=Qbun_eYptAEA:10 a=QImr5mNoz4qdmPyAnUcA: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=Vs7Y6NLUgGaOn21vBRHlQ2ZnW9/XpvL1KGkXKMMw5cs=; b=gx8x2ofFpJ6qTVuPOxzqWk2HG0 v4a/l0dW4dtJ24b4ytbP2lkvmwlx8QeMj6Z3BnOe629fUlCwfUCo44TRDw5PWUfj+p4bLDAVKun4H Aa6DCEeoMHTm53aLcm2sAXn5n; Received: from 97-122-68-157.hlrn.qwest.net ([97.122.68.157]:45122 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 1rQB7s-004FFp-31 for gdb-patches@sourceware.org; Wed, 17 Jan 2024 11:59:00 -0700 From: Tom Tromey Date: Wed, 17 Jan 2024 11:58:50 -0700 Subject: [PATCH 3/7] Add move operators for addrmap MIME-Version: 1.0 Message-Id: <20240117-die-map-madness-v1-3-42fb435ad1ed@tromey.com> References: <20240117-die-map-madness-v1-0-42fb435ad1ed@tromey.com> In-Reply-To: <20240117-die-map-madness-v1-0-42fb435ad1ed@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.68.157 X-Source-L: No X-Exim-ID: 1rQB7s-004FFp-31 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-68-157.hlrn.qwest.net ([192.168.0.21]) [97.122.68.157]:45122 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: MS4xfLzM7z4H6Arq4XklRlRJOszExdB+G+FkMpWWvFH2ztIFaQc33DLhHSdyC6WTPd/jqaU6dIp6OrJ5zeqDRIxBqjpMR6XpKKh7Ou0XuH8QPCrebS8MTMGW MaXLzDdg+FjUcU63QuBLTouGSWXZ1c3ioaSbsmcOntyqmK3KUjHupK33HG8KuaX89l0HchlrXP2HQu+kTVLfAc101TZQUMwLMyo= X-Spam-Status: No, score=-3022.7 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, T_SCC_BODY_TEXT_LINE 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 162ab84763b..682ffa98573 100644 --- a/gdb/addrmap.c +++ b/gdb/addrmap.c @@ -251,12 +251,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; @@ -274,10 +275,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; }); @@ -345,7 +346,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 ba83607ad8c..1dd1e35ec11 100644 --- a/gdb/addrmap.h +++ b/gdb/addrmap.h @@ -84,9 +84,14 @@ struct addrmap_fixed : 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: @@ -123,6 +128,18 @@ struct addrmap_mutable : 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