From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 6BAqCmJky2BHLAAAWB0awg (envelope-from ) for ; Thu, 17 Jun 2021 11:04:02 -0400 Received: by simark.ca (Postfix, from userid 112) id 27C691F163; Thu, 17 Jun 2021 11:04:02 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=MAILING_LIST_MULTI, RDNS_DYNAMIC autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 3E5241F0FE for ; Thu, 17 Jun 2021 11:04:01 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BE50A3951899 for ; Thu, 17 Jun 2021 15:04:00 +0000 (GMT) Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by sourceware.org (Postfix) with ESMTPS id E4C483955404 for ; Thu, 17 Jun 2021 14:57:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E4C483955404 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f52.google.com with SMTP id n23so3645831wms.2 for ; Thu, 17 Jun 2021 07:57:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=yCU/Q25jihmw+2y4ZB9Tmf5jivm8Hbd/bNjmg04VPNI=; b=bxWyJWwLfurycmfHFJLW1qXB6cEyl4+QgIuG7ahooT5YWSvBx1cJPfm6IR/UNlYKIU aHxyik1U93SYurVYNGbydY0dOGL46Q5IrYYLPWCja1itWFA4GU3osu0HULZTw4JfnUMo u7AzZWLWjzLvOiZn2LTbS/uj5tfhdxXtdoiTtNs23WUWcHytOHQt3pBKG4IKOWzDZ5KD ebo3WP2UBFcWUKDjNyhQzGhH19sOUwDV/FE6xoAg4nP7xbGhhS2AQ63HQTg2HhXi2/Xp uZp0NxZQt3sbEf0ZTbeQ5lbhirbkpYUfDO6/wjQMwocZXkgV1EAAHUOXPqtPJl2CjIwG Kh5g== X-Gm-Message-State: AOAM532fhHaXNzAeNFAuZoA1FOdJh56UTa+XEZTGaFUGsuDD7GdXCZp0 IYsxt2atr1GGpsMLGFBWiHglwjSfd6F1favo X-Google-Smtp-Source: ABdhPJyscSA0EI+y/bFzqp31TgGahYWEEmcTsvfjXj2qalQk6OkH/e+QGyboIp16NUls+1+IykBnfQ== X-Received: by 2002:a1c:ba56:: with SMTP id k83mr78901wmf.143.1623941829387; Thu, 17 Jun 2021 07:57:09 -0700 (PDT) Received: from ?IPv6:2001:8a0:f932:6a00:6b6e:c7b6:c5a7:aac3? ([2001:8a0:f932:6a00:6b6e:c7b6:c5a7:aac3]) by smtp.gmail.com with ESMTPSA id k2sm5444441wrw.93.2021.06.17.07.57.08 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Jun 2021 07:57:08 -0700 (PDT) Subject: Re: [PATCH 2/4] Introduce scoped_restore_signal From: Pedro Alves To: gdb-patches@sourceware.org References: <20210615111429.1879286-1-pedro@palves.net> <20210615111429.1879286-3-pedro@palves.net> Message-ID: <84b8034c-9f79-9774-dbfc-cf8d4935b62b@palves.net> Date: Thu, 17 Jun 2021 15:57:07 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210615111429.1879286-3-pedro@palves.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" On 2021-06-15 12:14 p.m., Pedro Alves wrote: > +/* Simple wrapper that allows lazy initialization / destruction of T. > + Slightly more efficient than gdb::optional, because it doesn't > + carry storage to track whether the object has been initialized. */ > +template > +class lazy_init > +{ > +public: > + void emplace () > + { > + new (m_buf) T (); > + } > + > + void reset () > + { > + reinterpret_cast (m_buf)->~T (); > + } > + > +private: > + alignas (T) gdb_byte m_buf[sizeof (T)]; > +}; > + I was looking at this again, and realized that a raw buffer like that isn't super convenient when you're debugging gdb and want to inspect T (you'll need to cast). So I made it a union instead (see below). It has the added advantage that no cast is necessary. I'm going to push the series with this change. diff --git c/gdbsupport/scoped_ignore_sigttou.h w/gdbsupport/scoped_ignore_sigttou.h index 7b29f2b79a3..1fc8f80d7fd 100644 --- c/gdbsupport/scoped_ignore_sigttou.h +++ w/gdbsupport/scoped_ignore_sigttou.h @@ -34,16 +34,23 @@ class lazy_init public: void emplace () { - new (m_buf) T (); + new (&m_u.obj) T (); } void reset () { - reinterpret_cast (m_buf)->~T (); + m_u.obj.~T (); } private: - alignas (T) gdb_byte m_buf[sizeof (T)]; + union u + { + /* Must define ctor/dtor if T has non-trivial ctor/dtor. */ + u () {} + ~u () {} + + T obj; + } m_u; };