[glib: 1/3] gwin32: Do not ignore exceptions when running under a debugger



commit 6919a719c1eaf21525de8962d39cf17f7bbde7fa
Author: Nirbheek Chauhan <nirbheek centricular com>
Date:   Tue Feb 18 22:57:51 2020 +0530

    gwin32: Do not ignore exceptions when running under a debugger
    
    We're supposed to return `EXCEPTION_CONTINUE_SEARCH` here to tell the
    vectored exception handler (VEH) to move on to the next exception
    handler instead of skipping them all and trying to continue execution.
    
    Swallowing exceptions messes up CLR exception processing and breaks C#
    code. For more details, see:
    
https://blogs.msdn.microsoft.com/jmstall/2006/05/24/beware-of-the-vectored-exception-handler-and-managed-code/
    
    Fixes https://gitlab.gnome.org/GNOME/glib/issues/2025

 glib/gwin32.c | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)
---
diff --git a/glib/gwin32.c b/glib/gwin32.c
index a8847482c..297c58e7a 100644
--- a/glib/gwin32.c
+++ b/glib/gwin32.c
@@ -1071,7 +1071,8 @@ g_win32_veh_handler (PEXCEPTION_POINTERS ExceptionInfo)
   SECURITY_ATTRIBUTES  sa;
 
   if (ExceptionInfo == NULL ||
-      ExceptionInfo->ExceptionRecord == NULL)
+      ExceptionInfo->ExceptionRecord == NULL ||
+      IsDebuggerPresent ())
     return EXCEPTION_CONTINUE_SEARCH;
 
   er = ExceptionInfo->ExceptionRecord;
@@ -1081,7 +1082,6 @@ g_win32_veh_handler (PEXCEPTION_POINTERS ExceptionInfo)
     case EXCEPTION_ACCESS_VIOLATION:
     case EXCEPTION_STACK_OVERFLOW:
     case EXCEPTION_ILLEGAL_INSTRUCTION:
-    case EXCEPTION_BREAKPOINT: /* DebugBreak() raises this */
       break;
     default:
       catch_list = getenv ("G_VEH_CATCH");
@@ -1109,17 +1109,6 @@ g_win32_veh_handler (PEXCEPTION_POINTERS ExceptionInfo)
       return EXCEPTION_CONTINUE_SEARCH;
     }
 
-  if (IsDebuggerPresent ())
-    {
-      /* This shouldn't happen, but still try to
-       * avoid recursion with EXCEPTION_BREAKPOINT and
-       * DebugBreak().
-       */
-      if (er->ExceptionCode != EXCEPTION_BREAKPOINT)
-        DebugBreak ();
-      return EXCEPTION_CONTINUE_EXECUTION;
-    }
-
   fprintf_s (stderr,
              "Exception code=0x%lx flags=0x%lx at 0x%p",
              er->ExceptionCode,


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