From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id KBm0Bdpom19gGAAAWB0awg (envelope-from ) for ; Thu, 29 Oct 2020 21:14:02 -0400 Received: by simark.ca (Postfix, from userid 112) id 1568E1EFC1; Thu, 29 Oct 2020 21:14: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=-1.0 required=5.0 tests=MAILING_LIST_MULTI, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.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 BE9D41E590 for ; Thu, 29 Oct 2020 21:14:01 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DC6DE385780E; Fri, 30 Oct 2020 01:14:00 +0000 (GMT) Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by sourceware.org (Postfix) with ESMTPS id 31443385780E for ; Fri, 30 Oct 2020 01:13:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 31443385780E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=alves.ped@gmail.com Received: by mail-wr1-f45.google.com with SMTP id n18so4720455wrs.5 for ; Thu, 29 Oct 2020 18:13:58 -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:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=6/PkHbWtPG25cSaq96WREKlzwd5BPRq8Bk8JMZhHJXE=; b=hNA4uLwPfWtPoTiJuh5+SpQNt3L2HWSbviPQrSr0EOYk6WsN9/G6ILM9+XFcstU3Gr 3mjASseRxH667ZYpcUq3BmkA9EcKKLRn+ObZ8P8TbTNCgtC6XLwGwGRhEzR4+GSROuPQ WZCWpII1TBYjNzTEPnuZrbxWsbJgZD77+lktmu5q9DU7vh52qQnMWB0jZ8kWxOLLSo1t eFPte5Tt2/qS8WvRFTOMyv4CPK0Qu8tbLqhb17hGW/7NQNvQV0TD4ElBB/zlN6X+Gbo/ cDY0JRUCtkORV4UOzVAgMtD3MGBZhC/EKSX4KCthG/olTIo1BCRpiDlwdT+WNpYuFFw1 b9Nw== X-Gm-Message-State: AOAM531Z1tPYNsb0xNpGLz5//UttruT86JFd301I7Djgl4avnXkKOeIe q30sqBUUdL41rrt7Cyz1e2kK7rO/JlXLuQ== X-Google-Smtp-Source: ABdhPJyewL6Y2LcoSXPthcWmXkIpYVhTYXV4kYN4Mr24NjPaL+ni5BHXX+JkM4fsxlOqdi7wUVrNog== X-Received: by 2002:a5d:6cc8:: with SMTP id c8mr8533926wrc.233.1604020435394; Thu, 29 Oct 2020 18:13:55 -0700 (PDT) Received: from ?IPv6:2001:8a0:f925:3b00:b96b:919a:aa14:2400? ([2001:8a0:f925:3b00:b96b:919a:aa14:2400]) by smtp.gmail.com with ESMTPSA id 205sm2685413wme.38.2020.10.29.18.13.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 29 Oct 2020 18:13:54 -0700 (PDT) Subject: Re: [PATCH 3/3] Make scoped_restore_current_thread's cdtors exception free (RFC) To: Simon Marchi , gdb-patches@sourceware.org References: <20200708233125.1030-1-pedro@palves.net> <20200708233125.1030-4-pedro@palves.net> <58a4020f-fbbb-611f-eb23-c1b3fa25d4f2@simark.ca> <39ad8351-3f99-1162-4d2f-b5dbee5756f8@simark.ca> <47b34393-3833-bb85-84dc-9a8bde3e1a77@palves.net> <3293dbc2-922a-8589-dbc7-75ebd5a26175@simark.ca> From: Pedro Alves Message-ID: Date: Fri, 30 Oct 2020 01:13:53 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <3293dbc2-922a-8589-dbc7-75ebd5a26175@simark.ca> 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@sourceware.org Sender: "Gdb-patches" On 7/10/20 3:55 AM, Simon Marchi wrote: >>> I don't know if it would be worth it, but I'd like if we could assert (abort >>> GDB) if an exception does try to exit the destructor. The `restore` method >>> is non-trivial and calls into other non-trivial functions, so it would be >>> possible for a change far far away to cause that to happen. >> >> It will already abort. Destructors are noexcept by default, so if an exception >> escapes a destructor, std::terminate() is called, and that calls abort by default. > > Oh, didn't know that! I thought it was just "undefined behavior". > >>> What do you think of keeping the try/catch, but using `gdb_assert_not_reached` >>> in it? >> >> Not sure. If we do that, we do get a nicer error message. However if the user >> says "n" to "Quit this debugging session" we still abort. >> >> /home/pedro/brno/pedro/gdb/binutils-gdb-2/build/../src/gdb/thread.c:1441: internal-error: scoped_restore_current_thread::~scoped_restore_current_thread(): unexpected exception thrown from destructor: hello >> A problem internal to GDB has been detected, >> further debugging may prove unreliable. >> Quit this debugging session? (y or n) n >> >> This is a bug, please report it. For instructions, see: >> . >> >> /home/pedro/brno/pedro/gdb/binutils-gdb-2/build/../src/gdb/thread.c:1441: internal-error: scoped_restore_current_thread::~scoped_restore_current_thread(): unexpected exception thrown from destructor: hello >> A problem internal to GDB has been detected, >> further debugging may prove unreliable. >> Create a core file of GDB? (y or n) n >> terminate called after throwing an instance of 'gdb_exception_quit' >> Aborted (core dumped) >> >> Maybe it would be interesting to add a variant of internal_error that did >> not throw a quit, so the user could swallow the exception... Maybe consider >> wrapping that as a generic facility to add to all non-trivial RAII destructors >> we have? Like a function that takes a function_view as parameter, so >> we would write: >> >> foo::~foo () >> { >> safe_dtor (__FILE__, __LINE__, [&] () >> { >> restore (); >> }); >> } >> >> Even better, add a SAFE_DTOR macro using similar magic SCOPE_EXIT >> macro uses to be able to write: >> >> foo::~foo () >> { >> SAFE_DTOR { restore (); }; >> } > > That's fancier than what I hoped for :). My goal was just to make sure > we catch it if we ever make a change that causes an exception to escape. > Although I wouldn't be against what you proposed. > >> Here's the current version of the patch. > > That looks fine to me. FYI, I've finally merged this to master. Thanks, Pedro Alves