From patchwork Fri Apr 20 13:31:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 26879 Received: (qmail 70070 invoked by alias); 20 Apr 2018 13:32:00 -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 70054 invoked by uid 89); 20 Apr 2018 13:31:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.2 spammy= 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; Fri, 20 Apr 2018 13:31:57 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1DD7682FC480; Fri, 20 Apr 2018 13:31:56 +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 866582026DFD; Fri, 20 Apr 2018 13:31:55 +0000 (UTC) Subject: Re: [PATCH] [PR gdb/23077] Fix error 'Couldn't get registers: Device busy' on FreeBSD To: Rajendra SY , gdb-patches@sourceware.org References: From: Pedro Alves Message-ID: <18fee772-45c7-1f03-a40f-c9d5c524384c@redhat.com> Date: Fri, 20 Apr 2018 14:31:54 +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 10:46 AM, Rajendra SY wrote: > > > Problem: > GDB "attach pid" command shows error message "Couldn't get registers: > Device busy" because of which below gdb tests fail. > > Cause: > On FreeBSD ptrace() syscall requires LWP id to fetch info from the > inferior process. > The current implementation is every command is executed completely and > then it wait's for asynchronous events. > > When attach command is executed it calls inf_ptrace_attach() function > which is currently doing just the ptrace(PT_ATTACH), it does not wait > for the process to stop to fetch LWP info. > The fbsd_wait() function is the one which fetches LWP info which is > being called after the command completes. > > Command execution code flow - > gdb_do_one_event() => .. => handle_file_event() => .. => > execute_command() => check_frame_language_change() > > The async event handling code flow where LWP info gets updated - > gdb_one_event() => check_async_event_handlers() => .. > ->do_target_wait() => .. => fbsd_wait() > > The check, if the frame language changed via > check_frame_language_change() function is trying to read registers > using ptrace(pid) which fails because LWP id is not fetched. > > The purposed patch tries to avoid this situation by avoiding calling > check_frame_language_change() function just for the "attach" command. > Thanks for the patch, but we need to find a better fix. It seems to me that the problem is that we fail to mark the thread as executing between the initial attach, and the subsequent target_wait. Can you give the attached patch a try? check_frame_language_change() then becomes a nop until the thread is marked not-executing again, after target_wait is called. We don't see 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. Pedro Alves From d1a0ee089d0d59af19fd65267e0e1d2f5f7821c0 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Fri, 20 Apr 2018 12:22:05 +0100 Subject: [PATCH] Mark just-attached-to thread as executing --- gdb/inf-ptrace.c | 3 ++- gdb/remote.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c index e20388658fe..68d557138a0 100644 --- a/gdb/inf-ptrace.c +++ b/gdb/inf-ptrace.c @@ -235,7 +235,8 @@ 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 *tp = add_thread_silent (inferior_ptid); + set_executing (tp->ptid, true); unpusher.release (); } diff --git a/gdb/remote.c b/gdb/remote.c index f54a38833b3..dc1c62f214c 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -5316,7 +5316,8 @@ 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 *tp = add_thread_silent (inferior_ptid); + set_executing (tp->ptid, true); } /* Next, if the target can specify a description, read it. We do -- 2.14.3