From f7e74231cde7121af8cf261f8a4e7589c5e2f12f Mon Sep 17 00:00:00 2001 From: Takashi Yano Date: Wed, 18 Sep 2019 23:29:18 +0900 Subject: [PATCH] Cygwin: pty: Make GDB work again on pty. --- 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 2a1c34f7d..843807aab 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 */ }