Files
MSYS2-packages/gdb/7.8-windows-nat-cygwin.patch

230 lines
7.1 KiB
Diff

--- origsrc/gdb-7.8/gdb/windows-nat.c 2014-07-29 14:37:43.000000000 +0200
+++ src/gdb-7.8/gdb/windows-nat.c 2014-09-17 14:51:00.395014100 -0500
@@ -121,8 +121,7 @@ static COORD WINAPI (*GetConsoleFontSize
# 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 @@ thread_rec (DWORD id, int get_context)
{
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)
{
@@ -313,8 +313,11 @@ thread_rec (DWORD id, int get_context)
/* We get Access Denied (5) when trying to suspend
threads that Windows started on behalf of the
debuggee, usually when those threads are just
- about to exit. */
- if (err != ERROR_ACCESS_DENIED)
+ about to exit.
+ We can get Invalid Handle (6) if the main thread
+ has exited. */
+ if (err != ERROR_INVALID_HANDLE
+ && err != ERROR_ACCESS_DENIED)
warning (_("SuspendThread (tid=0x%x) failed."
" (winerr %u)"),
(unsigned) id, (unsigned) err);
@@ -435,8 +438,7 @@ do_windows_fetch_inferior_registers (str
if (current_thread->reload_context)
{
-#ifdef __COPY_CONTEXT_SIZE
- 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
@@ -444,10 +446,9 @@ do_windows_fetch_inferior_registers (str
"saved_context. */
memcpy (&current_thread->context, &saved_context,
__COPY_CONTEXT_SIZE);
- have_saved_context = 0;
+ signal_thread_id = 0;
}
else
-#endif
{
thread_info *th = current_thread;
th->context.ContextFlags = CONTEXT_DEBUGGER_DR;
@@ -896,12 +897,15 @@ handle_output_debug_string (struct targe
else if (strncmp (s, _CYGWIN_SIGNAL_STRING,
sizeof (_CYGWIN_SIGNAL_STRING) - 1) != 0)
{
-#ifdef __CYGWIN__
- if (strncmp (s, "cYg", 3) != 0)
-#endif
- warning (("%s"), s);
+ if (strncmp (s, "cYg", 3) != 0 || (strncmp (s + 3, "FFFFFFFF", 8) != 0
+ && strncmp (s + 3, "std", 3) != 0))
+ {
+ char *p = strchr (s, '\0');
+ if (p > s && *--p == '\n')
+ *p = '\0';
+ warning (("%s"), s);
+ }
}
-#ifdef __COPY_CONTEXT_SIZE
else
{
/* Got a cygwin signal marker. A cygwin signal is followed by
@@ -930,11 +934,14 @@ handle_output_debug_string (struct targe
&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;
}
}
-#endif
if (s)
xfree (s);
@@ -1315,7 +1322,7 @@ windows_resume (struct target_ops *ops,
}
}
#endif
- DEBUG_EXCEPT(("Can only continue with recieved signal %d.\n",
+ DEBUG_EXCEPT(("Can only continue with received signal %d.\n",
last_sig));
}
@@ -1399,7 +1406,7 @@ get_windows_debug_event (struct target_o
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;
@@ -1412,7 +1419,6 @@ get_windows_debug_event (struct target_o
event_code = current_event.dwDebugEventCode;
ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
th = NULL;
- have_saved_context = 0;
switch (event_code)
{
@@ -1430,14 +1436,14 @@ get_windows_debug_event (struct target_o
/* 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,
@@ -1480,7 +1486,7 @@ get_windows_debug_event (struct target_o
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:
@@ -1499,7 +1505,7 @@ get_windows_debug_event (struct target_o
{
ourstatus->kind = TARGET_WAITKIND_EXITED;
ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode;
- retval = main_thread_id;
+ thread_id = main_thread_id;
}
break;
@@ -1514,7 +1520,7 @@ get_windows_debug_event (struct target_o
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:
@@ -1527,7 +1533,7 @@ get_windows_debug_event (struct target_o
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:
@@ -1543,7 +1549,7 @@ get_windows_debug_event (struct target_o
continue_status = DBG_EXCEPTION_NOT_HANDLED;
break;
case 1:
- retval = current_event.dwThreadId;
+ thread_id = current_event.dwThreadId;
break;
case -1:
last_sig = 1;
@@ -1559,7 +1565,7 @@ get_windows_debug_event (struct target_o
"OUTPUT_DEBUG_STRING_EVENT"));
if (saw_create != 1)
break;
- retval = handle_output_debug_string (ourstatus);
+ thread_id = handle_output_debug_string (ourstatus);
break;
default:
@@ -1573,7 +1579,7 @@ get_windows_debug_event (struct target_o
break;
}
- if (!retval || saw_create != 1)
+ if (!thread_id || saw_create != 1)
{
if (continue_status == -1)
windows_resume (ops, minus_one_ptid, 0, 1);
@@ -1583,12 +1589,12 @@ get_windows_debug_event (struct target_o
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. */
@@ -2536,7 +2542,7 @@ windows_get_tib_address (struct target_o
{
thread_info *th;
- th = thread_rec (ptid_get_tid (ptid), 0);
+ th = thread_rec (ptid_get_tid (ptid), FALSE);
if (th == NULL)
return 0;