--- exceptions.cc.org	2003-11-04 09:19:29.470659200 +0100
+++ exceptions.cc	2003-11-04 09:24:02.796536000 +0100
@@ -424,9 +424,19 @@ handle_exceptions (EXCEPTION_RECORD *e, 
   static int NO_COPY debugging = 0;
   static int NO_COPY recursed = 0;
 
-  if (debugging && ++debugging < 500000)
+  if (debugging)
     {
-      SetThreadPriority (hMainThread, THREAD_PRIORITY_NORMAL);
+      if (!being_debugged ())
+        {
+          /*
+           * Give debugger CPU time to attach
+           */
+          LONG prio = GetThreadPriority (GetCurrentThread ());
+          SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_IDLE);
+          Sleep (0);
+          SetThreadPriority (GetCurrentThread (), prio);
+        }
+
       return 0;
     }
 
