From owner-freebsd-current@FreeBSD.ORG Thu Feb 9 00:54:12 2012 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 98649106566B for ; Thu, 9 Feb 2012 00:54:11 +0000 (UTC) (envelope-from dmitrym@juniper.net) Received: from exprod7og124.obsmtp.com (exprod7og124.obsmtp.com [64.18.2.26]) by mx1.freebsd.org (Postfix) with ESMTP id 248A28FC08 for ; Thu, 9 Feb 2012 00:54:11 +0000 (UTC) Received: from P-EMHUB03-HQ.jnpr.net ([66.129.224.36]) (using TLSv1) by exprod7ob124.postini.com ([64.18.6.12]) with SMTP ID DSNKTzMZMfHolQunqHEANY6CrBMtRjX/LT5v@postini.com; Wed, 08 Feb 2012 16:54:11 PST Received: from magenta.juniper.net (172.17.27.123) by P-EMHUB03-HQ.jnpr.net (172.24.192.33) with Microsoft SMTP Server (TLS) id 8.3.213.0; Wed, 8 Feb 2012 16:51:58 -0800 Received: from [172.24.26.191] (dmitrym-lnx.jnpr.net [172.24.26.191]) by magenta.juniper.net (8.11.3/8.11.3) with ESMTP id q190pw110535; Wed, 8 Feb 2012 16:51:58 -0800 (PST) (envelope-from dmitrym@juniper.net) Message-ID: <4F3318AD.6000607@juniper.net> Date: Wed, 8 Feb 2012 16:51:57 -0800 From: Dmitry Mikulin User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111229 Thunderbird/9.0 MIME-Version: 1.0 References: <20120125074824.GD2726@deviant.kiev.zoral.com.ua> <4F2094B4.70707@juniper.net> <20120126122326.GT2726@deviant.kiev.zoral.com.ua> <4F22E8FD.6010201@juniper.net> <20120129074843.GL2726@deviant.kiev.zoral.com.ua> <4F26E0D1.8040100@juniper.net> <20120130192727.GZ2726@deviant.kiev.zoral.com.ua> <4F2C756A.80900@juniper.net> <20120204204218.GC3283@deviant.kiev.zoral.com.ua> <4F3043E2.6090607@juniper.net> <20120207121022.GC3283@deviant.kiev.zoral.com.ua> <4F318D74.9030506@juniper.net> <4F31C89C.7010705@juniper.net> In-Reply-To: <4F31C89C.7010705@juniper.net> Content-Type: multipart/mixed; boundary="------------080604060607090502060303" X-EXCLAIMER-MD-CONFIG: e4081efb-6d29-443c-8708-750833aec629 X-Mailman-Approved-At: Thu, 09 Feb 2012 02:34:48 +0000 Cc: Konstantin Belousov , freebsd-current Current , Marcel Moolenaar Subject: Re: [ptrace] please review follow fork/exec changes X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Feb 2012 00:54:12 -0000 --------------080604060607090502060303 Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit The patch I sent earlier works for me. Just wanted to let you know to illustrate what I would like to see from the kernel. I'm trying to see if there's way not to add flags with semantics similar to TDB_EXEC. I think the problem with TDB_EXEC is that is serves a trigger for a stop as well as an indicator to return PL_FLAG_EXEC. And in my case I still want to see all the stops but I only want to see the PL_FLAG_EXEC when PT_FOLLOW_EXEC is specified. Do you think the attached patch will do what I'd like without compromising existing functionality? --------------080604060607090502060303 Content-Type: text/x-patch; name="follow-exec-4.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="follow-exec-4.diff" Index: sys/proc.h =================================================================== --- sys/proc.h (revision 231228) +++ sys/proc.h (working copy) @@ -384,6 +384,7 @@ do { \ process */ #define TDB_STOPATFORK 0x00000080 /* Stop at the return from fork (child only) */ +#define TDB_CHILD 0x00000100 /* New child indicator for ptrace() */ /* * "Private" flags kept in td_pflags: @@ -613,6 +614,7 @@ struct proc { #define P_HWPMC 0x800000 /* Process is using HWPMCs */ #define P_JAILED 0x1000000 /* Process is in jail. */ +#define P_FOLLOWEXEC 0x2000000 /* Report execs with ptrace. */ #define P_INEXEC 0x4000000 /* Process is in execve(). */ #define P_STATCHILD 0x8000000 /* Child process stopped or exited. */ #define P_INMEM 0x10000000 /* Loaded into memory. */ Index: sys/ptrace.h =================================================================== --- sys/ptrace.h (revision 231228) +++ sys/ptrace.h (working copy) @@ -64,6 +64,7 @@ #define PT_SYSCALL 22 #define PT_FOLLOW_FORK 23 +#define PT_FOLLOW_EXEC 24 #define PT_GETREGS 33 /* get general-purpose registers */ #define PT_SETREGS 34 /* set general-purpose registers */ @@ -106,7 +107,8 @@ struct ptrace_lwpinfo { #define PL_FLAG_SCX 0x08 /* syscall leave point */ #define PL_FLAG_EXEC 0x10 /* exec(2) succeeded */ #define PL_FLAG_SI 0x20 /* siginfo is valid */ -#define PL_FLAG_FORKED 0x40 /* new child */ +#define PL_FLAG_FORKED 0x40 /* child born */ +#define PL_FLAG_CHILD 0x80 /* I am from child */ sigset_t pl_sigmask; /* LWP signal mask */ sigset_t pl_siglist; /* LWP pending signal */ struct __siginfo pl_siginfo; /* siginfo for signal */ Index: kern/kern_exec.c =================================================================== --- kern/kern_exec.c (revision 231228) +++ kern/kern_exec.c (working copy) @@ -56,6 +56,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include Index: kern/kern_fork.c =================================================================== --- kern/kern_fork.c (revision 231228) +++ kern/kern_fork.c (working copy) @@ -1035,7 +1035,9 @@ fork_return(struct thread *td, struct trapframe *f p->p_oppid = p->p_pptr->p_pid; proc_reparent(p, dbg); sx_xunlock(&proctree_lock); + td->td_dbgflags |= TDB_CHILD; ptracestop(td, SIGSTOP); + td->td_dbgflags &= ~TDB_CHILD; } else { /* * ... otherwise clear the request. Index: kern/sys_process.c =================================================================== --- kern/sys_process.c (revision 231228) +++ kern/sys_process.c (working copy) @@ -660,6 +660,7 @@ kern_ptrace(struct thread *td, int req, pid_t pid, case PT_TO_SCX: case PT_SYSCALL: case PT_FOLLOW_FORK: + case PT_FOLLOW_EXEC: case PT_DETACH: sx_xlock(&proctree_lock); proctree_locked = 1; @@ -873,6 +874,12 @@ kern_ptrace(struct thread *td, int req, pid_t pid, else p->p_flag &= ~P_FOLLOWFORK; break; + case PT_FOLLOW_EXEC: + if (data) + p->p_flag |= P_FOLLOWEXEC; + else + p->p_flag &= ~P_FOLLOWEXEC; + break; case PT_STEP: case PT_CONTINUE: @@ -936,7 +943,8 @@ kern_ptrace(struct thread *td, int req, pid_t pid, p->p_sigparent = SIGCHLD; } p->p_oppid = 0; - p->p_flag &= ~(P_TRACED | P_WAITED | P_FOLLOWFORK); + p->p_flag &= ~(P_TRACED | P_WAITED | P_FOLLOWFORK | + P_FOLLOWEXEC); /* should we send SIGCHLD? */ /* childproc_continued(p); */ @@ -1139,12 +1147,15 @@ kern_ptrace(struct thread *td, int req, pid_t pid, pl->pl_flags |= PL_FLAG_SCE; else if (td2->td_dbgflags & TDB_SCX) pl->pl_flags |= PL_FLAG_SCX; - if (td2->td_dbgflags & TDB_EXEC) + if (td2->td_dbgflags & TDB_EXEC && + (p->p_stops & S_PT_SCX || p->p_flag & P_FOLLOWEXEC)) pl->pl_flags |= PL_FLAG_EXEC; if (td2->td_dbgflags & TDB_FORK) { pl->pl_flags |= PL_FLAG_FORKED; pl->pl_child_pid = td2->td_dbg_forked; } + if (td2->td_dbgflags & TDB_CHILD) + pl->pl_flags |= PL_FLAG_CHILD; pl->pl_sigmask = td2->td_sigmask; pl->pl_siglist = td2->td_siglist; strcpy(pl->pl_tdname, td2->td_name); --------------080604060607090502060303--