From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1224 invoked by alias); 8 Apr 2007 11:37:52 -0000 Received: (qmail 1215 invoked by uid 22791); 8 Apr 2007 11:37:51 -0000 X-Spam-Check-By: sourceware.org Received: from ug-out-1314.google.com (HELO ug-out-1314.google.com) (66.249.92.171) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sun, 08 Apr 2007 12:37:49 +0100 Received: by ug-out-1314.google.com with SMTP id 75so1529436ugb for ; Sun, 08 Apr 2007 04:37:47 -0700 (PDT) Received: by 10.67.92.1 with SMTP id u1mr4489909ugl.1176032267201; Sun, 08 Apr 2007 04:37:47 -0700 (PDT) Received: from ?62.169.93.168? ( [62.169.93.168]) by mx.google.com with ESMTP id y2sm14548854mug.2007.04.08.04.37.45; Sun, 08 Apr 2007 04:37:46 -0700 (PDT) Message-ID: <4618D3F7.3040700@portugalmail.pt> Date: Sun, 08 Apr 2007 11:37:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pt-BR; rv:1.8.0.10) Gecko/20070221 Thunderbird/1.5.0.10 Mnenhy/0.7.4.0 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: [Cygwin] Fix for: detaching crashes the inferior. Content-Type: multipart/mixed; boundary="------------080503000501090605020801" X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-04/txt/msg00058.txt.bz2 This is a multi-part message in MIME format. --------------080503000501090605020801 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 718 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 --------------080503000501090605020801 Content-Type: text/x-diff; name="win32_detach.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="win32_detach.diff" Content-length: 1436 2007-04-08 Pedro Alves * 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)) { --------------080503000501090605020801--