From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14117 invoked by alias); 7 Feb 2013 16:59:22 -0000 Received: (qmail 14093 invoked by uid 22791); 7 Feb 2013 16:59:20 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_SPAMHAUS_DROP,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 07 Feb 2013 16:59:15 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r17GxCb3016104 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 7 Feb 2013 11:59:12 -0500 Received: from host2.jankratochvil.net (ovpn-116-18.ams2.redhat.com [10.36.116.18]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r17Gx8LM000909 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 7 Feb 2013 11:59:11 -0500 Date: Thu, 07 Feb 2013 16:59:00 -0000 From: Jan Kratochvil To: Pedro Alves Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] [native x86 GNU/Linux] Access debug register mirror from the corresponding inferior. Message-ID: <20130207165907.GB15297@host2.jankratochvil.net> References: <20130207163339.19427.73350.stgit@brno.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20130207163339.19427.73350.stgit@brno.lan> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 X-SW-Source: 2013-02/txt/msg00184.txt.bz2 On Thu, 07 Feb 2013 17:33:39 +0100, Pedro Alves wrote: > There's one wrinkle though, and one which we already handle somewhat. > When detaching the fork child that we're not interested in debugging > (set detach-on-fork off / follow-fork parent), we don't even create an set detach-on-fork on > inferior for that fork child, so there's no place to get the struct > i386_debug_reg_state from, as that's stored in the inferior. > > I thought of more than one way to fix this, and this seemed the > simplest - special case the null inferior case. > > Other options involved creating a about_to_detach/about_to_fork_detach > hook; > > Create a target side "struct process_info", thus decoupling from > struct inferior (mildly complicated, lots of mechanical changes across > all native targets that do x86 watchpoints, or > > Always creating an inferior (that has lots of complications). I tried that in the past and I agree it was not worth it. > --- a/gdb/amd64-linux-nat.c > +++ b/gdb/amd64-linux-nat.c > @@ -394,9 +394,22 @@ amd64_linux_prepare_to_resume (struct lwp_info *lwp) > > if (lwp->arch_private->debug_registers_changed) > { > - struct i386_debug_reg_state *state = i386_debug_reg_state (); > + int pid = ptid_get_pid (lwp->ptid); > + struct inferior *inf = find_inferior_pid (pid); > + struct i386_debug_reg_state *state; > int i; > > + if (inf == NULL) > + { > + /* NULL means this is a fork child we're not interested in > + debugging being detached. We want to leave it with its > + debug registers cleared. */ > + amd64_linux_dr_set (lwp->ptid, DR_CONTROL, 0); > + return; > + } It is already handled by this code which seems to be skipped by this patch. if (detached_inf_pid != ptid_get_pid (inferior_ptid)) { /* Reinitialize the local cache if INFERIOR_PTID is different from the LWP last detached. Linux kernel before 2.6.33 commit 72f674d203cd230426437cdcf7dd6f681dad8b0d will inherit hardware debug registers from parent on fork/vfork/clone. Newer Linux kernels create such tasks with zeroed debug registers. GDB will remove all breakpoints (and watchpoints) from the forked off process. We also need to reset the debug registers in that process to be compatible with the older Linux kernels. Copy the debug registers mirrors into the new process so that all breakpoints and watchpoints can be removed together. The debug registers mirror will become zeroed in the end before detaching the forked off process. */ detached_inf_pid = ptid_get_pid (inferior_ptid); detached_inf_data_local = *inf_data; } Also it seems incorrect to me to use 'ptid_get_pid (inferior_ptid)' there when the detached LWP may not come from the current inferior, it is expected to be the PID of the process remaining under control of GDB. I did not try it but what about temporarily switching current inferior? Thanks, Jan