From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by sourceware.org (Postfix) with ESMTPS id EA52A3856143 for ; Mon, 24 Oct 2022 16:51:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EA52A3856143 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-wr1-f45.google.com with SMTP id o4so8952141wrq.6 for ; Mon, 24 Oct 2022 09:51:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:to:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kl12+/8vJLbNbvRN6cK9dUFptd0solAb8gG2TS0MPKs=; b=POsSG0XXV63uxKrIVzE9oIfh8exWJdmhHnqECeAT/FlYeYTHWdOpzdVUPsbhbs3dA0 Fg27NrDK715L7zxnMhk4EgZ6n/j9odYH/P7L8xIG3QEvZdcMdou4XDKUnDR9rMwjVXuY b+YSftYaJWhJt3ZttcItBfoMOTRhewd/2dCq0oCfwFexcgTxGSjyBgRl7NcdUeT5BZO/ VC08+Y6YfuFJGVHOy0xAGFlE/uhiCZYrklWAnBoiKsPmSqKgHVaVo9O/WW+QFZQ8Fk9j DKtn8WGOjeOskhSABsdF1waLD6a4QgMDu7uf3igSMfGEMOoFJhp+oxc3xsVuSivUaEz9 7eew== X-Gm-Message-State: ACrzQf3v24rbDFWys2lNZauiLpVFsTgPdgF8fx4IJKnnY2m7v009Ytky 1rlTWD7JZ+WqXxWgKrJhklRFfmDN/Vq6iA== X-Google-Smtp-Source: AMsMyM7+gAIcr4mw8UKN6UN0yCWHPvT1LoSp61CaxZpCsg+jUu899F9VYAETcNLlK70ifsMfWD7NiA== X-Received: by 2002:a5d:58d9:0:b0:236:5b81:2c99 with SMTP id o25-20020a5d58d9000000b002365b812c99mr9726731wrf.494.1666630293271; Mon, 24 Oct 2022 09:51:33 -0700 (PDT) Received: from ?IPv6:2001:8a0:f93a:3b00:e038:5cdc:b8bf:4653? ([2001:8a0:f93a:3b00:e038:5cdc:b8bf:4653]) by smtp.gmail.com with ESMTPSA id r11-20020adfda4b000000b0022e653f5abbsm92441wrl.69.2022.10.24.09.51.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 24 Oct 2022 09:51:32 -0700 (PDT) Subject: Re: [PATCH 2/2] [gdb] Fix rethrow exception slicing in insert_bp_location To: Tom de Vries , gdb-patches@sourceware.org References: <20221024084913.19429-1-tdevries@suse.de> <20221024084913.19429-3-tdevries@suse.de> <02ad6f69-2a1b-b938-0ab4-ba6288f10fde@suse.de> From: Pedro Alves Message-ID: <0203ad6e-426f-3e8f-fac8-1d2f0e8781a6@palves.net> Date: Mon, 24 Oct 2022 17:51:32 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <02ad6f69-2a1b-b938-0ab4-ba6288f10fde@suse.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,BODY_8BITS,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2022-10-24 5:43 p.m., Tom de Vries wrote: > On 10/24/22 18:36, Pedro Alves wrote: >> On 2022-10-24 9:49 a.m., Tom de Vries via Gdb-patches wrote: >> >>> +#define RETHROW_ON_TARGET_CLOSE_ERROR(E)                \ >>> +  do                                    \ >>> +    {                                    \ >>> +      if ((E).reason != 0)                        \ >>> +    {                                \ >>> +      /* Can't set the breakpoint.  */                \ >>> +                                    \ >>> +      if ((E).error == TARGET_CLOSE_ERROR)                \ >>> +        /* If the target has closed then it will have deleted any    \ >>> +           breakpoints inserted within the target inferior, as a    \ >>> +           result any further attempts to interact with the        \ >>> +           breakpoint objects is not possible.  Just rethrow the    \ >>> +           error.  Don't use E to rethrow, to prevent object    \ >>> +           slicing of the exception.  */                \ >>> +        throw;                            \ >>> +    }                                \ >>> +    } while (0) >> >> Is there a reason this is a macro instead of a function? > > yes, the throw without expression. > > Do you know of a way to do this using a function? WDYM? I believe it should Just Work. E.g.: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include struct excpt { }; struct excpt2 : excpt { }; void rethrow () { throw; } int main () { try { try { throw excpt2{}; } catch (const excpt &) { rethrow (); } } catch (const excpt2 &) { printf ("caught excpt2\n"); } return 0; } $ g++ test_rethrow.cc -o test_rethrow $ ./test_rethrow caught excpt2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~