From patchwork Sat Apr 21 18:04:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 26887 Received: (qmail 92884 invoked by alias); 21 Apr 2018 18:04:17 -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 92875 invoked by uid 89); 21 Apr 2018 18:04:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=thr, UD:release X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 21 Apr 2018 18:04:14 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 76B2C406C782; Sat, 21 Apr 2018 18:04:13 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF57EAFD55; Sat, 21 Apr 2018 18:04:12 +0000 (UTC) Subject: [pushed v2] FreeBSD: Fix 'Couldn't get registers: Device busy' error (PR gdb/23077) To: Rajendra SY References: <18fee772-45c7-1f03-a40f-c9d5c524384c@redhat.com> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: Date: Sat, 21 Apr 2018 19:04:12 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: On 04/20/2018 04:19 PM, Rajendra SY wrote: > I tested your patch it works on FreeBSD. > No error message after attach. Great, I've pushed it in now, as below. Thanks, Pedro Alves From 00aecdcf6224e44fedf31a07340e9da11500fcfb Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Sat, 21 Apr 2018 18:19:30 +0100 Subject: [PATCH] FreeBSD: Fix 'Couldn't get registers: Device busy' error (PR gdb/23077) As Rajendra SY reported at , several attach-related tests are failing on FreeBSD. The "attach" command errors with "Couldn't get registers: Device busy". When the "attach" command is executed, it calls target_attach -> inf_ptrace_attach, which just does the ptrace(PT_ATTACH), it does not wait for the child to stop with SIGSTOP. Afterwards, the command is complete and we go back to the event loop. The event loop wakes up and we end up in target_wait -> fbsd_wait, and handle the SIGSTOP stop. At the end of execute_command, though, before going back to the event loop, we check if the frame language changed via check_frame_language_change(). That reads the current PC, which is what leads to the registers read that fails. The problem is that we fail to mark the attached-to thread as executing between the initial attach, and the subsequent target_wait. Until we see the thread stop with SIGSTOP, we shouldn't try to read registers off of it. I guess there may a timing issue here - if you're "lucky", the thread may stop before gdb reads its registers, masking the problem. With that fixed, check_frame_language_change() becomes a nop until the thread is marked not-executing again, after target_wait is called and we go through handle_inferior_event -> normal_stop. We haven't seen the problem on Linux because there, the target_attach implementation waits for the thread to stop before returning. Still, that's supposedly hidden from the core, since the Linux target, like most targets, is a '!to_attach_no_wait' target. This fixes: FAIL: gdb.base/attach.exp: attach1, after setting file FAIL: gdb.base/attach.exp: attach2, with no file FAIL: gdb.base/attach.exp: load file manually, after attach2 (re-read) (got interactive prompt) FAIL: gdb.base/attach.exp: attach when process' a.out not in cwd FAIL: gdb.base/dprintf-detach.exp: bai=on ds=gdb dd=on: re-attach to inferior FAIL: gdb.base/dprintf-detach.exp: bai=on ds=gdb dd=off: re-attach to inferior FAIL: gdb.base/dprintf-detach.exp: bai=on ds=call dd=on: re-attach to inferior FAIL: gdb.base/dprintf-detach.exp: bai=on ds=call dd=off: re-attach to inferior FAIL: gdb.base/dprintf-detach.exp: bai=on ds=agent dd=on: re-attach to inferior FAIL: gdb.base/dprintf-detach.exp: bai=on ds=agent dd=off: re-attach to inferior FAIL: gdb.base/dprintf-detach.exp: bai=off ds=gdb dd=on: re-attach to inferior FAIL: gdb.base/dprintf-detach.exp: bai=off ds=gdb dd=off: re-attach to inferior FAIL: gdb.base/dprintf-detach.exp: bai=off ds=call dd=on: re-attach to inferior FAIL: gdb.base/dprintf-detach.exp: bai=off ds=call dd=off: re-attach to inferior FAIL: gdb.base/dprintf-detach.exp: bai=off ds=agent dd=on: re-attach to inferior FAIL: gdb.base/dprintf-detach.exp: bai=off ds=agent dd=off: re-attach to inferior gdb/ChangeLog: 2018-04-21 Pedro Alves Rajendra SY * inf-ptrace.c (inf_ptrace_attach): Mark the thread as executing. * remote.c (extended_remote_attach): In all-stop mode, mark the thread as executing. --- gdb/ChangeLog | 7 +++++++ gdb/inf-ptrace.c | 5 ++++- gdb/remote.c | 5 ++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 0db5c46f6cd..70c461a4b3a 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2018-04-21 Pedro Alves + Rajendra SY + + * inf-ptrace.c (inf_ptrace_attach): Mark the thread as executing. + * remote.c (extended_remote_attach): In all-stop mode, mark the + thread as executing. + 2018-04-19 Philippe Waroquiers * thread.c (thread_apply_all_command): Fix comment. diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c index e20388658fe..942494bbdac 100644 --- a/gdb/inf-ptrace.c +++ b/gdb/inf-ptrace.c @@ -235,7 +235,10 @@ inf_ptrace_attach (struct target_ops *ops, const char *args, int from_tty) /* Always add a main thread. If some target extends the ptrace target, it should decorate the ptid later with more info. */ - add_thread_silent (inferior_ptid); + thread_info *thr = add_thread_silent (inferior_ptid); + /* Don't consider the thread stopped until we've processed its + initial SIGSTOP stop. */ + set_executing (thr->ptid, true); unpusher.release (); } diff --git a/gdb/remote.c b/gdb/remote.c index f54a38833b3..49013848d55 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -5316,7 +5316,10 @@ extended_remote_attach (struct target_ops *target, const char *args, inferior_ptid = remote_current_thread (inferior_ptid); /* Add the main thread to the thread list. */ - add_thread_silent (inferior_ptid); + thread_info *thr = add_thread_silent (inferior_ptid); + /* Don't consider the thread stopped until we've processed the + saved stop reply. */ + set_executing (thr->ptid, true); } /* Next, if the target can specify a description, read it. We do