Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [Cygwin] Fix for: detaching crashes the inferior.
@ 2007-04-08 11:37 Pedro Alves
  2007-04-08 23:03 ` Pedro Alves
  0 siblings, 1 reply; 16+ messages in thread
From: Pedro Alves @ 2007-04-08 11:37 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 718 bytes --]

Hi all,

Detaching on Cygwin often crashes the inferior, either
when gdb attaches to the inferior, or when gdb launches
the inferior as a child.

Initially I thought that somehow the FLAGS_TRACE_BIT
would be set in the context, and after detaching there would
be no debugger to catch the exception, but it turns out that
it isn't the case - I couldn't find a case where FLAGS_TRACE_BIT
was set.  But, surprisingly doing a SetThreadContext with
CONTEXT_CONTROL makes the crashes go away - even if you don't
change the contents of the context.  I'm not 100% sure why, but,
it fixes it.  If MSFT sends me the Windows sources, I'll look
deeper :)

No regressions on i686-pc-cygwin on XP Pro.

OK?

Cheers,
Pedro Alves





[-- Attachment #2: win32_detach.diff --]
[-- Type: text/x-diff, Size: 1436 bytes --]

2007-04-08  Pedro Alves  <pedro_alves@portugalmail.pt>

	* win32-nat.c (win32_detach): Reset the CONTEXT_CONTROL part of
	the main thread's context and clear the FLAGS_TRACE_BIT
	before detaching.

---
 gdb/win32-nat.c |   18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

Index: src/gdb/win32-nat.c
===================================================================
--- src.orig/gdb/win32-nat.c	2007-04-08 12:11:22.000000000 +0100
+++ src/gdb/win32-nat.c	2007-04-08 12:11:54.000000000 +0100
@@ -1775,7 +1775,23 @@ win32_detach (char *args, int from_tty)
 
   if (has_detach_ability ())
     {
-      delete_command (NULL, 0);
+      thread_info *th;
+
+      /* Don't leave breakpoints in the inferior.  */
+      remove_breakpoints ();
+
+      /* We also need to reset the thread's context,
+	 else we'll get frequent inferior crashes.  */
+      th = thread_rec (current_event.dwThreadId, FALSE);
+      th->context.ContextFlags = CONTEXT_CONTROL;
+      win32_fetch_inferior_registers (PS_REGNUM);
+      /* Doing a SetThreadContext with CONTEXT_CONTROL seems to be
+	 enough, but let's clear FLAGS_TRACE_BIT just in case
+	 somewhere else it gets set.   */
+      th->context.EFlags &= ~FLAG_TRACE_BIT;
+      CHECK (SetThreadContext (th->h, &th->context));
+      th->context.ContextFlags = 0;
+
       win32_continue (DBG_CONTINUE, -1);
       if (!DebugActiveProcessStop (current_event.dwProcessId))
 	{

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2007-04-19 19:39 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-08 11:37 [Cygwin] Fix for: detaching crashes the inferior Pedro Alves
2007-04-08 23:03 ` Pedro Alves
2007-04-09  2:08   ` Pedro Alves
2007-04-09  7:06     ` Eli Zaretskii
2007-04-10 10:33       ` Pedro Alves
2007-04-10 12:07         ` Daniel Jacobowitz
2007-04-10 18:35         ` Michael Snyder
2007-04-10 18:58         ` Eli Zaretskii
2007-04-10  5:15     ` Christopher Faylor
2007-04-10  9:31       ` Corinna Vinschen
2007-04-10 10:48         ` Pedro Alves
2007-04-10 10:45       ` Pedro Alves
2007-04-19 12:20         ` Christopher Faylor
2007-04-19 22:06           ` Pedro Alves
2007-04-10 21:40       ` Pedro Alves
2007-04-13 13:40         ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox