From patchwork Mon Sep 8 15:25:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 2689 Received: (qmail 23348 invoked by alias); 8 Sep 2014 16:02: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 23131 invoked by uid 89); 8 Sep 2014 16:02:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.4 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 08 Sep 2014 16:02:08 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s88FPS7Y016184 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 8 Sep 2014 11:25:28 -0400 Received: from blade.nx (ovpn-116-108.ams2.redhat.com [10.36.116.108]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s88FPQwx022094 for ; Mon, 8 Sep 2014 11:25:27 -0400 Received: from blade.nx (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id 40E882640F5 for ; Mon, 8 Sep 2014 16:25:25 +0100 (BST) From: Gary Benson To: gdb-patches@sourceware.org Subject: [PATCH 06/14] Introduce basic LWP accessors Date: Mon, 8 Sep 2014 16:25:14 +0100 Message-Id: <1410189922-18320-7-git-send-email-gbenson@redhat.com> In-Reply-To: <1410189922-18320-1-git-send-email-gbenson@redhat.com> References: <1410189922-18320-1-git-send-email-gbenson@redhat.com> X-IsSubscribed: yes This commit introduces three accessors that shared Linux code can use to access fields of struct lwp_info. The GDB and gdbserver Linux x86 code is modified to use them. gdb/ChangeLog: * nat/linux-nat.h (ptid_of_lwp): New declaration. (lwp_is_stopped): Likewise. (lwp_is_stopped_by_watchpoint): Likewise. * linux-nat.c (ptid_of_lwp): New function. (lwp_is_stopped): Likewise. (lwp_is_stopped_by_watchpoint): Likewise. * x86-linux-nat.c (update_debug_registers_callback): Use lwp_is_stopped. (x86_linux_prepare_to_resume): Use ptid_of_lwp and lwp_is_stopped_by_watchpoint. gdb/gdbserver/ChangeLog: * linux-low.c (ptid_of_lwp): New function. (lwp_is_stopped): Likewise. (lwp_is_stopped_by_watchpoint): Likewise. * linux-x86-low.c (update_debug_registers_callback): Use lwp_is_stopped. (x86_linux_prepare_to_resume): Use ptid_of_lwp and lwp_is_stopped_by_watchpoint. --- gdb/ChangeLog | 13 +++++++++++++ gdb/gdbserver/ChangeLog | 10 ++++++++++ gdb/gdbserver/linux-low.c | 26 ++++++++++++++++++++++++++ gdb/gdbserver/linux-x86-low.c | 6 +++--- gdb/linux-nat.c | 27 +++++++++++++++++++++++++++ gdb/nat/linux-nat.h | 14 ++++++++++++++ gdb/x86-linux-nat.c | 15 ++++++++------- 7 files changed, 101 insertions(+), 10 deletions(-) diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index 652d351..b1982be 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -134,6 +134,32 @@ typedef struct } Elf64_auxv_t; #endif +/* LWP accessors. */ + +/* See nat/linux-nat.h. */ + +ptid_t +ptid_of_lwp (struct lwp_info *lwp) +{ + return ptid_of (get_lwp_thread (lwp)); +} + +/* See nat/linux-nat.h. */ + +int +lwp_is_stopped (struct lwp_info *lwp) +{ + return lwp->stopped; +} + +/* See nat/linux-nat.h. */ + +int +lwp_is_stopped_by_watchpoint (struct lwp_info *lwp) +{ + return lwp->stopped_by_watchpoint; +} + /* A list of all unknown processes which receive stop signals. Some other process will presumably claim each of these as forked children momentarily. */ diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c index 7d5b52b..ead70a0 100644 --- a/gdb/gdbserver/linux-x86-low.c +++ b/gdb/gdbserver/linux-x86-low.c @@ -569,7 +569,7 @@ update_debug_registers_callback (struct lwp_info *lwp, void *arg) /* If the lwp isn't stopped, force it to momentarily pause, so we can update its debug registers. */ - if (!lwp->stopped) + if (!lwp_is_stopped (lwp)) linux_stop_lwp (lwp); return 0; @@ -769,7 +769,7 @@ x86_debug_reg_state (pid_t pid) static void x86_linux_prepare_to_resume (struct lwp_info *lwp) { - ptid_t ptid = ptid_of (get_lwp_thread (lwp)); + ptid_t ptid = ptid_of_lwp (lwp); int clear_status = 0; if (lwp->arch_private->debug_registers_changed) @@ -798,7 +798,7 @@ x86_linux_prepare_to_resume (struct lwp_info *lwp) lwp->arch_private->debug_registers_changed = 0; } - if (clear_status || lwp->stopped_by_watchpoint) + if (clear_status || lwp_is_stopped_by_watchpoint (lwp)) x86_linux_dr_set (ptid, DR_STATUS, 0); } diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 7626d68..f51f7d3 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -281,6 +281,33 @@ static void delete_lwp (ptid_t ptid); static struct lwp_info *find_lwp_pid (ptid_t ptid); +/* LWP accessors. */ + +/* See nat/linux-nat.h. */ + +ptid_t +ptid_of_lwp (struct lwp_info *lwp) +{ + return lwp->ptid; +} + +/* See nat/linux-nat.h. */ + +int +lwp_is_stopped (struct lwp_info *lwp) +{ + return lwp->stopped; +} + +/* See nat/linux-nat.h. */ + +int +lwp_is_stopped_by_watchpoint (struct lwp_info *lwp) +{ + return lwp->stopped_by_watchpoint; +} + + /* Trivial list manipulation functions to keep track of a list of new stopped processes. */ static void diff --git a/gdb/nat/linux-nat.h b/gdb/nat/linux-nat.h index da77d6b..8dada8e 100644 --- a/gdb/nat/linux-nat.h +++ b/gdb/nat/linux-nat.h @@ -40,6 +40,20 @@ extern struct lwp_info *iterate_over_lwps (ptid_t filter, iterate_over_lwps_ftype callback, void *data); +/* Return the ptid of LWP. */ + +extern ptid_t ptid_of_lwp (struct lwp_info *lwp); + +/* Return nonzero if LWP is stopped, zero otherwise. This function + must be provided by the client. */ + +extern int lwp_is_stopped (struct lwp_info *lwp); + +/* Return nonzero if LWP is stopped with a data watchpoint trap, + zero otherwise. This function must be provided by the client. */ + +extern int lwp_is_stopped_by_watchpoint (struct lwp_info *lwp); + /* Cause LWP to stop. This function must be provided by the client. */ diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c index 92bdfec..3c96740 100644 --- a/gdb/x86-linux-nat.c +++ b/gdb/x86-linux-nat.c @@ -131,7 +131,7 @@ update_debug_registers_callback (struct lwp_info *lwp, void *arg) /* If the lwp isn't stopped, force it to momentarily pause, so we can update its debug registers. */ - if (!lwp->stopped) + if (!lwp_is_stopped (lwp)) linux_stop_lwp (lwp); /* Continue the iteration. */ @@ -167,6 +167,7 @@ x86_linux_dr_set_addr (int regnum, CORE_ADDR addr) static void x86_linux_prepare_to_resume (struct lwp_info *lwp) { + ptid_t ptid = ptid_of_lwp (lwp); int clear_status = 0; /* NULL means this is the main thread still going through the shell, @@ -178,7 +179,7 @@ x86_linux_prepare_to_resume (struct lwp_info *lwp) if (lwp->arch_private->debug_registers_changed) { struct x86_debug_reg_state *state - = x86_debug_reg_state (ptid_get_pid (lwp->ptid)); + = x86_debug_reg_state (ptid_get_pid (ptid)); int i; /* On Linux kernel before 2.6.33 commit @@ -191,12 +192,12 @@ x86_linux_prepare_to_resume (struct lwp_info *lwp) /* Clear DR_CONTROL first. In some cases, setting DR0-3 to a value that doesn't match what is enabled in DR_CONTROL results in EINVAL. */ - x86_linux_dr_set (lwp->ptid, DR_CONTROL, 0); + x86_linux_dr_set (ptid, DR_CONTROL, 0); ALL_DEBUG_ADDRESS_REGISTERS (i) if (state->dr_ref_count[i] > 0) { - x86_linux_dr_set (lwp->ptid, i, state->dr_mirror[i]); + x86_linux_dr_set (ptid, i, state->dr_mirror[i]); /* If we're setting a watchpoint, any change the inferior had done itself to the debug registers needs to be @@ -208,13 +209,13 @@ x86_linux_prepare_to_resume (struct lwp_info *lwp) /* If DR_CONTROL is supposed to be zero, we've already set it above. */ if (state->dr_control_mirror != 0) - x86_linux_dr_set (lwp->ptid, DR_CONTROL, state->dr_control_mirror); + x86_linux_dr_set (ptid, DR_CONTROL, state->dr_control_mirror); lwp->arch_private->debug_registers_changed = 0; } - if (clear_status || lwp->stopped_by_watchpoint) - x86_linux_dr_set (lwp->ptid, DR_STATUS, 0); + if (clear_status || lwp_is_stopped_by_watchpoint (lwp)) + x86_linux_dr_set (ptid, DR_STATUS, 0); } static void