From owner-freebsd-arch@FreeBSD.ORG Thu Jul 1 13:42:22 2010 Return-Path: Delivered-To: arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B147B1065670 for ; Thu, 1 Jul 2010 13:42:22 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id C30188FC1C for ; Thu, 1 Jul 2010 13:42:21 +0000 (UTC) Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id o61DgHjM006071 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 1 Jul 2010 16:42:17 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.4/8.14.4) with ESMTP id o61DgHfK000165 for ; Thu, 1 Jul 2010 16:42:17 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.4/8.14.4/Submit) id o61DgHOO000164 for arch@freebsd.org; Thu, 1 Jul 2010 16:42:17 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 1 Jul 2010 16:42:17 +0300 From: Kostik Belousov To: arch@freebsd.org Message-ID: <20100701134217.GM13238@deviant.kiev.zoral.com.ua> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="w9Xseu/t+w8u+RRD" Content-Disposition: inline User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-2.3 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_50, DNS_FROM_OPENWHOIS autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: Subject: Access to siginfo for the signal from debugger X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Jul 2010 13:42:22 -0000 --w9Xseu/t+w8u+RRD Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, below is the patch that provides the debugger with access to siginfo of the signal that stopped the debuggee. This allows to see a lot more details for the cause of the process stop. E.g. you can see a fault address if process get SIGSEGV or SIGBUS, you can distinguish between breakpoint-generated SIGTRAP and non-breakpoint, whether the signal was send due to external event etc. The change to struct ptrace_lwpinfo is backward-compatible in the sense that programs that were compiled with old definition for the struct will work on new kernels. I tested the change on i386 and amd64, both native and ia32 mode. diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/f= reebsd32_misc.c index f0fde2b..1d60ed4 100644 --- a/sys/compat/freebsd32/freebsd32_misc.c +++ b/sys/compat/freebsd32/freebsd32_misc.c @@ -2208,7 +2208,7 @@ freebsd32_thr_suspend(struct thread *td, struct freeb= sd32_thr_suspend_args *uap) } =20 void -siginfo_to_siginfo32(siginfo_t *src, struct siginfo32 *dst) +siginfo_to_siginfo32(const siginfo_t *src, struct siginfo32 *dst) { bzero(dst, sizeof(*dst)); dst->si_signo =3D src->si_signo; diff --git a/sys/compat/freebsd32/freebsd32_signal.h b/sys/compat/freebsd32= /freebsd32_signal.h index ba0922a..2669581 100644 --- a/sys/compat/freebsd32/freebsd32_signal.h +++ b/sys/compat/freebsd32/freebsd32_signal.h @@ -96,6 +96,6 @@ struct sigevent32 { } _sigev_un; }; =20 -void siginfo_to_siginfo32(siginfo_t *src, struct siginfo32 *dst); +void siginfo_to_siginfo32(const siginfo_t *src, struct siginfo32 *dst); =20 #endif /* !_COMPAT_FREEBSD32_SIGNAL_H_ */ diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index 04c2ba7..af3c7da 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -2522,7 +2522,6 @@ issignal(struct thread *td, int stop_allowed) struct sigacts *ps; struct sigqueue *queue; sigset_t sigpending; - ksiginfo_t ksi; int sig, prop, newsig; =20 p =3D td->td_proc; @@ -2565,10 +2564,10 @@ issignal(struct thread *td, int stop_allowed) * be thrown away. */ queue =3D &td->td_sigqueue; - ksi.ksi_signo =3D 0; - if (sigqueue_get(queue, sig, &ksi) =3D=3D 0) { + td->td_dbgksi.ksi_signo =3D 0; + if (sigqueue_get(queue, sig, &td->td_dbgksi) =3D=3D 0) { queue =3D &p->p_sigqueue; - sigqueue_get(queue, sig, &ksi); + sigqueue_get(queue, sig, &td->td_dbgksi); } =20 mtx_unlock(&ps->ps_mtx); @@ -2595,13 +2594,13 @@ issignal(struct thread *td, int stop_allowed) continue; signotify(td); } else { - if (ksi.ksi_signo !=3D 0) { - ksi.ksi_flags |=3D KSI_HEAD; + if (td->td_dbgksi.ksi_signo !=3D 0) { + td->td_dbgksi.ksi_flags |=3D KSI_HEAD; if (sigqueue_add(&td->td_sigqueue, sig, - &ksi) !=3D 0) - ksi.ksi_signo =3D 0; + &td->td_dbgksi) !=3D 0) + td->td_dbgksi.ksi_signo =3D 0; } - if (ksi.ksi_signo =3D=3D 0) + if (td->td_dbgksi.ksi_signo =3D=3D 0) sigqueue_add(&td->td_sigqueue, sig, NULL); } diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c index 40c861b..525c0e2 100644 --- a/sys/kern/sys_process.c +++ b/sys/kern/sys_process.c @@ -64,6 +64,7 @@ __FBSDID("$FreeBSD$"); =20 #ifdef COMPAT_FREEBSD32 #include +#include =20 struct ptrace_io_desc32 { int piod_op; @@ -85,6 +86,15 @@ struct ptrace_vm_entry32 { uint32_t pve_path; }; =20 +struct ptrace_lwpinfo32 { + lwpid_t pl_lwpid; /* LWP described. */ + int pl_event; /* Event that stopped the LWP. */ + int pl_flags; /* LWP flags. */ + sigset_t pl_sigmask; /* LWP signal mask */ + sigset_t pl_siglist; /* LWP pending signal */ + struct siginfo32 pl_siginfo; /* siginfo for signal */ +}; + #endif =20 /* @@ -498,6 +508,19 @@ ptrace_vm_entry32(struct thread *td, struct proc *p, pve32->pve_pathlen =3D pve.pve_pathlen; return (error); } + +static void +ptrace_lwpinfo_to32(const struct ptrace_lwpinfo *pl, + struct ptrace_lwpinfo32 *pl32) +{ + + pl32->pl_lwpid =3D pl->pl_lwpid; + pl32->pl_event =3D pl->pl_event; + pl32->pl_flags =3D pl->pl_flags; + pl32->pl_sigmask =3D pl->pl_sigmask; + pl32->pl_siglist =3D pl->pl_siglist; + siginfo_to_siginfo32(&pl->pl_siginfo, &pl32->pl_siginfo); +} #endif /* COMPAT_FREEBSD32 */ =20 /* @@ -552,6 +575,7 @@ ptrace(struct thread *td, struct ptrace_args *uap) struct fpreg32 fpreg32; struct reg32 reg32; struct ptrace_io_desc32 piod32; + struct ptrace_lwpinfo32 pl32; struct ptrace_vm_entry32 pve32; #endif } r; @@ -662,6 +686,8 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void= *addr, int data) #ifdef COMPAT_FREEBSD32 int wrap32 =3D 0, safe =3D 0; struct ptrace_io_desc32 *piod32 =3D NULL; + struct ptrace_lwpinfo32 *pl32 =3D NULL; + struct ptrace_lwpinfo plr; #endif =20 curp =3D td->td_proc; @@ -1103,15 +1129,44 @@ kern_ptrace(struct thread *td, int req, pid_t pid, = void *addr, int data) break; =20 case PT_LWPINFO: - if (data <=3D 0 || data > sizeof(*pl)) { + if (data <=3D 0 || +#ifdef COMPAT_FREEBSD32 + (!wrap32 && data > sizeof(*pl)) || + (wrap32 && data > sizeof(*pl32))) { +#else + data > sizeof(*pl)) { +#endif error =3D EINVAL; break; } +#ifdef COMPAT_FREEBSD32 + if (wrap32) { + pl =3D &plr; + pl32 =3D addr; + } else +#endif pl =3D addr; pl->pl_lwpid =3D td2->td_tid; - if (td2->td_dbgflags & TDB_XSIG) - pl->pl_event =3D PL_EVENT_SIGNAL; pl->pl_flags =3D 0; + if (td2->td_dbgflags & TDB_XSIG) { + pl->pl_event =3D PL_EVENT_SIGNAL; + if (td2->td_dbgksi.ksi_signo !=3D 0 && +#ifdef COMPAT_FREEBSD32 + ((!wrap32 && data >=3D offsetof(struct ptrace_lwpinfo, + pl_siginfo) + sizeof(pl->pl_siginfo)) || + (wrap32 && data >=3D offsetof(struct ptrace_lwpinfo32, + pl_siginfo) + sizeof(struct siginfo32))) +#else + data >=3D offsetof(struct ptrace_lwpinfo, pl_siginfo) + + sizeof(pl->pl_siginfo) +#endif + ){ + pl->pl_flags |=3D PL_FLAG_SI; + pl->pl_siginfo =3D td2->td_dbgksi.ksi_info; + } + } + if ((pl->pl_flags & PL_FLAG_SI) =3D=3D 0) + bzero(&pl->pl_siginfo, sizeof(pl->pl_siginfo)); if (td2->td_dbgflags & TDB_SCE) pl->pl_flags |=3D PL_FLAG_SCE; else if (td2->td_dbgflags & TDB_SCX) @@ -1120,6 +1175,10 @@ kern_ptrace(struct thread *td, int req, pid_t pid, v= oid *addr, int data) pl->pl_flags |=3D PL_FLAG_EXEC; pl->pl_sigmask =3D td2->td_sigmask; pl->pl_siglist =3D td2->td_siglist; +#ifdef COMPAT_FREEBSD32 + if (wrap32) + ptrace_lwpinfo_to32(pl, pl32); +#endif break; =20 case PT_GETNUMLWPS: diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 3c9a2de..cd00550 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -259,6 +259,7 @@ struct thread { char td_name[MAXCOMLEN + 1]; /* (*) Thread name. */ struct file *td_fpop; /* (k) file referencing cdev under op */ int td_dbgflags; /* (c) Userland debugger flags */ + struct ksiginfo td_dbgksi; /* (c) ksi reflected to debugger. */ int td_ng_outbound; /* (k) Thread entered ng from above. */ struct osd td_osd; /* (k) Object specific data. */ #define td_endzero td_base_pri diff --git a/sys/sys/ptrace.h b/sys/sys/ptrace.h index a6dbe2c..f4b25d4 100644 --- a/sys/sys/ptrace.h +++ b/sys/sys/ptrace.h @@ -33,7 +33,7 @@ #ifndef _SYS_PTRACE_H_ #define _SYS_PTRACE_H_ =20 -#include +#include #include =20 #define PT_TRACE_ME 0 /* child declares it's being traced */ @@ -102,8 +102,10 @@ struct ptrace_lwpinfo { #define PL_FLAG_SCE 0x04 /* syscall enter point */ #define PL_FLAG_SCX 0x08 /* syscall leave point */ #define PL_FLAG_EXEC 0x10 /* exec(2) succeeded */ +#define PL_FLAG_SI 0x20 /* siginfo is valid */ sigset_t pl_sigmask; /* LWP signal mask */ sigset_t pl_siglist; /* LWP pending signal */ + struct __siginfo pl_siginfo; /* siginfo for signal */ }; =20 /* Argument structure for PT_VM_ENTRY. */ --w9Xseu/t+w8u+RRD Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (FreeBSD) iEYEARECAAYFAkwsmzkACgkQC3+MBN1Mb4ilGgCglKAG92I6om1+whCrt1gAY+WZ lC0AnAhdBxREUd2SU0xeOwL3aXWIxuIf =aH25 -----END PGP SIGNATURE----- --w9Xseu/t+w8u+RRD--