From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 4B43B3858D37; Sun, 27 Feb 2022 23:31:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4B43B3858D37 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-3_3-branch] Cygwin: termios: Ensure detection of GDB inferior in process_sigs(). X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/cygwin-3_3-branch X-Git-Oldrev: a58cfd1fe9e186b85d6dd036457d02c53da27649 X-Git-Newrev: ded470093e5973a484ea0fff683d7b8420e2267d Message-Id: <20220227233147.4B43B3858D37@sourceware.org> Date: Sun, 27 Feb 2022 23:31:47 +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: Sun, 27 Feb 2022 23:31:47 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Dded470093e5= 973a484ea0fff683d7b8420e2267d commit ded470093e5973a484ea0fff683d7b8420e2267d Author: Takashi Yano Date: Mon Feb 28 07:24:45 2022 +0900 Cygwin: termios: Ensure detection of GDB inferior in process_sigs(). =20 - In some situations, some cygwin processes might wrongly identified as GDB inferior. This patch ensures the detection of GDB inferior. Diff: --- winsup/cygwin/fhandler_termios.cc | 12 ++++++------ winsup/cygwin/include/sys/cygwin.h | 1 + winsup/cygwin/pinfo.cc | 2 ++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/winsup/cygwin/fhandler_termios.cc b/winsup/cygwin/fhandler_ter= mios.cc index f82ac76dc..028210d98 100644 --- a/winsup/cygwin/fhandler_termios.cc +++ b/winsup/cygwin/fhandler_termios.cc @@ -345,7 +345,8 @@ fhandler_termios::process_sigs (char c, tty* ttyp, fhan= dler_termios *fh) without pcon enabled. In this case, the inferior is not cygwin process list. PID_NEW_PG is set as a marker for GDB with non-cygwin inferior in pty code. - !PID_CYGPARENT: check this for GDB with cygwin inferior. */ + !PID_CYGPARENT: check this for GDB with cygwin inferior or + cygwin apps started from non-cygwin shell. */ 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) @@ -408,13 +409,12 @@ fhandler_termios::process_sigs (char c, tty* ttyp, fh= andler_termios *fh) if (p->process_state & PID_TTYIN) cyg_reader =3D true; /* Theh process is reading the tty */ if (!p->cygstarted && !(p->process_state & PID_NOTCYGWIN) - && (p !=3D myself || being_debugged ()) - && cyg_leader) /* inferior is cygwin app */ - with_debugger =3D true; + && (p->process_state & PID_DEBUGGED)) + with_debugger =3D true; /* inferior is cygwin app */ 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; + && p->pid =3D=3D pgid) + with_debugger_nat =3D true; /* inferior is non-cygwin app */ } } if ((with_debugger || with_debugger_nat) && need_discard_input) diff --git a/winsup/cygwin/include/sys/cygwin.h b/winsup/cygwin/include/sys= /cygwin.h index ac55ab09c..c9d4599a3 100644 --- a/winsup/cygwin/include/sys/cygwin.h +++ b/winsup/cygwin/include/sys/cygwin.h @@ -276,6 +276,7 @@ enum PID_PROCINFO =3D 0x08000, /* caller just asks for process info */ PID_NEW_PG =3D 0x10000, /* Process created with CREATE_NEW_PROCESS_GROUOP flag */ + PID_DEBUGGED =3D 0x20000, /* Process being debugged */ PID_EXITED =3D 0x40000000, /* Free entry. */ PID_REAPED =3D 0x80000000 /* Reaped */ }; diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index bb7c16547..5e04ea3da 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -106,6 +106,8 @@ pinfo_init (char **envp, int envc) =20 myself->process_state |=3D PID_ACTIVE; myself->process_state &=3D ~(PID_INITIALIZING | PID_EXITED | PID_REAPED); + if (being_debugged ()) + myself->process_state |=3D PID_DEBUGGED; myself.preserve (); debug_printf ("pid %d, pgid %d, process_state %y", myself->pid, myself->pgid, myself->process_state);