From patchwork Tue Feb 27 21:42:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 86483 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 3EB9E385840B for ; Tue, 27 Feb 2024 21:42:53 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by sourceware.org (Postfix) with ESMTPS id A67D13858D37 for ; Tue, 27 Feb 2024 21:42:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A67D13858D37 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A67D13858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d2c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709070142; cv=none; b=j3Xjs2jMWIr9Iszm8hoYKhJaHD/8XuYwUiX8qrDAB5luqG84X5EHXpw6HEmyKBAGsWj804vK3NQwztGGbYoiJTpFQsOUeHHbkFNCbHJA3OFlNiMDxJVhduUHqwvejNh9vinuXUQlvemg4UwXLgQpgPGzCwRXNgbIu8Eitlr1qok= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709070142; c=relaxed/simple; bh=DuMsqP5MTlKBRrHpXgL9gii2oeXws2wOkbKbVg9ysxQ=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=YEINsPovy5yyr/fbzbtFyzGeeVlmhMM+3rLOvryv5w0yqia92nmk7M3vvOv4YylSsApxC23fpU86vUR3SUBg0mKUXJWk30ckQE9sdFFz08u+x6xgC4nOgdUSHnNxOJ2LgK6dt7MOV7d8r6SbX9Cx6RtWCZM72qFd+attzpRTHFI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd2c.google.com with SMTP id ca18e2360f4ac-7c7476a11e0so267749439f.3 for ; Tue, 27 Feb 2024 13:42:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1709070140; x=1709674940; darn=sourceware.org; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Ni9XezHSZahNmWgqIdD5f2wKaKYT8/o5ySjZ7hSs4m0=; b=BsES4YCATzw7xlVY1vn4d35/hbPSVtEQw5ArHOIo99qRMCLJQpzuPFdSwO9X/pychQ itJYyd1Klj97L0Su7qvxf6ffkEteXW4MoJfjZWuwe1E14FCsXisceU4ndBm4zR/LuEMb LBTPpD+JIuMfSNiiVtp5EFbYi9HFgHj2eEj42m3RQ/ZYg0xagLXOQJBhZ1OqszwMktbW wNF6/AV3xvGz+kHwMb3AYpsa0KYxwFpDC1YDHXbK0FfXXHEhXJN+3yWZ6iChFDvF3Ld4 4odPEp+o4kumnjsgfxPx19lirxMQisD7jySHHiNDOzCP8JEwNcx0Qm6BX0JHXJSdrEXV tACw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709070140; x=1709674940; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ni9XezHSZahNmWgqIdD5f2wKaKYT8/o5ySjZ7hSs4m0=; b=j3XAe2HZAxXXkHruwlQLtlX1Evx8mQJwO5d5NRD51mS/EAs0y9H+ouXzxlEuv8MT8g fj5+Crf9QFn3FgiG96X491MklCTFal5hqhoKj50Yfpvx7y+Kf71qfVJCt3pJRNae/5tS YnHNekI0xzrt3sLts4IZsOzY6syUc8qijMEpGH2GrdrIUOB7AT9tVYenAuvbSiClbw7M MwTEF+UPNrYPjXPLw3+EKfCYffaJ80QjCX1qkosozRBPx4R5egyM8UQ7+CY9BMtPNGMk brLFUBywMDmbUgV+ISbXCuA4P2xLfeCtn4FTemRy+H6JNRAqiiWyuPPxjae1ipmVKjpS NX8A== X-Gm-Message-State: AOJu0Yx35KW3DbdRlEiMpqBTJBlVahJVn21XllZ2ZxcjyhB/wvBzgYvT RfumudGTLo/5dd3uVtO8BDE/zMYouyk1ukWpYiiZ3HYC+fHZFO/xThfVGY4IYSU7BxP/6S84sHs = X-Google-Smtp-Source: AGHT+IFb6NkZof+UA5SwNvLl6+SrKVI7aZL82JMPIIjngZqu9fIAVUN4CXN/YR0tUFlXngVW0gltQA== X-Received: by 2002:a6b:ea04:0:b0:7c7:ee05:7fa with SMTP id m4-20020a6bea04000000b007c7ee0507famr2270856ioc.14.1709070139800; Tue, 27 Feb 2024 13:42:19 -0800 (PST) Received: from localhost.localdomain (71-211-170-195.hlrn.qwest.net. [71.211.170.195]) by smtp.gmail.com with ESMTPSA id gh4-20020a056638698400b0047438454db4sm1983600jab.9.2024.02.27.13.42.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 13:42:19 -0800 (PST) From: Tom Tromey Date: Tue, 27 Feb 2024 14:42:17 -0700 Subject: [PATCH 1/3] Use addrmap_fixed in a few spots MIME-Version: 1.0 Message-Id: <20240227-obstac-alloc-v1-1-bd079aad35cd@adacore.com> References: <20240227-obstac-alloc-v1-0-bd079aad35cd@adacore.com> In-Reply-To: <20240227-obstac-alloc-v1-0-bd079aad35cd@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 There are a few spots in the tree that use 'addrmap' where only an addrmap_fixed will ever really be seen. This patch changes this code to use the more specific type. --- gdb/block.h | 10 +++++----- gdb/dwarf2/cooked-index.h | 2 +- gdb/dwarf2/read.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/gdb/block.h b/gdb/block.h index 00630123120..4c29f6599ef 100644 --- a/gdb/block.h +++ b/gdb/block.h @@ -30,7 +30,7 @@ struct compunit_symtab; struct block_namespace_info; struct using_direct; struct obstack; -struct addrmap; +struct addrmap_fixed; /* Blocks can occupy non-contiguous address ranges. When this occurs, startaddr and endaddr within struct block (still) specify the lowest @@ -410,22 +410,22 @@ struct blockvector { return this->block (STATIC_BLOCK); } /* Return the address -> block map of this blockvector. */ - addrmap *map () + addrmap_fixed *map () { return m_map; } /* Const version of the above. */ - const addrmap *map () const + const addrmap_fixed *map () const { return m_map; } /* Set this blockvector's address -> block map. */ - void set_map (addrmap *map) + void set_map (addrmap_fixed *map) { m_map = map; } private: /* An address map mapping addresses to blocks in this blockvector. This pointer is zero if the blocks' start and end addresses are enough. */ - struct addrmap *m_map; + addrmap_fixed *m_map; /* Number of blocks in the list. */ int m_num_blocks; diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index 629a5b6b9ee..928c4ef655c 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -362,7 +362,7 @@ class cooked_index_shard cooked_index_entry *m_main = nullptr; /* The addrmap. This maps address ranges to dwarf2_per_cu_data objects. */ - addrmap *m_addrmap = nullptr; + addrmap_fixed *m_addrmap = nullptr; /* Storage for canonical names. */ std::vector> m_names; }; diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index 5ee7e09a743..73def88c4c0 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -536,7 +536,7 @@ struct dwarf2_per_bfd abstract_to_concrete; /* The address map that is used by the DWARF index code. */ - struct addrmap *index_addrmap = nullptr; + addrmap_fixed *index_addrmap = nullptr; }; /* An iterator for all_units that is based on index. This From patchwork Tue Feb 27 21:42:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 86485 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 D37253858429 for ; Tue, 27 Feb 2024 21:43:25 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by sourceware.org (Postfix) with ESMTPS id 126783858C98 for ; Tue, 27 Feb 2024 21:42:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 126783858C98 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 126783858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d2a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709070142; cv=none; b=XpsIjWVTzIvnsBoR9fVelxbuBGfNAxoTdWeeu5R2w267xVXEQmpJQ8czuxbbSLX1PgdhPB4s6Tz9+B64vG1IzAULvTmJ1vJmctC/3GQo3pu67Tq5a52dvMarwd9g3+I7Y9GOBnPauxUfsIvnvzjq9sWKYxQweOtCHsIIk0JTCVE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709070142; c=relaxed/simple; bh=3M2SgEvGI4K1PcoLnm9azXFcwzMlfmpV/9P+wV8rxGk=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=sul51dqa3FjSH88zc2oH3CViRlT/77hFjLhYkxOIB299/1CDFZnIFmQHeMjHjVisOl5Z/B+REWhpvOpRs/Ri32bKArzY+j0JRC0MnKG10HyDM0QfEUOzxSZsK9TAC4tN5gkle3E1YdjCGe4Dc78gpf7z1H56D0bEYxPcGWYw1J0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd2a.google.com with SMTP id ca18e2360f4ac-7c7f3f66d17so22048539f.0 for ; Tue, 27 Feb 2024 13:42:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1709070140; x=1709674940; darn=sourceware.org; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=u5YQASyCBX8RcgSArxeYMV+wwdJ+nUuSfurxZClQyXQ=; b=V5oXLnIyqz4Ptt2kA/sDTgqz26qUGDpDKkhblIZUkJyRrQgnwy3XeBHab3TBgno13U cW0o/rGzB2+kpNAJPily0IITNpHv/eDXRgHml3tSxoXM1OCjk8gYSGLThrTEQich86l8 4Ixw9iigDYzi8Z3889BtLsPRPSRSnj3hSYYKvmbwj13GCDB33FczzL8Idg7p89sfaXiw 6d4STm1toDpJqdTvqfFXztudX7O1FkRBWFnVac+axnCVw3VNptu1ND5gYpHVnoOwYzSd vACFRSfjjq9id/UYmJlu04vlJGPVYRUPciH4d7K92NwmcAw5DcLjveXbRBTplNZYUd7H BhPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709070140; x=1709674940; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u5YQASyCBX8RcgSArxeYMV+wwdJ+nUuSfurxZClQyXQ=; b=Vx58NaD1cmtseDXdr/P/Ia5F6uKU3Er6pqmzirhZ7AlLdyTqnPfhUBZld6NqPK5Cmh vTHNTPvKFiuXTWAW0HadvMA4PJqm2qc+HcqPbKm/cp7yqdsw8PV1hFpgaBAodB+p5UHv b/7BIZL6m+eYO/t0j6devfOqRTiFxWXa9+q+tWniSvJAzjQwLNkIaHtV8Iq8vyVil9LT r1ndw9hwP+PSxobTjINLlN2lk7QDlUZu7n0SrDlpv2jVjLcY4j7ULIf2wW1hmsY/M2M6 Pp9dynBKNZ1TDo0kg4FWN/6nKGFpbJAJwOOiYSCrJDGhnk0o+GJQaNm69ysGsP4jzePJ huUQ== X-Gm-Message-State: AOJu0YxNfQbhKI3zKDcZtrHb1hJEFRa4ezqrpMxH87WwKwkUBH3QpjX7 7mWu4QpjUEz/UWHol3ctjEOPUZJdBRfRD3cRBFnb4LV6hz34CRgKnAprt3XFErMF3K02NnatdMU = X-Google-Smtp-Source: AGHT+IFBkPgIYRGppQeNaFBDztfrVbA4HaiXMHvl19m4TvEMtfmbmGuqU0qmKn/R/rMJR7EAdd9ZMA== X-Received: by 2002:a6b:4e16:0:b0:7c7:f5d2:1815 with SMTP id c22-20020a6b4e16000000b007c7f5d21815mr538961iob.1.1709070140377; Tue, 27 Feb 2024 13:42:20 -0800 (PST) Received: from localhost.localdomain (71-211-170-195.hlrn.qwest.net. [71.211.170.195]) by smtp.gmail.com with ESMTPSA id gh4-20020a056638698400b0047438454db4sm1983600jab.9.2024.02.27.13.42.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 13:42:20 -0800 (PST) From: Tom Tromey Date: Tue, 27 Feb 2024 14:42:18 -0700 Subject: [PATCH 2/3] Don't use virtual destructor in addrmap MIME-Version: 1.0 Message-Id: <20240227-obstac-alloc-v1-2-bd079aad35cd@adacore.com> References: <20240227-obstac-alloc-v1-0-bd079aad35cd@adacore.com> In-Reply-To: <20240227-obstac-alloc-v1-0-bd079aad35cd@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 The addrmap polymorphism is sort of "phony" in that there isn't really code in the tree that can be presented with either type. I haven't tried to fix this (though perhaps I may); but meanwhile it's handy for the next patch if addrmap_fixed has a trivial destructor. This patch achieves this by making the addrmap destructor non-virtual, and also making it protected so that objects of any of these types cannot be destroyed when only the base class is known. --- gdb/addrmap.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gdb/addrmap.h b/gdb/addrmap.h index ba83607ad8c..0d61046cebd 100644 --- a/gdb/addrmap.h +++ b/gdb/addrmap.h @@ -44,8 +44,6 @@ using addrmap_foreach_const_fn /* The base class for addrmaps. */ struct addrmap { - virtual ~addrmap () = default; - /* Return the object associated with ADDR in MAP. */ const void *find (CORE_ADDR addr) const { return this->do_find (addr); } @@ -68,6 +66,9 @@ struct addrmap { return this->do_foreach (fn); } +protected: + ~addrmap () = default; + private: /* Worker for find, implemented by sub-classes. */ virtual void *do_find (CORE_ADDR addr) const = 0; From patchwork Tue Feb 27 21:42:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 86484 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 D43073858415 for ; Tue, 27 Feb 2024 21:43:23 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by sourceware.org (Postfix) with ESMTPS id CDF413858C5E for ; Tue, 27 Feb 2024 21:42:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CDF413858C5E Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CDF413858C5E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::12f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709070143; cv=none; b=ji2Y/aeuC6SVxaQvir4FQX0bYRwG/Vcc4r3xyxlQ7L0ApAk6JyiZGHR8RLvyJvD3VGxGz3Q1rKBvOuh5xgygVt02jeKKePRfwC+b1s74HZ4VQBEottw+XtjZWlMNARDNCqLaf061UTayVTD7ZyiB26R9VwagUIQmjtMJlQSCq4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709070143; c=relaxed/simple; bh=4NxKL3Ucvs9cJHjAd5lirHiZl1bLHj4zfKF5JKvq25c=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=n/5nJha4DYH4DNE7KTuCGLYwDAm0B1PEO1bFUaIItHnpvs0SiADftfx+ZYXBmWwHfcZHYQ2JaKeQhCqPGp5bdt62f0O92oXZ3o2R+w7E97qgK/1GdW6/Vf+AtWEsAOxdRJoGBo2u0JeHNndnusZ7jUIbu6f25B9c/dQA8US0f6U= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x12f.google.com with SMTP id e9e14a558f8ab-3657dbe2008so16087475ab.1 for ; Tue, 27 Feb 2024 13:42:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1709070141; x=1709674941; darn=sourceware.org; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=pLfUQn+nT3Yp81ZCcoOgVEBbLzfuJUXPwn0lR0TTcd4=; b=IZ9UG9uiFlgBcfkMfNt1cRpgTU/yRMu6kg6atNo9c6c+X5prbMkVbUd+Ty2YtgKqQo 4m8AbYiOx0bBPEV3luCphB2ZTueDStd4kTS8A2HaFZ7DtasF+LlBXNCkJ0JGqcrKoQnD LxoOY8jIxEz+RrW93tEKhISplO5iktwpSEryLqBCff+ZJowkKAmx/zM3JjFJNNELeLmX aW4IIOfURgCT143UYSveO+8+hSdhSjmr+N/Pm0Oo4pRC496yq0FGHQanJrqm6iZgvuR8 1e/x/v/PZZBoomEBiKruZuc+jJveiyNhLoWp5ewll8l7ZqaFXEizp8DDQ2LA5/+dfBQc Nyvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709070141; x=1709674941; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pLfUQn+nT3Yp81ZCcoOgVEBbLzfuJUXPwn0lR0TTcd4=; b=qHktIqHW8djMjZeRaND3UTMsri7jFHLOVirymw81zm8zVVjtAsHhBXFW/ocD3fhIc5 bljrKAEmrd48+FdjgVSum+qzs/J3RQq5UdI2tfXMCVhOtxg1yUfPJh/UZOGBScQKS/1Z 8RSo9o7uJv6uaXKrOurl3zDhMLDWs4bM0bnGTOcFX8mHCEkWWEusz0Rq5peTCTigHQLk 9OAiCDlR5MF8/8xk3HcLZ0oY78vTUi/qTiQZGcjL+ESkOduV2FVusfw8kk4LBwcExfYV 3kD2eZW1iZPQgCX0zo2QmUUVW/YDElTJugxSFNTmBGa1wIjFI5nqDPgVfMkSoeu+I6bT n2Gw== X-Gm-Message-State: AOJu0YyFEQ7D27xQ0gvKTxNJWc5ar4Cab+2+UDawu5bUouf0XRKKiPxD vpnd6U13XVF1xvFe4Hr0BDRHYlaujqIKTCDVrHoX/DT3hyWcRicqSZcG/jWxWuL4/gLfAn0e/zw = X-Google-Smtp-Source: AGHT+IGYqCMEWrHAeUzEUql2E6qGXENH/gCuGB8PVu3xZYZ4lo9FmVnr5NJXLnymu3L2SMwLN16VgQ== X-Received: by 2002:a92:cd0d:0:b0:365:1749:cae0 with SMTP id z13-20020a92cd0d000000b003651749cae0mr13771883iln.7.1709070140931; Tue, 27 Feb 2024 13:42:20 -0800 (PST) Received: from localhost.localdomain (71-211-170-195.hlrn.qwest.net. [71.211.170.195]) by smtp.gmail.com with ESMTPSA id gh4-20020a056638698400b0047438454db4sm1983600jab.9.2024.02.27.13.42.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 13:42:20 -0800 (PST) From: Tom Tromey Date: Tue, 27 Feb 2024 14:42:19 -0700 Subject: [PATCH 3/3] Require trivial destructor in allocate_on_obstack MIME-Version: 1.0 Message-Id: <20240227-obstac-alloc-v1-3-bd079aad35cd@adacore.com> References: <20240227-obstac-alloc-v1-0-bd079aad35cd@adacore.com> In-Reply-To: <20240227-obstac-alloc-v1-0-bd079aad35cd@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 This patch makes allocate_on_obstack a little bit safer, by enforcing the rule that objects allocated on an obstack must have a trivial destructor. The static assert is done in a method -- doing it inside the class itself won't work because the class is incomplete at that point. --- gdb/addrmap.h | 2 +- gdb/block.c | 2 +- gdb/block.h | 2 +- gdb/dwarf2/cooked-index.h | 2 +- gdb/gdbtypes.h | 4 ++-- gdb/symtab.h | 2 +- gdbsupport/gdb_obstack.h | 6 +++++- 7 files changed, 12 insertions(+), 8 deletions(-) diff --git a/gdb/addrmap.h b/gdb/addrmap.h index 0d61046cebd..55dea36b877 100644 --- a/gdb/addrmap.h +++ b/gdb/addrmap.h @@ -81,7 +81,7 @@ struct addrmap_mutable; /* Fixed address maps. */ struct addrmap_fixed : public addrmap, - public allocate_on_obstack + public allocate_on_obstack { public: diff --git a/gdb/block.c b/gdb/block.c index 079053cd79e..6d0d33fa85e 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -31,7 +31,7 @@ C++ files, namely using declarations and the current namespace in scope. */ -struct block_namespace_info : public allocate_on_obstack +struct block_namespace_info : public allocate_on_obstack { const char *scope = nullptr; struct using_direct *using_decl = nullptr; diff --git a/gdb/block.h b/gdb/block.h index 4c29f6599ef..ae676c4ba67 100644 --- a/gdb/block.h +++ b/gdb/block.h @@ -105,7 +105,7 @@ struct blockranges This implies that within the body of one function the blocks appear in the order of a depth-first tree walk. */ -struct block : public allocate_on_obstack +struct block : public allocate_on_obstack { /* Return this block's start address. */ CORE_ADDR start () const diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index 928c4ef655c..0d4fcb8538e 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -104,7 +104,7 @@ extern bool language_requires_canonicalization (enum language lang); This is an "open" class and the members are all directly accessible. It is read-only after the index has been fully read and processed. */ -struct cooked_index_entry : public allocate_on_obstack +struct cooked_index_entry : public allocate_on_obstack { cooked_index_entry (sect_offset die_offset_, enum dwarf_tag tag_, cooked_index_flag flags_, diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 435a040544a..f80bd7e071a 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -211,7 +211,7 @@ struct variant_part; control other variant parts as well. This struct corresponds to DW_TAG_variant in DWARF. */ -struct variant : allocate_on_obstack +struct variant : allocate_on_obstack { /* * The discriminant ranges for this variant. */ gdb::array_view discriminants; @@ -243,7 +243,7 @@ struct variant : allocate_on_obstack and holds an array of variants. This struct corresponds to DW_TAG_variant_part in DWARF. */ -struct variant_part : allocate_on_obstack +struct variant_part : allocate_on_obstack { /* * The index of the discriminant field in the outer type. This is an index into the type's array of fields. If this is -1, there diff --git a/gdb/symtab.h b/gdb/symtab.h index 5bd63979132..d49b7066e3a 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -1244,7 +1244,7 @@ extern gdb::array_view symbol_impls; /* This structure is space critical. See space comments at the top. */ -struct symbol : public general_symbol_info, public allocate_on_obstack +struct symbol : public general_symbol_info, public allocate_on_obstack { symbol () /* Class-initialization of bitfields is only allowed in C++20. */ diff --git a/gdbsupport/gdb_obstack.h b/gdbsupport/gdb_obstack.h index 20f888660f9..7b3bb05bc00 100644 --- a/gdbsupport/gdb_obstack.h +++ b/gdbsupport/gdb_obstack.h @@ -133,14 +133,18 @@ struct auto_obstack : obstack { obstack_free (this, obstack_base (this)); } }; -/* Objects are allocated on obstack instead of heap. */ +/* Objects are allocated on obstack instead of heap. This is a mixin + that uses CRTP to ensure that the type in question is trivially + destructible. */ +template struct allocate_on_obstack { allocate_on_obstack () = default; void* operator new (size_t size, struct obstack *obstack) { + static_assert (IsFreeable::value); return obstack_alloc (obstack, size); }