Cygwin: termios: Ensure detection of GDB inferior in process_sigs().

- In some situations, some cygwin processes might wrongly identified
  as GDB inferior. This patch ensures the detection of GDB inferior.
This commit is contained in:
Takashi Yano 2022-02-28 07:24:45 +09:00
parent 33d8578feb
commit 15a35758d8
3 changed files with 9 additions and 6 deletions

View File

@ -345,7 +345,8 @@ fhandler_termios::process_sigs (char c, tty* ttyp, fhandler_termios *fh)
without pcon enabled. In this case, the inferior is not without pcon enabled. In this case, the inferior is not
cygwin process list. PID_NEW_PG is set as a marker for cygwin process list. PID_NEW_PG is set as a marker for
GDB with non-cygwin inferior in pty code. 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 == '\003' && p && p->ctty == ttyp->ntty && p->pgid == pgid if (c == '\003' && p && p->ctty == ttyp->ntty && p->pgid == pgid
&& ((p->process_state & PID_NOTCYGWIN) && ((p->process_state & PID_NOTCYGWIN)
|| (p->process_state & PID_NEW_PG) || (p->process_state & PID_NEW_PG)
@ -408,13 +409,12 @@ fhandler_termios::process_sigs (char c, tty* ttyp, fhandler_termios *fh)
if (p->process_state & PID_TTYIN) if (p->process_state & PID_TTYIN)
cyg_reader = true; /* Theh process is reading the tty */ cyg_reader = true; /* Theh process is reading the tty */
if (!p->cygstarted && !(p->process_state & PID_NOTCYGWIN) if (!p->cygstarted && !(p->process_state & PID_NOTCYGWIN)
&& (p != myself || being_debugged ()) && (p->process_state & PID_DEBUGGED))
&& cyg_leader) /* inferior is cygwin app */ with_debugger = true; /* inferior is cygwin app */
with_debugger = true;
if (!(p->process_state & PID_NOTCYGWIN) if (!(p->process_state & PID_NOTCYGWIN)
&& (p->process_state & PID_NEW_PG) /* Check marker */ && (p->process_state & PID_NEW_PG) /* Check marker */
&& p->pid == pgid) /* inferior is non-cygwin app */ && p->pid == pgid)
with_debugger_nat = true; with_debugger_nat = true; /* inferior is non-cygwin app */
} }
} }
if ((with_debugger || with_debugger_nat) && need_discard_input) if ((with_debugger || with_debugger_nat) && need_discard_input)

View File

@ -276,6 +276,7 @@ enum
PID_PROCINFO = 0x08000, /* caller just asks for process info */ PID_PROCINFO = 0x08000, /* caller just asks for process info */
PID_NEW_PG = 0x10000, /* Process created with PID_NEW_PG = 0x10000, /* Process created with
CREATE_NEW_PROCESS_GROUOP flag */ CREATE_NEW_PROCESS_GROUOP flag */
PID_DEBUGGED = 0x20000, /* Process being debugged */
PID_EXITED = 0x40000000, /* Free entry. */ PID_EXITED = 0x40000000, /* Free entry. */
PID_REAPED = 0x80000000 /* Reaped */ PID_REAPED = 0x80000000 /* Reaped */
}; };

View File

@ -106,6 +106,8 @@ pinfo_init (char **envp, int envc)
myself->process_state |= PID_ACTIVE; myself->process_state |= PID_ACTIVE;
myself->process_state &= ~(PID_INITIALIZING | PID_EXITED | PID_REAPED); myself->process_state &= ~(PID_INITIALIZING | PID_EXITED | PID_REAPED);
if (being_debugged ())
myself->process_state |= PID_DEBUGGED;
myself.preserve (); myself.preserve ();
debug_printf ("pid %d, pgid %d, process_state %y", debug_printf ("pid %d, pgid %d, process_state %y",
myself->pid, myself->pgid, myself->process_state); myself->pid, myself->pgid, myself->process_state);