From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 836623858407; Wed, 23 Feb 2022 17:48:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 836623858407 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: pty, console: Add a workaround for GDB SIGINT handling. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: d2b14c303c04989ae87bf1341357d059d266bf02 X-Git-Newrev: 2f2b91550547001b005393097c5a4328451343d6 Message-Id: <20220223174855.836623858407@sourceware.org> Date: Wed, 23 Feb 2022 17:48:55 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Feb 2022 17:48:55 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D2f2b9155054= 7001b005393097c5a4328451343d6 commit 2f2b91550547001b005393097c5a4328451343d6 Author: Takashi Yano Date: Thu Feb 24 00:57:37 2022 +0900 Cygwin: pty, console: Add a workaround for GDB SIGINT handling. =20 - The inferior of the GDB cannot be continued after SIGINT even though nopass option is set. This seems because cygwin GDB does not support hooking cygwin signal. Therefore, a workaround for GDB is added. With this patch, only CTRL_C_EVENT is sent to the GDB inferior by Ctrl-C and sending SIGINT is omitted. Note that "handle SIGINT (no)pass" command does not take effect even with or without this patch. Diff: --- winsup/cygwin/fhandler.h | 3 ++- winsup/cygwin/fhandler_console.cc | 1 + winsup/cygwin/fhandler_termios.cc | 29 ++++++++++++++++++++++++++++- winsup/cygwin/fhandler_tty.cc | 9 ++++++++- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index b252b6e1c..7ddf7e450 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -1906,7 +1906,8 @@ class fhandler_termios: public fhandler_base signalled, not_signalled, not_signalled_but_done, - not_signalled_with_nat_reader + not_signalled_with_nat_reader, + done_with_debugger }; =20 public: diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_con= sole.cc index a7516f238..b290cde08 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -251,6 +251,7 @@ fhandler_console::cons_master_thread (handle_set_t *p, = tty *ttyp) { case signalled: case not_signalled_but_done: + case done_with_debugger: processed =3D true; ttyp->output_stopped =3D false; if (ti.c_lflag & NOFLSH) diff --git a/winsup/cygwin/fhandler_termios.cc b/winsup/cygwin/fhandler_ter= mios.cc index 953aeade0..383e20764 100644 --- a/winsup/cygwin/fhandler_termios.cc +++ b/winsup/cygwin/fhandler_termios.cc @@ -315,12 +315,16 @@ fhandler_termios::process_sigs (char c, tty* ttyp, fh= andler_termios *fh) termios &ti =3D ttyp->ti; pid_t pgid =3D ttyp->pgid; =20 + pinfo leader (pgid); + bool cyg_leader =3D leader && !(leader->process_state & PID_NOTCYGWIN); bool ctrl_c_event_sent =3D false; bool need_discard_input =3D false; bool pg_with_nat =3D false; bool need_send_sig =3D false; bool nat_shell =3D false; bool cyg_reader =3D false; + bool with_debugger =3D false; + bool with_debugger_nat =3D false; =20 winpids pids ((DWORD) 0); for (unsigned i =3D 0; i < pids.npids; i++) @@ -328,6 +332,7 @@ fhandler_termios::process_sigs (char c, tty* ttyp, fhan= dler_termios *fh) _pinfo *p =3D pids[i]; if (c =3D=3D '\003' && p && p->ctty =3D=3D ttyp->ntty && p->pgid =3D= =3D pgid && ((p->process_state & PID_NOTCYGWIN) + || (p->process_state & PID_NEW_PG) || !(p->process_state & PID_CYGPARENT))) { pinfo pinfo_resume =3D pinfo (myself->ppid); @@ -350,7 +355,8 @@ fhandler_termios::process_sigs (char c, tty* ttyp, fhan= dler_termios *fh) /* CTRL_C_EVENT does not work for the process started with CREATE_NEW_PROCESS_GROUP flag, so send CTRL_BREAK_EVENT instead. */ - if (p->process_state & PID_NEW_PG) + if ((p->process_state & PID_NEW_PG) + && (p->process_state & PID_NOTCYGWIN)) { GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, p->dwProcessId); @@ -378,8 +384,28 @@ fhandler_termios::process_sigs (char c, tty* ttyp, fha= ndler_termios *fh) nat_shell =3D true; if (p->process_state & PID_TTYIN) cyg_reader =3D true; + if (!p->cygstarted && !(p->process_state & PID_NOTCYGWIN) + && (p !=3D myself || being_debugged ()) + && cyg_leader) /* inferior is cygwin app */ + with_debugger =3D true; + if (!(p->process_state & PID_NOTCYGWIN) + && (p->process_state & PID_NEW_PG) /* Check marker */ + && p->pid =3D=3D pgid) /* inferior is non-cygwin app */ + with_debugger_nat =3D true; } } + if ((with_debugger || with_debugger_nat) && need_discard_input) + { + if (!(ti.c_lflag & NOFLSH) && fh) + { + fh->eat_readahead (-1); + fh->discard_input (); + } + ti.c_lflag &=3D ~FLUSHO; + return done_with_debugger; + } + if (with_debugger_nat) + return not_signalled; /* Send SIGQUIT to non-cygwin process. */ if ((ti.c_lflag & ISIG) && CCEQ (ti.c_cc[VQUIT], c) && pg_with_nat && need_send_sig && !nat_shell) @@ -491,6 +517,7 @@ fhandler_termios::line_edit (const char *rptr, size_t n= read, termios& ti, sawsig =3D true; fallthrough; case not_signalled_but_done: + case done_with_debugger: get_ttyp ()->output_stopped =3D false; continue; case not_signalled_with_nat_reader: diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index b9549bba9..4aafe08fa 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -2293,7 +2293,14 @@ fhandler_pty_master::write (const void *ptr, size_t = len) =20 for (size_t i =3D 0; i < nlen; i++) { - fhandler_termios::process_sigs (buf[i], get_ttyp (), this); + process_sig_state r =3D process_sigs (buf[i], get_ttyp (), this); + if (r =3D=3D done_with_debugger) + { + for (size_t j =3D i; j < nlen - 1; j++) + buf[j] =3D buf[j + 1]; + nlen--; + i--; + } process_stop_start (buf[i], get_ttyp (), true); }