--- gdb/windows-nat.c.orig 2014-09-12 09:08:38.714405700 -0400 +++ gdb/windows-nat.c 2014-09-12 12:33:12.853775100 -0400 @@ -121,8 +121,7 @@ # define bad_GetModuleFileNameEx bad_GetModuleFileNameExW #endif -static int have_saved_context; /* True if we've saved context from a - cygwin signal. */ +static DWORD signal_thread_id; /* Non-zero if we saved context. */ static CONTEXT saved_context; /* Containes the saved context from a cygwin signal. */ @@ -304,7 +303,8 @@ { if (!th->suspended && get_context) { - if (get_context > 0 && id != current_event.dwThreadId) + if (get_context > 0 && id != current_event.dwThreadId + && id != signal_thread_id) { if (SuspendThread (th->h) == (DWORD) -1) { @@ -438,7 +438,7 @@ do_windows_fetch_inferior_registers (str if (current_thread->reload_context) { - if (have_saved_context) + if (signal_thread_id) { /* Lie about where the program actually is stopped since cygwin has informed us that we should consider the signal @@ -446,7 +446,7 @@ do_windows_fetch_inferior_registers (str "saved_context. */ memcpy (¤t_thread->context, &saved_context, __COPY_CONTEXT_SIZE); - have_saved_context = 0; + signal_thread_id = 0; } else { @@ -934,8 +934,12 @@ &saved_context, __COPY_CONTEXT_SIZE, &n) && n == __COPY_CONTEXT_SIZE) - have_saved_context = 1; - current_event.dwThreadId = retval; + { + signal_thread_id = retval; + saved_context.ContextFlags = 0; /* Don't attempt to call SetContext */ + } + else + retval = 0; } } @@ -1402,7 +1406,7 @@ DWORD continue_status, event_code; thread_info *th; static thread_info dummy_thread_info; - int retval = 0; + DWORD thread_id = 0; last_sig = GDB_SIGNAL_0; @@ -1415,7 +1419,6 @@ event_code = current_event.dwDebugEventCode; ourstatus->kind = TARGET_WAITKIND_SPURIOUS; th = NULL; - have_saved_context = 0; switch (event_code) { @@ -1433,14 +1436,14 @@ /* Kludge around a Windows bug where first event is a create thread event. Caused when attached process does not have a main thread. */ - retval = fake_create_process (); - if (retval) + thread_id = fake_create_process (); + if (thread_id) saw_create++; } break; } /* Record the existence of this thread. */ - retval = current_event.dwThreadId; + thread_id = current_event.dwThreadId; th = windows_add_thread (ptid_build (current_event.dwProcessId, 0, current_event.dwThreadId), current_event.u.CreateThread.hThread, @@ -1483,7 +1486,7 @@ current_event.dwThreadId), current_event.u.CreateProcessInfo.hThread, current_event.u.CreateProcessInfo.lpThreadLocalBase); - retval = current_event.dwThreadId; + thread_id = current_event.dwThreadId; break; case EXIT_PROCESS_DEBUG_EVENT: @@ -1502,7 +1505,7 @@ { ourstatus->kind = TARGET_WAITKIND_EXITED; ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode; - retval = main_thread_id; + thread_id = main_thread_id; } break; @@ -1517,7 +1520,7 @@ catch_errors (handle_load_dll, NULL, (char *) "", RETURN_MASK_ALL); ourstatus->kind = TARGET_WAITKIND_LOADED; ourstatus->value.integer = 0; - retval = main_thread_id; + thread_id = main_thread_id; break; case UNLOAD_DLL_DEBUG_EVENT: @@ -1530,7 +1533,7 @@ catch_errors (handle_unload_dll, NULL, (char *) "", RETURN_MASK_ALL); ourstatus->kind = TARGET_WAITKIND_LOADED; ourstatus->value.integer = 0; - retval = main_thread_id; + thread_id = main_thread_id; break; case EXCEPTION_DEBUG_EVENT: @@ -1546,7 +1549,7 @@ continue_status = DBG_EXCEPTION_NOT_HANDLED; break; case 1: - retval = current_event.dwThreadId; + thread_id = current_event.dwThreadId; break; case -1: last_sig = 1; @@ -1562,7 +1565,7 @@ "OUTPUT_DEBUG_STRING_EVENT")); if (saw_create != 1) break; - retval = handle_output_debug_string (ourstatus); + thread_id = handle_output_debug_string (ourstatus); break; default: @@ -1576,7 +1579,7 @@ break; } - if (!retval || saw_create != 1) + if (!thread_id || saw_create != 1) { if (continue_status == -1) windows_resume (ops, minus_one_ptid, 0, 1); @@ -1586,12 +1589,12 @@ else { inferior_ptid = ptid_build (current_event.dwProcessId, 0, - retval); - current_thread = th ?: thread_rec (current_event.dwThreadId, TRUE); + thread_id); + current_thread = th ?: thread_rec (thread_id, TRUE); } out: - return retval; + return (int) thread_id; } /* Wait for interesting events to occur in the target process. */