ptrace and threads (libthr)

John Schumacher schumjs at gmail.com
Fri Jun 17 01:53:41 UTC 2011


Does anybody know if FreeBSD allow for ptracing to be done on threads ex.
PT_ATTACH, or PT_SUSPEND?
I recall this being impossible before,
http://lists.freebsd.org/pipermail/freebsd-threads/2004-January/001511.html
but maybe this has changed now. Is there a viable alternative to getting
around this?

  if (ptrace (PT_ATTACH, ikipp->ki_tid, 0, 0) != 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) != 0)
 {
      fprintf (stderr, "Cannot attach to lwp %ld: %s (%d)\n",tid,strerror
(errno), errno);
      fflush (stderr);
 }

both yield:
Cannot suspend lwp 100167: Device busy (16)
Cannot attach to lwp 100167: Device busy (16)

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 the
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.


Thanks !

-- 
John Schumacher
University of Minnesota (TC)
Electrical Engineering


More information about the freebsd-threads mailing list