[newlib-cygwin] Cygwin: pty: Make GDB work again on pty.

Ken Brown kbrown@sourceware.org
Fri Sep 20 21:59:00 GMT 2019


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=ac5357b9fe3486b909076ec706de64e91ba8ad81

commit ac5357b9fe3486b909076ec706de64e91ba8ad81
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date:   Wed Sep 18 23:29:18 2019 +0900

    Cygwin: pty: Make GDB work again on pty.

Diff:
---
 winsup/cygwin/fhandler_tty.cc | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 2a1c34f..843807a 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -197,6 +197,9 @@ DEF_HOOK (ReadConsoleInputA);
 DEF_HOOK (ReadConsoleInputW);
 DEF_HOOK (PeekConsoleInputA);
 DEF_HOOK (PeekConsoleInputW);
+/* CreateProcess() is hooked for GDB etc. */
+DEF_HOOK (CreateProcessA);
+DEF_HOOK (CreateProcessW);
 
 static BOOL WINAPI
 WriteFile_Hooked
@@ -331,6 +334,35 @@ PeekConsoleInputW_Hooked
   set_ishybrid_and_switch_to_pcon (h);
   return PeekConsoleInputW_Orig (h, r, l, n);
 }
+/* CreateProcess() is hooked for GDB etc. */
+static BOOL WINAPI
+CreateProcessA_Hooked
+     (LPCSTR n, LPSTR c, LPSECURITY_ATTRIBUTES pa, LPSECURITY_ATTRIBUTES ta,
+      BOOL inh, DWORD f, LPVOID e, LPCSTR d,
+      LPSTARTUPINFOA si, LPPROCESS_INFORMATION pi)
+{
+  HANDLE h;
+  if (si->dwFlags & STARTF_USESTDHANDLES)
+    h = si->hStdOutput;
+  else
+    h = GetStdHandle (STD_OUTPUT_HANDLE);
+  set_ishybrid_and_switch_to_pcon (h);
+  return CreateProcessA_Orig (n, c, pa, ta, inh, f, e, d, si, pi);
+}
+static BOOL WINAPI
+CreateProcessW_Hooked
+     (LPCWSTR n, LPWSTR c, LPSECURITY_ATTRIBUTES pa, LPSECURITY_ATTRIBUTES ta,
+      BOOL inh, DWORD f, LPVOID e, LPCWSTR d,
+      LPSTARTUPINFOW si, LPPROCESS_INFORMATION pi)
+{
+  HANDLE h;
+  if (si->dwFlags & STARTF_USESTDHANDLES)
+    h = si->hStdOutput;
+  else
+    h = GetStdHandle (STD_OUTPUT_HANDLE);
+  set_ishybrid_and_switch_to_pcon (h);
+  return CreateProcessW_Orig (n, c, pa, ta, inh, f, e, d, si, pi);
+}
 #else /* USE_API_HOOK */
 #define WriteFile_Orig 0
 #define ReadFile_Orig 0
@@ -2778,6 +2810,9 @@ fhandler_pty_slave::fixup_after_exec ()
       DO_HOOK (NULL, ReadConsoleInputW);
       DO_HOOK (NULL, PeekConsoleInputA);
       DO_HOOK (NULL, PeekConsoleInputW);
+      /* CreateProcess() is hooked for GDB etc. */
+      DO_HOOK (NULL, CreateProcessA);
+      DO_HOOK (NULL, CreateProcessW);
     }
 #endif /* USE_API_HOOK */
 }



More information about the Cygwin-cvs mailing list