emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 1048151 1/2: Don't install keyboard hook when debug


From: Eli Zaretskii
Subject: [Emacs-diffs] master 1048151 1/2: Don't install keyboard hook when debugged on MS-Windows
Date: Tue, 12 Jul 2016 13:19:37 +0000 (UTC)

branch: master
commit 1048151cc4bec79f7310f4f2ede309889822a6bb
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Don't install keyboard hook when debugged on MS-Windows
    
    * src/w32fns.c (setup_w32_kbdhook): Don't install the keyboard
    hook if we are being debugged.  This avoids hosing the debugger,
    because the hook is global, and is called in the context of the
    thread which installed it, and that thread is stopped when GDB has
    control.  Reported by Fabrice Popineau <address@hidden>.
---
 src/w32fns.c |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/w32fns.c b/src/w32fns.c
index 0eb720e..f5e5b33 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -276,6 +276,8 @@ static struct
 } kbdhook;
 typedef HWND (WINAPI *GetConsoleWindow_Proc) (void);
 
+typedef BOOL (WINAPI *IsDebuggerPresent_Proc) (void);
+
 /* stdin, from w32console.c */
 extern HANDLE keyboard_handle;
 
@@ -2303,6 +2305,19 @@ setup_w32_kbdhook (void)
 {
   kbdhook.hook_count++;
 
+  /* This hook gets in the way of debugging, since when Emacs stops,
+     its input thread stops, and there's nothing to process keyboard
+     events, whereas this hook is global, and is invoked in the
+     context of the thread that installed it.  So we don't install the
+     hook if the process is being debugged. */
+  if (w32_kbdhook_active)
+    {
+      IsDebuggerPresent_Proc is_debugger_present = (IsDebuggerPresent_Proc)
+       GetProcAddress (GetModuleHandle ("kernel32.dll"), "IsDebuggerPresent");
+      if (is_debugger_present && is_debugger_present ())
+       return;
+    }
+
   /* Hooking is only available on NT architecture systems, as
      indicated by the w32_kbdhook_active variable.  */
   if (kbdhook.hook_count == 1 && w32_kbdhook_active)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]