From owner-freebsd-threads@FreeBSD.ORG Fri Jun 17 21:10:18 2011 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 44F56106564A for ; Fri, 17 Jun 2011 21:10:18 +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 D7A378FC08 for ; Fri, 17 Jun 2011 21:10:17 +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 p5HKhgMP095932 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 17 Jun 2011 23:43:42 +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 p5HKhgrc006889; Fri, 17 Jun 2011 23:43:42 +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 p5HKhfj2006887; Fri, 17 Jun 2011 23:43:41 +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: Fri, 17 Jun 2011 23:43:41 +0300 From: Kostik Belousov To: John Schumacher Message-ID: <20110617204341.GV48734@deviant.kiev.zoral.com.ua> References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="pdzG5fwa2AGbKqcK" Content-Disposition: inline In-Reply-To: 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=-3.3 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00, 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: freebsd-threads@freebsd.org Subject: Re: ptrace and threads (libthr) X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Jun 2011 21:10:18 -0000 --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--