delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2020/08/16/18:39:32

X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 235323857C65
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1597617518;
bh=cuxspjkXla79Ga/GB4h0ufvT1zVpUXI+7slgcMz9Spk=;
h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:
From;
b=pUSJDlEeBMuP/EGSznvzUMU+/I9oy4402McpEh998XleZwbSC+1QZNBIgZLEJ3kwk
s7/dDn6ucnJ2WH32cBJOW3BdXubYuiNyStJQllva/steKWBTThx0MHFgmA3FjhuKfi
jRiUwJomgDJID+t0C7OJ/wJdXu8K3gxOJw9UV8Y0=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 829C63858D37
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
b=Z6h+SEqHo7242DMRTe759DUXd7Uw/RPcBaMiiEihsvhm9GYgYFgX5ppas9ufIjijKXJW0LIUATHZZinkSO7JfJ+rEPCiVQ/bT4hGL8xbNKq/AQ0CrnXp8QtZP+lu0aWC6bM8D4cmWrCTbX1GR4VGby28oPTTjrjS88Pxl5MyHex54EsnPKd2hNk7NMDNEUx8C4ye3zs6weS5XkeGf/N+/tPvd6WugKfXgvzGTyITwpEp09qYuBV1HNMWme167M54aA4ZlaJhYE0UEU8fxX8Gkxc4D/frOcTAGkA3I9h1rMpSJKevB2UIXpdjfitgFwqNsaw86IOv/s+BuOn9hMARTg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;
s=arcselector9901;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
bh=oV91jkJpr1IXGY3t25v++KMRAdqygkH8JDh72iE+7qk=;
b=mNuIFP+Lk4ruEfmEbjyykb/hW6dE3LHeaMRdR+GkvTGHSm99LN+1G3TAL/bJwEGo1vRSphIBmP5G4nunGBv6tsirbtRbgnMAlSi9ghtIoTHGgO37bsjhKhHFQSYmHDtExHVValBfnEx3JHrYHsLVBF1qmg9VmF2XzRrf0syaLgKUZj53HLbtauyVjP0mnMZga3fMsjVO+YWxW/blS6VSH6Z6DT26J/sv0Tfjs+VzaGT76sAvA6rstL+hLZMMlitWQGp9ZryQq6NoWrjDZP8YHlC1mwweYk5FuUmdVZcF8dJddx0F/j7bM2W9+ylyQsLuIovvqi7O5SoW8v6Zj68eig==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
smtp.mailfrom=cornell.edu; dmarc=pass action=none header.from=cornell.edu;
dkim=pass header.d=cornell.edu; arc=none
Subject: Re: unhandled C++ exceptions not propagating
To: cygwin AT cygwin DOT com
References: <vritk0xzfpk6 DOT fsf AT gmail DOT com>
<20200816125306 DOT 60dc246baf63d7f9fba60611 AT nifty DOT ne DOT jp>
<6c27d8d6-876a-6c09-bccd-a9123400cfdb AT cornell DOT edu>
<20200816225221 DOT d7c41334927c9766d6e26415 AT nifty DOT ne DOT jp>
<84a15cee-d772-4422-9cf0-1cec8d188cae AT cornell DOT edu>
Message-ID: <70f23307-6aaf-db8a-103e-81303350ffec@cornell.edu>
Date: Sun, 16 Aug 2020 18:38:24 -0400
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101
Thunderbird/68.11.0
In-Reply-To: <84a15cee-d772-4422-9cf0-1cec8d188cae@cornell.edu>
X-ClientProxiedBy: MN2PR08CA0008.namprd08.prod.outlook.com
(2603:10b6:208:239::13) To MN2PR04MB6176.namprd04.prod.outlook.com
(2603:10b6:208:e3::13)
MIME-Version: 1.0
X-MS-Exchange-MessageSentRepresentingType: 1
X-Originating-IP: [68.175.129.7]
X-MS-PublicTrafficType: Email
X-MS-Office365-Filtering-Correlation-Id: d5a25b16-4fae-45c2-0cb0-08d84235175b
X-MS-TrafficTypeDiagnostic: MN2PR04MB5968:
X-Microsoft-Antispam-PRVS: <MN2PR04MB59686D86C8E5FE8A9AAE3480D85E0 AT MN2PR04MB5968 DOT namprd04 DOT prod DOT outlook DOT com>
X-MS-Oob-TLC-OOBClassifiers: OLM:2887;
X-MS-Exchange-SenderADCheck: 1
X-Microsoft-Antispam: BCL:0;
X-Microsoft-Antispam-Message-Info: w95dmz4N9/rmtkZ/pMVcYB2KrCr9RBERI/Uiz09X3gY4EobMDVyqa3789W0Si5rxozQU8NHdNEIMdkS4GGF2db5tRJXve/hsEtzgh/a64Wm3/GIuiySa0hm4aAywJt+ThTK/4dqg0CKkq2ftJyySnd1d/GmtIGJGFon8rCcHz2X8eullyFIKVbQVqm9sRg+QhxlJEP9bs+bok9JsmUb6T2ypacTz27ENXAoU9741loIv0L7CrHsZor1l1aqjjdkgznF9Rg1z7e3KIMpKIsZLGUunitqsNMV0D1ypQQPNDDlcif+jtGgbHpOG6CrJHIM8VODyyU9U4uZ508DVl58IOB8IPyL3erLDpgPlk9xLS1F6cQG+eLxFZvN2chlm3POvDud32XViSvszi3yjdRfd3WHVDRQLUIMpEFKGBasaEO6BS7wilDSk2VYGennoEiJPc4gAc8t+wrIQcvYZ/fqmdQ==
X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
IPV:NLI; SFV:NSPM; H:MN2PR04MB6176.namprd04.prod.outlook.com; PTR:; CAT:NONE;
SFS:(4636009)(396003)(39860400002)(376002)(136003)(346002)(366004)(66946007)(2906002)(16576012)(66556008)(66476007)(16526019)(75432002)(83380400001)(31696002)(966005)(186003)(8676002)(8936002)(4326008)(786003)(5660300002)(6916009)(316002)(36756003)(53546011)(66574015)(52116002)(19627235002)(478600001)(31686004)(86362001)(2616005)(26005)(6486002)(956004)(43740500002);
DIR:OUT; SFP:1102;
X-MS-Exchange-AntiSpam-MessageData: TF/e0PzbTx9M5u3U7EoO5xLxoitHvqzvJFnBQfweyRnCyMgEwpCD49/QCudRQCFi6a0fYAcGYFL9FM7HCjGM6UFDMwSHdb14M7n1OuwPSVX8Djcp3V6yXRVfIXf5/1aJfTbb6hHhTBJZrGojyoJhxAtMQBg9Wk7DpJY2f+WXt9xs1FqCuvvND3p7F8VXg2vt7yjiZWFP/LnFk74aC1pGwFBgIu/8C808VwJ3S7e6unWxdhAoRMv1E2GdUWmhkP5+bYltoZOK7hLa3jVGrwa0zWSc5BHyoEiy9ifg8L6qRrEDaDVvU1AWv37p2PduOnuLZOwpXl3V76uX9PIzXdtpNvB046pnfvRP8ntvcUm3giK/lSrI8LJ+cyoRA0xHmKWUyYAWIXOhl5sS602x1T+N0uvBVyRtLbvdBrjD01XwKFgV7RT6Bvd4xYt+jh/nlDNdLXjKhjSKLe9XFnNO+W/LfhD5F8T90UIxc5nXTVUPI+1EFyr+IFOWd/mtP6FZJYjtCfjcB4UB30TtVxqFXYud2PkCxpOkSUWiUB1busQnqNcMt8vIc4Xhv5j/8hUFABGsTbN924nZ4ts1bHf0Qo6VpKDkFj8HPmIc1XlweqwzqZw0m6EkKJQzndhbjfH3xH+P8Cwoueax2o8xRghVF/ds4w==
X-OriginatorOrg: cornell.edu
X-MS-Exchange-CrossTenant-Network-Message-Id: d5a25b16-4fae-45c2-0cb0-08d84235175b
X-MS-Exchange-CrossTenant-AuthSource: MN2PR04MB6176.namprd04.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Aug 2020 22:38:26.6827 (UTC)
X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted
X-MS-Exchange-CrossTenant-Id: 5d7e4366-1b9b-45cf-8e79-b14b27df46e1
X-MS-Exchange-CrossTenant-MailboxType: HOSTED
X-MS-Exchange-CrossTenant-UserPrincipalName: 8b9IiTotDvvDX0u1zCSoEijMsPK5DZWeczunXMtnUtpPIkzd53iKCgbJDNbhIy8b9sDShBCWOqg3Whytd3E6Tg==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR04MB5968
X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00, DKIM_INVALID,
DKIM_SIGNED, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, MSGID_FROM_MTA_HEADER,
NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS,
TXREP autolearn=no autolearn_force=no version=3.4.2
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on
server2.sourceware.org
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.29
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Ken Brown via Cygwin <cygwin AT cygwin DOT com>
Reply-To: Ken Brown <kbrown AT cornell DOT edu>
Cc: David McFarland <corngood AT gmail DOT com>
Errors-To: cygwin-bounces AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces AT cygwin DOT com>
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id 07GMd7sD019373

