Date: Fri, 17 Jun 2011 23:43:41 +0300 From: Kostik Belousov <kostikbel@gmail.com> To: John Schumacher <schumjs@gmail.com> Cc: freebsd-threads@freebsd.org Subject: Re: ptrace and threads (libthr) Message-ID: <20110617204341.GV48734@deviant.kiev.zoral.com.ua> In-Reply-To: <BANLkTik73ryAGhdRqgFOepRkrgobnzUaQQ@mail.gmail.com> References: <BANLkTik73ryAGhdRqgFOepRkrgobnzUaQQ@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--pdzG5fwa2AGbKqcK Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jun 16, 2011 at 08:30:19PM -0500, John Schumacher wrote: > Does anybody know if FreeBSD allow for ptracing to be done on threads ex. > PT_ATTACH, or PT_SUSPEND? Yes, there are people who know. Then answer is contained in the file sys/kern/sys_process.c. > I recall this being impossible before, > http://lists.freebsd.org/pipermail/freebsd-threads/2004-January/001511.ht= ml > but maybe this has changed now. Is there a viable alternative to getting > around this? >=20 > if (ptrace (PT_ATTACH, ikipp->ki_tid, 0, 0) !=3D 0) > { > fprintf (stderr, "Cannot attach to lwp %ld: %s (%d)\n", tid,strerror > (errno), errno); > fflush (stderr); > } > if (ptrace (PT_SUSPEND, ikipp->ki_tid, 0, 0) !=3D 0) > { > fprintf (stderr, "Cannot attach to lwp %ld: %s (%d)\n",tid,strerror > (errno), errno); > fflush (stderr); > } >=20 > both yield: > Cannot suspend lwp 100167: Device busy (16) > Cannot attach to lwp 100167: Device busy (16) >=20 > In my understanding how ptrace works, the thread or process to be traced > must be 'stopped'. Is there a way to pause threads to allow an attach to > occur(SIGSTOP)? Is thread the correct term in this case? Or is anything t= he > kernel can manipulate via signals and pt_methods technically a > light-weight-process or kernel thread 'mapped' to that user-thread > (pthread)? This is FreeBSD 8.1 with the libthr library. The ptrace(2) requires the debugger to be attached to debuggee. The attachment can only happen at the process level, you cannot attach to thread. After the attachment is done, operations like PT_SUSPEND, PT_CONTINUE, PT_STEP etc operate on the lwps, and not on the process. This is somewhat obscured by two issues. First is the mention of the "pid" in the man page. In fact, pid may be process identifier, in which case the kernel will select some random thread in the target process, or it may be an lwp id, in the later case the exact lwp is acted upon. The namespace of the pid and lwpid do not cross. You can obtain the list of the debugee lwps with PT_GETLWPLIST. Second issue is that for the singlethreaded process, the only random thread the kernel can select is the only process thread. So the man page needs an update to be exact on the scope of the action, either the process or lwp. Anybody volunteer to do this ? >=20 >=20 > Thanks ! >=20 > --=20 > John Schumacher > University of Minnesota (TC) > Electrical Engineering > _______________________________________________ > freebsd-threads@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-threads > To unsubscribe, send any mail to "freebsd-threads-unsubscribe@freebsd.org" --pdzG5fwa2AGbKqcK Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (FreeBSD) iEYEARECAAYFAk37vH0ACgkQC3+MBN1Mb4hARwCgp4SOxOrkTc/HMSXeSdVbZULb e2YAniRal+gxy18nKgBQHOA04CdEiat8 =6dWP -----END PGP SIGNATURE----- --pdzG5fwa2AGbKqcK--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110617204341.GV48734>