[PATCH] Cygwin: pty: Make Ctrl-C work for non-cygwin app in GDB
Takashi Yano
takashi.yano@nifty.ne.jp
Sat Feb 28 09:02:11 GMT 2026
At some point in the past, GDB sets its own pgid to inferior pid
when the inferior is running. Due to this behaviour, Ctrl-C does
not work if the inferior is a non-cygwin app. This is because,
the current code sends Ctrl-C to GDB only when GDB's pgid equeals
to terminal pgid. This patch omit checking pgid when recognizing
GDB process whose inferior is non-cygwin app.
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Reviewed-by:
---
winsup/cygwin/fhandler/termios.cc | 18 +++++++++---------
winsup/cygwin/tty.cc | 4 ++--
2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/winsup/cygwin/fhandler/termios.cc b/winsup/cygwin/fhandler/termios.cc
index 694a5c20f..00700aed8 100644
--- a/winsup/cygwin/fhandler/termios.cc
+++ b/winsup/cygwin/fhandler/termios.cc
@@ -346,11 +346,11 @@ fhandler_termios::process_sigs (char c, tty* ttyp, fhandler_termios *fh)
a marker for GDB with non-cygwin inferior in pty code.
!PID_CYGPARENT: check this for GDB with cygwin inferior or
cygwin apps started from non-cygwin shell. */
- if (c == '\003' && p && p->ctty == ttyp->ntty && p->pgid == pgid
- && ((p->process_state & PID_NOTCYGWIN)
+ if (c == '\003' && p && p->ctty == ttyp->ntty
+ && ((p->pgid == pgid && ((p->process_state & PID_NOTCYGWIN)
+ || !(p->process_state & PID_CYGPARENT)))
|| ((p->exec_dwProcessId == p->dwProcessId)
- && ttyp->pty_input_state_eq (tty::to_nat))
- || !(p->process_state & PID_CYGPARENT)))
+ && ttyp->pty_input_state_eq (tty::to_nat))))
{
/* Ctrl-C event will be sent only to the processes attaching
to the same console. Therefore, attach to the console to
@@ -403,12 +403,12 @@ fhandler_termios::process_sigs (char c, tty* ttyp, fhandler_termios *fh)
if (!p->cygstarted && !(p->process_state & PID_NOTCYGWIN)
&& (p->process_state & PID_DEBUGGED))
with_debugger = true; /* inferior is cygwin app */
- if (!(p->process_state & PID_NOTCYGWIN)
- && (p->exec_dwProcessId == p->dwProcessId) /* Check marker */
- && ttyp->pty_input_state_eq (tty::to_nat)
- && p->pid == pgid)
- with_debugger_nat = true; /* inferior is non-cygwin app */
}
+ if (p && p->ctty == ttyp->ntty
+ && !(p->process_state & PID_NOTCYGWIN)
+ && (p->exec_dwProcessId == p->dwProcessId) /* Check marker */
+ && ttyp->pty_input_state_eq (tty::to_nat))
+ with_debugger_nat = true; /* inferior is non-cygwin app */
}
if ((with_debugger || with_debugger_nat) && need_discard_input)
{
diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc
index 0c49dc2bd..3ab30c0a7 100644
--- a/winsup/cygwin/tty.cc
+++ b/winsup/cygwin/tty.cc
@@ -340,8 +340,8 @@ tty::nat_fg (pid_t pgid)
for (unsigned i = 0; i < pids.npids; i++)
{
_pinfo *p = pids[i];
- if (p->ctty == ntty && p->pgid == pgid
- && ((p->process_state & PID_NOTCYGWIN)
+ if (p->ctty == ntty
+ && (((p->process_state & PID_NOTCYGWIN) && p->pgid == pgid)
/* Below is true for GDB with non-cygwin inferior */
|| p->exec_dwProcessId == p->dwProcessId))
return true;
--
2.51.0
More information about the Cygwin-patches
mailing list