Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: gdb-patches@sourceware.org
Subject: [PATCH 3/5] Adjust gdb.base/exitsignal.exp for Cygwin
Date: Fri, 22 May 2026 01:16:24 +0100	[thread overview]
Message-ID: <20260522001626.393908-4-pedro@palves.net> (raw)
In-Reply-To: <20260522001626.393908-1-pedro@palves.net>

Cygwin has this feature where if the program is about to die with a
signal, and there's a debugger attached, it raises a SIGTRAP via
DebugBreak.  So if you try to pass a terminating signal to the
inferior, you see that SIGTRAP first, before the process exits with
the signal.  E.g.:

 Thread 1 "segfault" received signal SIGSEGV, Segmentation fault.
 0x0000000100401092 in main () at segfault.cc:5
 5         *(volatile int *)0;
 (gdb) c
 Continuing.
 Thread 1 "segfault" received signal SIGTRAP, Trace/breakpoint trap.
 0x00007ffe99d35a13 in KERNELBASE!DebugBreak () from C:/WINDOWS/System32/KERNELBASE.dll
 (gdb) bt
 #0  0x00007ffe99d35a13 in KERNELBASE!DebugBreak () from C:/WINDOWS/System32/KERNELBASE.dll
 #1  0x00007ffe896163b7 in break_here () at /usr/src/debug/cygwin-3.6.9-1/winsup/cygwin/dcrt0.cc:473
 #2  0x00007ffe8962fe13 in try_to_debug () at /usr/src/debug/cygwin-3.6.9-1/winsup/cygwin/exceptions.cc:599
 #3  exception::handle (e=0x7ffffc9b0, frame=<optimized out>, in=0x7ffffc4c0, dispatch=<optimized out>) at /usr/src/debug/cygwin-3.6.9-1/winsup/cygwin/exceptions.cc:812
 #4  0x00007ffe9c5e63df in ntdll!.chkstk () from C:/WINDOWS/SYSTEM32/ntdll.dll
 #5  0x00007ffe9c499497 in ntdll!RtlLocateExtendedFeature () from C:/WINDOWS/SYSTEM32/ntdll.dll
 #6  0x00007ffe9c5e5d1e in ntdll!KiUserExceptionDispatcher () from C:/WINDOWS/SYSTEM32/ntdll.dll
 #7  0x0000000100401092 in main () at segfault.cc:5
 (gdb) c
 Continuing.
 ...
 [Inferior 1 (process 8032) exited with code 05400]
 (gdb)

gdb.base/exitsignal.exp fails on Cygwin partly because it doesn't take
that into account.  This commit fixes it.

In addition, the typical adjustement for the fact that all programs
are multi-threaded on Cygwin is also necessary.

gdb.base/exitsignal.exp still won't pass cleanly yet.  That'll be
finally fixed in the next patch.

Change-Id: I2d18e2604afe3a4f80987848e2c1cd307ed43401
commit-id: 013964ce
---
 gdb/testsuite/gdb.base/exitsignal.exp | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/gdb.base/exitsignal.exp b/gdb/testsuite/gdb.base/exitsignal.exp
index aa2710450b5..f1effcd8cea 100644
--- a/gdb/testsuite/gdb.base/exitsignal.exp
+++ b/gdb/testsuite/gdb.base/exitsignal.exp
@@ -50,7 +50,13 @@ gdb_test "print \$_exitcode" " = void" \
     "\$_exitcode is void before running"
 
 # Trigger SIGSEGV.
-gdb_test "continue" "Program received signal SIGSEGV.*" "trigger SIGSEGV"
+gdb_test "continue" "(Thread .*|Program) received signal SIGSEGV.*" "trigger SIGSEGV"
+
+if {[istarget "*-*-cygwin*"]} {
+    # Cygwin calls DebugBreak before it lets the process exit.
+    gdb_test "continue" "Thread .* received signal SIGTRAP.*" \
+	"trigger try_to_debug SIGTRAP"
+}
 
 # Continue until the end.
 gdb_test "continue" "Program terminated with signal SIGSEGV.*" \
-- 
2.53.0


  parent reply	other threads:[~2026-05-22  0:17 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-22  0:16 [PATCH 0/5] Fix a few Cygwin/MinGW problems Pedro Alves
2026-05-22  0:16 ` [PATCH 1/5] Fix "set cwd ..." on Cygwin, part 1 Pedro Alves
2026-05-22 13:54   ` Tom Tromey
2026-05-22  0:16 ` [PATCH 2/5] Fix "set cwd ..." on Cygwin, part 2 Pedro Alves
2026-05-22 14:37   ` Tom Tromey
2026-05-25 16:43     ` Pedro Alves
2026-05-22  0:16 ` Pedro Alves [this message]
2026-05-22 15:09   ` [PATCH 3/5] Adjust gdb.base/exitsignal.exp for Cygwin Tom Tromey
2026-05-22  0:16 ` [PATCH 4/5] Fix exit/signal code on Cygwin Pedro Alves
2026-05-22  7:15   ` Eli Zaretskii
2026-05-25 16:47     ` Pedro Alves
2026-05-22  0:16 ` [PATCH 5/5] Adjust gdb.python/py-events.exp for Cygwin/MinGW Pedro Alves
2026-05-22  7:18   ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260522001626.393908-4-pedro@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox