From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by sourceware.org (Postfix) with ESMTPS id 76BA63858C2C for ; Wed, 22 Dec 2021 15:26:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 76BA63858C2C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qt1-x82a.google.com with SMTP id f9so2227706qtk.4 for ; Wed, 22 Dec 2021 07:26:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:cc:date:message-id:mime-version :content-transfer-encoding; bh=NPc75GqmXfC6y6zm/vaovHepHOGs0BN0hgQWfDMKqq8=; b=SMYsRA2MpoQo58mP0TKfS1/Zl+aYcV1Iff/qoXQMdExbtxu/Dteh3moPkRxwp2Q1wV 5nRqnV8Z8AvsQsSa3VdMgydiqq/ln73K9dT1XvDVWOYkEBkvnGS4h3nkJz2rCvpd7kzx /zN4dxrqazJsk3ipoCwRf6hla1sRQQhMtOQ+8s9EC90X8f/kYVIhtGREF6FQqKh7SoYW saTlC0TyVduCWNb2DWA2VhEgIDm1gaOsBda5iLe2dDpm6XTEVA75x3MwwmCNii0zxNR0 t7mo2UtXN+WzSA3+nldDJWBx4EYe+hRcupsLEAf4dsLjwByKVH9SXdszerxfO4Xqps+3 5DyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:cc:date:message-id:mime-version :content-transfer-encoding; bh=NPc75GqmXfC6y6zm/vaovHepHOGs0BN0hgQWfDMKqq8=; b=E46M0DVivgSgKk6LbMLDCsnH9hqhtKTwrHnJdfBodu11n9W3Y+zpC2jDd8S9fKBaZT fAYdorrsDC/nEWS4nrGgFLcGHMcHS1eZeXSk7XjuN5dq+NTRXBVMwCAzTrm6EG6AjxWl rWV/PHqpFcVIIB8Hn80c8dPS0uJzJtESOIpHQ5KxCdSnlLNGLBtlK+cKtXrhmTTDVBUM R2phVDN79jBrJWFCoKD+18eFtkUYc43PFr9IY5o5/cbYZmAY64jDg0Of0m82Z+KxWa+F IKl5F4a/bBgonBSkJGn75Y+q+D3ZNyEjfBZo4lhasTsSfUQzT7cujVxlmg28pCxa2IcK 295w== X-Gm-Message-State: AOAM530ybbvk5Kpdv7rzyB48KSfovnz2A0q8IiVTG3tWkCrdjG4Dfz4a McfBns4rmwc7yxQvG/dManQ= X-Google-Smtp-Source: ABdhPJzSe6/NL2I8+gaR5PMQyonpxb2eH5LlU01S5zh6cEOR2DJKMN7T0DQuSvOhg8mbM9baUjXrMA== X-Received: by 2002:ac8:7b21:: with SMTP id l1mr2488180qtu.380.1640186817014; Wed, 22 Dec 2021 07:26:57 -0800 (PST) Received: from davidm-laptop (hlfxns018gw-134-41-172-106.dhcp-dynamic.fibreop.ns.bellaliant.net. [134.41.172.106]) by smtp.gmail.com with ESMTPSA id l15sm354947qkp.16.2021.12.22.07.26.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Dec 2021 07:26:56 -0800 (PST) From: David McFarland To: cygwin-developers@cygwin.com Subject: deadlock on console mutex in gdb CC: David McFarland , Takashi Yano Date: Wed, 22 Dec 2021 11:26:54 -0400 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: cygwin-developers@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component developers mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Dec 2021 15:26:59 -0000 I'm seeing a deadlock when using gdb on a process with a lot of console output and thread creation: Thread 1 (Thread 13016.0x2804): #0 0x00007ffca30ecdf4 in ntdll!ZwWaitForSingleObject () from /cygdrive/c/W= INDOWS/SYSTEM32/ntdll.dll #1 0x00007ffca0d91a5e in WaitForSingleObjectEx () from /cygdrive/c/WINDOWS= /System32/KERNELBASE.dll #2 0x0000000180071719 in fhandler_console::set_output_mode (m=3Dtty::cygwi= n, t=3D0x180000028, p=3D0x1803a3418) at ../../../../winsup/cygwin/fhandler_= console.cc:524 #3 0x0000000180079c6e in fhandler_console::write (this=3D0x1803a3218, vsrc= =3D0x800312dc0, len=3D26) at ../../../../winsup/cygwin/fhandler_console.cc:= 3115 #4 0x000000018014a022 in write (fd=3D1, ptr=3D0x800312dc0, len=3D26) at ..= /../../../winsup/cygwin/syscalls.cc:1360 #5 0x0000000180227349 in _write_r (ptr=3D0xffffd680, fd=3D1, buf=3D0x80031= 2dc0, cnt=3D26) at ../../../../../newlib/libc/reent/writer.c:49 #6 0x00000001801e8e0c in __swrite64 (ptr=3D0xffffd680, cookie=3D0x180273c7= 0 , buf=3D0x800312dc0 "[New Thread 11424.0x244c]\ne/c/cygw= in64/home/David_M/src/nix/test/bin/nix build -f nixpkgs/test --log-format r= aw -vvvvvvvvv\n", n=3D26) at ../../../../../newlib/libc/stdio64/stdio64.c:69 #7 0x00000001801d13cf in __sflush_r (ptr=3D0xffffd680, fp=3D0x180273c70 ) at ../../../../../newlib/libc/stdio/fflush.c:224 #8 0x00000001801d14d5 in _fflush_r (ptr=3D0xffffd680, fp=3D0x180273c70 ) at ../../../../../newlib/libc/stdio/fflush.c:278 #9 0x00000001801d8bbd in __sfvwrite_r (ptr=3D0xffffd680, fp=3D0x180273c70 = , uio=3D0xffffbbb0) at ../../../../../newlib/libc/stdio/fv= write.c:251 #10 0x00000001801d5026 in _fputs_r (ptr=3D0xffffd680, s=3D0x10097cdd5 "\n", fp=3D0x180273c70 ) at ../../../../..= /newlib/libc/stdio/fputs.c:107 #11 0x00000001801d509d in fputs (s=3D0x10097cdd5 "\n",= fp=3D0x180273c70 ) at ../../../../../newlib/libc/stdio/fp= uts.c:140 #12 0x00000001801a6beb in _sigfe () at sigfe.s:37 #13 0x0000000100716246 in fputs_maybe_filtered (linebuffer=3D, stream=3D0x8002f8910, filter=3D0) at /usr/src/debug/gdb-10.2-1/gdb/utils= .c:1828 #14 0x00000001007174db in vfprintf_styled_no_gdbfmt (stream=3D0x8002f8910, = style=3D..., filter=3D, format=3D, args=3D0xf= fffbe18 "") at /usr/lib/gcc/x86_64-pc-cygwin/10/include/c++/bits/basic_stri= ng.h:3360 #15 0x0000000100482e57 in cli_ui_out::do_message (args=3D0xffffbe18 "", for= mat=3D0x808ba1359 "]\n", style=3D..., this=3D0xffffbf30) at /usr/lib/gcc/x8= 6_64-pc-cygwin/10/include/c++/bits/stl_iterator.h:953 #16 cli_ui_out::do_message (this=3D0xffffbf30, style=3D..., format=3D0x808b= a1359 "]\n", args=3D0xffffbe18 "") at /usr/src/debug/gdb-10.2-1/gdb/cli-out= .c:227 #17 0x000000010070f21e in ui_out::call_do_message (this=3Dthis@entry=3D0xff= ffbf30, style=3D..., format=3D) at /usr/src/debug/gdb-10.2-1= /gdb/ui-out.c:597 #18 0x000000010070f9db in ui_out::vmessage (this=3Dthis@entry=3D0xffffbf30,= in_style=3D..., format=3D, format@entry=3D0x100970683 "[New %s]\n", args=3D0xffffc170 "\030", args@entry=3D0x= ffffc168 "8=C4=B5\t\b") at /usr/src/debug/gdb-10.2-1/gdb/ui-out.c:778 #19 0x000000010071634c in vfprintf_maybe_filtered (stream=3Dstream@entry=3D= 0x8002f8910, format=3Dformat@entry=3D0x100970683 "= [New %s]\n", args=3Dargs@entry=3D0xffffc168 "8=C4=B5\t\b", filter=3Dfilter@= entry=3Dfalse, gdbfmt=3Dgdbfmt@entry=3Dtrue) at /usr/src/debug/gdb-10.2-1/g= db/utils.c:2064 #20 0x00000001007154dc in vfprintf_unfiltered (stream=3D0x8002f8910, format= =3Dformat@entry=3D0x100970683 "[New %s]\n", args= =3Dargs@entry=3D0xffffc168 "8=C4=B5\t\b") at /usr/src/debug/gdb-10.2-1/gdb/= utils.c:2107 #21 0x0000000100715878 in printf_unfiltered (format=3D0x100970683 "[New %s]\n") at /usr/src/debug/gdb-10.2-1/gdb/utils.c:2218 #22 0x00000001006e1f86 in add_thread_with_info (targ=3Dtarg@entry=3D0x10089= 3b80 , ptid=3D..., priv=3Dpriv@entry=3D0x0) at /usr= /src/debug/gdb-10.2-1/gdb/thread.c:297 #23 0x00000001006e2023 in add_thread (targ=3Dtarg@entry=3D0x100893b80 , ptid=3D) at /usr/src/debug/gdb-10.2-1/gdb/thread.c:306 #24 0x000000010073906c in windows_add_thread (ptid=3D..., h=3D, tlb=3D, main_thread_p=3Dmain_thread_p@entry=3Dfalse) at = /usr/src/debug/gdb-10.2-1/gdb/windows-nat.c:451 #25 0x000000010073999c in windows_nat_target::get_windows_debug_event (this= =3Dthis@entry=3D0x100893b80 , pid=3Dpid@entry=3D-1,= ourstatus=3Dourstatus@entry=3D0xffffca28) at /usr/src/debug/gdb-10.2-1/gdb= /../gdbsupport/ptid.h:49 #26 0x0000000100739c72 in windows_nat_target::wait (this=3D0x100893b80 , ptid=3D..., ourstatus=3D0xffffca28, options=3D0) at /= usr/src/debug/gdb-10.2-1/gdb/windows-nat.c:1801 #27 0x00000001006d91cf in target_wait (ptid=3D..., status=3Dstatus@entry=3D= 0xffffca28, options=3Doptions@entry=3D0) at /usr/src/debug/gdb-10.2-1/gdb/t= arget.c:2017 #28 0x0000000100593c2e in do_target_wait_1 (inf=3Dinf@entry=3D0x800262c70, = ptid=3D..., status=3Dstatus@entry=3D0xffffca28, options=3D0, options@entry= =3D1) at /usr/src/debug/gdb-10.2-1/gdb/infrun.c:3544 #29 0x0000000100594058 in operator() (inf=3D0x800262c70, __closure=3D) at /usr/src/debug/gdb-10.2-1/gdb/infrun.c:3606 #30 do_target_wait (wait_ptid=3D..., ecs=3Decs@entry=3D0xffffca00, options= =3Doptions@entry=3D1) at /usr/src/debug/gdb-10.2-1/gdb/infrun.c:3619 #31 0x00000001005a1f26 in fetch_inferior_event () at /usr/src/debug/gdb-10.= 2-1/gdb/infrun.c:3905 #32 0x0000000100435d76 in check_async_event_handlers () at /usr/src/debug/g= db-10.2-1/gdb/async-event.c:295 #33 0x0000000100803522 in gdb_do_one_event () at /usr/src/debug/gdb-10.2-1/= gdbsupport/event-loop.cc:194 #34 0x00000001005c0a1d in start_event_loop () at /usr/src/debug/gdb-10.2-1/= gdb/main.c:356 #35 captured_command_loop () at /usr/src/debug/gdb-10.2-1/gdb/main.c:416 #36 0x00000001005c2b25 in captured_main (data=3D0xffffcb90) at /usr/src/deb= ug/gdb-10.2-1/gdb/main.c:1253 #37 gdb_main (args=3Dargs@entry=3D0xffffcbf0) at /usr/src/debug/gdb-10.2-1/= gdb/main.c:1268 #38 0x000000010087c3d9 in main (argc=3D9, argv=3D0xffffcc50) at /usr/src/de= bug/gdb-10.2-1/gdb/gdb.c:32 No other threads appear to be doing anything relevant. I believe the inferior process holds the mutex, but I haven't 100% confirmed that. I can't attach another debugger to it, so I'm not sure how I'd do that. It looks like gdb is getting a new thread event (and trying to log it) while the inferior process has a lock on the inter-process output mutex. I'm not sure how we'd avoid a deadlock in that case. I can reproduce this on 3.3.3 as well as master. The mutexes were added in: commit f4b47827cf87f055687a0c52a3485d42b3e2b941 Author: Takashi Yano Date: Mon Apr 1 00:47:48 2019 +0900 Cygwin: console: Make I/O functions thread-safe - POSIX states I/O functions shall be thread-safe, however, cygwin console I/O functions were not. This patch makes console I/O functions thread-safe.