From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14623 invoked by alias); 9 Oct 2014 10:18:21 -0000 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 Received: (qmail 14561 invoked by uid 89); 9 Oct 2014 10:18:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD 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; Thu, 09 Oct 2014 10:18:18 +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 s999qtHF013522 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 9 Oct 2014 05:52:55 -0400 Received: from blade.nx (ovpn-116-100.ams2.redhat.com [10.36.116.100]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s999qr4C023461 for ; Thu, 9 Oct 2014 05:52:54 -0400 Received: from blade.nx (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id BE59B2626C9 for ; Thu, 9 Oct 2014 10:52:48 +0100 (BST) From: Gary Benson To: gdb-patches@sourceware.org Subject: [PATCH 07/13 v2] Make lwp_info.arch_private handling shared Date: Thu, 09 Oct 2014 10:18:00 -0000 Message-Id: <1412848358-9958-8-git-send-email-gbenson@redhat.com> In-Reply-To: <1412848358-9958-1-git-send-email-gbenson@redhat.com> References: <1412848358-9958-1-git-send-email-gbenson@redhat.com> X-IsSubscribed: yes X-SW-Source: 2014-10/txt/msg00191.txt.bz2 This commit moves the code to handle lwp_info.arch_private for Linux x86 into a new shared file, nat/x86-linux.c. gdb/ChangeLog: * nat/x86-linux.h: New file. * nat/x86-linux.c: Likewise. * Makefile.in (HFILES_NO_SRCDIR): Add nat/x86-linux.h. (x86-linux.o): New rule. * config/i386/linux.mh (NATDEPFILES): Add x86-linux.o. * config/i386/linux64.mh (NATDEPFILES): Likewise. * nat/linux-nat.h (struct arch_lwp_info): New forward declaration. (lwp_set_arch_private_info): New declaration. (lwp_arch_private_info): Likewise. * linux-nat.c (lwp_set_arch_private_info): New function. (lwp_arch_private_info): Likewise. * x86-linux-nat.c: Include nat/x86-linux.h. (arch_lwp_info): Removed structure. (update_debug_registers_callback): Use lwp_set_debug_registers_changed. (x86_linux_prepare_to_resume): Use lwp_debug_registers_changed and lwp_set_debug_registers_changed. (x86_linux_new_thread): Use lwp_set_debug_registers_changed. gdb/gdbserver/ChangeLog: * Makefile.in (x86-linux.o): New rule. * configure.srv: Add x86-linux.o to relevant targets. * linux-low.c (lwp_set_arch_private_info): New function. (lwp_arch_private_info): Likewise. * linux-x86-low.c: Include nat/x86-linux.h. (arch_lwp_info): Removed structure. (update_debug_registers_callback): Use lwp_set_debug_registers_changed. (x86_linux_prepare_to_resume): Use lwp_debug_registers_changed and lwp_set_debug_registers_changed. (x86_linux_new_thread): Use lwp_set_debug_registers_changed. --- gdb/ChangeLog | 21 +++++++++++++++ gdb/Makefile.in | 6 +++- gdb/config/i386/linux.mh | 2 +- gdb/config/i386/linux64.mh | 2 +- gdb/gdbserver/ChangeLog | 14 ++++++++++ gdb/gdbserver/Makefile.in | 3 ++ gdb/gdbserver/configure.srv | 4 +- gdb/gdbserver/linux-low.c | 17 ++++++++++++ gdb/gdbserver/linux-x86-low.c | 21 +++----------- gdb/linux-nat.c | 17 ++++++++++++ gdb/nat/linux-nat.h | 12 ++++++++ gdb/nat/x86-linux.c | 57 +++++++++++++++++++++++++++++++++++++++++ gdb/nat/x86-linux.h | 38 +++++++++++++++++++++++++++ gdb/x86-linux-nat.c | 22 +++------------ 14 files changed, 198 insertions(+), 38 deletions(-) create mode 100644 gdb/nat/x86-linux.c create mode 100644 gdb/nat/x86-linux.h diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 1ffa62a..3379347 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -940,7 +940,7 @@ common/print-utils.h common/rsp-low.h nat/x86-dregs.h x86-linux-nat.h \ i386-linux-nat.h common/common-defs.h common/errors.h common/common-types.h \ common/common-debug.h common/cleanups.h common/gdb_setjmp.h \ common/common-exceptions.h target/target.h common/symbol.h \ -common/common-regcache.h fbsd-tdep.h +common/common-regcache.h fbsd-tdep.h nat/x86-linux.h # Header files that already have srcdir in them, or which are in objdir. @@ -2218,6 +2218,10 @@ mips-linux-watch.o: ${srcdir}/nat/mips-linux-watch.c $(COMPILE) $(srcdir)/nat/mips-linux-watch.c $(POSTCOMPILE) +x86-linux.o: ${srcdir}/nat/x86-linux.c + $(COMPILE) $(srcdir)/nat/x86-linux.c + $(POSTCOMPILE) + # # gdb/tui/ dependencies # diff --git a/gdb/config/i386/linux.mh b/gdb/config/i386/linux.mh index a4e4842..f409bfe 100644 --- a/gdb/config/i386/linux.mh +++ b/gdb/config/i386/linux.mh @@ -5,7 +5,7 @@ NATDEPFILES= inf-ptrace.o fork-child.o \ x86-nat.o x86-dregs.o i386-linux-nat.o x86-linux-nat.o \ proc-service.o linux-thread-db.o \ linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \ - linux-btrace.o linux-waitpid.o + linux-btrace.o linux-waitpid.o x86-linux.o NAT_CDEPS = $(srcdir)/proc-service.list # The dynamically loaded libthread_db needs access to symbols in the diff --git a/gdb/config/i386/linux64.mh b/gdb/config/i386/linux64.mh index d557202..1d40167 100644 --- a/gdb/config/i386/linux64.mh +++ b/gdb/config/i386/linux64.mh @@ -5,7 +5,7 @@ NATDEPFILES= inf-ptrace.o fork-child.o \ linux-nat.o linux-osdata.o \ proc-service.o linux-thread-db.o linux-fork.o \ linux-procfs.o linux-ptrace.o linux-btrace.o \ - linux-waitpid.o + linux-waitpid.o x86-linux.o NAT_FILE= config/nm-linux.h NAT_CDEPS = $(srcdir)/proc-service.list diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in index 8b0318a..a58fd68 100644 --- a/gdb/gdbserver/Makefile.in +++ b/gdb/gdbserver/Makefile.in @@ -581,6 +581,9 @@ linux-waitpid.o: ../nat/linux-waitpid.c mips-linux-watch.o: ../nat/mips-linux-watch.c $(COMPILE) $< $(POSTCOMPILE) +x86-linux.o: ../nat/x86-linux.c + $(COMPILE) $< + $(POSTCOMPILE) aarch64.c : $(srcdir)/../regformats/aarch64.dat $(regdat_sh) $(SHELL) $(regdat_sh) $(srcdir)/../regformats/aarch64.dat aarch64.c diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv index 679fc9f..2c261dc 100644 --- a/gdb/gdbserver/configure.srv +++ b/gdb/gdbserver/configure.srv @@ -109,7 +109,7 @@ case "${target}" in srv_xmlfiles="${srv_xmlfiles} $srv_amd64_linux_xmlfiles" fi srv_tgtobj="$srv_linux_obj linux-x86-low.o x86-low.o x86-dregs.o i387-fp.o" - srv_tgtobj="${srv_tgtobj} linux-btrace.o" + srv_tgtobj="${srv_tgtobj} linux-btrace.o x86-linux.o" srv_linux_usrregs=yes srv_linux_regsets=yes srv_linux_thread_db=yes @@ -316,7 +316,7 @@ case "${target}" in ;; x86_64-*-linux*) srv_regobj="$srv_amd64_linux_regobj $srv_i386_linux_regobj" srv_tgtobj="$srv_linux_obj linux-x86-low.o x86-low.o x86-dregs.o i387-fp.o" - srv_tgtobj="${srv_tgtobj} linux-btrace.o" + srv_tgtobj="${srv_tgtobj} linux-btrace.o x86-linux.o" srv_xmlfiles="$srv_i386_linux_xmlfiles $srv_amd64_linux_xmlfiles" srv_linux_usrregs=yes # This is for i386 progs. srv_linux_regsets=yes diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index 15a5c56..31c7878 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -146,6 +146,23 @@ ptid_of_lwp (struct lwp_info *lwp) /* See nat/linux-nat.h. */ +void +lwp_set_arch_private_info (struct lwp_info *lwp, + struct arch_lwp_info *info) +{ + lwp->arch_private = info; +} + +/* See nat/linux-nat.h. */ + +struct arch_lwp_info * +lwp_arch_private_info (struct lwp_info *lwp) +{ + return lwp->arch_private; +} + +/* See nat/linux-nat.h. */ + int lwp_is_stopped (struct lwp_info *lwp) { diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c index f04e1f1..445a07e 100644 --- a/gdb/gdbserver/linux-x86-low.c +++ b/gdb/gdbserver/linux-x86-low.c @@ -38,6 +38,7 @@ #include "tracepoint.h" #include "ax.h" #include "nat/linux-nat.h" +#include "nat/x86-linux.h" #ifdef __x86_64__ /* Defined in auto-generated file amd64-linux.c. */ @@ -152,14 +153,6 @@ struct arch_process_info struct x86_debug_reg_state debug_reg_state; }; -/* Per-thread arch-specific data we want to keep. */ - -struct arch_lwp_info -{ - /* Non-zero if our copy differs from what's recorded in the thread. */ - int debug_registers_changed; -}; - #ifdef __x86_64__ /* Mapping between the general-purpose registers in `struct user' @@ -566,7 +559,7 @@ update_debug_registers_callback (struct lwp_info *lwp, void *arg) { /* The actual update is done later just before resuming the lwp, we just mark that the registers need updating. */ - lwp->arch_private->debug_registers_changed = 1; + lwp_set_debug_registers_changed (lwp, 1); /* If the lwp isn't stopped, force it to momentarily pause, so we can update its debug registers. */ @@ -747,11 +740,7 @@ x86_linux_new_process (void) static void x86_linux_new_thread (struct lwp_info *lwp) { - struct arch_lwp_info *info = XCNEW (struct arch_lwp_info); - - info->debug_registers_changed = 1; - - lwp->arch_private = info; + lwp_set_debug_registers_changed (lwp, 1); } /* See nat/x86-dregs.h. */ @@ -773,7 +762,7 @@ x86_linux_prepare_to_resume (struct lwp_info *lwp) ptid_t ptid = ptid_of_lwp (lwp); int clear_status = 0; - if (lwp->arch_private->debug_registers_changed) + if (lwp_debug_registers_changed (lwp)) { struct x86_debug_reg_state *state = x86_debug_reg_state (ptid_get_pid (ptid)); @@ -796,7 +785,7 @@ x86_linux_prepare_to_resume (struct lwp_info *lwp) if (state->dr_control_mirror != 0) x86_linux_dr_set (ptid, DR_CONTROL, state->dr_control_mirror); - lwp->arch_private->debug_registers_changed = 0; + lwp_set_debug_registers_changed (lwp, 0); } if (clear_status || lwp_is_stopped_by_watchpoint (lwp)) diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 4a32bb9..16151b5 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -290,6 +290,23 @@ ptid_of_lwp (struct lwp_info *lwp) /* See nat/linux-nat.h. */ +void +lwp_set_arch_private_info (struct lwp_info *lwp, + struct arch_lwp_info *info) +{ + lwp->arch_private = info; +} + +/* See nat/linux-nat.h. */ + +struct arch_lwp_info * +lwp_arch_private_info (struct lwp_info *lwp) +{ + return lwp->arch_private; +} + +/* See nat/linux-nat.h. */ + int lwp_is_stopped (struct lwp_info *lwp) { diff --git a/gdb/nat/linux-nat.h b/gdb/nat/linux-nat.h index 502c2cb..5d3ef90 100644 --- a/gdb/nat/linux-nat.h +++ b/gdb/nat/linux-nat.h @@ -21,6 +21,7 @@ #define LINUX_NAT_H struct lwp_info; +struct arch_lwp_info; /* Unlike other extended result codes, WSTOPSIG (status) on PTRACE_O_TRACESYSGOOD syscall events doesn't return SIGTRAP, but @@ -49,6 +50,17 @@ extern struct lwp_info *iterate_over_lwps (ptid_t filter, extern ptid_t ptid_of_lwp (struct lwp_info *lwp); +/* Set the architecture-specific data of LWP. This function must be + provided by the client. */ + +extern void lwp_set_arch_private_info (struct lwp_info *lwp, + struct arch_lwp_info *info); + +/* Return the architecture-specific data of LWP. This function must + be provided by the client. */ + +extern struct arch_lwp_info *lwp_arch_private_info (struct lwp_info *lwp); + /* Return nonzero if LWP is stopped, zero otherwise. This function must be provided by the client. */ diff --git a/gdb/nat/x86-linux.c b/gdb/nat/x86-linux.c new file mode 100644 index 0000000..efeeab9 --- /dev/null +++ b/gdb/nat/x86-linux.c @@ -0,0 +1,57 @@ +/* Native-dependent code for GNU/Linux x86 (i386 and x86-64). + + Copyright (C) 1999-2014 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include "common-defs.h" +#include "x86-linux.h" + +/* Per-thread arch-specific data we want to keep. */ + +struct arch_lwp_info +{ + /* Non-zero if our copy differs from what's recorded in the + thread. */ + int debug_registers_changed; +}; + +/* See nat/x86-linux.h. */ + +void +lwp_set_debug_registers_changed (struct lwp_info *lwp, int value) +{ + if (lwp_arch_private_info (lwp) == NULL) + lwp_set_arch_private_info (lwp, XCNEW (struct arch_lwp_info)); + + lwp_arch_private_info (lwp)->debug_registers_changed = value; +} + +/* See nat/x86-linux.h. */ + +int +lwp_debug_registers_changed (struct lwp_info *lwp) +{ + struct arch_lwp_info *info = lwp_arch_private_info (lwp); + + /* NULL means either that this is the main thread still going + through the shell, or that no watchpoint has been set yet. + The debug registers are unchanged in either case. */ + if (info == NULL) + return 0; + + return info->debug_registers_changed; +} diff --git a/gdb/nat/x86-linux.h b/gdb/nat/x86-linux.h new file mode 100644 index 0000000..6409898 --- /dev/null +++ b/gdb/nat/x86-linux.h @@ -0,0 +1,38 @@ +/* Native-dependent code for GNU/Linux x86 (i386 and x86-64). + + Copyright (C) 1999-2014 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef X86_LINUX_H +#define X86_LINUX_H + +#include "nat/linux-nat.h" + +/* Set whether our local mirror of LWP's debug registers has been + changed since the values were last written to the thread. Nonzero + indicates that a change has been made, zero indicates no change. */ + +extern void lwp_set_debug_registers_changed (struct lwp_info *lwp, + int value); + +/* Return nonzero if our local mirror of LWP's debug registers has + been changed since the values were last written to the thread, + zero otherwise. */ + +extern int lwp_debug_registers_changed (struct lwp_info *lwp); + +#endif /* X86_LINUX_H */ diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c index c25240d..c4387eb 100644 --- a/gdb/x86-linux-nat.c +++ b/gdb/x86-linux-nat.c @@ -39,6 +39,7 @@ #include "x86-xstate.h" #include "nat/linux-btrace.h" #include "nat/linux-nat.h" +#include "nat/x86-linux.h" /* Per-thread arch-specific data we want to keep. */ @@ -124,12 +125,9 @@ x86_linux_dr_get_status (void) static int update_debug_registers_callback (struct lwp_info *lwp, void *arg) { - if (lwp->arch_private == NULL) - lwp->arch_private = XCNEW (struct arch_lwp_info); - /* The actual update is done later just before resuming the lwp, we just mark that the registers need updating. */ - lwp->arch_private->debug_registers_changed = 1; + lwp_set_debug_registers_changed (lwp, 1); /* If the lwp isn't stopped, force it to momentarily pause, so we can update its debug registers. */ @@ -172,13 +170,7 @@ 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, - or, no watchpoint has been set yet. In that case, there's - nothing to do. */ - if (lwp->arch_private == NULL) - return; - - if (lwp->arch_private->debug_registers_changed) + if (lwp_debug_registers_changed (lwp)) { struct x86_debug_reg_state *state = x86_debug_reg_state (ptid_get_pid (ptid)); @@ -213,7 +205,7 @@ x86_linux_prepare_to_resume (struct lwp_info *lwp) if (state->dr_control_mirror != 0) x86_linux_dr_set (ptid, DR_CONTROL, state->dr_control_mirror); - lwp->arch_private->debug_registers_changed = 0; + lwp_set_debug_registers_changed (lwp, 0); } if (clear_status || lwp_is_stopped_by_watchpoint (lwp)) @@ -223,11 +215,7 @@ x86_linux_prepare_to_resume (struct lwp_info *lwp) static void x86_linux_new_thread (struct lwp_info *lp) { - struct arch_lwp_info *info = XCNEW (struct arch_lwp_info); - - info->debug_registers_changed = 1; - - lp->arch_private = info; + lwp_set_debug_registers_changed (lp, 1); } -- 1.7.1