]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/inflow.c
Cygwin: Fix putting inferior in foreground (fix input)
[thirdparty/binutils-gdb.git] / gdb / inflow.c
index a413957a1dd9bc5591353de3d2f5a4eee3042a60..3dd70b97fe53a5d298aca5b5a6c8efb57705114a 100644 (file)
 #include <sys/ioctl.h>
 #endif
 
+#ifdef __CYGWIN__
+#include <sys/cygwin.h>
+#endif
+
 #ifndef O_NOCTTY
 #define O_NOCTTY 0
 #endif
@@ -345,11 +349,25 @@ child_terminal_inferior (struct target_ops *self)
             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