From patchwork Sat Apr 19 08:33:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eli Zaretskii X-Patchwork-Id: 625 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx20.g.dreamhost.com (mx2.sub5.homie.mail.dreamhost.com [208.113.200.128]) by wilcox.dreamhost.com (Postfix) with ESMTP id 2B7EF36007E for ; Sat, 19 Apr 2014 01:33:38 -0700 (PDT) Received: by homiemail-mx20.g.dreamhost.com (Postfix, from userid 14314964) id CD48141362A92; Sat, 19 Apr 2014 01:33:37 -0700 (PDT) X-Original-To: gdb@patchwork.siddhesh.in Delivered-To: x14314964@homiemail-mx20.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx20.g.dreamhost.com (Postfix) with ESMTPS id A200F41362A92 for ; Sat, 19 Apr 2014 01:33:37 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:subject:in-reply-to:to:cc:reply-to :message-id:references; q=dns; s=default; b=EZgRa8W5u+rzAqsIZ9De nxdOVitKvEYsZqYWIIX4KCRt2c+N42409mLEFxzb6EZTvUJixBfXdwAK6r4Mu6Lf wfJ67Or8kTw2RX8GhEibPYL5oK8DxMCSWbaIj2JloZJA/r9Xr8CrbAtF6PWIqM0G zxClSu8z95DKXF8L83VGo/c= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:subject:in-reply-to:to:cc:reply-to :message-id:references; s=default; bh=BgKn0jA0Yv2yyzfbGjE1dtGMex g=; b=FhuUvWG+90oIh6eYwnExafQoWRRLuNv4YzWV8t92xucCZRCoLu5X1mwrc9 d7gxAKNC8PkSI5vCTBlOa0N4RlL7yZaKpiEaRRt2zE3/6UW75u2JL7JLwL3B0L/G lzjF2o8W97Ich7ZKVbEWVWn6ItJBY3vcQlOm53IlYXph3WsWE= Received: (qmail 28803 invoked by alias); 19 Apr 2014 08:33:35 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 28789 invoked by uid 89); 19 Apr 2014 08:33:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL, BAYES_00, SPF_SOFTFAIL autolearn=no version=3.3.2 X-HELO: mtaout25.012.net.il Received: from mtaout25.012.net.il (HELO mtaout25.012.net.il) (80.179.55.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 19 Apr 2014 08:33:34 +0000 Received: from conversion-daemon.mtaout25.012.net.il by mtaout25.012.net.il (HyperSendmail v2007.08) id <0N4900000QP2JH00@mtaout25.012.net.il> for gdb-patches@sourceware.org; Sat, 19 Apr 2014 11:31:37 +0300 (IDT) Received: from HOME-C4E4A596F7 ([87.69.4.28]) by mtaout25.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0N4900IKIROPLE90@mtaout25.012.net.il>; Sat, 19 Apr 2014 11:31:37 +0300 (IDT) Date: Sat, 19 Apr 2014 11:33:49 +0300 From: Eli Zaretskii Subject: Re: [PATCH] Fix "PC register is not available" issue In-reply-to: <20140411200609.GM4250@adacore.com> To: Joel Brobecker Cc: palves@redhat.com, gdb-patches@sourceware.org Reply-to: Eli Zaretskii Message-id: <83d2gdhg5u.fsf@gnu.org> References: <5335B619.6040605@redhat.com> <8361myfa6l.fsf@gnu.org> <83ioqucrkw.fsf@gnu.org> <5342DBBC.4090500@redhat.com> <83lhvh6lqi.fsf@gnu.org> <5343DE45.5050707@redhat.com> <53442710.60104@redhat.com> <83sipn6937.fsf@gnu.org> <534433A5.4060006@redhat.com> <83ob0b671j.fsf@gnu.org> <20140411200609.GM4250@adacore.com> X-IsSubscribed: yes X-DH-Original-To: gdb@patchwork.siddhesh.in > Date: Fri, 11 Apr 2014 13:06:09 -0700 > From: Joel Brobecker > Cc: Pedro Alves , gdb-patches@sourceware.org > > I was wondering what the status of the GDB-side of the patch was. > I thought we were all set to commit it, while also looking at > applying the same patch on the GDBserver side? I don't think we are > in any hurry to get anything committed, but I'd had to see all > this work get forgotten and lost... Also, I don't think the patch > is all that risky, but the earlier we put it in, the more exposure > it'll get before we release 7.8! As I wrote on gdb@, I have committed the patch to fix the GDB side of the problem. See below for what I actually committed, both to master and to the GDB 7.7 branch. Should we now close the Bugzilla PR? If I can do that, any pointers as to how? commit 17617f2d366ca969ccbc784be4f75931a1afd20f Author: Eli Zaretskii Date: Sat Apr 19 11:12:19 2014 +0300 PR gdb/14018 -- avoid "PC register not available" errors. gdb/windows-nat.c (thread_rec): Don't display a warning when SuspendThread fails with ERROR_ACCESS_DENIED. If SuspendThread fails for any reason, set th->suspended to -1, so that we don't try to resume such a thread. Also, don't return NULL in these cases, to avoid completely ruin the session due to "PC register is not available" error. (do_windows_fetch_inferior_registers): Check errors in GetThreadContext call. (windows_continue): Accept an additional argument KILLED; if not zero, ignore errors in the SetThreadContext call, since the inferior was killed and is shutting down. (windows_resume, get_windows_debug_event) (windows_create_inferior, windows_mourn_inferior) (windows_kill_inferior): All callers of windows_continue changed to adjust to its new calling sequence. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index fd9677b..23ca6c0 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,22 @@ +2014-04-19 Eli Zaretskii + + PR gdb/14018 + * windows-nat.c (thread_rec): Don't display a warning when + SuspendThread fails with ERROR_ACCESS_DENIED. If SuspendThread + fails for any reason, set th->suspended to -1, so that we don't + try to resume such a thread. Also, don't return NULL in these + cases, to avoid completely ruin the session due to "PC register is + not available" error. + (do_windows_fetch_inferior_registers): Check errors in + GetThreadContext call. + (windows_continue): Accept an additional argument KILLED; if not + zero, ignore errors in the SetThreadContext call, since the + inferior was killed and is shutting down. + (windows_resume, get_windows_debug_event) + (windows_create_inferior, windows_mourn_inferior) + (windows_kill_inferior): All callers of windows_continue changed + to adjust to its new calling sequence. + 2014-04-19 Yao Qi * ctf.c (ctf_open): Call post_create_inferior. diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index fe40c4d..bad7408 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -309,12 +309,18 @@ thread_rec (DWORD id, int get_context) { DWORD err = GetLastError (); - warning (_("SuspendThread (tid=0x%x) failed." - " (winerr %u)"), - (unsigned) id, (unsigned) err); - return NULL; + /* 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) + warning (_("SuspendThread (tid=0x%x) failed." + " (winerr %u)"), + (unsigned) id, (unsigned) err); + th->suspended = -1; } - th->suspended = 1; + else + th->suspended = 1; } else if (get_context < 0) th->suspended = -1; @@ -444,7 +450,7 @@ do_windows_fetch_inferior_registers (struct regcache *regcache, int r) { thread_info *th = current_thread; th->context.ContextFlags = CONTEXT_DEBUGGER_DR; - GetThreadContext (th->h, &th->context); + CHECK (GetThreadContext (th->h, &th->context)); /* Copy dr values from that thread. But only if there were not modified since last stop. PR gdb/2388 */ @@ -1181,10 +1187,12 @@ handle_exception (struct target_waitstatus *ourstatus) return 1; } -/* Resume all artificially suspended threads if we are continuing - execution. */ +/* Resume thread specified by ID, or all artificially suspended + threads, if we are continuing execution. KILLED non-zero means we + have killed the inferior, so we should ignore weird errors due to + threads shutting down. */ static BOOL -windows_continue (DWORD continue_status, int id) +windows_continue (DWORD continue_status, int id, int killed) { int i; thread_info *th; @@ -1212,7 +1220,16 @@ windows_continue (DWORD continue_status, int id) } if (th->context.ContextFlags) { - CHECK (SetThreadContext (th->h, &th->context)); + DWORD ec = 0; + + if (GetExitCodeThread (th->h, &ec) + && ec == STILL_ACTIVE) + { + BOOL status = SetThreadContext (th->h, &th->context); + + if (!killed) + CHECK (status); + } th->context.ContextFlags = 0; } if (th->suspended > 0) @@ -1340,9 +1357,9 @@ windows_resume (struct target_ops *ops, Otherwise complain. */ if (resume_all) - windows_continue (continue_status, -1); + windows_continue (continue_status, -1, 0); else - windows_continue (continue_status, ptid_get_tid (ptid)); + windows_continue (continue_status, ptid_get_tid (ptid), 0); } /* Ctrl-C handler used when the inferior is not run in the same console. The @@ -1560,7 +1577,7 @@ get_windows_debug_event (struct target_ops *ops, if (continue_status == -1) windows_resume (ops, minus_one_ptid, 0, 1); else - CHECK (windows_continue (continue_status, -1)); + CHECK (windows_continue (continue_status, -1, 0)); } else { @@ -2337,13 +2354,13 @@ windows_create_inferior (struct target_ops *ops, char *exec_file, do_initial_windows_stuff (ops, pi.dwProcessId, 0); - /* windows_continue (DBG_CONTINUE, -1); */ + /* windows_continue (DBG_CONTINUE, -1, 0); */ } static void windows_mourn_inferior (struct target_ops *ops) { - (void) windows_continue (DBG_CONTINUE, -1); + (void) windows_continue (DBG_CONTINUE, -1, 0); i386_cleanup_dregs(); if (open_process_used) { @@ -2412,7 +2429,7 @@ windows_kill_inferior (struct target_ops *ops) for (;;) { - if (!windows_continue (DBG_CONTINUE, -1)) + if (!windows_continue (DBG_CONTINUE, -1, 1)) break; if (!WaitForDebugEvent (¤t_event, INFINITE)) break;