From patchwork Fri May 22 00:16:22 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 135441 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5A43648F6651 for ; Fri, 22 May 2026 00:17:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5A43648F6651 X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by sourceware.org (Postfix) with ESMTPS id 5080C48F66CA for ; Fri, 22 May 2026 00:16:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5080C48F66CA Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5080C48F66CA Authentication-Results: sourceware.org; arc=none smtp.remote-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779408991; cv=none; b=jd9RexX8O5PZSq1QbRiaqeWCPBEBoP0wKlLGNu7ubo41KE/muojGfgHllVjJ58pELeW55mlNVLgidNcKh7Rdgr3sduk2amsFmKOsdILQqIq3ajaJOXLTKu98c6O6dRdFefAnZZc0n5SDkzG9I3IWl+Rn6czb4PI4ZMjsOyVKeSg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779408991; c=relaxed/simple; bh=sCa7IsrU8ug7tgTWXMJ+19FFfYTYUsYdyeIDrfup1sE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=MJmK7UYH/5LgWdT3Dhw+74Ngk+ZgIq7WPcDbiSYmywH3jBHStNxxIjXOjETYy/BcRJcfLAEIEVioyRCJXfVmSf7z5i3waNvQ0dJgOo+OXo4uC8pgDlKnMsqU6ZeA9BGnis5FNTZXCsCyqL2zazUQ+kp63GD5CHSB7Rg3G6U6R8E= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5080C48F66CA Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-45e6a4d0be0so2953321f8f.1 for ; Thu, 21 May 2026 17:16:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779408990; x=1780013790; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=qgrI5UuwPWAfRdSr735HAu2BwFuDCx0jt1Cy0B6W7T8=; b=CFxVMj5WBePJ2/usaZk1f7qgT6Gpg3b863Du6yTBKk9TcyiQaUVQjKDLYvE3aBU73x Ah+M55+ll08p5UuQjLk+R6WcKImcCQHeuzBqOTIVoluMzIDNGgqVdePuj1qGy+E7II9y /j/m22d7Q7OW/EGgzIZqx6+XfKecEJNefWQjx5UG4tLN+JEjtP/2m4aP8iOM8LApfj2J /Bw6YXlbtHJRCWf0Hr1MAA+jFN+9/40wkKsGc2SHGzrRB62xMtyr+P6W+GxYVhFG89ek MSt9ATb0oXHFAgxcp5SNOcJdY1E+sSRYCo47nkoHramg3zRZPxT92n3DSzCm3OQ4/712 XnYw== X-Gm-Message-State: AOJu0Yx7ZS+492txLfNwmRHklT9ustI8jkFd5VBdB9gPtndTit+Z9Y8P WXQvusohNLvsvq0flu27DnHUCTJNFgpAhrFmy9wWKTunVw6jy+owhULE1ANuZg== X-Gm-Gg: Acq92OH8oZ98RlRTIa90Uw5KRgBGuqBhnrTCyYhKdGa7eTTtEkupD8B1HFsJ7W2YSPD EisncmhDTqgJrrTUfa50tvOpzl6us8F3ncOZJwsCWsCgoGplhIlOaYXoqV/ebaB9msyF72/QEJB bObC/LJcwdt3DxiZCmmpf1puuMswFMly9kaJ4CEp6Ne0pmq13ISQ0p5cE1AvqtP6+Cr+kX1+LbL sakRlwkbUZs38F5feC9OVXSSX7fr97j255/nsOoGVciUhDTFdbFaesD2/r1RDKb/krMMyPMwCnj wDSQpM84+v1v3ldsT+jWRLtrcTWXmUpcyeTMZxhLMtkhrMQUjqICR05SrAZjQjURb4E9NRnIj+J o2CxC1jZHBlbOwgUyRd97y4286Z2JrpqtyxeaTcU0yoRdTogpV8yjkKqZHIRxAr0tDzvMs3u88u j9kkf+Luw44nGjGgvXVERTwA== X-Received: by 2002:a05:6000:41f0:b0:45e:9ea3:ce9a with SMTP id ffacd0b85a97d-45eb3688c81mr952834f8f.8.1779408990096; Thu, 21 May 2026 17:16:30 -0700 (PDT) Received: from localhost ([2001:8a0:fae3:2600:cb04:347e:aaad:ca08]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-45eb4982891sm966573f8f.16.2026.05.21.17.16.29 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 May 2026 17:16:29 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 1/5] Fix "set cwd ..." on Cygwin, part 1 Date: Fri, 22 May 2026 01:16:22 +0100 Message-ID: <20260522001626.393908-2-pedro@palves.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260522001626.393908-1-pedro@palves.net> References: <20260522001626.393908-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_NUMSUBJECT, POISEN_SPAM_PILL, POISEN_SPAM_PILL_1, POISEN_SPAM_PILL_3, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_PBL, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org When running gdb.base/exitsignal.exp on Cygwin, we see: (gdb) set cwd /cygdrive/d/cygwin-gdb/build-testsuite/outputs/gdb.base/exitsignal (gdb) run Starting program: /cygdrive/d/cygwin-gdb/build-testsuite/outputs/gdb.base/exitsignal/exitsignal Error converting inferior cwd: 28 (gdb) FAIL: gdb.base/exitsignal.exp: runto: run to main 28 is ENOSPC. But this isn't really literally no space left, though. cygwin_conv_path documentation mentions that error code. According to the Cygwin API documentation for cygwin_conv_path, the function fails with ENOSPC ("No space left on device") when the size of the destination buffer is smaller than what is required for the conversion. See: https://cygwin.com/cygwin-api/func-cygwin-conv-path.html If we look closely at how the buffer size argument is being passed, we see we have two problems here: 1) Incorrectly passing down the input buffer size instead of the output size. The code passes strlen(inferior_cwd) as the size of the destination buffer (infcwd). However, the target Windows path format (e.g. "D:\cygwin-gdb\..." in my case) could be longer or shorter than the POSIX source path ("/cygdrive/d/..."). In my specific case, the source string is 64 characters, while the target Windows string is 61 (wide) characters (and twice as many bytes). 2) Incorrectly passing character count instead of byte count The conversion target token is CCP_POSIX_TO_WIN_W. The _W means that the destination buffer infcwd takes wide characters (wchar_t). The documentation states that the size argument is in bytes, not characters. This commit fixes it, by passing the byte size of the destination buffer. Change-Id: I70af6ef394f48da35ccc2e04ef764915e09e59de commit-id: 66c930c2 --- gdb/windows-nat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index d506b42fbda..862568fa21e 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -2925,7 +2925,7 @@ windows_nat_target::create_inferior (const char *exec_file, if (inferior_cwd != NULL && cygwin_conv_path (CCP_POSIX_TO_WIN_W, inferior_cwd, - infcwd, strlen (inferior_cwd)) < 0) + infcwd, sizeof (infcwd)) < 0) error (_("Error converting inferior cwd: %d"), errno); args = (wchar_t *) alloca ((wcslen (toexec) + wcslen (cygallargs) + 2) From patchwork Fri May 22 00:16:23 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 135437 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B1FE048F52C1 for ; Fri, 22 May 2026 00:17:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B1FE048F52C1 X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by sourceware.org (Postfix) with ESMTPS id A27D148F66DC for ; Fri, 22 May 2026 00:16:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A27D148F66DC Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A27D148F66DC Authentication-Results: sourceware.org; arc=none smtp.remote-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779408993; cv=none; b=MSWD1dtX1DP7THjfy/vLoaHbUg4tbpBiaQ2WTE5i9+RlPuDPad12/1NIHuQRbjGZQ1HB/SCYXCEJaV64N2fsJ2+HNoHUPFw3c73240wlEFc6nGC4LFtlb2A8zONHcsKZ/GCR1h05tGzWbTS/3PawJIi0ijFyQlEYJEA7SSuHrhI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779408993; c=relaxed/simple; bh=zhCj2jYPrlMmnvTgAxhBK3mlGLmYtqPedGNdfaSUH/Q=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Tb/7Jd1gdglTxLdHeOnXckhjH9ARHqwSVEkVK3X7Nk98NF82AaX8KrI6LIKw+tlJBBQsy8a1f9vGPkGRn/78JU3Gaju1uAiWo34mCYKJ/Pr5+qg/AOX2BWIcexrUBKCUDAxoGgIoPL+N5bLL84zZicitU3+zr2j+CXXVwHdCO8c= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A27D148F66DC Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-48a563e4ef7so52869105e9.0 for ; Thu, 21 May 2026 17:16:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779408992; x=1780013792; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=OUYzLk69iaS+lwwNC84ALdpJwJKsqyVShDA++8NJdfQ=; b=VeodPcv/OpWgaJYYVm+meF/4hiqLrh62gPuVROmqcPtSl7XYxbBPALy/Qk1iN5K+sI FPGjl248wpc9Y7q4LMG501njhS9f14mlAr96CloPBbUSUC9lHzzXzaIA5sVZ6GVGSIT4 jjsXmldZQkSm+Fi9M/t2WB3PNlTILSlD6JPhmfVuolY5QDmEhkAEHABFfarwwIM9N9Ln lTTf26SIqPS/IyxlZC+cN4tSo/vImkziGFkQJi4QBBzysH2HXYLLqPhLFmHPztr3FboS 7bwdtyRWmrnW3+bHTr3EhDuliwPUvJSo0lZWJELa5sDn3GwSdsvn6r4FNDPh6X8u5Qst f/QQ== X-Gm-Message-State: AOJu0Yz6+mHyTSWGWIWxdRc0OsKAzgr9tvU0KJxykkbfPv9X1AvZwLQE 9NDshKN8BQa1tX4RxSkwe7jhvmdgOpPmuQg0G5U4ANZdWWY3DMK9NiAPRaIt2A== X-Gm-Gg: Acq92OGm4bWyGNgA2yrW16H8djVUkbk60m2dk0G1GQ6Q/nFAKwG6i2pduLJZ7VWaFEJ SzdvAJgPBcnP0THKXCeK3RP6m9EsvILs+dOZ66oylwpf84c8pbqdH59vTIJFL/pOKP6gpM3lZ5k JOEiX25fZBJhxorB9RuM70iMWD/tp2PR+BUESsepFFw7BGM7IzSkTSvt6qUY+KD8JSOYXHC9YKr +GRkG3lIpgFizy4mUv168nz0ORRDaYjoJgLIqadPdFgJP13Vrw9+mPKhKHLbkDMyTolklYuAJOO tob/hhSW37hOCf394GviTZQIlnIAx/v3piXhucBUIxUV/CBKOtdbtGQs3KE53XM4H1EmnoY5ORL iWhLFErwOxP9Hn74Jz0I4xjFxqNVcpNjgt6+0a3PDw/W3l9qIg5QZq0n0V6LJwGe/HPS/rLxUqy tiUsub+ADyBjavewmKPmz5aw== X-Received: by 2002:a05:600c:3547:b0:48f:e230:8cab with SMTP id 5b1f17b1804b1-49042adfb3fmr11846745e9.31.1779408992133; Thu, 21 May 2026 17:16:32 -0700 (PDT) Received: from localhost ([2001:8a0:fae3:2600:cb04:347e:aaad:ca08]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-49045282201sm6416565e9.8.2026.05.21.17.16.31 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 May 2026 17:16:31 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 2/5] Fix "set cwd ..." on Cygwin, part 2 Date: Fri, 22 May 2026 01:16:23 +0100 Message-ID: <20260522001626.393908-3-pedro@palves.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260522001626.393908-1-pedro@palves.net> References: <20260522001626.393908-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_NUMSUBJECT, POISEN_SPAM_PILL, POISEN_SPAM_PILL_1, POISEN_SPAM_PILL_3, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_PBL, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org Even after the previous patch, on both native and gdbserver Cygwin, we get: (gdb) set cwd /cygdrive/d/cygwin-gdb/build-testsuite/outputs/gdb.base/exitsignal (gdb) start Temporary breakpoint 3 at 0x100401094: file /home/alves/rocm/gdb/src/gdb/testsuite/gdb.base/segv.c, line 26. Starting program: /cygdrive/d/cygwin-gdb/build-testsuite/outputs/gdb.base/exitsignal/exitsignal.exe ❌️ Error creating process /cygdrive/d/cygwin-gdb/build-testsuite/outputs/gdb.base/exitsignal/exitsignal.exe (error 6): The handle is invalid. (gdb) On the native side, this is because in windows_nat_target::create_inferior, we unconditionally convert forward slashes to backward slashes: /cygdrive/d/cygwin-gdb/build-testsuite/outputs/gdb.base/exitsignal => \cygdrive\d\cygwin-gdb\build-testsuite\outputs\gdb.base\exitsignal and then cygwin_conv_path(CCP_POSIX_TO_WIN_W) does nothing on such path, as the backward slashes make the path not look like a Unix-style path. CreateProcess then fails to CD into that directory, as that's not a real Windows native path. The fix is to not do the slashes replacement on Cygwin. On the gdbserver side, we're just completely missing the cygwin_conv_path logic. This commit adds it. The code isn't shared with GDB because GDB uses wide chars, and gdbserver uses narrow char. Change-Id: I004f2a562757a566423f6acb9aecfcc1a7f2f746 commit-id: 85aa8c22 --- gdb/windows-nat.c | 14 ++++++++------ gdbserver/win32-low.cc | 30 +++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 862568fa21e..a284438bd36 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -2881,10 +2881,17 @@ windows_nat_target::create_inferior (const char *exec_file, else { expanded_infcwd = gdb_tilde_expand (inferior_cwd); + inferior_cwd = expanded_infcwd.c_str (); +#ifndef __CYGWIN__ /* Mirror slashes on inferior's cwd. */ std::replace (expanded_infcwd.begin (), expanded_infcwd.end (), '/', '\\'); - inferior_cwd = expanded_infcwd.c_str (); +#else + if (cygwin_conv_path (CCP_POSIX_TO_WIN_W, + inferior_cwd, + infcwd, sizeof (infcwd)) < 0) + error (_("Error converting inferior cwd: %d"), errno); +#endif } memset (&si, 0, sizeof (si)); @@ -2923,11 +2930,6 @@ windows_nat_target::create_inferior (const char *exec_file, flags |= DEBUG_PROCESS; } - if (inferior_cwd != NULL - && cygwin_conv_path (CCP_POSIX_TO_WIN_W, inferior_cwd, - infcwd, sizeof (infcwd)) < 0) - error (_("Error converting inferior cwd: %d"), errno); - args = (wchar_t *) alloca ((wcslen (toexec) + wcslen (cygallargs) + 2) * sizeof (wchar_t)); wcscpy (args, toexec); diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index 469ff32f070..6f1cf5ed025 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -448,9 +448,11 @@ static BOOL create_process (const char *program, char *args, DWORD flags, PROCESS_INFORMATION *pi) { - const std::string &inferior_cwd = get_inferior_cwd (); BOOL ret; size_t argslen, proglen; +#ifdef __CYGWIN__ + char infcwd_buf[PATH_MAX]; +#endif proglen = strlen (program) + 1; argslen = strlen (args) + proglen; @@ -458,6 +460,27 @@ create_process (const char *program, char *args, STARTUPINFOA si = { sizeof (STARTUPINFOA) }; char *program_and_args = (char *) alloca (argslen + 1); + const char *inferior_cwd = get_inferior_cwd ().c_str (); + std::string expanded_infcwd; + if (*inferior_cwd == '\0') + inferior_cwd = nullptr; + else + { + expanded_infcwd = gdb_tilde_expand (inferior_cwd); + inferior_cwd = expanded_infcwd.c_str (); +#ifndef __CYGWIN__ + /* Mirror slashes on inferior's cwd. */ + std::replace (expanded_infcwd.begin (), expanded_infcwd.end (), + '/', '\\'); +#else + if (cygwin_conv_path (CCP_POSIX_TO_WIN_A, + inferior_cwd, + infcwd_buf, sizeof (infcwd_buf)) < 0) + error (_("Error converting inferior cwd: %d"), errno); + inferior_cwd = infcwd_buf; +#endif + } + strcpy (program_and_args, program); strcat (program_and_args, " "); strcat (program_and_args, args); @@ -465,10 +488,7 @@ create_process (const char *program, char *args, program_and_args, /* command line */ flags, /* start flags */ NULL, /* environment */ - /* current directory */ - (inferior_cwd.empty () - ? NULL - : gdb_tilde_expand (inferior_cwd).c_str()), + inferior_cwd, /* current directory */ get_client_state ().disable_randomization, &si, /* start info */ pi); /* proc info */ From patchwork Fri May 22 00:16:24 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 135438 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EF8E148F60F6 for ; Fri, 22 May 2026 00:17:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EF8E148F60F6 X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by sourceware.org (Postfix) with ESMTPS id 792A848F665B for ; Fri, 22 May 2026 00:16:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 792A848F665B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 792A848F665B Authentication-Results: sourceware.org; arc=none smtp.remote-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779408995; cv=none; b=MSpBphix3Quutk4mYFhyPskMrcl+qBY9rU9CfHZKs1TEfwaxOAKRDyf2u/S7krSNyumh3j0MvbQ6FEeNQArc/X8UASW1pHufBxTqbyvCbQ0mKN1NdtanVD3wrvvpFFXCWvLo5YbHA8Ey5XSNizmj/3kim71csq+tF0fu56wCnq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779408995; c=relaxed/simple; bh=QHg5OeNep0/AYM7Qk/xXIzWz1LG2oH03NPQJOC9mRt8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=VdofuFceOdc0QC9cKuLa+6LtV6tTeYdxdXElf3/Z2/Ik3YaAd1Oqft9sBwyU76NsYjqRWCoJ+ZRnLJaasqjW2fHnBffHsgV/57OFA+1TITKnofMirP6aQipk4DTrrgsGNJD5t4uEnBGJ9vPQsBP1FHd5M1Py6PqtxKwUy2fy93M= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 792A848F665B Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4903d5c67bfso4848585e9.1 for ; Thu, 21 May 2026 17:16:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779408994; x=1780013794; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=GnDPWNM1q5J6fU6MDnAfdMuutyrofVXOmfDNcR2JGbE=; b=FHLzIxXdDsUCCXHGm2pCV3H1aVLdCtnWRnKZPFYKuvu3X31t2ICQooXK+S41w0/DtI hdhB/KE9jrGRqmNhoLEZVnJl2tCCa7XJpQeka2noniMYQ5OncPDaZUx7myRzJodpaXgr 1a8Y7sIpoxWuEQjtsifpauB26wHSBrc0XMlSi6q3xYVY4XIS2OaYqvR3iqIOwKHoHUqh rcYQ8t4dvmhb/KBdBOUI4+SUUA4gUjT2qeYxIqKFeYR4Si7opzzSIX3BS9oGQpdoFytg 1uY83Cf98gIVRdUV4MgrgqR4s71nsRvoyQGPw/Q+xVN8vwqRUDRe5Da9qQ/lix80qWwy oeSQ== X-Gm-Message-State: AOJu0Yy2ICvhZ9KwK4g6aTfJPQlQQqbbCr7W8NqUYfUZ4xLxqkfSVyYq jYZUGeTGZbx5vo45bbBDj+zdOtwmo/vNzElynwYcZYUsvgbF2VP+9nWjvsfaxA== X-Gm-Gg: Acq92OEY1m7SIMgyOfsbgn1yLfr9oesCVdLgXU7oB93Nk1WFwsxip5Zey3xrPLVh623 /sgiAUfinsoYmHknCUTbBV07v1JkrEiP+P+N4fdSZtCDcWCL0xve9TTq6RigLGPu6hkZZNbnXAG ZtPJtR3P/wqb7/5KUaYZOCW14pqk+n5d+qAcwSYHkAZ9lkiVnvS+TwnL8tPcvrS85lKGTLvsSEA BQ0sPdW/w30SBn3efVUxMz2oqqQbJt5T+pv+VjHyPNGMZgOrx9IEZkA0TMDo/2D2H9wSp9L1YJ0 icCHktlJ0uEYkAR2a5VbUEjvgebORdqLH1Yd3erCDeFuwevhw9IRsEkKrShGlScxTbIQC82ejOy CUCqhXQtgHcXZYsRUcH/CQZOH2e5r69zN4SwYFkjDqwUCAq2ZO7zm4YxlWANTOsHprbI3eRzvLE DN4Ni/dC6Kqs9eCOMLzoXhpQ== X-Received: by 2002:a05:600c:4fc9:b0:48a:93d2:60d2 with SMTP id 5b1f17b1804b1-4904225331amr11975115e9.0.1779408994261; Thu, 21 May 2026 17:16:34 -0700 (PDT) Received: from localhost ([2001:8a0:fae3:2600:cb04:347e:aaad:ca08]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-45eb4ae8fb5sm797211f8f.36.2026.05.21.17.16.33 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 May 2026 17:16:33 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 3/5] Adjust gdb.base/exitsignal.exp for Cygwin Date: Fri, 22 May 2026 01:16:24 +0100 Message-ID: <20260522001626.393908-4-pedro@palves.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260522001626.393908-1-pedro@palves.net> References: <20260522001626.393908-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-8.7 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_PBL, SPF_HELO_NONE, SPF_PASS, TXREP, WEIRD_PORT shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org Cygwin has this feature where if the program is about to die with a signal, and there's a debugger attached, it raises a SIGTRAP via DebugBreak. So if you try to pass a terminating signal to the inferior, you see that SIGTRAP first, before the process exits with the signal. E.g.: Thread 1 "segfault" received signal SIGSEGV, Segmentation fault. 0x0000000100401092 in main () at segfault.cc:5 5 *(volatile int *)0; (gdb) c Continuing. Thread 1 "segfault" received signal SIGTRAP, Trace/breakpoint trap. 0x00007ffe99d35a13 in KERNELBASE!DebugBreak () from C:/WINDOWS/System32/KERNELBASE.dll (gdb) bt #0 0x00007ffe99d35a13 in KERNELBASE!DebugBreak () from C:/WINDOWS/System32/KERNELBASE.dll #1 0x00007ffe896163b7 in break_here () at /usr/src/debug/cygwin-3.6.9-1/winsup/cygwin/dcrt0.cc:473 #2 0x00007ffe8962fe13 in try_to_debug () at /usr/src/debug/cygwin-3.6.9-1/winsup/cygwin/exceptions.cc:599 #3 exception::handle (e=0x7ffffc9b0, frame=, in=0x7ffffc4c0, dispatch=) at /usr/src/debug/cygwin-3.6.9-1/winsup/cygwin/exceptions.cc:812 #4 0x00007ffe9c5e63df in ntdll!.chkstk () from C:/WINDOWS/SYSTEM32/ntdll.dll #5 0x00007ffe9c499497 in ntdll!RtlLocateExtendedFeature () from C:/WINDOWS/SYSTEM32/ntdll.dll #6 0x00007ffe9c5e5d1e in ntdll!KiUserExceptionDispatcher () from C:/WINDOWS/SYSTEM32/ntdll.dll #7 0x0000000100401092 in main () at segfault.cc:5 (gdb) c Continuing. ... [Inferior 1 (process 8032) exited with code 05400] (gdb) gdb.base/exitsignal.exp fails on Cygwin partly because it doesn't take that into account. This commit fixes it. In addition, the typical adjustement for the fact that all programs are multi-threaded on Cygwin is also necessary. gdb.base/exitsignal.exp still won't pass cleanly yet. That'll be finally fixed in the next patch. Change-Id: I2d18e2604afe3a4f80987848e2c1cd307ed43401 commit-id: 013964ce --- gdb/testsuite/gdb.base/exitsignal.exp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gdb/testsuite/gdb.base/exitsignal.exp b/gdb/testsuite/gdb.base/exitsignal.exp index aa2710450b5..f1effcd8cea 100644 --- a/gdb/testsuite/gdb.base/exitsignal.exp +++ b/gdb/testsuite/gdb.base/exitsignal.exp @@ -50,7 +50,13 @@ gdb_test "print \$_exitcode" " = void" \ "\$_exitcode is void before running" # Trigger SIGSEGV. -gdb_test "continue" "Program received signal SIGSEGV.*" "trigger SIGSEGV" +gdb_test "continue" "(Thread .*|Program) received signal SIGSEGV.*" "trigger SIGSEGV" + +if {[istarget "*-*-cygwin*"]} { + # Cygwin calls DebugBreak before it lets the process exit. + gdb_test "continue" "Thread .* received signal SIGTRAP.*" \ + "trigger try_to_debug SIGTRAP" +} # Continue until the end. gdb_test "continue" "Program terminated with signal SIGSEGV.*" \ From patchwork Fri May 22 00:16:25 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 135439 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 39BBE48F536F for ; Fri, 22 May 2026 00:17:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 39BBE48F536F X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by sourceware.org (Postfix) with ESMTPS id 0B29D48F60CE for ; Fri, 22 May 2026 00:16:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0B29D48F60CE Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0B29D48F60CE Authentication-Results: sourceware.org; arc=none smtp.remote-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779408998; cv=none; b=gHHCE9SopSUUjJ8VCydeoaDFb7puSZA3DNH0eQWd1/rbDPccyhvXA4UqRAKjWYpncp5nLQCYpP822TOnFvvJxsfUkmTOL4HFh+IpihdlTvpB+o1EsO6vBHEznXBbyObY1ebuvQD6P+NeCNuI4l2bmRdNRQbGFuWvV+Y/6CZeINk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779408998; c=relaxed/simple; bh=79avVuj9z0/rTXR+gRHTelriPmaE6GTyp3H+RPR9uLg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=x0W1t5TidnkXVlMYLHj+GsaWLS1FMSX7WRcZeaOFMib9ygNw3/MeXmIpWGh2NDNAgZ7Zoo0xx7cpD9aZqElNXIXyzA0EazUOXY3CZRYAxq640Od4uNwJ4aqIBIOJ+hu9GUfb/dJj5quOSI1CmJpsFUdJmsV1kVPMEd7TSunxk9E= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0B29D48F60CE Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-49039a8851fso13106155e9.2 for ; Thu, 21 May 2026 17:16:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779408997; x=1780013797; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=xMEA4emqv+Wk/IurI4EGU3gCGGC7bXRlKSl07aetTCs=; b=eHDNas53eeUxJwZHqV2OJR5aauTdTlUSrUgcXRAdadUHC41KlnkjtKrxr6G6TKa8+l PbYD2azSS5laF+kDmZqPcCn8zSnAEktlAS+IE4Ydce8VQQujuJg2n70BC/mtYYit/5YQ wGwvSAfMg20ttTxT4o/tMYM1UM3hdTN/3kLg6obpy1zTCRVLARmkR30uY1bgJgOm1ga+ /xywFHPLfgi0/7ukSnKMm2zBhcBQcRCJEpisc2B4ByS+osAnw7eauOswl/BAJpFbAx10 CblvE0X0j3BGFpJJwgVD7PPb2GDGvOJ34Mnkao3VFMbSo4X+VOutp5VFpzlKXNgAOyDW 9sKg== X-Gm-Message-State: AOJu0YweKXy7Iiq/bmxB4g2SyzO1NkBgZ9YnExj389Sb/fzFMrSMtTqk Rj4i28THRpUXYKcPVeGydH4vphMxO4yC07mAG0kiRX0SM6lOr09qg311O1Y5+g== X-Gm-Gg: Acq92OGrBjkSX1aqsnRi2TFH10238H5PLEdzubo0VX3YYyXSBKeS2tY6hhwdVmWk3z9 ALnel8YP5mg3Ij8L1o/gjoDEm9UZ4eyOdU7Qti235SoH8Yhu+RQioTD9EmVdm8WbaX+FB7M93ri Eu+qa5klZ7YsMy73KOux3R+mbRfpT84YQpJZmM7wDMC6n8srbQBbamposXa2ceGaQykZqBUZIXI 74lYujasxgxFV36dptwaBcvSW0+UGJ83btPSy7Tef1P+dyDm1pflKujjHGNI0UM2Ak799lZJSXt t/LpFtlDt9GW8kAOx76h5yYMATNXKpPlJacdrRNmJPWbgeijes5Gr6HfGuueGLeLR2SrDHqkBrC vzXeSevnoHYLnjtEu8bUuX678RYiSM+T2Mgm6oH7Gye2WL9QZd83qvQykhbjON+TpXvB8GGLDab vsJKRAWYl/ZjJC5VE6mLDPPOOkRKg1bhaKbk1U7z6gZHI= X-Received: by 2002:a05:6000:4a05:b0:451:bee9:17c8 with SMTP id ffacd0b85a97d-45eb36b0275mr1133100f8f.6.1779408996789; Thu, 21 May 2026 17:16:36 -0700 (PDT) Received: from localhost ([2001:8a0:fae3:2600:cb04:347e:aaad:ca08]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-45eb4977c81sm862665f8f.11.2026.05.21.17.16.36 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 May 2026 17:16:36 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 4/5] Fix exit/signal code on Cygwin Date: Fri, 22 May 2026 01:16:25 +0100 Message-ID: <20260522001626.393908-5-pedro@palves.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260522001626.393908-1-pedro@palves.net> References: <20260522001626.393908-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-8.7 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_PBL, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org I noticed that on native Cygwin, gdb.python/py-events.exp has this: [Thread 15952.0x534 (id 1) exited with code 12] ... Program terminated with signal SIGSYS, Bad system call. ... (gdb) FAIL: gdb.python/py-events.exp: Inferior 1 terminated. The program exits with normal exit code 12, not a signal. SIGSYS is 12. Similarly, gdb.base/exitsignal.exp has this: continue Continuing. [Thread 15220.0x219c (id 1) exited with code 2816] [Thread 15220.0x3a50 (id 3) exited with code 2816] [Thread 15220.0x25a0 (id 4) exited with code 2816] [Inferior 1 (process 15220) exited with code 05400] (gdb) FAIL: gdb.base/exitsignal.exp: program terminated with SIGSEGV (the program exited) Here, the program exits with SIGSEGV, not normal exit code 2816 (05400 in octal). The problem is that gdb/windows-nat.c does not know about Cygwin's exit codes as seen from the native Windows side. Same for gdbserver's win32-low.c. This commit fixes it. To avoid duplicating code, it adds a new native_exit_code_to_target_status function in nat/windows-nat.c used by both GDB and GDBserver, with the MinGW-specific logic added by commit 559e7e5056 ("Improve process exit status macros on MinGW") moved there too. Change-Id: I5c4d9cd81209d46598575518ef2fd205d77f9b66 commit-id: 153617c2 Reviewed-By: Eli Zaretskii --- gdb/nat/windows-nat.c | 42 ++++++++++++++++++++++++++++++++++++++++++ gdb/nat/windows-nat.h | 4 ++++ gdb/windows-nat.c | 14 ++------------ gdbserver/win32-low.cc | 13 ++----------- 4 files changed, 50 insertions(+), 23 deletions(-) diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c index b093acda342..4c8c9ea32a8 100644 --- a/gdb/nat/windows-nat.c +++ b/gdb/nat/windows-nat.c @@ -18,6 +18,8 @@ #include "nat/windows-nat.h" #include "gdbsupport/common-debug.h" +#include "gdbsupport/gdb_signals.h" +#include "gdbsupport/gdb_wait.h" #include "target/target.h" #undef GetModuleFileNameEx @@ -694,6 +696,46 @@ windows_process_info::add_all_dlls () /* See nat/windows-nat.h. */ +target_waitstatus +native_exit_code_to_target_status (DWORD exit_code) +{ + target_waitstatus tstatus; + +#ifdef __CYGWIN__ + /* /usr/include/cygwin/wait.h explains that a wait status is 16 + bits, and looks like: + + "<1 byte info> <1 byte code> + == 0, child has exited, info is the exit value + == 1..7e, child has exited, code is the signal number. + == 7f, child has stopped, info was the signal number. + == 80, there was a core dump." + + However, when passing the wait status to native ExitProcess as a + native exit code, cygwin1.dll swaps the / bytes. + Swap them back into a wait status here. */ + int wstatus = ((exit_code & 0xff) << 8) | ((exit_code >> 8) & 0xff); + if (!WIFSIGNALED (wstatus)) + tstatus.set_exited (WEXITSTATUS (wstatus)); + else + tstatus.set_signalled (gdb_signal_from_host (WTERMSIG (wstatus))); +#else + /* If the exit status looks like a fatal exception, but we don't + recognize the exception's code, make the original exit status + value available, to avoid losing information. */ + int exit_signal + = WIFSIGNALED (exit_code) ? WTERMSIG (exit_code) : -1; + if (exit_signal == -1) + tstatus.set_exited (exit_code); + else + tstatus.set_signalled (gdb_signal_from_host (exit_signal)); +#endif + + return tstatus; +} + +/* See nat/windows-nat.h. */ + std::string event_code_to_string (DWORD event_code) { diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index 52378765438..1cabe288cee 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -347,6 +347,10 @@ struct windows_process_info int get_exec_module_filename (char *exe_name_ret, size_t exe_name_max_len); }; +/* Convert a native ExitProcess exit code to a target wait status. */ + +extern target_waitstatus native_exit_code_to_target_status (DWORD exit_code); + /* Return a string version of EVENT_CODE. */ extern std::string event_code_to_string (DWORD event_code); diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index a284438bd36..54755a4c996 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -62,7 +62,6 @@ #include "complaints.h" #include "gdbsupport/gdb_tilde_expand.h" #include "gdbsupport/pathstuff.h" -#include "gdbsupport/gdb_wait.h" #include "gdbsupport/symbol.h" #include "inf-loop.h" @@ -1610,17 +1609,8 @@ windows_nat_target::get_windows_debug_event } else if (windows_process->saw_create == 1) { - DWORD exit_status = current_event->u.ExitProcess.dwExitCode; - /* If the exit status looks like a fatal exception, but we - don't recognize the exception's code, make the original - exit status value available, to avoid losing - information. */ - int exit_signal - = WIFSIGNALED (exit_status) ? WTERMSIG (exit_status) : -1; - if (exit_signal == -1) - ourstatus->set_exited (exit_status); - else - ourstatus->set_signalled (gdb_signal_from_host (exit_signal)); + DWORD exit_code = current_event->u.ExitProcess.dwExitCode; + *ourstatus = native_exit_code_to_target_status (exit_code); thread_id = current_event->dwThreadId; diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index 6f1cf5ed025..23812c0689f 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -33,7 +33,6 @@ #include #include "gdbsupport/gdb_tilde_expand.h" #include "gdbsupport/common-inferior.h" -#include "gdbsupport/gdb_wait.h" using namespace windows_nat; @@ -1062,16 +1061,8 @@ get_child_debug_event (DWORD *continue_status, case EXIT_PROCESS_DEBUG_EVENT: { - DWORD exit_status = current_event->u.ExitProcess.dwExitCode; - /* If the exit status looks like a fatal exception, but we - don't recognize the exception's code, make the original - exit status value available, to avoid losing information. */ - int exit_signal - = WIFSIGNALED (exit_status) ? WTERMSIG (exit_status) : -1; - if (exit_signal == -1) - ourstatus->set_exited (exit_status); - else - ourstatus->set_signalled (gdb_signal_from_host (exit_signal)); + DWORD exit_code = current_event->u.ExitProcess.dwExitCode; + *ourstatus = native_exit_code_to_target_status (exit_code); } continue_last_debug_event (DBG_CONTINUE, debug_threads); break; From patchwork Fri May 22 00:16:26 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 135440 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8223048F5373 for ; Fri, 22 May 2026 00:17:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8223048F5373 X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by sourceware.org (Postfix) with ESMTPS id 33CD048F6659 for ; Fri, 22 May 2026 00:16:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 33CD048F6659 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 33CD048F6659 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779409000; cv=none; b=sj+pzVqWE8qMMujVU7wcnZMSeAfY71jbWNeChawxFMGJLZxdnNa3uMje/V31P0Yf7MsAkzddGmZfrD637k9K/xcNvq4r96ydWhA2OJlCe34r+clIaid1Ev3qv3+JSgyOfEtzdVuyyaR42XDY8rrurXCRqVXhBwWU+3S/ccRBOlA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779409000; c=relaxed/simple; bh=syHqas2lAYSpR8Ab2A3dMX/2hoAb3DzH4FiJCoz9ajc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=F+Hi7up88J1D706RZNlReptmT2vGT2U98Bf9esyfwTBoXwoyBYfzBrKDs7Nfves+6RoHicuClNV2ot72KgZMyvI3DtcLqge/zeUPQKaXPyZGhUSo4vLZble2Brv7UhBXfORpmLfMdWFzvStYGU6RDY7WcFO4GcW6zw+kSWjo/c4= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 33CD048F6659 Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-44e1ebb3122so4131620f8f.2 for ; Thu, 21 May 2026 17:16:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779408999; x=1780013799; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=kaY8hi3y29CjtTuME3dfffBIT8MGQ8chdKybPwYdooQ=; b=Kl/4DLWmY48NjrEGC+rvm8Ok1Z6xAeLgSjIQJNnI8zCS+N6gP+ii1CcL8XW6FKiQHO s9yGAvewZMyVqIelnVaT+86/iLtYFZUGC1UiXSOZoxwxKM4O5qTyMkN72EngTixcAJRI +Hm5K4HTqOpTkS9F1FzFvlMpO/M6toN8vKTJA/+xK2hgVqeIUYCMjzU3ijHfuuWMTwV3 HEj4YMeB46TyKxqAdG+hQH8XQGr5GUBZXeT4h9NRdQO6T51De8XnQDYYHVDFqlKUcErQ HOTfkcvjh7K8HtDBOzHzBIZ831MeS1qzN+SlVlHZslT5JMyrfMIlv6ChtHFfzqeDAuPg +T8g== X-Gm-Message-State: AOJu0Ywyp+xT/7pjpcxNWBSpPNWlbHmyVzRzOBwDlqe2aMSlWwkB3Ajf wr7Q0JXuZWqN0yiZxekjsl5KtkczySUapwCSNczeuVCdyp5MFHedQn0/dMEaag== X-Gm-Gg: Acq92OEsccS1MUfabywq0jT1DXWDlfa64h17FqU1fGONhCWDMwFv2Db0+5aFfyeml8G b6FxtkFN+Dz284+tQFna4C7BOkjgOnojUAG4KqyQ9mFzq1wtdKiUiiMwIjXLq3CMlH9euRb4OBp ZASsapjzOyAHOxekRxtzb2UIHRpNGer5U7g6w53M48WJISo2gfkUe+XJ8sJJzqpAn2ignHNVNDD S5ztEFjd6cyC/qoCOowSt5H8431L+MCEVSDRE0e66ox/XEPkgrwIoT310IeVK2l02g7siIQ+eBB oq8G9cIG7eJHqHVzc0CVbNw99z6YxGhsJletQpZk5yhgDtUp+4x/pTOF8BZ1mrKp8fDKwqtGQZb NDVYGZL4XCeAq5NCDMK4lFOrVm/q0l2HnuoUY8F8AezS0jY3oxQ6itvjzW3VZZY+oZxhLoZjc9P lXfkr5zTh3F4sh5xUUOh0BXg== X-Received: by 2002:a05:6000:2481:b0:43c:d665:3830 with SMTP id ffacd0b85a97d-45eb39e963bmr1356869f8f.32.1779408998994; Thu, 21 May 2026 17:16:38 -0700 (PDT) Received: from localhost ([2001:8a0:fae3:2600:cb04:347e:aaad:ca08]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-45eb497810dsm862965f8f.15.2026.05.21.17.16.38 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 May 2026 17:16:38 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 5/5] Adjust gdb.python/py-events.exp for Cygwin/MinGW Date: Fri, 22 May 2026 01:16:26 +0100 Message-ID: <20260522001626.393908-6-pedro@palves.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260522001626.393908-1-pedro@palves.net> References: <20260522001626.393908-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-8.7 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_PBL, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org This commit fixes several issues in gdb.python/py-events.exp for Cygwin and MinGW. With these fixed, the testcase passes cleanly on Cygwin. I haven't tested on MinGW, but at least the test should be able to compile & run there now. 1) - GDB prints Windows thread IDs in hex: (gdb) thread [Current thread is 1 (Thread 9528.0xa9c)] The corrent code assume decimal, so we only (incorrectly) extract the "0" after the dot. 2) - Thread and process ID number spaces are different. The current code assumes that the extract thread is is the same number as the extracted process id, which is not true on Windows. 3) - there is no "info proc" command on Windows The testcase is using "info proc" to extract the inferior's process it. But "info proc" does not exist on all targets, including Windows. Switch to using "inferior" instead. 4) - The testcase uses fork, and relies on "set detach-on-fork off" There is fork on Cygwin, but GDB can't follow forks there, so "detach-on-fork off" has no effect. And also, there is no fork on native Windows, which makes the testcase unusable on MinGW currently. I don't see any reason the testcase needs to use fork or multiple inferiors: - To test the clear_objfiles event, test a more directed "file" command instead of testing that following a fork emits it. - There's a test that quits gdb while some inferiors are being debugged, and it test that GDB emits gdb.ExitedEvent with no 'exit_code' attribute. Quitting while an inferior is being debugged makes GDB kill the inferior. So what that is really being tested is that killing an inferior emits such an event. So write such an explicit test. Also tested on x86_64-unknown-linux-gnu. Change-Id: I21ee8af7b52653c6fdff9b4c1596cdde3cfe751a commit-id: de2bf164 --- gdb/testsuite/gdb.python/py-events.c | 3 -- gdb/testsuite/gdb.python/py-events.exp | 73 ++++++++++++++------------ 2 files changed, 40 insertions(+), 36 deletions(-) diff --git a/gdb/testsuite/gdb.python/py-events.c b/gdb/testsuite/gdb.python/py-events.c index b1910f75ed9..6a0b407042a 100644 --- a/gdb/testsuite/gdb.python/py-events.c +++ b/gdb/testsuite/gdb.python/py-events.c @@ -15,12 +15,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include - extern void do_nothing (void); int second(){ - fork() ; return 12; } diff --git a/gdb/testsuite/gdb.python/py-events.exp b/gdb/testsuite/gdb.python/py-events.exp index 16a290c31c2..5a40ee4ac97 100644 --- a/gdb/testsuite/gdb.python/py-events.exp +++ b/gdb/testsuite/gdb.python/py-events.exp @@ -45,8 +45,6 @@ gdb_breakpoint "main" {temporary} gdb_test "run" ".*event type: new_objfile.*new objfile name.*" "new objfile notification" -gdb_test_no_output "set detach-on-fork off" "" - gdb_test "test-events" "Event testers registered." gdb_breakpoint "first" @@ -76,17 +74,23 @@ delete_breakpoints # Test inferior call events set process_id "invalid" +set thread_id "invalid" gdb_test_multiple "thread" "get current thread" { -re -wrap "process ($decimal).*" { set process_id $expect_out(1,string) + set thread_id $process_id pass $gdb_test_name } -re -wrap "Thread $hex \\(LWP ($decimal)\\).*" { set process_id $expect_out(1,string) + set thread_id $process_id pass $gdb_test_name } - -re -wrap "Thread $decimal\.($decimal).*" { + -re -wrap "Thread ($decimal)\.($hex|$decimal).*" { set process_id $expect_out(1,string) + set thread_id $expect_out(2,string) + # Convert from hex to decimal. + set thread_id [expr {$thread_id}] pass $gdb_test_name } } @@ -99,9 +103,9 @@ gdb_test_multiple "print do_nothing" "get address of do_nothing" { } set expected [list "event type: pre-call"] -lappend expected "ptid: \\($process_id, $process_id, 0\\)" "address: $addr" +lappend expected "ptid: \\($process_id, $thread_id, 0\\)" "address: $addr" lappend expected "event type: post-call" -lappend expected "ptid: \\($process_id, $process_id, 0\\)" "address: $addr" +lappend expected "ptid: \\($process_id, $thread_id, 0\\)" "address: $addr" gdb_test_sequence "call do_nothing()" "" $expected # Test register changed event @@ -202,7 +206,7 @@ gdb_test_no_output "delete $second_breakpoint" #test exited event. proc get_process_id {test} { global gdb_prompt - gdb_test_multiple "info proc" $test { + gdb_test_multiple "inferior" $test { -re "process (\\d+).*$gdb_prompt $" { set process_id $expect_out(1,string) pass $gdb_test_name @@ -211,24 +215,13 @@ proc get_process_id {test} { return ${process_id} } -set process_id [get_process_id "get inferior 1 process id"] +set process_id [get_process_id "get inferior process id"] gdb_test "continue" ".*event type: continue.* -.*clear_objfiles\[\r\n\]*progspace: .*py-events.* .*event type: exit.* .*exit code: 12.* .*exit inf: 1.* .*exit pid: $process_id.* -dir ok: True.*" "Inferior 1 terminated." - -gdb_test "inferior 2" ".*Switching to inferior 2.*" -set process_id [get_process_id "get inferior 2 process id"] -gdb_test "continue" ".*event type: continue.* -.*event type: exit.* -.*exit code: 12.* -.*exit inf: 2.* -.*exit pid: $process_id.* -dir ok: True.*" "Inferior 2 terminated." - +dir ok: True.*" "inferior terminated" # Test before_prompt event. gdb_test_multiline "define new user command" \ @@ -280,29 +273,30 @@ with_test_prefix "inferior continue exit" { gdb_test "print \$_foo" "= 2" "check foo after start continue" } -# Check that when GDB exits, we see gdb.ExitedEvent objects with no -# 'exit_code' attribute, and that a gdb.GdbExitingEvent is emitted. -with_test_prefix "gdb exiting: normal" { +# Check that when GDB kills an inferior, we see gdb.ExitedEvent +# objects with no 'exit_code' attribute. +with_test_prefix "kill inferior" { + if {![runto_main]} { + return + } gdb_test "test-exiting-event normal" "GDB exiting event registered\\." + gdb_test "with confirm off -- kill" \ + "event type: exit\r\nexit code: not-present\r\nexit inf: $decimal\r\nexit pid: $decimal\r\ndir ok: False\r\n.*" \ + "exit code not present" +} + +# Check that when GDB exits, we see that a gdb.GdbExitingEvent is +# emitted. +with_test_prefix "gdb exiting: normal" { set saw_exiting_event 0 - set saw_inferior_exit 0 - gdb_test_multiple "quit" "" { - -re "Quit anyway\\? \\(y or n\\) $" { - send_gdb "y\n" - exp_continue - } + gdb_test_multiple "with confirm off -- quit" "quit" { -re "event type: gdb-exiting\r\nexit code: $decimal" { incr saw_exiting_event exp_continue } - -re "event type: exit\r\nexit code: not-present\r\nexit inf: $decimal\r\nexit pid: $decimal\r\ndir ok: False\r\n" { - incr saw_inferior_exit - exp_continue - } eof { gdb_assert { $saw_exiting_event == 1 } - gdb_assert { $saw_inferior_exit == 2 } pass $gdb_test_name } } @@ -348,3 +342,16 @@ with_test_prefix "gdb exiting: error" { } } } + +# Test clear_objfiles event. + +with_test_prefix "clear_objfiles" { + clean_restart ${testfile} + + gdb_test_no_output "source ${pyfile}" "load python file" + gdb_test "test-objfile-events" "Object file events registered." + + gdb_test "with confirm off -- file" \ + "event type: clear_objfiles\r\nprogspace: None\r\n.*" \ + "file cleared" +}