#include <sys/ioctl.h>
#endif
+#ifdef __CYGWIN__
+#include <sys/cygwin.h>
+#endif
+
#ifndef O_NOCTTY
#define O_NOCTTY 0
#endif
then restore whatever was the foreground pgrp the last
time the inferior was running. See also comments
describing terminal_state::process_group. */
-#ifdef HAVE_GETPGID
- result = tcsetpgrp (0, getpgid (inf->pid));
-#else
- result = tcsetpgrp (0, tinfo->process_group);
+ pid_t pgrp = tinfo->process_group;
+#ifdef __CYGWIN__
+ /* The Windows native target uses Win32 routines to run or
+ attach to processes (CreateProcess / DebugActiveProcess),
+ so a Cygwin inferior has a Windows PID, rather than a
+ Cygwin PID. We want to pass the Cygwin PID to Cygwin
+ tcsetpgrp if we have a Cygwin inferior, so try to convert
+ first. If we have a non-Cygwin inferior, we'll end up
+ passing down the WINPID to tcsetpgrp, stored in
+ terminal_state::process_group. tcsetpgrp still succeeds
+ in that case, and it seems preferable to switch the
+ foreground pgrp away from GDB, for consistency. */
+ pid_t cygpid = cygwin_internal (CW_WINPID_TO_CYGWIN_PID, inf->pid);
+ if (cygpid <= cygwin_internal (CW_MAX_CYGWIN_PID))
+ pgrp = getpgid (cygpid);
+#elif defined (HAVE_GETPGID)
+ pgrp = getpgid (inf->pid);
#endif
+ result = tcsetpgrp (0, pgrp);
if (result == -1)
{
#if 0