On 8/16/2020 10:56 AM, Ken Brown via Cygwin wrote:
> On 8/16/2020 9:52 AM, Takashi Yano via Cygwin wrote:
>> On Sun, 16 Aug 2020 09:21:24 -0400
>> Ken Brown via Cygwin <cygwin AT cygwin DOT com> wrote:
>>> On 8/15/2020 11:53 PM, Takashi Yano via Cygwin wrote:
>>>> On Sat, 15 Aug 2020 20:38:01 -0300
>>>> David McFarland via Cygwin <cygwin AT cygwin DOT com> wrote:
>>>>>
>>>>> I was just debugging a c++ app (b2 build system from boost), and noticed
>>>>> that it would appear to exit unexpectedly without an error.  This turned
>>>>> out to be when an unhandled C++ exception was thrown.
>>>>>
>>>>> On a fresh install of cygwin with gcc-g++, this program will throw an
>>>>> exception from the std::string constructor:
>>>>>
>>>>> c++ -x c++ - <<END
>>>>> #include <string>
>>>>> int main() { std::string str(nullptr); return 0; }
>>>>> END
>>>>>
>>>>> When it's executed from the shell it returns zero, but execution stops
>>>>> at the exception.
>>>>>
>>>>> $ ./a; echo $?
>>>>> 0
>>>>>
>>>>> When executed under gdb, the exception is caught, and the process exits
>>>>> non-zero when continued:
>>>>>
>>>>> (gdb) r
>>>>> Starting program: /home/corngood/a
>>>>> [New Thread 4300.0x1390]
>>>>> [New Thread 4300.0x1d24]
>>>>> [New Thread 4300.0x1d48]
>>>>> [New Thread 4300.0x80c]
>>>>> gdb: unknown target exception 0x20474343 at 0x7ff8d2cfa799
>>>>> Thread 1 "a" received signal ?, Unknown signal.
>>>>> 0x00007ff8d2cfa799 in RaiseException () from 
>>>>> /cygdrive/c/WINDOWS/System32/KERNELBASE.dll
>>>>> (gdb) c
>>>>> Continuing.
>>>>> [Thread 4300.0x1d24 exited with code 541541187]
>>>>> [Thread 4300.0x1870 exited with code 541541187]
>>>>> [Thread 4300.0x1d48 exited with code 541541187]
>>>>> [Thread 4300.0x1390 exited with code 541541187]
>>>>> [Inferior 1 (process 4300) exited with code 04021641503]
>>>>> (gdb)
>>>>>
>>>>> When executed under strace, it exits with an error as expected:
>>>>>
>>>>> $ strace -o /dev/null a; echo $?
>>>>> 67
>>>>>
>>>>> That's as far as I've investigated so far.
>>>>
>>>> Is this the same issue with
>>>> https://cygwin.com/pipermail/cygwin/2019-October/242795.html ?
>>>>
>>>> As far as I tested, this does not occur in 32-bit cygwin.
>>>
>>> This doesn't seem to be a new issue.  I found the following report from 6 years
>>> ago, on Cygwin 1.7.30 with GCC 4.9.0:
>>>
>>> https://stackoverflow.com/questions/24402412/program-executed-on-cygwin-does-not-report-a-thrown-exception 
>>>
>>
>> Thanks for the information. But I still wonder why 32-bit and 64-bit
>> cygwin behave differently.
> 
> I'm no C++ expert, but my understanding after a brief internet search is that an 
> uncaught exception is supposed to cause std::terminate to be called.  So I 
> installed gcc-debuginfo and ran the OP's test case under gdb with a breakpoint 
> at 'terminate'.  On 32-bit Cygwin I got the expected behavior:
> 
> Thread 1 "exception_test" hit Breakpoint 1, std::terminate ()
>      at /usr/src/debug/gcc-9.3.0-2/libstdc++-v3/libsupc++/eh_terminate.cc:96
> 96        __atomic_load (&__terminate_handler, &func, __ATOMIC_ACQUIRE);
> (gdb) bt
> #0  std::terminate ()
>      at /usr/src/debug/gcc-9.3.0-2/libstdc++-v3/libsupc++/eh_terminate.cc:96
> #1  0x57c45909 in __cxxabiv1::__cxa_throw (obj=obj AT entry=0x800396e8,
>      tinfo=tinfo AT entry=0x57c646a8 <typeinfo for std::logic_error>,
>      dest=0x57be6c60 <std::logic_error::~logic_error()>)
>      at /usr/src/debug/gcc-9.3.0-2/libstdc++-v3/libsupc++/eh_throw.cc:95
> #2  0x57c49223 in std::__throw_logic_error (
>      __s=__s AT entry=0x57c60160 <cplus_demangle_builtin_types+10272> "basic_string::
> _S_construct null not valid")
>      at /usr/src/debug/gcc-9.3.0-2/libstdc++-v3/src/c++11/functexcept.cc:66
> [...]
> 
> On 64-bit Cygwin, however, I got the behavior reported by the OP:
> 
> gdb: unknown target exception 0x20474343 at 0x7ff8cccca719
> 
> Thread 1 "exception_test" received signal ?, Unknown signal.
> 0x00007ff8cccca719 in RaiseException () from /c/WINDOWS/System32/KERNELBASE.dll
> (gdb) c
> Continuing.
> [Thread 4508.0x3e20 exited with code 541541187]
> [Thread 4508.0x5bc exited with code 541541187]
> [Thread 4508.0x5ee8 exited with code 541541187]
> [Thread 4508.0x1cd0 exited with code 541541187]
> [Inferior 1 (process 4508) exited with code 04021641503]
> 
> Note that the breakpoint at 'terminate' is not reached.  I tried putting a 
> breakpoint at __cxa_throw and stepping through from there, but I don't really 
> understand what's going on.  Someone who knows the innards of exception handling 
> will have to look at this.

One further comment, and then I'll shut up and leave it to people who know what 
they're talking about: In the 64-bit case, the function _Unwind_RaiseException 
in libgcc/unwind-seh.c gets called, and it calls the Win32 function 
RaiseException as follows:

   RaiseException (STATUS_GCC_THROW, 0, 1, (ULONG_PTR *)&exc);

Then the following comment appears:

   /* The exception handler installed in crt0 will continue any GCC
      exception that reaches there (and isn't marked non-continuable).
      Returning allows the C++ runtime to call std::terminate.  */

Apparently this doesn't actually happen.

Ken
--
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019