From patchwork Thu Sep 15 12:01:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Arnez X-Patchwork-Id: 15662 Received: (qmail 53626 invoked by alias); 15 Sep 2016 12:01:56 -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 53608 invoked by uid 89); 15 Sep 2016 12:01:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM autolearn=no version=3.3.2 spammy=H*Ad:U*uweigand X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 15 Sep 2016 12:01:53 +0000 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id u8FBwu0H076756 for ; Thu, 15 Sep 2016 08:01:52 -0400 Received: from e06smtp06.uk.ibm.com (e06smtp06.uk.ibm.com [195.75.94.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 25fmcqkump-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 15 Sep 2016 08:01:52 -0400 Received: from localhost by e06smtp06.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 15 Sep 2016 13:01:50 +0100 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp06.uk.ibm.com (192.168.101.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 15 Sep 2016 13:01:49 +0100 X-IBM-Helo: d06dlp01.portsmouth.uk.ibm.com X-IBM-MailFrom: arnez@linux.vnet.ibm.com X-IBM-RcptTo: gdb-patches@sourceware.org Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 7DE7017D8024 for ; Thu, 15 Sep 2016 13:03:44 +0100 (BST) Received: from d06av09.portsmouth.uk.ibm.com (d06av09.portsmouth.uk.ibm.com [9.149.37.250]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u8FC1mtG11665736 for ; Thu, 15 Sep 2016 12:01:48 GMT Received: from d06av09.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u8FC1loY031061 for ; Thu, 15 Sep 2016 06:01:48 -0600 Received: from oc1027705133.ibm.com (dyn-9-152-212-159.boeblingen.de.ibm.com [9.152.212.159]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u8FC1ln3031017; Thu, 15 Sep 2016 06:01:47 -0600 From: Andreas Arnez To: gdb-patches@sourceware.org Cc: Ulrich Weigand Subject: [PATCH 3/6] S390: Multi-inferior watchpoint support Date: Thu, 15 Sep 2016 14:01:44 +0200 In-Reply-To: <1473940399-2891-1-git-send-email-arnez@linux.vnet.ibm.com> References: <1473940399-2891-1-git-send-email-arnez@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16091512-0024-0000-0000-0000021A5A59 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16091512-0025-0000-0000-00002066CD0C Message-Id: <1473940907-4449-2-git-send-email-arnez@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-09-15_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609020000 definitions=main-1609150162 X-IsSubscribed: yes Support different sets of watchpoints in multiple inferiors. gdb/ChangeLog: * s390-linux-nat.c (watch_areas): Remove variable. Replace by a member of... (struct s390_debug_reg_state): ...this. New struct. (struct s390_process_info): New struct. (s390_process_list): New variable. (s390_find_process_pid, s390_add_process, s390_process_info_get) (s390_get_debug_reg_state): New functions. (s390_stopped_by_watchpoint): Now access the watch_areas VEC via s390_get_debug_reg_state. (s390_prepare_to_resume): Likewise. (s390_insert_watchpoint): Likewise. (s390_remove_watchpoint): Likewise. (s390_forget_process, s390_linux_new_fork): New linux_nat target methods. (_initialize_s390_nat): Register them. --- gdb/s390-linux-nat.c | 149 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 139 insertions(+), 10 deletions(-) diff --git a/gdb/s390-linux-nat.c b/gdb/s390-linux-nat.c index 13bf7fd..b549246 100644 --- a/gdb/s390-linux-nat.c +++ b/gdb/s390-linux-nat.c @@ -430,8 +430,8 @@ s390_linux_store_inferior_registers (struct target_ops *ops, /* Hardware-assisted watchpoint handling. */ -/* We maintain a list of all currently active watchpoints in order - to properly handle watchpoint removal. +/* For each process we maintain a list of all currently active + watchpoints, in order to properly handle watchpoint removal. The only thing we actually need is the total address space area spanned by the watchpoints. */ @@ -444,17 +444,138 @@ typedef struct watch_area DEF_VEC_O (s390_watch_area); -VEC_s390_watch_area *watch_areas = NULL; +/* Hardware debug state. */ + +struct s390_debug_reg_state +{ + VEC_s390_watch_area *watch_areas; +}; + +/* Per-process data. */ + +struct s390_process_info +{ + struct s390_process_info *next; + pid_t pid; + struct s390_debug_reg_state state; +}; + +static struct s390_process_info *s390_process_list = NULL; + +/* Find process data for process PID. */ + +static struct s390_process_info * +s390_find_process_pid (pid_t pid) +{ + struct s390_process_info *proc; + + for (proc = s390_process_list; proc; proc = proc->next) + if (proc->pid == pid) + return proc; + + return NULL; +} + +/* Add process data for process PID. Returns newly allocated info + object. */ + +static struct s390_process_info * +s390_add_process (pid_t pid) +{ + struct s390_process_info *proc = XCNEW (struct s390_process_info); + + proc->pid = pid; + proc->next = s390_process_list; + s390_process_list = proc; + + return proc; +} + +/* Get data specific info for process PID, creating it if necessary. + Never returns NULL. */ + +static struct s390_process_info * +s390_process_info_get (pid_t pid) +{ + struct s390_process_info *proc; + + proc = s390_find_process_pid (pid); + if (proc == NULL) + proc = s390_add_process (pid); + + return proc; +} + +/* Get hardware debug state for process PID. */ + +static struct s390_debug_reg_state * +s390_get_debug_reg_state (pid_t pid) +{ + return &s390_process_info_get (pid)->state; +} + +/* Called whenever GDB is no longer debugging process PID. It deletes + data structures that keep track of hardware debug state. */ + +static void +s390_forget_process (pid_t pid) +{ + struct s390_process_info *proc, **proc_link; + + proc = s390_process_list; + proc_link = &s390_process_list; + + while (proc != NULL) + { + if (proc->pid == pid) + { + VEC_free (s390_watch_area, proc->state.watch_areas); + *proc_link = proc->next; + xfree (proc); + return; + } + + proc_link = &proc->next; + proc = *proc_link; + } +} + +/* linux_nat_new_fork hook. */ + +static void +s390_linux_new_fork (struct lwp_info *parent, pid_t child_pid) +{ + pid_t parent_pid; + struct s390_debug_reg_state *parent_state; + struct s390_debug_reg_state *child_state; + + /* NULL means no watchpoint has ever been set in the parent. In + that case, there's nothing to do. */ + if (lwp_arch_private_info (parent) == NULL) + return; + + /* GDB core assumes the child inherits the watchpoints/hw breakpoints of + the parent. So copy the debug state from parent to child. */ + + parent_pid = ptid_get_pid (parent->ptid); + parent_state = s390_get_debug_reg_state (parent_pid); + child_state = s390_get_debug_reg_state (child_pid); + + child_state->watch_areas = VEC_copy (s390_watch_area, + parent_state->watch_areas); +} static int s390_stopped_by_watchpoint (struct target_ops *ops) { + struct s390_debug_reg_state *state + = s390_get_debug_reg_state (ptid_get_pid (inferior_ptid)); per_lowcore_bits per_lowcore; ptrace_area parea; int result; /* Speed up common case. */ - if (VEC_empty (s390_watch_area, watch_areas)) + if (VEC_empty (s390_watch_area, state->watch_areas)) return 0; parea.len = sizeof (per_lowcore); @@ -483,6 +604,7 @@ static void s390_prepare_to_resume (struct lwp_info *lp) { int tid; + pid_t pid = ptid_get_pid (ptid_of_lwp (lp)); per_struct per_info; ptrace_area parea; @@ -491,6 +613,7 @@ s390_prepare_to_resume (struct lwp_info *lp) unsigned ix; s390_watch_area *area; struct arch_lwp_info *lp_priv = lwp_arch_private_info (lp); + struct s390_debug_reg_state *state = s390_get_debug_reg_state (pid); if (lp_priv == NULL || !lp_priv->per_info_changed) return; @@ -499,7 +622,7 @@ s390_prepare_to_resume (struct lwp_info *lp) tid = ptid_get_lwp (ptid_of_lwp (lp)); if (tid == 0) - tid = ptid_get_pid (ptid_of_lwp (lp)); + tid = pid; parea.len = sizeof (per_info); parea.process_addr = (addr_t) & per_info; @@ -507,10 +630,10 @@ s390_prepare_to_resume (struct lwp_info *lp) if (ptrace (PTRACE_PEEKUSR_AREA, tid, &parea, 0) < 0) perror_with_name (_("Couldn't retrieve watchpoint status")); - if (!VEC_empty (s390_watch_area, watch_areas)) + if (!VEC_empty (s390_watch_area, state->watch_areas)) { for (ix = 0; - VEC_iterate (s390_watch_area, watch_areas, ix, area); + VEC_iterate (s390_watch_area, state->watch_areas, ix, area); ix++) { watch_lo_addr = min (watch_lo_addr, area->lo_addr); @@ -580,10 +703,12 @@ s390_insert_watchpoint (struct target_ops *self, struct expression *cond) { s390_watch_area area; + struct s390_debug_reg_state *state + = s390_get_debug_reg_state (ptid_get_pid (inferior_ptid)); area.lo_addr = addr; area.hi_addr = addr + len - 1; - VEC_safe_push (s390_watch_area, watch_areas, &area); + VEC_safe_push (s390_watch_area, state->watch_areas, &area); return s390_refresh_per_info (); } @@ -595,14 +720,16 @@ s390_remove_watchpoint (struct target_ops *self, { unsigned ix; s390_watch_area *area; + struct s390_debug_reg_state *state + = s390_get_debug_reg_state (ptid_get_pid (inferior_ptid)); for (ix = 0; - VEC_iterate (s390_watch_area, watch_areas, ix, area); + VEC_iterate (s390_watch_area, state->watch_areas, ix, area); ix++) { if (area->lo_addr == addr && area->hi_addr == addr + len - 1) { - VEC_unordered_remove (s390_watch_area, watch_areas, ix); + VEC_unordered_remove (s390_watch_area, state->watch_areas, ix); return s390_refresh_per_info (); } } @@ -753,4 +880,6 @@ _initialize_s390_nat (void) linux_nat_add_target (t); linux_nat_set_new_thread (t, s390_new_thread); linux_nat_set_prepare_to_resume (t, s390_prepare_to_resume); + linux_nat_set_forget_process (t, s390_forget_process); + linux_nat_set_new_fork (t, s390_linux_new_fork); }