From patchwork Tue Mar 10 10:31:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Arnez X-Patchwork-Id: 5544 Received: (qmail 48195 invoked by alias); 10 Mar 2015 10:31:42 -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 48184 invoked by uid 89); 10 Mar 2015 10:31:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: e06smtp13.uk.ibm.com Received: from e06smtp13.uk.ibm.com (HELO e06smtp13.uk.ibm.com) (195.75.94.109) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Tue, 10 Mar 2015 10:31:40 +0000 Received: from /spool/local by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 10 Mar 2015 10:31:36 -0000 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 10 Mar 2015 10:31:34 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 73D23219004D for ; Tue, 10 Mar 2015 10:31:25 +0000 (GMT) Received: from d06av10.portsmouth.uk.ibm.com (d06av10.portsmouth.uk.ibm.com [9.149.37.251]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t2AAVYFh5898560 for ; Tue, 10 Mar 2015 10:31:34 GMT Received: from d06av10.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t2AAVYMr012367 for ; Tue, 10 Mar 2015 04:31:34 -0600 Received: from br87z6lw.de.ibm.com (sig-9-84-137-148.evts.de.ibm.com [9.84.137.148]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t2AAVWtr012254; Tue, 10 Mar 2015 04:31:33 -0600 From: Andreas Arnez To: gdb-patches@sourceware.org Cc: Ulrich Weigand Subject: [PATCH] S390: Defer PER info update until resume Date: Tue, 10 Mar 2015 11:31:31 +0100 Message-ID: <87385dgn3w.fsf@br87z6lw.de.ibm.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15031010-0013-0000-0000-0000033F1283 X-IsSubscribed: yes For multi-threaded inferiors on S390 GNU/Linux targets, GDB tried to update the PER info via ptrace() in a newly attached thread before assuring that the thread is stopped. Depending on the timing, this could lead to a GDB internal error. The patch defers the PER info update until just before resuming the thread. gdb/ChangeLog: * s390-linux-nat.c (struct arch_lwp_info): New. (s390_fix_watch_points): Rename to... (s390_prepare_to_resume): ...this. Skip the PER info update unless the watch points have changed. (s390_refresh_per_info, s390_new_thread): New functions. (s390_insert_watchpoint): Call s390_refresh_per_info instead of s390_fix_watch_points. (s390_remove_watchpoint): Likewise. (_initialize_s390_nat): Reflect renaming of s390_fix_watch_points. Register s390_prepare_to_resume. --- gdb/s390-linux-nat.c | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/gdb/s390-linux-nat.c b/gdb/s390-linux-nat.c index 367b610..9298bcc 100644 --- a/gdb/s390-linux-nat.c +++ b/gdb/s390-linux-nat.c @@ -46,6 +46,14 @@ #define PTRACE_SETREGSET 0x4205 #endif +/* Per-thread arch-specific data. */ + +struct arch_lwp_info +{ + /* Non-zero if the thread's PER info must be re-written. */ + int per_info_changed; +}; + static int have_regset_last_break = 0; static int have_regset_system_call = 0; static int have_regset_tdb = 0; @@ -465,8 +473,10 @@ s390_stopped_by_watchpoint (struct target_ops *ops) return result; } +/* Each time before resuming a thread, update its PER info. */ + static void -s390_fix_watch_points (struct lwp_info *lp) +s390_prepare_to_resume (struct lwp_info *lp) { int tid; @@ -476,6 +486,12 @@ s390_fix_watch_points (struct lwp_info *lp) CORE_ADDR watch_lo_addr = (CORE_ADDR)-1, watch_hi_addr = 0; struct watch_area *area; + if (lp->arch_private == NULL + || !lp->arch_private->per_info_changed) + return; + + lp->arch_private->per_info_changed = 0; + tid = ptid_get_lwp (lp->ptid); if (tid == 0) tid = ptid_get_pid (lp->ptid); @@ -509,6 +525,30 @@ s390_fix_watch_points (struct lwp_info *lp) perror_with_name (_("Couldn't modify watchpoint status")); } +/* Make sure that LP is stopped and mark its PER info as changed, so + the next resume will update it. */ + +static void +s390_refresh_per_info (struct lwp_info *lp) +{ + if (lp->arch_private == NULL) + lp->arch_private = XCNEW (struct arch_lwp_info); + + lp->arch_private->per_info_changed = 1; + + if (!lp->stopped) + linux_stop_lwp (lp); +} + +/* When attaching to a new thread, mark its PER info as changed. */ + +static void +s390_new_thread (struct lwp_info *lp) +{ + lp->arch_private = XCNEW (struct arch_lwp_info); + lp->arch_private->per_info_changed = 1; +} + static int s390_insert_watchpoint (struct target_ops *self, CORE_ADDR addr, int len, int type, @@ -527,7 +567,7 @@ s390_insert_watchpoint (struct target_ops *self, watch_base = area; ALL_LWPS (lp) - s390_fix_watch_points (lp); + s390_refresh_per_info (lp); return 0; } @@ -556,7 +596,7 @@ s390_remove_watchpoint (struct target_ops *self, xfree (area); ALL_LWPS (lp) - s390_fix_watch_points (lp); + s390_refresh_per_info (lp); return 0; } @@ -699,5 +739,6 @@ _initialize_s390_nat (void) /* Register the target. */ linux_nat_add_target (t); - linux_nat_set_new_thread (t, s390_fix_watch_points); + linux_nat_set_new_thread (t, s390_new_thread); + linux_nat_set_prepare_to_resume (t, s390_prepare_to_resume); }