From patchwork Mon May 25 19:18:19 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 135625 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 B04C54BABF39 for ; Mon, 25 May 2026 19:19:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B04C54BABF39 X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) by sourceware.org (Postfix) with ESMTPS id 6524A4BA23C4 for ; Mon, 25 May 2026 19:18:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6524A4BA23C4 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 6524A4BA23C4 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779736716; cv=none; b=J9/pjsM3E+87YMjUXv68ePnqCOdZ3Kg4WH6pkWtPT8Wm/2jQhpAbfi6U0KYxwEeoQYjMQhnBjMP0j9UyoReiitU02104Ne7igswDOzSsoX8lGn8wuEQLJ/KOAzDyXxZAwxBr1iydPpFE95dHbCzOEHSuo51orotP6MoJtlrARgw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779736716; c=relaxed/simple; bh=Mem6+J8deZuK006GGyyVH+VQatCH59k6sVmX7yOed9c=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=YRb3PM7HSvoT4HPwXGbxaUOyySjchBlyRTOgOpINWB8EBxpJjvem6jgOEZSJxEBGgJ75ac7O9JUxXeYTv1DEskQ3wJTWVaqTKNkaSPD3g0PV0j+0MQiKIi4FmeqzDy/fS4rd4dmpg/q7iY/3HkEK3p7nyxmDDGSAkEvGPNZtFB0= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6524A4BA23C4 Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-43d77f6092eso5623339f8f.2 for ; Mon, 25 May 2026 12:18:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779736715; x=1780341515; 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=OX9J6tAxXKrG5Twz/WphNqxiLQ1CwWk1OJRCvewLmGA=; b=fWftI21rw9B6F/WsPuQGvQxaHUsIf4KAZzm9ua7TDsBn9ZwZEUIq7WirSiZ4vyd8e3 lgLUHsKyuV0QBHyyoJvqtA67e7sSvI3UzRsLs1htrPM05sm7N89WQCxWYsv9pJ7HOsBV z1oWmIyYSJdHCa2Q9JrSVo4fghxeHZQT3A8lJfmCx9jfeH/Cz7kzB0wkVu8y0aai4PpS xbfx/9rs06ZEHuPcnI4zZq0aha0xi2NBxcjvLR8be0ew5yvVmQj4NDuMQOHrTJR2gQDI sh5yYaYw1hr6xFXLbwcSZuGb/YRaoP4PfBmh3tfJ5tRNvIErJJKvws7dnAS5R0ckfKyr XsDQ== X-Gm-Message-State: AOJu0YyKUM65bpG9VCNzeeK7moQRkzJcM6Nxxiu5+xWWadJs1T5o8Xlj yGql91mSYuHdqwiHQ3fz309srqEv+P9QomszQjoSnkLdibGGL02CS5QnR+T8Uw== X-Gm-Gg: Acq92OHXQisTXKd81dtmPrQnvaHA3KO9ZCiDhMx7woqsOGLTjJSs1b5zbhJJaUtURki y27sClOvmlG2ovCJU43iKRR5vnuCcSA6pqhlbUAiB0e+w7SxSyLcGR73nwiPmHpoyFHiyPtdmCE joTEbWTeq92ULodds97W6A7LsiufzBEH0niKTuxK2KR45JYN1RpujBH/tzy6yNjK+aHb+Ci4CqH yQo31nwMxl3PzkFxLVh8rxaDojWZ/yW92GIojmF6IBoDfDAg4EGBTeuwSIBuQ26+GpqkmDZ/Gd5 ykqXyM2Avzd6POzmHlJVr/C4p/DeECj+M1P1RT+5AqylUCpBsgCH9oYtolq5KW81ucyAa7zAHAM uj69dw3cvmGYCOhT2LRV54SGtce1L9fN56pCu7IDfCXb4kYJvkq1wgOsNGmDg/M6pVF+YY/o3qo EKGrVHiJWi9xtYIMUBzkJ7CQ== X-Received: by 2002:a05:6000:4606:b0:44b:cb31:b767 with SMTP id ffacd0b85a97d-45eb38bdf65mr26613486f8f.36.1779736715222; Mon, 25 May 2026 12:18:35 -0700 (PDT) Received: from localhost ([2001:8a0:fae3:2600:dc16:ec0f:632c:5ba7]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-45eb6d64eb1sm32971235f8f.32.2026.05.25.12.18.34 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 May 2026 12:18:34 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 01/11] Adjust gdb.base/exitsignal.exp for MinGW, trigger fault Date: Mon, 25 May 2026 20:18:19 +0100 Message-ID: <20260525191829.984105-2-pedro@palves.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260525191829.984105-1-pedro@palves.net> References: <20260525191829.984105-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-8.8 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 gdb.base/segv.c uses raise(SIGSEGV) to generate a SIGSEGV. On native Windows that does not generate an EXCEPTION_ACCESS_VIOLATION; raise is a pure userspace construct: it dispatches to the registered SIGSEGV handler if there is one, otherwise calls abort. GDB therefore never sees an exception to intercept. E.g.: ... continue Continuing. [Thread 1908.0x3308 (id 2) exited with code 3] [Inferior 1 (process 1908) exited with code 03] (gdb) FAIL: gdb.base/exitsignal.exp: trigger SIGSEGV (the program exited) continue The program is not being run. ... Replace the raise with a real null dereference so the kernel actually raises an access violation. Note: I confirmed no other tests use segv.c. segv.c and normal.c are both "owned" by gdb.base/exitsignal.exp. Change-Id: Ib54d9e6998cf9bfc18dcb5e76d31a9deb0458da4 commit-id: 86fcf2ce --- gdb/testsuite/gdb.base/segv.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/gdb/testsuite/gdb.base/segv.c b/gdb/testsuite/gdb.base/segv.c index a3db6d292db..fd43d95e9b2 100644 --- a/gdb/testsuite/gdb.base/segv.c +++ b/gdb/testsuite/gdb.base/segv.c @@ -17,13 +17,11 @@ /* This test can be used just to generate a SIGSEGV. */ -#include - int main (int argc, char *argv[]) { /* Generating a SIGSEGV. */ - raise (SIGSEGV); + *(volatile int *) 0; return 0; } From patchwork Mon May 25 19:18:20 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 135629 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 9755D4BA7982 for ; Mon, 25 May 2026 19:19:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9755D4BA7982 X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by sourceware.org (Postfix) with ESMTPS id BABDF4BA79A7 for ; Mon, 25 May 2026 19:18:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BABDF4BA79A7 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 BABDF4BA79A7 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779736720; cv=none; b=bnyWFib/hSApOPiHYnCkzP9RxSdp5y8K4P2ujwouodOPwBfH/8USCgq1NWaeh/oFUef3ugOBIl3Wgknt86ZnB1PXtcEuAiWfGNgq2sgmu1Bf7kI/vHY8iU5GajTJNoAjQdSl3WTu26DFM0Xl6lbNxiuMo04m025mJa/g9nVxcDE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779736720; c=relaxed/simple; bh=JkQBqua09L3/oD0ArLq6+j2hsbfYSrv0LB0qGT3+vhY=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=W5o+V4UQh9uL9GBgnSN5nYBNK0LtS1MZH1juC/gXpQXWxgyCMMDidrXzyEb+0S20ivzvoMWdExZNiwyzLyjLhUIO9JIS6xpo9Ehhab9LCWO/yljvWHW7i4gR7c2Z4Ei3Y3eAjk5goVdC5lAZXC1w505ubj1Nc7QC46bbhWS3XLE= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BABDF4BA79A7 Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4896c22fcbaso83239565e9.0 for ; Mon, 25 May 2026 12:18:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779736720; x=1780341520; 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=AFs82120LrTgeK7dqja1srAiqsB4Eb0fXbQpF+IC4tk=; b=gpZfUeoQGG9t5Rmc69XoD/e05epRbdTaSkGadM6OTHynhHc9XIMM++CAZ6qvVUGv1x //jOCFFVDemGUx/PKN5CP8HjIaQP8333Io56vvBLgaFnAD2PDuoygNrlpLLqSBd5o30L bk888z2xcUwbXA8II08MJ3YwT8QKa6ZwZMz62K9PXkOV42Yhl5rSzhE6kISXEyYom3Rt aCoWOfaGrq/TJxmex8f4I7XCwVhcW5Mkl7AuA6XAXhT0TYb5e50ulKm1+17Cz17gUeov bl+RK785K4yBMJIAcN2BO7iuSMmbEaAQa+E7+WU5D16gR96mUNAicw5XwiyrbTgHZxwP joow== X-Gm-Message-State: AOJu0Yz4+bL7hMBJ9vB7FMPbyt1f9i/svfYat1zC0ZDXBO2KQDE72oXo LkVmWyce7nAXEC72wacjuzVqgLywst5H4d+zp1cKUXK/hQU1IuE4tzOnQq+tmA== X-Gm-Gg: Acq92OGUUbMeRE6BKO3MmAhNYTfxXtkXSGzHq+2ek6ddwiVKHk3iduPx9iOZz43b+nJ ZzgAzuyGgE8vrnZ/7fMjjdMpjmE6YlLbEL1FYZNyAJP0JfbS9P69iuIFMe+LObjZMQueHBzjMkY bl+SgMNpLIfahcKO828r8pLMOK6KYnL823xcngURF0wYKrVKZRJ4bUm9/LxSOAgiISCcfD8zUNP ImaRnA00fjoPMrSE8uqiE/AKMRcFjYLXM9gXCTs+YvH8U772w0MRn2YQPV7kWrt+MTjxrcvgPRW PuLU5X5Qyo2nryknu9N5boI/2NiE1HoYpGZuSaXXl44wZJ14PgVCvZzM1o52BKl1KSnMWbInhfy 2crnMkstihZPy0p5YARukUlHBNc+ESu03zBAQxavuedv+sr55Yt7rufqZy+mL9SEO4NP37aAhnu O8UKuIa6dyGhy5U2zSrfi0UA== X-Received: by 2002:a05:600c:1392:b0:490:46bf:17ab with SMTP id 5b1f17b1804b1-49046ce6026mr243647965e9.29.1779736719341; Mon, 25 May 2026 12:18:39 -0700 (PDT) Received: from localhost ([2001:8a0:fae3:2600:dc16:ec0f:632c:5ba7]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-490428ee444sm93772685e9.24.2026.05.25.12.18.38 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 May 2026 12:18:39 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 02/11] Adjust gdb.base/exitsignal.exp for MinGW, second-chance SIGSEGV Date: Mon, 25 May 2026 20:18:20 +0100 Message-ID: <20260525191829.984105-3-pedro@palves.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260525191829.984105-1-pedro@palves.net> References: <20260525191829.984105-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_BLOCKED, 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 On native Windows a segmentation fault is delivered as a SEH exception, so GDB stops twice: once for the first-chance exception, and -- if no SEH handler in the inferior catches it -- again for the second-chance exception, after which the process dies. The testcase currently continues only once, resulting in: ... continue Continuing. Thread 1 received signal SIGSEGV, Segmentation fault. 0x00007ff765ac1469 in main (argc=1, argv=0x9f2640) at C:/rocgdb/src.cascais-rsync/gdb/testsuite/gdb.base/segv.c:24 24 *(volatile int *) 0; (gdb) PASS: gdb.base/exitsignal.exp: trigger SIGSEGV continue Continuing. Thread 1 received signal SIGSEGV, Segmentation fault. 0x00007ff765ac1469 in main (argc=1, argv=0x9f2640) at C:/rocgdb/src.cascais-rsync/gdb/testsuite/gdb.base/segv.c:24 24 *(volatile int *) 0; (gdb) FAIL: gdb.base/exitsignal.exp: program terminated with SIGSEGV ... Add a second continue on MinGW to step past the second-chance stop. With this, gdb.base/exitsignal.exp passes cleanly on MinGW: -FAIL: gdb.base/exitsignal.exp: program terminated with SIGSEGV +PASS: gdb.base/exitsignal.exp: trigger SIGSEGV, second-chance +PASS: gdb.base/exitsignal.exp: program terminated with SIGSEGV Change-Id: Ibda1540a602b62c26a5b218d930402eccc3ba98f commit-id: 385755c8 --- 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 5099ae1a1d6..341197cf0c8 100644 --- a/gdb/testsuite/gdb.base/exitsignal.exp +++ b/gdb/testsuite/gdb.base/exitsignal.exp @@ -53,7 +53,13 @@ gdb_test "print \$_exitcode" " = void" \ gdb_test "continue" "(Thread .*|Program) received signal SIGSEGV.*" \ "trigger SIGSEGV" -if {[istarget "*-*-cygwin*"]} { +if {[istarget "*-*-mingw*"]} { + # We're debugging a pure Win32 program with no SEH handler. The + # previous continue caught the first-chance exception. Now we + # catch the second-chance. + gdb_test "continue" "Thread .* received signal SIGSEGV.*" \ + "trigger SIGSEGV, second-chance" +} elseif {[istarget "*-*-cygwin*"]} { # Cygwin calls DebugBreak before it lets the process exit. gdb_test "continue" "Thread .* received signal SIGTRAP.*" \ "trigger try_to_debug SIGTRAP" From patchwork Mon May 25 19:18:21 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 135626 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 4C0144BA23F9 for ; Mon, 25 May 2026 19:19:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4C0144BA23F9 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 370EC4BA7992 for ; Mon, 25 May 2026 19:18:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 370EC4BA7992 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 370EC4BA7992 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=1779736723; cv=none; b=Nc1PXhlC6OfIzjsbv8hRQxEBoIZEAjBuMFt/sWKNZj2VhnVi16Uk+LTe4JYALAvExZmyShohHiO88rmIkksZ6k5zzt78Kb1vymTFYAnXAPnOZ694t2WoT7+2zZK0hq3Qi0vvdw3ROISIuPwcNw0kma++5AGoxylJRHGu72/WvnY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779736723; c=relaxed/simple; bh=kL5uXCsKasVui+N2ygVGkAF2xmDIBf2F3ytt8TNSrLI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=rn56kVahk00ZUUp/RRJ6oOAKphWpZvFzDdhHw44/9UmklIuP8xcMP1HH83bUef81ktXvrjLer/wZCt3aULCKL+AWelhNioXTiKtotnPlmcKQqqmLZUN1kPlmrivazFIM+IGG0ZThegoKgAT0tT/rKtGRhvS1zddBg1LKUcj0LAo= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 370EC4BA7992 Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-490426d72f7so31321115e9.3 for ; Mon, 25 May 2026 12:18:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779736722; x=1780341522; 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=3SJ7VDP5/qri78M2h1iaf4Ojwdkv8S8pYvaFL7Sq9fI=; b=BjUJHk21iLOmRGY1LnbtxAFaAW6ZJvesOAagKOiqb+JSox1xEXHM1HEcUhKzwKjy8t +0JYIyt5Tev7upARRyZ2+8gBXcvzaWOQdJTwbhwekzBgAqDeh2bp6SnReAe6gGs6dJy0 hK/uzI16ESh6TqGATEo2mVjES+/GpbP77C92vUOrbRfZt8GJROZ8Q8CWimkzeGYUfX0s 3IkbntL9dl9JWq6xMV/Ht6PQybU8w+EQ6aSMW+CtxIRQS9jlXVcxBcsl8qFjUS2hhXay 9bS8QoRwHSP2JGKyr1QlUkKTk3E9o7JmY1vohC76lznkkDHFNCtmAoBxTs5hFU4y1/BQ +Ymg== X-Gm-Message-State: AOJu0YzyztyoDP//i7TaBgkUniPZ2hz6rEJHoBkt4D7njx6/Ad16jgwH NOc9trJwN1v3nq5W/QaG14HzkZKxUkCruGUpR/lj9u8LoirEXWDX0Cu4PulYzA== X-Gm-Gg: Acq92OGlDlkDAnLrS/qoxKqx6GXiWHbPGqr6076JMKAQ/gaTrH2RIfYNBOMCB37zR6F QJfSatF/dOfKzYMC/OhMtg/VmKbnXTp8m1Y5h3XubICpXrF1cW+dVWsHkcDIcWJavKH4beg21p3 t4Ua76sIH6brpDUZIG64fLhAnoe6sKWtOBt0JUtp/4gNpjOVjS+pRtpXZ18lKNcY/DRMHBBDqKT 1w+RDn6nXExahZ3Nav35KooKgNwCx8gfzpHAegRi7rMlmNaqLqbHf+KeFozjf4gNlr9c0A/48bI uCbSUevuHn+tqw9k/Bfmn9eoyTsvzC+6uamuCQpSPTgFvVVM5n6UT/aMvP1AbHFj+beioMLzZXe O3Wc+821wKL7WU1aQUYg3gQ9ZEvzZ1MiCWi8OC4xWm4HcAc3faVRKgu2z9Eim/Tq4ZJqnJIshfe 4CxsgTaxOjubY1pJ9RiH9mZA== X-Received: by 2002:a05:600d:844a:10b0:490:4b89:535d with SMTP id 5b1f17b1804b1-4904b8955f6mr150977675e9.1.1779736721794; Mon, 25 May 2026 12:18:41 -0700 (PDT) Received: from localhost ([2001:8a0:fae3:2600:dc16:ec0f:632c:5ba7]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-490417ac7dasm92969345e9.7.2026.05.25.12.18.41 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 May 2026 12:18:41 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 03/11] Adjust gdb.base/exitsignal.exp for MinGW, separate program names Date: Mon, 25 May 2026 20:18:21 +0100 Message-ID: <20260525191829.984105-4-pedro@palves.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260525191829.984105-1-pedro@palves.net> References: <20260525191829.984105-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-8.8 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 Currently, gdb.base/exitsignal.exp on MinGW skips half the tests, like so: # of expected passes 13 # of untested testcases 1 ... because the testcase actually compiles two programs, but the second program is compiled using the same executable name as the first, at a time when gdb still has the first executable open, resulting in: .../x86_64-w64-mingw32/bin/ld.exe: cannot open output file C:/.../gdb.base/exitsignal/exitsignal.exe: Permission denied The use of standard_testfile in the middle of a testcase is a bit surprising. Fix this by moving the second compilation to the top, and give each executable its own name. Move the bulk of test code to two procedures, one for testing exiting with signal, another for testing normal exit. With this, gdb.base/exitsignal.exp passes cleanly on x86_64-w64-mingw32. Change-Id: I9a1af298b0e4f62f38b5c4b14787d7e40a2b5e2c commit-id: e496754c --- gdb/testsuite/gdb.base/exitsignal.exp | 201 ++++++++++++++------------ 1 file changed, 112 insertions(+), 89 deletions(-) diff --git a/gdb/testsuite/gdb.base/exitsignal.exp b/gdb/testsuite/gdb.base/exitsignal.exp index 341197cf0c8..4f4c53e37cb 100644 --- a/gdb/testsuite/gdb.base/exitsignal.exp +++ b/gdb/testsuite/gdb.base/exitsignal.exp @@ -23,103 +23,126 @@ require {!target_info exists gdb,nosignals} -standard_testfile segv.c +set testfile "exitsignal" -if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { - return -} +set exec1 "segv" +set srcfile1 ${exec1}.c +set binfile1 [standard_output_file ${exec1}] -# Run to main. But, before, change cwd to get the core into the -# output directory. -set_inferior_cwd_to_output_dir +set exec2 "normal" +set srcfile2 ${exec2}.c +set binfile2 [standard_output_file ${exec2}] -if { ![runto_main] } { - return +if { [build_executable "failed to build $exec1" ${exec1} "${srcfile1}" \ + {debug}] == -1 } { + return -1 } -# Get the inferior's PID for later. -set pid [get_inferior_pid] - -# Print $_exitsignal. It should be void now, because nothing -# happened. -gdb_test "print \$_exitsignal" " = void" \ - "\$_exitsignal is void before running" - -# Just to guarantee, making sure that $_exitcode is also void. -gdb_test "print \$_exitcode" " = void" \ - "\$_exitcode is void before running" - -# Trigger SIGSEGV. -gdb_test "continue" "(Thread .*|Program) received signal SIGSEGV.*" \ - "trigger SIGSEGV" - -if {[istarget "*-*-mingw*"]} { - # We're debugging a pure Win32 program with no SEH handler. The - # previous continue caught the first-chance exception. Now we - # catch the second-chance. - gdb_test "continue" "Thread .* received signal SIGSEGV.*" \ - "trigger SIGSEGV, second-chance" -} elseif {[istarget "*-*-cygwin*"]} { - # Cygwin calls DebugBreak before it lets the process exit. - gdb_test "continue" "Thread .* received signal SIGTRAP.*" \ - "trigger try_to_debug SIGTRAP" +if { [build_executable "failed to build $exec2" ${exec2} "${srcfile2}" \ + {debug}] == -1} { + return -1 } -# Continue until the end. -gdb_test "continue" "Program terminated with signal SIGSEGV.*" \ - "program terminated with SIGSEGV" - -# We don't need the core file, remove it. -remove_core $pid - -# Now, print $_exitsignal again. It should be 11 (SIGSEGV). -gdb_test "print \$_exitsignal" " = 11" \ - "\$_exitsignal is 11 (SIGSEGV) after SIGSEGV." - -# And $_exitcode should still be void, since the inferior died because -# of a signal, and did not return. -gdb_test "print \$_exitcode" " = void" \ - "\$_exitcode is still void after SIGSEGV" - -# Re-run to main, i.e., restart the executable. -rerun_to_main - -# Print the $_exitsignal again. Even in this normal scenario, it -# should still contain the signal triggered in the other run. -gdb_test "print \$_exitsignal" " = 11" \ - "\$_exitsignal is 11 (SIGSEGV) after restarting the inferior" - -# And, again, print $_exitcode. -gdb_test "print \$_exitcode" " = void" \ - "\$_exitcode is still void after restarting the inferior" - -# Now we test the behavior of $_exit{code,signal} during a normal -# inferior execution. -standard_testfile normal.c - -if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { - return +proc test_signal {} { + clean_restart $::exec1 + + # Run to main. But, before, change cwd to get the core into the + # output directory. + set_inferior_cwd_to_output_dir + + if { ![runto_main] } { + return + } + + # Get the inferior's PID for later. + set pid [get_inferior_pid] + + # Print $_exitsignal. It should be void now, because nothing + # happened. + gdb_test "print \$_exitsignal" " = void" \ + "\$_exitsignal is void before running" + + # Just to guarantee, making sure that $_exitcode is also void. + gdb_test "print \$_exitcode" " = void" \ + "\$_exitcode is void before running" + + # Trigger SIGSEGV. + gdb_test "continue" "(Thread .*|Program) received signal SIGSEGV.*" \ + "trigger SIGSEGV" + + if {[istarget "*-*-mingw*"]} { + # We're debugging a pure Win32 program with no SEH handler. The + # previous continue caught the first-chance exception. Now we + # catch the second-chance one. + gdb_test "continue" "Thread .* received signal SIGSEGV.*" \ + "trigger SIGSEGV, second-chance" + } elseif {[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.*" \ + "program terminated with SIGSEGV" + + # We don't need the core file, remove it. + remove_core $pid + + # Now, print $_exitsignal again. It should be 11 (SIGSEGV). + gdb_test "print \$_exitsignal" " = 11" \ + "\$_exitsignal is 11 (SIGSEGV) after SIGSEGV." + + # And $_exitcode should still be void, since the inferior died + # because of a signal, and did not return. + gdb_test "print \$_exitcode" " = void" \ + "\$_exitcode is still void after SIGSEGV" + + # Re-run to main, i.e., restart the executable. + rerun_to_main + + # Print the $_exitsignal again. Even in this normal scenario, it + # should still contain the signal triggered in the other run. + gdb_test "print \$_exitsignal" " = 11" \ + "\$_exitsignal is 11 (SIGSEGV) after restarting the inferior" + + # And, again, print $_exitcode. + gdb_test "print \$_exitcode" " = void" \ + "\$_exitcode is still void after restarting the inferior" } -# Checking $_exitsignal and $_exitcode, both should be void before the -# inferior is executed. -gdb_test "print \$_exitsignal" " = void" \ - "\$_exitsignal is void before normal inferior is executed" -gdb_test "print \$_exitcode" " = void" \ - "\$_exitcode is void before normal inferior is executed" - -# Run the inferior until the end. -if { ![runto_main] } { - return +# Test the behavior of $_exit{code,signal} during a normal inferior +# execution. +proc test_normal {} { + clean_restart $::exec2 + + # Check $_exitsignal and $_exitcode, both should be void before + # the inferior is executed. + gdb_test "print \$_exitsignal" " = void" \ + "\$_exitsignal is void before normal inferior is executed" + gdb_test "print \$_exitcode" " = void" \ + "\$_exitcode is void before normal inferior is executed" + + # Run the inferior until the end. + if { ![runto_main] } { + return + } + + gdb_continue_to_end + + # Check $_exitcode. It should be 0. + gdb_test "print \$_exitcode" " = 0" \ + "\$_exitcode is zero after normal inferior is executed" + + # Check $_exitsignal. It should still be void, since the inferior + # has not received any signal. + gdb_test "print \$_exitsignal" " = void" \ + "\$_exitsignal is still void after normal inferior is executed" } -gdb_continue_to_end - -# Checking $_exitcode. It should be 0. -gdb_test "print \$_exitcode" " = 0" \ - "\$_exitcode is zero after normal inferior is executed" - -# Checking $_exitsignal. It should still be void, since the inferior -# has not received any signal. -gdb_test "print \$_exitsignal" " = void" \ - "\$_exitsignal is still void after normal inferior is executed" +with_test_prefix "signal" { + test_signal +} +with_test_prefix "normal" { + test_normal +} From patchwork Mon May 25 19:18: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: 135627 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 A1EA24BAD162 for ; Mon, 25 May 2026 19:19:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A1EA24BAD162 X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) by sourceware.org (Postfix) with ESMTPS id 32AB24BA7980 for ; Mon, 25 May 2026 19:18:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 32AB24BA7980 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 32AB24BA7980 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779736725; cv=none; b=o7IB8dYqDOpKYpEeUnmvUMyjKl0mHFkIJ4CKh2VcuF0sFEhOTKCleXq7HF2GZAmJ5Fh8wZHmKANYUBH4vJx3Wwp6KT2t60EyZvltVFtM6vfD4J48Kw9+GL5PeiCCJNw8/UlX4jleB2J+mCx3pHak25pnZSlYFlDEQJVCV6u9FD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779736725; c=relaxed/simple; bh=FeDkQZPX8RoDs21ZDXBttD8PbrmdiXmCBsw+Z2ns12w=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=hqTk0xjjCf5BVLsfcd1ac2y/v9LwXtVO0Z6qrlY7kqXohbs0st6LO73r6gtrvO4KOXT0RSusTghIoDEJMw6Wutj6NMevOTJfc6wPB86bbh2IEHgQeS4isQjY8y9iIdJeXs3nZZpsGg2magsCnzTtNr6dyXI95+lOjCS7kErJUlI= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 32AB24BA7980 Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4891e86fabeso124845335e9.1 for ; Mon, 25 May 2026 12:18:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779736724; x=1780341524; 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=/I5afAWHFckBkPdQEQo05RoV8uFpOBELkWl7LtUJhIc=; b=UoZE0OCvPI3tlkg2MLAYSBIge8AjkgOJh5A9nE8Wj9nRt3nfZYanOoVnbhF2Kfxsye dkRuhmvxUNTwvc4yag/IHeB1PZ441J94ylJHO19YgC9lLdnpXrnNl32xl5oFhzc1+cV7 6EGmF+fgHCBtX9OKP3/8fcUaBH9HV9Tmwy1iYI2rQLL+1QPNVVhQbT/D7bp7TY7INTrv KYNW+Ub4AnXkS/qku7uL3f36fC3/4nKlAdKBWulpweXcwWzL0Igd7GbMTop+M+4lXJlS MbEf1ZKX2XGHcvUd8gvEYnU35km3wzQXnZyNthHZOCdLzt3LALhRwRiIwc91nVqInzY5 Yn+g== X-Gm-Message-State: AOJu0YyT7xhVXv8p0nKaqlZJU4sjM9T5nLgR+GbGdYMpagHlkXMi5BYA 0TBUFeVfbAmehjVTWQYeiU/9xb0kpgNG3Xlb3b4gSwEWCiLHVTxBy42U3RPwsQ== X-Gm-Gg: Acq92OFqEbNH2hJ3XNI+kJIKYEGSke7f/3RQyXmIDvRZPY37xu6ctWWGczx4TrRqoxm P4EJOWhoLWinNtc4meTQlcGdhn91F82qJvUt8WswbOBYdbh9HCxXpoZFyJ0GN0FzfvX/vR1aTka 3aya8e2VJIo86Y3fjU9JMlP0KAhK+MrmKm1FyCyGsZ6JVHPPW982g87ZA/zqT3OhOgEi4zuAkP+ Wt7laO5eGoXs7ZVBJdyVJjT1mf0hzhwTpQCXcdgeYYGQrZgbbnR62qmKxV/Ua2ZcEV4I+3iHf6D x6j17nX+reFWKfLkEQ0H61lQTeLCvCF48z5fgSP9sJT9AzIDjmuX2R/puc2kpkF35XJJBYW07za rs5at7qgrzFV67si0nE2vp2r0ajWwU9j6ctsnROWl8VWzyWGm4kWifyawRrGOi8H262QjD/rytg MTovb0zK38UXIQwq8ekmnRW4LKVcv69nKL X-Received: by 2002:a05:600c:1553:b0:490:53b0:9e53 with SMTP id 5b1f17b1804b1-49053b0a086mr187203725e9.1.1779736723840; Mon, 25 May 2026 12:18:43 -0700 (PDT) Received: from localhost ([2001:8a0:fae3:2600:dc16:ec0f:632c:5ba7]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-49041787932sm122370415e9.1.2026.05.25.12.18.43 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 May 2026 12:18:43 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 04/11] gdb.base/exitsignal.exp: Exit with non-zero Date: Mon, 25 May 2026 20:18:22 +0100 Message-ID: <20260525191829.984105-5-pedro@palves.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260525191829.984105-1-pedro@palves.net> References: <20260525191829.984105-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-8.8 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_BLOCKED, 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 gdb.base/exitsignal.exp currently tests exiting with exit code 0. But, testing for 0 is typically more "dangerous" in the sense that it's easy for some bug in GDB or the target backend to fail to extract the exit code and return 0. Make it test exit code 1 instead. gdb.base/coredump-filter-build-id.exp currently reuses normal.c. It could still use it with this patch, but it seems better to me to remove the coupling. Simply add a new .c file for that testcase, which still returns 0. Change-Id: I49ccfdbbe4be4445172476e7dd4e06142c8a672e commit-id: d6b526ac --- .../gdb.base/coredump-filter-build-id.c | 22 +++++++++++++++++++ .../gdb.base/coredump-filter-build-id.exp | 2 +- gdb/testsuite/gdb.base/exitsignal.exp | 8 +++---- gdb/testsuite/gdb.base/normal.c | 7 ++++-- 4 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 gdb/testsuite/gdb.base/coredump-filter-build-id.c diff --git a/gdb/testsuite/gdb.base/coredump-filter-build-id.c b/gdb/testsuite/gdb.base/coredump-filter-build-id.c new file mode 100644 index 00000000000..d78df952cb5 --- /dev/null +++ b/gdb/testsuite/gdb.base/coredump-filter-build-id.c @@ -0,0 +1,22 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2013-2026 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +int +main () +{ + return 0; +} diff --git a/gdb/testsuite/gdb.base/coredump-filter-build-id.exp b/gdb/testsuite/gdb.base/coredump-filter-build-id.exp index d267221e1bf..d8251e5c25f 100644 --- a/gdb/testsuite/gdb.base/coredump-filter-build-id.exp +++ b/gdb/testsuite/gdb.base/coredump-filter-build-id.exp @@ -21,7 +21,7 @@ # external tool, eu-unstrip, to verify if the corefile contains # build-ids. -standard_testfile "normal.c" +standard_testfile # This test is Linux x86_64 only. if { ![istarget *-*-linux*] } { diff --git a/gdb/testsuite/gdb.base/exitsignal.exp b/gdb/testsuite/gdb.base/exitsignal.exp index 4f4c53e37cb..7ae6e19b093 100644 --- a/gdb/testsuite/gdb.base/exitsignal.exp +++ b/gdb/testsuite/gdb.base/exitsignal.exp @@ -128,11 +128,11 @@ proc test_normal {} { return } - gdb_continue_to_end + gdb_test "continue" " exited with code 01\\\].*" "continue to exit" - # Check $_exitcode. It should be 0. - gdb_test "print \$_exitcode" " = 0" \ - "\$_exitcode is zero after normal inferior is executed" + # Check $_exitcode. It should be 1. + gdb_test "print \$_exitcode" " = 1" \ + "\$_exitcode is one after normal inferior is executed" # Check $_exitsignal. It should still be void, since the inferior # has not received any signal. diff --git a/gdb/testsuite/gdb.base/normal.c b/gdb/testsuite/gdb.base/normal.c index dd371746235..ba04c861dad 100644 --- a/gdb/testsuite/gdb.base/normal.c +++ b/gdb/testsuite/gdb.base/normal.c @@ -15,10 +15,13 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -/* This test is just a normal return 0. */ +/* This test is just a normal return 1. */ int main (int argc, char *argv[]) { - return 0; + /* Non-zero specifically, as it would be otherwise easier for a + buggy GDB to report exit code 0 when it shouldn't and that + wouldn't be noticed. */ + return 1; } From patchwork Mon May 25 19:18:23 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 135632 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 408444BA9025 for ; Mon, 25 May 2026 19:19:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 408444BA9025 X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) by sourceware.org (Postfix) with ESMTPS id C85DD4BA23C4 for ; Mon, 25 May 2026 19:18:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C85DD4BA23C4 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 C85DD4BA23C4 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779736727; cv=none; b=OWzlQwfiqNkRJ41xo85tU0wEPX9q6l5R53poAXKfsEcfSQDydgfWtPKJqfNreRurUdHNEvFpGIZ25V62jwk4ichZBHF+2YS7B2XikGTed+eM9/Wx2IxFSuCAHudVbXVw4atBOtHvFgL2F4JXN4hK8YPPpoGUlsaOWhMu0IXg12s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779736727; c=relaxed/simple; bh=mBBFVEfZsx+2DSqZaWIUwexvJOxisvJiZ55dclsWsQ8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Lwf9e7RM+BOLWTJ2AAsYEmtkpatp73FtuYGSkc7N4iqTv/IIAgoCOiB+XnRpo7uBSF4pq+kCob2PWJYGbdgE7yPCm7YLMgjAExb6vqqOhsFvpchoskGf8D3bG/Y7aH0A7orI4DhRddHH2X32Xlbu45W/T/QueiUmOFk/NW4oFCs= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C85DD4BA23C4 Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4906238c62eso12735805e9.3 for ; Mon, 25 May 2026 12:18:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779736726; x=1780341526; 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=zAQWdDTV6yRCgW1uo7OZ3fcimriK4tn6NK+hY8ia6CA=; b=h14Ugt6ONemnD6P2/fC0V/enCs/pe2OLojY9Gd7R17+AhB71Go+RElbhyzoIvz4fms R3uIXQi0pq2TlPJxcdoObnnNSo9wygewvqOn8pwJLLZiBABlyylaPlgTB8sHjwHzJ8BO CJlFbuEvaZte9uWgVwvMNWfLJAl4FRLHMVSSHQGj64+pwL4pS/Fd5FGEvWYLe9dYTKOh XA9SHY8y1iYXDa3aqda/oHiNLTLT0huexyyRYl7wCE+Tjqil5sy2FF2hfu6VBa2gc8Qu w+4/BH4WsvQUX5UTrWltOwJBVeXuCgKJZbsIV4c7MXrQ/jzeWjwAYs8RY+EFmunn09i7 madw== X-Gm-Message-State: AOJu0Yy8KHOOECfpiJ/+mfvqnRP1EV8xk59h9tuZWYJhqhNE7f2bhPpN n0AKj0UMyyzMVTlhdsVpWu6M3+0i6qxIIkh4Fe5jB69ybbfyqjY2B1w59Jg5ig== X-Gm-Gg: Acq92OFBKHOlYdJzynBe092KeCNaQZH4igfKrNr68IZfir8HCudVW8KyI+sTtns2AKx gbySyDZfboFR/Fglfm5KJMWs2lAmsknvHWrlXT0Ew7bRjsXfD/m6VYfbqqAAmqzk9PFtz2fxqRJ F3C4T3+FV+S9jCdIRPrI5HuVEobawWyKXuW1BlGvYZhEANVLQax31zbSX7yAP933+e7hQeURpBy BFYZ5xaP3E71I57xwYWYsTGJOR1NxW3LAVMSDP7XnWXEkyZrKRMkaqrH5+FiCbZjXTDxXcTMbwj ez5oxceGrtW13VFuhWRAvEgOOL1fRX84XeshmyLdpnpqc8IQ32VdPDqPLCmKgZg0/JuzFgSXqwK tTc0zxIIwsNFx1pG26iD8dO2//zsTNLWhCgk0FkUnsXGnyMG6Ohrm+H5L0ml2Z/R7lL5aMoSYx2 YXOq05oe6sB+/dHi2uIp+nVTJVil9mc9s+ X-Received: by 2002:a05:600c:c0d2:10b0:490:33b3:4be0 with SMTP id 5b1f17b1804b1-490426c1759mr194073285e9.20.1779736725403; Mon, 25 May 2026 12:18:45 -0700 (PDT) Received: from localhost ([2001:8a0:fae3:2600:dc16:ec0f:632c:5ba7]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-49059cc9a91sm51830215e9.1.2026.05.25.12.18.44 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 May 2026 12:18:45 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 05/11] gdb.base/exitsignal.exp: Test attaching too Date: Mon, 25 May 2026 20:18:23 +0100 Message-ID: <20260525191829.984105-6-pedro@palves.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260525191829.984105-1-pedro@palves.net> References: <20260525191829.984105-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_BLOCKED, 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 On some targets, like Cygwin (see the following commit), extracting the exit code works differently depending on whether the inferior was run by GDB, or GDB attached to an existing process. Extend gdb.base/exitsignal.exp to test both scenarios. Note: We add a wait_for_gdb sleep loop to segv.c and normal.c so the attach path can synchronize with GDB before the inferior runs. For simplicity, the run path pokes the same variable from setup, so behavior there is unchanged. The testcase passes cleanly on Linux, native and gdbserver, and on MinGW too. Cygwin still requires more fixes. Change-Id: I9908aef0cea3eaec8134f05e347702baf753d10c commit-id: b74921d8 --- gdb/testsuite/gdb.base/exitsignal.exp | 86 +++++++++++++++++++++------ gdb/testsuite/gdb.base/normal.c | 7 +++ gdb/testsuite/gdb.base/segv.c | 7 +++ 3 files changed, 82 insertions(+), 18 deletions(-) diff --git a/gdb/testsuite/gdb.base/exitsignal.exp b/gdb/testsuite/gdb.base/exitsignal.exp index 7ae6e19b093..7684646b546 100644 --- a/gdb/testsuite/gdb.base/exitsignal.exp +++ b/gdb/testsuite/gdb.base/exitsignal.exp @@ -21,6 +21,10 @@ # killed by a signal. However, if it was killed by an uncaught # signal, then there is no way for it to have exited. +# On some targets, like Cygwin, extracting the exit code works +# differently depending on whether the inferior was run by GDB, or GDB +# attached to an existing process. We exercise both cases. + require {!target_info exists gdb,nosignals} set testfile "exitsignal" @@ -43,16 +47,48 @@ if { [build_executable "failed to build $exec2" ${exec2} "${srcfile2}" \ return -1 } -proc test_signal {} { +# Get the inferior under GDB's control in mode HOW ("run" or +# "attach"), using BINFILE. In "attach" mode, spawn the binary and +# attach to it; in "run" mode, run to main. In both modes, clear the +# inferior's wait_for_gdb flag so the spin loop in main exits when +# execution continues. + +proc setup {how binfile} { + if {$how == "run"} { + if { ![runto_main] } { + return + } + } else { + # Change directory so that the core file (for test_signal) + # doesn't end up outside the output directory. + with_cwd [standard_output_file {}] { + set ::test_spawn_id [spawn_wait_for_attach $binfile] + } + set test_pid [spawn_id_get_pid $::test_spawn_id] + gdb_test "attach $test_pid" "Attaching to program.*" \ + "attach to process" + } + + gdb_test "p wait_for_gdb = 0" " = 0" +} + +# Counterpart to setup. In "attach" mode, kill the spawned process +# started by setup. In "run" mode, nothing to do. + +proc teardown {how} { + if {$how == "attach"} { + kill_wait_spawned_process $::test_spawn_id + } +} + +proc test_signal {how} { clean_restart $::exec1 - # Run to main. But, before, change cwd to get the core into the - # output directory. + # Get the inferior under GDB's control. But, before, change cwd + # so the core file ends up in the output directory. set_inferior_cwd_to_output_dir - if { ![runto_main] } { - return - } + setup $how $::binfile1 # Get the inferior's PID for later. set pid [get_inferior_pid] @@ -98,8 +134,15 @@ proc test_signal {} { gdb_test "print \$_exitcode" " = void" \ "\$_exitcode is still void after SIGSEGV" - # Re-run to main, i.e., restart the executable. - rerun_to_main + # Start over. + if {$how == "run"} { + rerun_to_main + } else { + with_test_prefix "reattach" { + kill_wait_spawned_process $::test_spawn_id + setup $how $::binfile1 + } + } # Print the $_exitsignal again. Even in this normal scenario, it # should still contain the signal triggered in the other run. @@ -109,11 +152,13 @@ proc test_signal {} { # And, again, print $_exitcode. gdb_test "print \$_exitcode" " = void" \ "\$_exitcode is still void after restarting the inferior" + + teardown $how } # Test the behavior of $_exit{code,signal} during a normal inferior # execution. -proc test_normal {} { +proc test_normal {how} { clean_restart $::exec2 # Check $_exitsignal and $_exitcode, both should be void before @@ -124,10 +169,7 @@ proc test_normal {} { "\$_exitcode is void before normal inferior is executed" # Run the inferior until the end. - if { ![runto_main] } { - return - } - + setup $how $::binfile2 gdb_test "continue" " exited with code 01\\\].*" "continue to exit" # Check $_exitcode. It should be 1. @@ -138,11 +180,19 @@ proc test_normal {} { # has not received any signal. gdb_test "print \$_exitsignal" " = void" \ "\$_exitsignal is still void after normal inferior is executed" -} -with_test_prefix "signal" { - test_signal + teardown $how } -with_test_prefix "normal" { - test_normal + +foreach_with_prefix how {"run" "attach"} { + if {$how == "attach" && ![can_spawn_for_attach]} { + continue + } + + with_test_prefix "signal" { + test_signal $how + } + with_test_prefix "normal" { + test_normal $how + } } diff --git a/gdb/testsuite/gdb.base/normal.c b/gdb/testsuite/gdb.base/normal.c index ba04c861dad..fbe59653c97 100644 --- a/gdb/testsuite/gdb.base/normal.c +++ b/gdb/testsuite/gdb.base/normal.c @@ -17,9 +17,16 @@ /* This test is just a normal return 1. */ +#include + +volatile int wait_for_gdb = 1; + int main (int argc, char *argv[]) { + while (wait_for_gdb) + sleep (1); + /* Non-zero specifically, as it would be otherwise easier for a buggy GDB to report exit code 0 when it shouldn't and that wouldn't be noticed. */ diff --git a/gdb/testsuite/gdb.base/segv.c b/gdb/testsuite/gdb.base/segv.c index fd43d95e9b2..e1c295f50a5 100644 --- a/gdb/testsuite/gdb.base/segv.c +++ b/gdb/testsuite/gdb.base/segv.c @@ -17,9 +17,16 @@ /* This test can be used just to generate a SIGSEGV. */ +#include + +volatile int wait_for_gdb = 1; + int main (int argc, char *argv[]) { + while (wait_for_gdb) + sleep (1); + /* Generating a SIGSEGV. */ *(volatile int *) 0; From patchwork Mon May 25 19:18: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: 135630 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 F32804BA79A7 for ; Mon, 25 May 2026 19:19:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F32804BA79A7 X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by sourceware.org (Postfix) with ESMTPS id B55CE4BA799F for ; Mon, 25 May 2026 19:18:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B55CE4BA799F 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 B55CE4BA799F Authentication-Results: sourceware.org; arc=none smtp.remote-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779736727; cv=none; b=ay77vUCUExyERd1RVRFkbW1QR0ICrAdif5/h9ggJvQ9kUidxOhImE52nHFYLdOCqUs4Sqi8/nJdDMOADBmMx7LlDakTOV5fPJ2Wl/gfPHkpLASgUTApNuj4y8MkdbZDd/CMnUdpttBzo8stfiLMShqN3K4pi0mQH3fdk5NBB5eg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779736727; c=relaxed/simple; bh=c0fKZLlH9v3eQroP8Ib2FJWHgERT8NOrXIOPuxcAh20=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=VsJssVY2xeTfo2lU6D0JxqOyGgLoXbYgyS4/vsL0+UXIVDpKqq0fuZ7fpUfpyKasCUclFGFbkGq39RJWHdTV0L/rrxyLu0gxS310ciePnaP+hu5ZSFTbgl9f8HMMUIvBxoXFNQF5Zm3VLntYrsJm3A9GLUeO7+jf4vXHewT7XpA= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B55CE4BA799F Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-490686877a1so7917535e9.0 for ; Mon, 25 May 2026 12:18:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779736727; x=1780341527; 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=cfVe1e++3qHmpb19ahKoo2ZmTKmSDZ7/AlkgP6kHjPk=; b=ThyBEm6nYkFu7ooMsKJxn3RY/xrZn9FV6igSLLhzUl7k+2CQd0jUUD1Xg2GRyZnwfQ QIp/N349TvxnT64ncNCZX2GtP8Zcjbqz69ZTu6abK+9r5bij3euRUnDBHYvNEOZnXVBP t6A0LHOHz1quOnSw4F18mVIgoVLCavOXTlLzN9uxkteoAao4VTRNwHoY+1J0vlv2O2VD 6R6YRKyHHz4Nu+ugJQCUuKAajbe7sGcy7YiR7zs9lwb0H+r3ire+T2DSjXC5epksW1D0 DKFg7dJHsiZVvO9qDVscRB8z9oLsUoC0eOavGo0vSoUrPsxiC5BrZOqSnkBui19XsICC CKmQ== X-Gm-Message-State: AOJu0Yy132yFnsLp6QNtdBcRTO85mwsFn+uZJs7JfbpUZRT4mYJh6l3T nHqMeVpxu26KasQ2ncbGrQq04FGTipJqK3TU6gd25aJ/DcmvIN3ny53NqON0mA== X-Gm-Gg: Acq92OF7+9jgpkiWP/ZJs6g/ZtfVrepHdMk4RhOlf66KoWm0sBk3mx3+uUEq/5XAfAf +RlClqi12Yth6HHwYFDUNZt4Qt9PX221dHAZZis5NaLfu1VqlqNmuetG1EIXkqgdHCxS0wBcPD3 V8X9IT+sTBbbnNCxr+OoNmizQucfK1rbnF2iKRby1uHVSTgQ/ZeBKKMqZTOLI1cp5X4oGbelmwm lMEmnJISlbBt61OOgMVQk0fRFZQBKLTyqPJ8rlPq5I+W5fVYKK8H5igAGWpXkw0wxmyQVYUovW6 fNcX4jPlWbolctHHWc1jKmFdylULw/6rSP1a7TsW1wuzu1aqtsX8ei/gUN3PC1x9hz6pAxK7Zs4 JwFexUiGBzRAcTSCEBtviRvHxbvt9/trcx/AuvJ7oJRnQsX5xbvDpBbZ8VS92NTE1tJyjlO05nf hUaD1uqTlrypcTwjbleaO30Q== X-Received: by 2002:a05:600c:8b08:b0:490:5443:621e with SMTP id 5b1f17b1804b1-49054436375mr155515495e9.12.1779736726528; Mon, 25 May 2026 12:18:46 -0700 (PDT) Received: from localhost ([2001:8a0:fae3:2600:dc16:ec0f:632c:5ba7]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-49044f2bad3sm288062735e9.0.2026.05.25.12.18.46 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 May 2026 12:18:46 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 06/11] gdb/testsuite: Add mechanism to compile Windows native programs on Cygwin Date: Mon, 25 May 2026 20:18:24 +0100 Message-ID: <20260525191829.984105-7-pedro@palves.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260525191829.984105-1-pedro@palves.net> References: <20260525191829.984105-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_BLOCKED, 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 adds a new "win32" option to gdb_compile that lets us compile native Windows programs when testing Cygwin. Will be used in a following patch. The testsuite tries to find the compiler to use automatically. You can also explicitly set it with WIN32_CC_FOR_TARGET. Change-Id: I86e954494cf7f88164cdf1c9127be46d5437986f commit-id: c71b8812 --- gdb/testsuite/README | 22 ++++++++ gdb/testsuite/lib/gdb.exp | 104 +++++++++++++++++++++++++++++++++++++- 2 files changed, 124 insertions(+), 2 deletions(-) diff --git a/gdb/testsuite/README b/gdb/testsuite/README index 60fd322ea4d..479e81f90f5 100644 --- a/gdb/testsuite/README +++ b/gdb/testsuite/README @@ -414,6 +414,28 @@ Example: make check-gdb TESTS="gdb.multi/multi-arch.exp" RUNTESTFLAGS="ARM_CC_FOR_TARGET=arm-linux-gnueabihf-gcc" +WIN32_CC_FOR_TARGET + +The Cygwin ports of GDB and GDBserver include basic support for +debugging native Windows programs. Some tests exercise this +particular feature. + +By default, the testsuite tries to find a compiler capable of +generating native Windows executables. If no compiler is found, or if +the executable generated by the found compiler can't be executed +correctly, the tests are marked UNSUPPORTED. The list of compiler +names the testsuite tries can be found in +gdb/testsuite/lib/gdb.exp:win32_cc_for_target. + +You can set WIN32_CC_FOR_TARGET to override the search and explicitly +specify the compiler to use. This variable should contain the command +line for the compiler, including the full path to it, if the compiler +is not in $PATH. + +Example: + + make check-gdb TESTS="gdb.base/exitsignal.exp" RUNTESTFLAGS="WIN32_CC_FOR_TARGET=x86_64-w64-mingw32-gcc" + Race detection ************** diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 28709004570..e21c1c1224f 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -6128,6 +6128,10 @@ proc gdb_can_simple_compile_nodebug {name code {type object} {compile_flags ""} global gdb_saved_set_unbuffered_mode_obj set gdb_saved_set_unbuffered_mode_obj "" +# The name of the set_unbuffered_mode_saved.o object. Stored in a +# global variable so it can be overridden in some cases. +set gdb_saved_set_unbuffered_mode_obj_name set_unbuffered_mode_saved.o + # Escape STR sufficiently for use on host commandline. proc escape_for_host { str } { @@ -6201,6 +6205,7 @@ proc quote_for_host { args } { # Fortran 90, Go or Rust. # - debug: Build with debug information. # - optimize: Build with optimization. +# - win32: Build a native Windows program. Cygwin only. proc gdb_compile {source dest type options} { global GDB_TESTCASE_OPTIONS @@ -6212,6 +6217,11 @@ proc gdb_compile {source dest type options} { set outdir [file dirname $dest] + # Handle compiling native Windows programs when testing Cygwin. + if { [istarget *-*-cygwin*] && [lsearch -exact $options win32] != -1} { + return [gdb_compile_win32 $source $dest $type $options] + } + # GDB doesn't support minimal symbols in AIX, so fail the compilation # if nodebug is requested for an AIX target. if { [istarget *-*-aix*] && [lsearch -exact $options nodebug] != -1} { @@ -6635,9 +6645,11 @@ proc gdb_compile {source dest type options} { return $result } if {[is_remote host]} { - set gdb_saved_set_unbuffered_mode_obj set_unbuffered_mode_saved.o + set gdb_saved_set_unbuffered_mode_obj \ + $::gdb_saved_set_unbuffered_mode_obj_name } else { - set gdb_saved_set_unbuffered_mode_obj ${objdir}/set_unbuffered_mode_saved.o + set gdb_saved_set_unbuffered_mode_obj \ + ${objdir}/$::gdb_saved_set_unbuffered_mode_obj_name } # Link a copy of the output object, because the # original may be automatically deleted. @@ -7003,6 +7015,38 @@ proc gdb_compile_openmp {source dest type options} { return [gdb_compile $source $dest $type $options] } +# Build a native Windows program from SOURCE. See prefatory comment +# for gdb_compile, above, for discussion of the parameters to this +# proc. This is meant to be used on Cygwin, to smoke test debugging +# native Windows programs with the Cygwin native backend. + +proc gdb_compile_win32 {source dest type options} { + if {![istarget *-*-cygwin*]} { + error "cygwin procedure called on non-cygwin target" + } + + save_vars { + ::target_triplet + ::CC_FOR_TARGET + ::gdb_saved_set_unbuffered_mode_obj + ::gdb_saved_set_unbuffered_mode_obj_name + } { + # So we trigger the set_unbuffered_mode_obj paths. + set ::target_triplet "x86_64-w64-mingw32" + + # We need a Win32-specific compilation of the + # set_unbuffered_mode object. + set ::gdb_saved_set_unbuffered_mode_obj "" + set ::gdb_saved_set_unbuffered_mode_obj_name \ + set_unbuffered_mode_saved_win32.o + + # Do this last, as this tries compiling internally. + set ::CC_FOR_TARGET [win32_cc_for_target] + + return [gdb_compile $source $dest $type $options] + } +} + # Send a command to GDB. # For options for TYPE see gdb_stdin_log_write @@ -11248,6 +11292,62 @@ gdb_caching_proc arm_cc_for_target {} { return "" } +# Return the compiler that can generate native Windows executables. +# Used when testing basic native Windows support on Cygwin. If +# WIN32_CC_FOR_TARGET is set, use that. If not, try a few common +# compiler names, making sure that the executable they produce can +# run. Note, this assumes global state has been set to target native +# Windows programs. See gdb_compile_win32. + +gdb_caching_proc win32_cc_for_target {} { + if {[info exists ::WIN32_CC_FOR_TARGET]} { + # If the user specified the compiler explicitly, then don't + # check whether the resulting binary runs outside GDB. Assume + # that it does, and if it turns out it doesn't, then the user + # should get loud FAILs, instead of UNSUPPORTED. + return $::WIN32_CC_FOR_TARGET + } + + # Fallback to a few common compiler names. Also confirm the + # produced binary actually runs on the system before declaring + # we've found the right compiler. + + # Only one compiler for now. + set compilers { + x86_64-w64-mingw32-gcc + } + + save_vars { + ::CC_FOR_TARGET + } { + foreach compiler $compilers { + if {![is_remote host] && [which $compiler] == 0} { + # Avoid "default_target_compile: Can't find + # $compiler." warning issued from gdb_compile. + continue + } + + set ::CC_FOR_TARGET $compiler + + set src { int main() { return 0; } } + if {[gdb_simple_compile win32-test-prog $src executable]} { + set target_obj [gdb_remote_download target $obj] + set result [remote_exec target $target_obj] + set status [lindex $result 0] + set output [lindex $result 1] + + file delete $obj + + if { $output == "" && $status == 0} { + return $compiler + } + } + } + } + + return "" +} + # Step until the pattern REGEXP is found. Step at most # MAX_STEPS times, but stop stepping once REGEXP is found. # CURRENT matches current location From patchwork Mon May 25 19:18: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: 135628 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 9A3DF4BA9036 for ; Mon, 25 May 2026 19:19:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A3DF4BA9036 X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) by sourceware.org (Postfix) with ESMTPS id 594804BA902B for ; Mon, 25 May 2026 19:18:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 594804BA902B 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 594804BA902B Authentication-Results: sourceware.org; arc=none smtp.remote-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779736729; cv=none; b=QNFTct99pQKqcwinQC739bynG3DMpFET8SbFKnUFYlcLYx+rw5vX9EZRTe9pxoOgy0M4iBXuha27Fff0c792U+x3Aybr6a+X1iGPtb+JMifdcT/t0uHPua86vkpzH/JXI3X8S0vCp1ZIhFMWqlZ+jOJIEHXKXRhMOr7Ib5dKWto= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779736729; c=relaxed/simple; bh=jcRIRMFbAKvrCSQ2frf9AbowLjuwRwz5Cvb3TlBbUcQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=sv97TRpFrdrH906YHiFTXFO6K76dIBtwXJan3ernfYopCQbxe/KaWRCrXiPiT7K9tHfP7WheD1MddfqaPypsa0Ki8psyHMwP9sn5Ogaf8kzJCsoly0iP3CWhgVVunfMMCVUXvfUEJh3C1BCsI+F02cgaEnrj98f4RD4ggdjB00Y= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 594804BA902B Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-43fe608cb92so5961954f8f.2 for ; Mon, 25 May 2026 12:18:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779736728; x=1780341528; 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=KegiR+8QIiXNimEjLM//fKwwnb0+13QdRufAYYwEr4k=; b=PKNIUVAHJdj8CeIyiWEynbgsOMcFv9OAyODHqDJua1xXtPA2q+IWHQ/XbXxtHsCMXs OAZqwBVpU7hA34iYdrwBvrRF0ARedCyYNfOfylS+osCF/RU6Mo1ZBb5hLT8Vw4BcDKhx TSM6AoHZyekqy7DmOmOGjxL0wac70E7Xyoq9zw17lafgZRI8ILnsROUPwb1fcD3Y3N/h lljwBXF8/DdSFgG5diKMuropjzaANQywIZITYtITairenrHHpdqsPi1ja6XLCcniJ3CN LYL08WnOp+Bbld+TrqVf+iTPO43U98xjR+ffLribuNMtjtZiLtRTes42fMlvO35E+DYi LW9A== X-Gm-Message-State: AOJu0YwvIdZn+9hnd/+8NKpJai3vroph2Sz0fqK/9KPYpHrqKZeb8si4 HJ+3SG5pFQugpR5OvNCeWT+aiMgH48xSJRX9k67IXU2PIiHsmAsTdHo4J0zNwg== X-Gm-Gg: Acq92OFfprQ7nA5a4muWkgg1EZo6wzuE8r67lAUeQlrSpAZjLqKA7fHoGTMKd5+RWu+ PgJaehfUbxW+yLy7LPKLzJByQd17BV2fGMjgJAgRKZJoybbdeH3BXVbYzftlHj/ysAaQUwF0hau iyXqJjVCd+8reWBuHKdlWFATkq8frCTz9+jr8ouPaUYC/Rb2Ah9FJsUg8QBMsuNN0oJ98OJjXV1 /RBkE22iOe+RS+8Iypv3hsnD17MsPMgYwwf0zP8EjJZMf3NOshLsZ0S+Nq7Pr4VfEPTaLaI2287 B6Sz59O3LIMo8tvk0JTpUUnfUS6p8rFOEo6igvy10hHRpwjIjmXjd10ysJttulq8hndVVZHq7Pg jashv4to7AvpnYK0q/haI0L175V/ybhlZeGFNDEpoaRNoVy82AS3R35HQcG5sgOVPH4rQQdrYH0 EUFtM4P549VEL8SCDOTDXYgg== X-Received: by 2002:a05:6000:2003:b0:45e:653a:40df with SMTP id ffacd0b85a97d-45eb38e4d0dmr25084184f8f.41.1779736728025; Mon, 25 May 2026 12:18:48 -0700 (PDT) Received: from localhost ([2001:8a0:fae3:2600:dc16:ec0f:632c:5ba7]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-45eb6ccd211sm37107222f8f.10.2026.05.25.12.18.47 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 May 2026 12:18:47 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 07/11] Windows gdb+gdbserver: Share exit status logic Date: Mon, 25 May 2026 20:18:25 +0100 Message-ID: <20260525191829.984105-8-pedro@palves.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260525191829.984105-1-pedro@palves.net> References: <20260525191829.984105-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-8.8 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 Move the exit status logic added by commit 559e7e5056 ("Improve process exit status macros on MinGW") from both GDB and GDBserver to a shared routine used by both. The next patch extends this routine with Cygwin-specific decoding. Change-Id: I4bf08c6beff0d1688064a81d49bbdd615643735e commit-id: 586becd8 --- gdb/nat/windows-nat.c | 24 ++++++++++++++++++++++++ gdb/nat/windows-nat.h | 6 ++++++ gdb/windows-nat.c | 15 +++------------ gdbserver/win32-low.cc | 16 +++------------- 4 files changed, 36 insertions(+), 25 deletions(-) diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c index b093acda342..92f9394ca6d 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,28 @@ windows_process_info::add_all_dlls () /* See nat/windows-nat.h. */ +target_waitstatus +windows_process_info::exit_process_to_target_status + (const EXIT_PROCESS_DEBUG_INFO &info) +{ + DWORD exit_code = info.dwExitCode; + target_waitstatus tstatus; + + /* 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)); + + 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..d2e6adb4f40 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -315,6 +315,12 @@ struct windows_process_info }); } + /* Convert an EXIT_PROCESS_DEBUG_EVENT payload to a target wait + status. */ + + target_waitstatus exit_process_to_target_status + (const EXIT_PROCESS_DEBUG_INFO &info); + private: /* Handle MS_VC_EXCEPTION when processing a stop. MS_VC_EXCEPTION is diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index a284438bd36..26333238cfa 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,9 @@ 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)); + *ourstatus + = (windows_process->exit_process_to_target_status + (current_event->u.ExitProcess)); thread_id = current_event->dwThreadId; diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index 6f1cf5ed025..550994b0bf2 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; @@ -1061,18 +1060,9 @@ get_child_debug_event (DWORD *continue_status, break; 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)); - } + *ourstatus + = (windows_process.exit_process_to_target_status + (current_event->u.ExitProcess)); continue_last_debug_event (DBG_CONTINUE, debug_threads); break; From patchwork Mon May 25 19:18: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: 135634 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 178E74BA79AB for ; Mon, 25 May 2026 19:20:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 178E74BA79AB 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 A573D4BA23C4 for ; Mon, 25 May 2026 19:18:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A573D4BA23C4 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 A573D4BA23C4 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=1779736731; cv=none; b=rbbMvifFWcir5cPb7/cNVmRln7k7l6BguSOcpWBJNSy7blOt+HX/+aJGe33jjgxQa4DPaFlj6ETw/aLsV8UlzpCkT8nUgN0j8mssGaa31garP0gvE6icDbmmTn9YbmgJ3fCsnGYLz2wbGtLkHEwc8p7iPO3Q7qgQZw20sC69cw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779736731; c=relaxed/simple; bh=mc/jod1OutGtgpex+xQpRVJA5xZxdRzwiaOotHN3Y2g=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=sbTj6VnEy3ERU9rBV7nUI5ZLo0zpWLkpp1hBHJdUI1E/tvrDUnT8V/Rxk6JtYI49Gzfyd09fR4VgdVwAsK9EV1s6Z33bsmleS36IeZZ1Nhb3ELP6uvD5zz17Qyo3ZnQRjgfOnpNtKHuF0uqnL51Laa8/4q/luUmrM9o6GQC8/o8= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A573D4BA23C4 Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-4526a8170ceso4910172f8f.2 for ; Mon, 25 May 2026 12:18:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779736730; x=1780341530; 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=EdCbMg0S0ojg/ti6NtnZHXML4CCfO6RXjKKDQ9SjMzg=; b=HpkzN1oaV6+jmyBQiwaX8a0oFpwmf+WgkjLeGdbSb/Kl7GYmgL1cD3OCR5wgC2sBRC BW57QiONg25WzE/mSFLnyFS6NXbTD9Qz4tPBlKCtgqzXOxhBTLeZTnjItoWTzWQrtstO +pBkQ74ebHoYBPyE8uumSS3UsmpseVVm+Uk+mLWUfEx4jTSZfxlGyRM51rUDUnCe+f7P gSX3jpnH0uDH3oMmCJBmqGV6VplBjFr/wjHHsqEmGGd55L2lNpDYtx0bgKIxoY4p5hgP az0rW1TW9NkMZuLrnXOhBSMn+S9CiExwWfhC1pxRjcB/DK/2bJvUKMJQ3LzWYhGPercS Qx0g== X-Gm-Message-State: AOJu0Yypn9X2myHgE0zJH7d9iim7YuBu0qCfFVfeeLMM4WPiXx8D1E/f 1HHgXDC1oJDJHqwlczgOHR2Xr7UtNsZpBr513zx6TKVp6/rCdOjTuVkXD7tkKQ== X-Gm-Gg: Acq92OFHFxIO5TNv7Pf5yBWXTnkerjnfscBrmNZG12+YuIPtXWrLnf0dJQYjaPdgu9I bp6sW4P0cx53qSSbIdbw26RigUVVOu3ycxTc9q84Q+hLrBEQl6tKZmPlFqWl3sDq16VurYySbQA PVvxHm3eaGNMmT+KsNMJPOoEdB1a873iFeKy6Htmk3bMLuh0rLqtveNIc6l+Sk2/29JWvXM8j6+ HiLDOYpDOyPf9IxQUVh9DaYmGMNU8Gcli8XsXgj7zvba0/ZvDWVw7NmKiFCC04x9ZI8o/D5+heg P5QF03Vf70e9Mx86sQVp+ZDjztg5mGbxXmQjhoIacFQEGlJm7zrWwperJIK7S4XB8NrL3xqyxf0 v01pp1MZLHuzBuENWP4YzMRwYa3/n7Hr+ZL5mxwLp7w9TwTSW2Ze+bB3A6lZCKZP/UjCOIdwFoZ oWcWvybvLC0LZBW7qix1tHDA== X-Received: by 2002:a05:6000:480f:b0:43f:ea04:dcc7 with SMTP id ffacd0b85a97d-45eb38af9efmr25507800f8f.24.1779736730105; Mon, 25 May 2026 12:18:50 -0700 (PDT) Received: from localhost ([2001:8a0:fae3:2600:dc16:ec0f:632c:5ba7]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-45eb6d7167dsm29619879f8f.35.2026.05.25.12.18.49 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 May 2026 12:18:49 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 08/11] Windows gdb+gdbserver: Decode Cygwin ExitProcess codes Date: Mon, 25 May 2026 20:18:26 +0100 Message-ID: <20260525191829.984105-9-pedro@palves.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260525191829.984105-1-pedro@palves.net> References: <20260525191829.984105-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_BLOCKED, 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 On native Cygwin, GDB misreports the inferior's exit reason in several common cases, resulting in several gdb.base/exitsignal.exp failures: $ grep FAIL gdb.sum FAIL: gdb.base/exitsignal.exp: how=run: signal: program terminated with SIGSEGV (the program exited) FAIL: gdb.base/exitsignal.exp: how=run: signal: $_exitsignal is 11 (SIGSEGV) after SIGSEGV. FAIL: gdb.base/exitsignal.exp: how=run: signal: $_exitcode is still void after SIGSEGV FAIL: gdb.base/exitsignal.exp: how=run: signal: $_exitsignal is 11 (SIGSEGV) after restarting the inferior FAIL: gdb.base/exitsignal.exp: how=run: signal: $_exitcode is still void after restarting the inferior FAIL: gdb.base/exitsignal.exp: how=run: normal: continue to exit FAIL: gdb.base/exitsignal.exp: how=run: normal: $_exitcode is one after normal inferior is executed FAIL: gdb.base/exitsignal.exp: how=run: normal: $_exitsignal is still void after normal inferior is executed FAIL: gdb.base/exitsignal.exp: how=attach: normal: continue to exit (the program exited) FAIL: gdb.base/exitsignal.exp: how=attach: normal: $_exitcode is one after normal inferior is executed For example, from gdb.log, the normal exit case: ... [Thread 14300.0x4214 (id 1) exited with code 1] [Thread 14300.0x1b1c (id 4) exited with code 1] [Thread 14300.0x1e2c (id 2) exited with code 1] Program terminated with signal SIGHUP, Hangup. The program no longer exists. (gdb) FAIL: gdb.base/exitsignal.exp: how=run: normal: continue to exit The program in fact exited normally with code 1. SIGHUP happens to be signal 1, and GDB picked the wrong interpretation. Similarly, for the signal termination case: ... continue Continuing. [Thread 4600.0x3104 (id 4) exited with code 2816] [Thread 4600.0x2bcc (id 3) exited with code 2816] [Thread 4600.0x2f44 (id 1) exited with code 2816] [Inferior 1 (process 4600) exited with code 05400] (gdb) FAIL: gdb.base/exitsignal.exp: how=run: signal: program terminated with SIGSEGV (the program exited) Here the inferior died with SIGSEGV, but GDB reported exit decimal 2816 / octal 05400 / hex 0x0B00, which is SIGSEGV swapped into the high byte of a waitpid exit status. The problem is that Cygwin waitpid exit status and Windows exit codes do not have the same encoding, and GDB & GDBserver do not know about this. This commit fixes it. It adds a Cygwin-specific branch to the code that determines the terminating signal and status of a program. The branch for native Windows/MinGW GDB is left intact, no behavior change there. The way to decode the exit codes is a little bit tricky, see detailed comments added by the patch. To exercise the "raw NTSTATUS error code" path in windows_process_info::exit_process_to_target_status, gdb.base/exitsignal.exp is extended to debug a native Windows program that crashes with a segfault (STATUS_ACCESS_VIOLATION). With this, gdb.base/exitsignal.exp passes cleanly on Cygwin. Change-Id: Icaebcc234b71927915c996fd120884604441415b commit-id: bd0fbb9c Reviewed-By: Eli Zaretskii --- gdb/nat/windows-nat.c | 153 +++++++++++++++++++++++++- gdb/nat/windows-nat.h | 29 +++++ gdb/testsuite/gdb.base/exitsignal.exp | 32 +++++- gdb/windows-nat.c | 5 + gdbserver/win32-low.cc | 5 + 5 files changed, 217 insertions(+), 7 deletions(-) diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c index 92f9394ca6d..27bc65225cc 100644 --- a/gdb/nat/windows-nat.c +++ b/gdb/nat/windows-nat.c @@ -654,6 +654,7 @@ windows_process_info::add_dll (LPVOID load_addr) at which the DLL was loaded is equal to LOAD_ADDR. */ if (!(load_addr != nullptr && mi.lpBaseOfDll != load_addr)) { + maybe_note_cygwin1_dll (name); handle_load_dll (name, mi.lpBaseOfDll); if (load_addr != nullptr) return; @@ -681,7 +682,10 @@ windows_process_info::dll_loaded_event (const DEBUG_EVENT ¤t_event) by enumerating all the DLLs loaded into the inferior, looking for one that is loaded at base address = lpBaseOfDll. */ if (dll_name != nullptr) - handle_load_dll (dll_name, event->lpBaseOfDll); + { + maybe_note_cygwin1_dll (dll_name); + handle_load_dll (dll_name, event->lpBaseOfDll); + } else if (event->lpBaseOfDll != nullptr) add_dll (event->lpBaseOfDll); } @@ -694,6 +698,48 @@ windows_process_info::add_all_dlls () add_dll (nullptr); } +#ifdef __CYGWIN__ + +/* See nat/windows-nat.h. */ + +void +windows_process_info::maybe_note_cygwin1_dll (const char *dll_path) +{ + const char *base = dll_path + strlen (dll_path); + while (base > dll_path && base[-1] != '/' && base[-1] != '\\') + base--; + if (strcasecmp (base, "cygwin1.dll") == 0) + cygwin1_dll_loaded = true; +} + +/* See nat/windows-nat.h. */ + +bool +inferior_started_by_cygwin (DWORD winpid, bool attaching) +{ + /* In the run (non-attach) case this is called early when the + inferior has only just reached its first instruction and + cygwin1.dll hasn't initialized itself yet -- GDB launched the + inferior with raw CreateProcess, not through Cygwin's fork/spawn + path, so PID_CYGPARENT is necessarily false, so we can shortcut + without calling Cygwin. */ + if (!attaching) + return false; + + /* Note CW_WINPID_TO_CYGWIN_PID never fails. It returns a synthetic + pid for non-Cygwin or unknown winpids, in which case CW_GETPINFO + returns either a pinfo with PID_CYGPARENT unset, or NULL. */ + auto cygpid = (pid_t) cygwin_internal (CW_WINPID_TO_CYGWIN_PID, winpid); + + auto *pinfo = (external_pinfo *) cygwin_internal (CW_GETPINFO, cygpid); + if (pinfo == nullptr) + return false; + + return (pinfo->process_state & PID_CYGPARENT) != 0; +} + +#endif /* __CYGWIN__. */ + /* See nat/windows-nat.h. */ target_waitstatus @@ -703,6 +749,110 @@ windows_process_info::exit_process_to_target_status DWORD exit_code = info.dwExitCode; target_waitstatus tstatus; +#ifdef __CYGWIN__ + /* A Cygwin parent waiting on a Cygwin child via waitpid doesn't go + through GetExitCodeProcess / the Win32 exit code at all. It + reads the child's wait status directly out of the child's Cygwin + pinfo (shared memory), set by pinfo::exit in + winsup/cygwin/pinfo.cc. So sys/wait.h macros apply to that value + verbatim. + + GDB, however, even though it is itself a Cygwin program, drives + its inferiors via the native Win32 debugger API: it spawns them + with CreateProcess (DEBUG_PROCESS), not via Cygwin's + fork/spawn/posix_spawn, and consumes + EXIT_PROCESS_DEBUG_EVENT.dwExitCode from WaitForDebugEvent rather + than calling waitpid. That dwExitCode value comes from the + inferior's ExitProcess call. + + What that value means depends on two orthogonal things: + + 1. Is the inferior a Cygwin process at all? If not, dwExitCode + is a raw Win32 exit value. + + 2. For a Cygwin inferior, was it created through Cygwin's spawn + path? + + - If not, cygwin1.dll's pinfo::exit byte-swaps the wait status + on the way out, so that the meaningful exit value lands in + the low byte where native Win32 consumers (cmd.exe's "echo + %errorlevel%", and bare GetExitCodeProcess readers) expect + it. This is the case for Cygwin inferiors that we run, via + CreateProcess. + + - If yes, cygwin1.dll does not swap. We see this case if we + attach to an already-running process with a Cygwin parent. + + See winsup/cygwin/pinfo.cc: + + int exitcode = self->exitcode & 0xffff; + if (!self->cygstarted) + exitcode = ((exitcode & 0xff) << 8) | ((exitcode >> 8) & 0xff); + ... + ExitProcess (exitcode); + */ + + /* The inferior may also exit with a raw NTSTATUS error code, e.g., + STATUS_ACCESS_VIOLATION (0xc0000005), without going through the + pinfo::exit at all -- for example, if the unhandled-exception + filter didn't run, or for processes that don't link cygwin1.dll. + Detect those and map them the same way Cygwin's set_exit_code + does in winsup/cygwin/pinfo.cc. */ + if (exit_code >= 0xc0000000) + { + gdb_signal sig; + switch (exit_code) + { + case EXCEPTION_ACCESS_VIOLATION: + sig = GDB_SIGNAL_SEGV; + break; + case EXCEPTION_ILLEGAL_INSTRUCTION: + sig = GDB_SIGNAL_ILL; + break; + case STATUS_NO_MEMORY: + sig = GDB_SIGNAL_BUS; + break; + case STATUS_CONTROL_C_EXIT: + sig = GDB_SIGNAL_INT; + break; + default: + /* Cygwin maps any other NTSTATUS to exit 127. */ + tstatus.set_exited (127); + return tstatus; + } + tstatus.set_signalled (sig); + return tstatus; + } + + if (!this->cygwin1_dll_loaded) + { + /* Non-Cygwin inferior: dwExitCode is a raw Win32 exit value. + Limit to 8 bits, like Cygwin does, matching what happens with + Cygwin inferiors. */ + tstatus.set_exited (exit_code & 0xff); + return tstatus; + } + + /* Note: when GDB attaches to a Cygwin inferior and the inferior is + then killed externally (e.g., taskkill /F with exit code 1), GDB + and Cygwin disagree. Cygwin's parent waitpid reports WIFEXITED, + code=1; GDB reports SIGHUP (signal 1, no swap below because + started_by_cygwin). Cygwin's parent distinguishes "pinfo::exit + ran" from "didn't run" via the child's wait pipe and only applies + the swap-undo for the former. GDB has only dwExitCode and can't + tell. This can't be solved without Cygwin's help. OTOH, such an + external termination steps out of Cygwin and arguably falls into + undefined-behavior territory, so it is less important than the + other cases. */ + + int wstatus = exit_code & 0xffff; + if (!this->started_by_cygwin) + wstatus = ((wstatus & 0xff) << 8) | ((wstatus >> 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. */ @@ -712,6 +862,7 @@ windows_process_info::exit_process_to_target_status tstatus.set_exited (exit_code); else tstatus.set_signalled (gdb_signal_from_host (exit_signal)); +#endif return tstatus; } diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index d2e6adb4f40..2e4db9832ae 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -224,6 +224,23 @@ struct windows_process_info DWORD process_id = 0; DWORD main_thread_id = 0; +#ifdef __CYGWIN__ + /* True if the inferior was created through Cygwin's spawn path + (i.e., its Cygwin pinfo has PID_CYGPARENT set). We need this at + exit time, but we cache it early when we start debugging the + inferior, because by exit time the inferior's Cygwin pinfo may + have been torn down (CW_GETPINFO returns NULL). */ + bool started_by_cygwin = false; + + /* True if cygwin1.dll is loaded into the inferior. */ + bool cygwin1_dll_loaded = false; + + /* If DLL_PATH is cygwin1.dll, set cygwin1_dll_loaded to true. */ + void maybe_note_cygwin1_dll (const char *dll_path); +#else + void maybe_note_cygwin1_dll (const char *) {} +#endif + #ifdef __x86_64__ /* The target is a WOW64 process */ bool wow64_process = false; @@ -353,6 +370,18 @@ struct windows_process_info int get_exec_module_filename (char *exe_name_ret, size_t exe_name_max_len); }; +#ifdef __CYGWIN__ +/* Return true if the process with native Windows pid WINPID was + started by a Cygwin parent -- that is, its Cygwin pinfo exists and + has PID_CYGPARENT set. Returns false if the process is not a + Cygwin process at all, or if its parent is not a Cygwin process. + + ATTACHING indicates whether GDB is attaching to an already-running + inferior (true) or has just launched it via CreateProcess + (false). */ +extern bool inferior_started_by_cygwin (DWORD winpid, bool attaching); +#endif + /* Return a string version of EVENT_CODE. */ extern std::string event_code_to_string (DWORD event_code); diff --git a/gdb/testsuite/gdb.base/exitsignal.exp b/gdb/testsuite/gdb.base/exitsignal.exp index 7684646b546..348c7a72eff 100644 --- a/gdb/testsuite/gdb.base/exitsignal.exp +++ b/gdb/testsuite/gdb.base/exitsignal.exp @@ -37,6 +37,10 @@ set exec2 "normal" set srcfile2 ${exec2}.c set binfile2 [standard_output_file ${exec2}] +set exec3 "segv-win32" +set srcfile3 ${exec1}.c +set binfile3 [standard_output_file ${exec3}] + if { [build_executable "failed to build $exec1" ${exec1} "${srcfile1}" \ {debug}] == -1 } { return -1 @@ -47,6 +51,16 @@ if { [build_executable "failed to build $exec2" ${exec2} "${srcfile2}" \ return -1 } +# On Cygwin, also build a pure-Win32 segv binary, used to test that +# GDB extracts the terminating SIGSEGV out of the 0xc0000005 +# (STATUS_ACCESS_VIOLATION) Windows exit code. +if {[istarget "*-*-cygwin*"]} { + if { [build_executable "failed to build $exec3" ${exec3} "${srcfile3}" \ + {debug win32}] == -1} { + return -1 + } +} + # Get the inferior under GDB's control in mode HOW ("run" or # "attach"), using BINFILE. In "attach" mode, spawn the binary and # attach to it; in "run" mode, run to main. In both modes, clear the @@ -81,14 +95,14 @@ proc teardown {how} { } } -proc test_signal {how} { - clean_restart $::exec1 +proc test_signal {how exec binfile} { + clean_restart $exec # Get the inferior under GDB's control. But, before, change cwd # so the core file ends up in the output directory. set_inferior_cwd_to_output_dir - setup $how $::binfile1 + setup $how $binfile # Get the inferior's PID for later. set pid [get_inferior_pid] @@ -106,7 +120,8 @@ proc test_signal {how} { gdb_test "continue" "(Thread .*|Program) received signal SIGSEGV.*" \ "trigger SIGSEGV" - if {[istarget "*-*-mingw*"]} { + if {[istarget "*-*-mingw*"] + || ([istarget "*-*-cygwin*"] && $binfile == $::binfile3)} { # We're debugging a pure Win32 program with no SEH handler. The # previous continue caught the first-chance exception. Now we # catch the second-chance one. @@ -140,7 +155,7 @@ proc test_signal {how} { } else { with_test_prefix "reattach" { kill_wait_spawned_process $::test_spawn_id - setup $how $::binfile1 + setup $how $binfile } } @@ -190,9 +205,14 @@ foreach_with_prefix how {"run" "attach"} { } with_test_prefix "signal" { - test_signal $how + test_signal $how $exec1 $binfile1 } with_test_prefix "normal" { test_normal $how } + if {[istarget "*-*-cygwin*"]} { + with_test_prefix "signal, win32" { + test_signal $how $exec3 $binfile3 + } + } } diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 26333238cfa..16269671d95 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -1994,6 +1994,11 @@ windows_nat_target::do_initial_windows_stuff (DWORD pid, bool attaching) phase, and then process them all in one batch now. */ windows_process->add_all_dlls (); +#ifdef __CYGWIN__ + windows_process->started_by_cygwin + = inferior_started_by_cygwin (pid, attaching); +#endif + windows_process->windows_initialization_done = 1; return; } diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index 550994b0bf2..2150045e188 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -368,6 +368,11 @@ do_initial_child_stuff (HANDLE proch, DWORD pid, int attached) phase, and then process them all in one batch now. */ windows_process.add_all_dlls (); +#ifdef __CYGWIN__ + windows_process.started_by_cygwin + = inferior_started_by_cygwin (pid, attached); +#endif + windows_process.child_initialization_done = 1; } From patchwork Mon May 25 19:18:27 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 135631 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 A4B9F4B9DB71 for ; Mon, 25 May 2026 19:19:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A4B9F4B9DB71 X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by sourceware.org (Postfix) with ESMTPS id D41964BA900A for ; Mon, 25 May 2026 19:18:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D41964BA900A 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 D41964BA900A Authentication-Results: sourceware.org; arc=none smtp.remote-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779736733; cv=none; b=jRv3yzSbRz8blPYJCWac/sFrRGmkQUAHXZ/qRK9o3fY2LTu2EONpMmGfzJUrQlOwGdlq2s6hH4pQ58KmgHNy0369eXwQMBsMk2gRpeglvjxfvsVGhklmux5i0u0NZTcCRFx5CfiY97ATGFEMEJ8IzZOdsc0a/mLRd+XRG9cdPZk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779736733; c=relaxed/simple; bh=JTQ24kH1MQAdrkIwlpJiSHTaN2z/juU5J1q+TgCrhjk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Ck/rFGcdgghl7Q5yWpTkqRiV6EQ8wa6gCvtzT439ubtdzEsVXKw+u9yGc0+CZ4dmpHtpRm2/Y8H+2zuxTYmho5moYWLtcbJqZyPklBvi1tGt+Svx3lZMpILhJoug7IZlEQhbazthwMYdMj2V8LaCIMpicYw4bGODX+nZeVczARM= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D41964BA900A Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4905529b933so15569545e9.0 for ; Mon, 25 May 2026 12:18:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779736732; x=1780341532; 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=9HY628vdKYQ8UfNtqGT0JYZTL+BURuIZKygkNhbbF+k=; b=Xvnc9EnJqPqrY/gcesRMY8qDvjxTWiBF3EAtVR55fJ64+NiZ5NwcHdnQkG9h6h+ob4 UzkqutAe8J+qtTFLpM3R30uSwKM2UMgccdWZFG/biaUmHEka9j/2OGIiXbhJz+tTIj1j wOHcHdXHUHehPH/+ZHI0iXcDcTCeMEV7h1B1yjD3prAfbZ7/yWUawhef7Tv8oUlBcrJ1 sja3yXdROozOVMl9J7hEEZaryApflqBQZyXeoSCx+rUTrUsIFh8L33f1RxopKZX1NmvK lOPha4VEEtOUHrss++7/9QSoT+6y2YIRVagK8gOUGMsBhWt+uEVFy8xIx9Mjjd7DAAXo DS9w== X-Gm-Message-State: AOJu0Yx/enWgHQ5tSwK5URps1IhRVMMhZpqn7McC4Wfp5so7REGap+t1 KEF3o2Ix1AwkTGiCZtV3Pv1rHX3fDtwAOXKZLRS0MrzRNaCE3eIqDJPutnkjGg== X-Gm-Gg: Acq92OFGOrlpY29Ykp/eR0HPRJ+kv5iQz+qpD1fR0bpGjEvnV4932s4WX62MecSvLOu 8XUtydgR91OrFWqy6YQqRokDAjkYAG4RajqI309gU2PP73XT/lLZsczNd6Z7H/BRdzkIogQxd4I eRGaaicYRkyxJ3KK0wsHS1R2pcLgMLejHiGnIW+wXMJ+BKn76jd0Vwobv0wZQ8zN8DrpngITYMt zYu35SLeyUJ+YaU4fzqsul863VFdIsSBChbBBau7Pjm6b7oJdb7eDG1E7WWepNP5bi4pGpAAFXV FqKNEdoThIDkXU+vfkGJ74Yk+S+HWZO8/5KKcwhZ00AUxDG+2y4SUmCug0QjRaCa7bBWRhDt5P6 97pDLCKsdHbhHuhEv0NmRqsd+Tl3W+BqVps45QGgbvBJIQPvsH0KsjBXzvdqmXx3kKIJSVitg6k lZmvK0xcVnkzSsE5Zi256JB3uRcBx4M20C X-Received: by 2002:a05:600c:4510:b0:48a:53ea:140b with SMTP id 5b1f17b1804b1-490428ddf15mr242600255e9.28.1779736731606; Mon, 25 May 2026 12:18:51 -0700 (PDT) Received: from localhost ([2001:8a0:fae3:2600:dc16:ec0f:632c:5ba7]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-49045282201sm295842825e9.8.2026.05.25.12.18.50 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 May 2026 12:18:51 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 09/11] Adjust gdb.python/py-events.exp for Cygwin/MinGW, thread IDs Date: Mon, 25 May 2026 20:18:27 +0100 Message-ID: <20260525191829.984105-10-pedro@palves.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260525191829.984105-1-pedro@palves.net> References: <20260525191829.984105-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_BLOCKED, 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 a couple issues in gdb.python/py-events.exp for Cygwin and MinGW: 1) - GDB prints Windows thread IDs in hex: (gdb) thread [Current thread is 1 (Thread 9528.0xa9c)] The current code assumes 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 extracted thread ID is the same number as the extracted process ID, which is not true on Windows. Also tested on x86_64-unknown-linux-gnu. Change-Id: Iebcc07c3ad0845b548334c0d5177b3ab9e9350cf commit-id: 8009478e --- gdb/testsuite/gdb.python/py-events.exp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/gdb/testsuite/gdb.python/py-events.exp b/gdb/testsuite/gdb.python/py-events.exp index 16a290c31c2..b07eb2ec9b0 100644 --- a/gdb/testsuite/gdb.python/py-events.exp +++ b/gdb/testsuite/gdb.python/py-events.exp @@ -76,17 +76,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 +105,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 From patchwork Mon May 25 19:18:28 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 135635 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 DE0F54BA2E37 for ; Mon, 25 May 2026 19:20:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DE0F54BA2E37 X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by sourceware.org (Postfix) with ESMTPS id C22064BA7980 for ; Mon, 25 May 2026 19:18:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C22064BA7980 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 C22064BA7980 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779736735; cv=none; b=Iac743HoPLKABfRlVoeeLLGAUAsqVJMaNsCjQ185mYXjCMckeYqikbdXdpWR8RoPJ1QLd8XvV1tl7gxBeUotjj7UpK7UyTj8XHa9MT8xIymijgjnACMzmvAaMt8BsgI88gYQiuRPiBJ92lt4FTIfwuyHqxZrg4zVGXFPuIN9+NE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779736735; c=relaxed/simple; bh=ZJ+H2DT/1norlxbdqE+gLmaCPdSuBPmn+1fTwjK3WvM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=GAfMg/3v4gzINqJGBuh1b4yK7aERICCCtVfcHS2zsujIW/SS1EnjdXzCNDnwoy+CeebocmP56iTA6jOLZ/RBDdadW2Co/SzPjLs6cbZkuxuVTSP9gLcXGSN5UMLnTm4+Y65El2+MKqUOjH9hQH8P/pSGDQ4AFcIGSiSOdczHHGM= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C22064BA7980 Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4906869f0cbso10295215e9.1 for ; Mon, 25 May 2026 12:18:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779736734; x=1780341534; 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=gsIbbtO/KJs7GCTDOP6TPZT/D3PXgTtjADR+dh6foQw=; b=iPGprKd4a2BJsMAHVG0I4lSwk17xmEz7YDjNUxG1qhWABJr3tVd0cW4VJYuv2hxsTg 95S5QQ5hyEANjD1y34nKE9CKMKvIJzoHwtBrBQCPyGZdVo0Bp4n/4tFKcjfagU4P7ZnU 1jWqz+tsRuneFrLKa3YyfIZUJ2HOsgw0/gnje42otY4ig93CmrB/sTd1KhTog+J2ud/U AbE0h8F7wUhQVBYGo6ArSOqLRXqruuah4K6zCV0Lrit8SVVHSTNaFYEqcXL95DDwJuD6 0CWKN7+8qWwZDRz+ZU2qCCj9aCheZLoyB2qRgrhhsjchJgSGDO6i9ddLNwb9p/hcTIPw ACLw== X-Gm-Message-State: AOJu0YznCf9YhKF2RGMrXD+Olaw1sRmXsnqm0IrKtLuM/7k+d6VlVAoQ K584HfkUx8ljye9nYcg65ZU4DYO+EzDBlRdygofMkNp2RDBebCjSmELBr/4Msg== X-Gm-Gg: Acq92OFIsEYF1BGWcLYYlg1+WvpP8wtg1fgvh5wzHZ6orslJEJQ4NXhLPx0wTU0/bzm K9nzLuE3xvIj2qI5OHJ8zEfS4wkyD1hIspM+TJREmP+FkbFJE7ZXcnicFSCOS5YtMeM3qZVFLWB 6d3jI91CWTZ4zXdeFiQr5dbaUvIuwHmt95mY/3XJ2RrM5LzkwsVeJINoyzVaFSykZSzJW9uOUJ2 64dnkuT3JQ2bE4R4a0oFjwV/XXeos4HTQ+EAU8WCXSbeoJhWlsyyi9Gj6B73e43xZj/oIrbGieU sIQg3YAcJt/Hup1Z1x2GGu/enjr/BKlwJeM9hA4hMTwOJ+VF4/rsegp7QxzGNiwuVu3XPCiv87/ zOTE680cmop7dq9rDpSAWtq9s3gWCo9vpWoNbAW0uXOEOpMDKOvqWyD/n1bptI8g/Yugk7HfHzW M67eOkWPD01H+xmBRZrno9aYOWIJlQ1s7L X-Received: by 2002:a05:600c:4ecc:b0:490:3a07:c467 with SMTP id 5b1f17b1804b1-490426cf642mr247878655e9.22.1779736733512; Mon, 25 May 2026 12:18:53 -0700 (PDT) Received: from localhost ([2001:8a0:fae3:2600:dc16:ec0f:632c:5ba7]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-490454ea134sm299266755e9.8.2026.05.25.12.18.52 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 May 2026 12:18:53 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 10/11] Adjust gdb.python/py-events.exp for Cygwin/MinGW, no fork Date: Mon, 25 May 2026 20:18:28 +0100 Message-ID: <20260525191829.984105-11-pedro@palves.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260525191829.984105-1-pedro@palves.net> References: <20260525191829.984105-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-8.8 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_BLOCKED, 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 The gdb.python/py-events.exp testcase currently uses fork, and relies on "set detach-on-fork off". Cygwin does support the fork syscall, 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. We can replace what those parts were testing by more focused tests: - The clear_objfiles event was tested via following a fork. Instead, test a more directed "file" command. - Two-inferior quit was being used to test that gdb.ExitedEvent has no "exit_code". Quitting while an inferior is being debugged makes GDB kill the inferior. What's really being tested is the kill path, so write an explicit (single-inferior) kill test. 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 | 59 +++++++++++++------------- 2 files changed, 30 insertions(+), 32 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 b07eb2ec9b0..a34a423c014 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" @@ -217,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" \ @@ -286,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 } } @@ -354,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" +} From patchwork Mon May 25 19:18:29 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 135633 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 3A5984BA7988 for ; Mon, 25 May 2026 19:20:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3A5984BA7988 X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) by sourceware.org (Postfix) with ESMTPS id 708334BA7997 for ; Mon, 25 May 2026 19:18:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 708334BA7997 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 708334BA7997 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779736738; cv=none; b=p9R8X/AuAjE3D92ySfXKlPtT6Vtashr6vOqYG2wCIiN7hrSA+vBmzgSAD5maRhA5Qhdj1/dtSrmt7Fk21fTWA+iFLyGS2OsVTu6D8F3YFX+N+KbNStDVHEcnrOK2mLhwNo1JE6IqIB+AGJ5AoqLfAZvhnA9cUCRGds0SN0Guf7A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779736738; c=relaxed/simple; bh=qItVgjDNb7fHvT5bI9DqNmUV9cX/dByQOR0ztCaWGgc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=O7IyNEIUf/rx2MSDZIWb0gapLteamJHsYueQsm5ssjjov8vVtnAwBapyNP3BJhDYXsUaE6YqYYfsfLIvLLGvgx4IP4DTcjgABvq3j9ECqKzZPKJFlDrQvINk9HL6bl038lWBhElmIKk+sizRSPop5a2eMCaoaYHAnBIo2+g8tDc= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 708334BA7997 Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-45e9f4a3510so2538221f8f.1 for ; Mon, 25 May 2026 12:18:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779736737; x=1780341537; 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=eFWtp8UhFMfKPcqq396Z8hy6sxXaTUW2mjPOLFVaWQk=; b=ZHixrajQDLAsciUVZObZBUGuxqhHRZ15bT2q6B2gex5bNt2NW5ITyzb2IWNUDanDjD uy3zb9O4lF0iLIqUAD7rpIyMjIquZa4tCOTp/ygJmC8JoL6CF9HIJ4NEMxqlgUrBDo8G w7qggifae+JV5Wnc7u2I5l1kb+IQhzA3S+dBdPFeSl9y53oVUPQcw725r7y2NKFwdnsm pXXHyOxciotwAXw+IF/+DyZebti4ch8Pu52kKhvXr5OngircagblO3Cg44FkjKvtIuDr hTU+NTVjVk4nwJ2GdTPOrpnHT9o5m3YK4e0KBcVqaWdW0J+H5nNH/0mzjBAA+K2MznE7 FmvQ== X-Gm-Message-State: AOJu0YworONXG7/E5WVfxIWOc5W8VblO6HkUg84e0gmLmDU3naU9G0Ph s9PnCSumn5CiFtvxsCFSO3lLL/zrjk2Z38RBeNPHyZOGa9/fqpQxg/FMFyvOZA== X-Gm-Gg: Acq92OGeeVhqzDhDN/xGn9qlJx9nN1kz+YoN1jGvX3x1dZK5MKwa+T8wnwzZFfxbNtl asAlEPAw3hSxL0kvMx64otNAsrbqdijiUE9Jgof3fJf2gK1do/OtjozXM/8BfGcIbJCvolnrBp9 qdibZA3f/G01PC9sWz0DsHDlWXe1QSydMZ7sM9FYpYUgpUSP0HqQxqsnfFjKPCIDak8FpkMx82i LBzyKVHyfdpYuaS/wrGeh1pknwfMd1W+/V6a8FTwmEyBL3hk+avE8hKieKJAj38fRArD3Nqz+zM UC9qpg38PXpi4qBIpAkwCv0B/ubt9uBSdiiutXq3FGKlQvnXCxWf9OEnb6W0rn21IZ48//sInik 9TLD7IxETxjf3qvU6Vb+LmnX6Kdmh7DlRMeJbm49Hd8c7jg8Z3aHgLoCx+cvGWBNZ+OEvty1+2l 54M80bfngsMt1XkYG9Kbu2/w== X-Received: by 2002:a05:6000:4a1e:b0:44a:fa76:5193 with SMTP id ffacd0b85a97d-45eb36881a0mr23986844f8f.12.1779736737298; Mon, 25 May 2026 12:18:57 -0700 (PDT) Received: from localhost ([2001:8a0:fae3:2600:dc16:ec0f:632c:5ba7]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-45eb6d4ca0dsm28969998f8f.18.2026.05.25.12.18.56 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 May 2026 12:18:57 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 11/11] Adjust gdb.python/py-events.exp for Cygwin/MinGW, "info proc" => "inferior" Date: Mon, 25 May 2026 20:18:29 +0100 Message-ID: <20260525191829.984105-12-pedro@palves.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260525191829.984105-1-pedro@palves.net> References: <20260525191829.984105-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-8.8 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_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 The testcase is using "info proc" to extract the inferior's process ID. But "info proc" does not exist on all targets, including Windows. Switch to using the get_inferior_pid routine from lib/gdb.exp, which uses "inferior" instead. With this fixed, the testcase passes cleanly on Cygwin. I haven't tested on MinGW (I'm not set up for Python testing there currently), but at least (since the previous patches) the test should be able to compile & run there now. Also tested on x86_64-unknown-linux-gnu. Change-Id: If6ff482ceb011d9afe5ed40ef7e4e2f2cad8cae8 commit-id: 172fe262 --- gdb/testsuite/gdb.python/py-events.exp | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/gdb/testsuite/gdb.python/py-events.exp b/gdb/testsuite/gdb.python/py-events.exp index a34a423c014..35681cb178e 100644 --- a/gdb/testsuite/gdb.python/py-events.exp +++ b/gdb/testsuite/gdb.python/py-events.exp @@ -203,19 +203,7 @@ gdb_test_multiple "continue" $test { gdb_test_no_output "delete $second_breakpoint" -#test exited event. -proc get_process_id {test} { - global gdb_prompt - gdb_test_multiple "info proc" $test { - -re "process (\\d+).*$gdb_prompt $" { - set process_id $expect_out(1,string) - pass $gdb_test_name - } - } - return ${process_id} -} - -set process_id [get_process_id "get inferior process id"] +set process_id [get_inferior_pid] gdb_test "continue" ".*event type: continue.* .*event type: exit.* .*exit code: 12.*