Cygwin: pty: Stop to use PID_NEW_PG flag as a marker for GDB.

- Previously, the PID_NEW_PG flag was also used as a marker for GDB
  with non-cygwin inferior, unlike its original meaning. With this
  patch, the condition exec_dwProcessId == dwProcessId is used as a
  marker for that instead.
This commit is contained in:
Takashi Yano 2022-03-03 11:43:07 +09:00
parent efd153853c
commit 261acf7318
3 changed files with 16 additions and 13 deletions

View File

@ -341,15 +341,16 @@ fhandler_termios::process_sigs (char c, tty* ttyp, fhandler_termios *fh)
{
_pinfo *p = pids[i];
/* PID_NOTCYGWIN: check this for non-cygwin process.
PID_NEW_PG: check this ofr GDB with non-cygwin inferior in pty
exec_dwProcessId == dwProcessId:
check this for GDB with non-cygwin inferior in pty
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.
cygwin process list. This condition is set true as
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)
|| (p->process_state & PID_NEW_PG)
|| (p->exec_dwProcessId == p->dwProcessId)
|| !(p->process_state & PID_CYGPARENT)))
{
/* Ctrl-C event will be sent only to the processes attaching
@ -369,8 +370,7 @@ fhandler_termios::process_sigs (char c, tty* ttyp, fhandler_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)
&& (p->process_state & PID_NOTCYGWIN))
if (p->process_state & PID_NEW_PG)
GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, p->dwProcessId);
else if ((!fh || fh->need_send_ctrl_c_event () || cyg_leader)
&& !ctrl_c_event_sent) /* cyg_leader is needed by GDB
@ -405,7 +405,7 @@ fhandler_termios::process_sigs (char c, tty* ttyp, fhandler_termios *fh)
&& (p->process_state & PID_DEBUGGED))
with_debugger = true; /* inferior is cygwin app */
if (!(p->process_state & PID_NOTCYGWIN)
&& (p->process_state & PID_NEW_PG) /* Check marker */
&& (p->exec_dwProcessId == p->dwProcessId) /* Check marker */
&& p->pid == pgid)
with_debugger_nat = true; /* inferior is non-cygwin app */
}

View File

@ -116,8 +116,9 @@ fhandler_pty_common::get_console_process_id (DWORD pid, bool match,
return res_pri ?: res;
}
static bool isHybrid; /* Set true if the active pipe is set to nat pipe even
though the current process is a cygwin process. */
static bool isHybrid; /* Set true if the active pipe is set to nat pipe
owned by myself even though the current process
is a cygwin process. */
static HANDLE h_gdb_inferior; /* Handle of GDB inferior process. */
static void
@ -1079,8 +1080,9 @@ fhandler_pty_slave::set_switch_to_nat_pipe (void)
{
isHybrid = true;
setup_locale ();
myself->exec_dwProcessId = myself->dwProcessId;
myself->process_state |= PID_NEW_PG; /* Marker for nat_fg */
myself->exec_dwProcessId = myself->dwProcessId; /* Set this as a marker
for tty::nat_fg()
and process_sigs() */
bool stdin_is_ptys = GetStdHandle (STD_INPUT_HANDLE) == get_handle ();
setup_for_non_cygwin_app (false, NULL, stdin_is_ptys);
}
@ -1199,7 +1201,6 @@ fhandler_pty_slave::reset_switch_to_nat_pipe (void)
}
}
myself->exec_dwProcessId = 0;
myself->process_state &= ~PID_NEW_PG;
isHybrid = false;
}
}

View File

@ -342,7 +342,9 @@ tty::nat_fg (pid_t pgid)
{
_pinfo *p = pids[i];
if (p->ctty == ntty && p->pgid == pgid
&& (p->process_state & (PID_NOTCYGWIN | PID_NEW_PG)))
&& ((p->process_state & PID_NOTCYGWIN)
/* Below is true for GDB with non-cygwin inferior */
|| p->exec_dwProcessId == p->dwProcessId))
return true;
}
if (pgid > MAX_PID)