From owner-freebsd-threads@FreeBSD.ORG Thu Sep 25 09:03:29 2008 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 76E861065698; Thu, 25 Sep 2008 09:03:29 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.terabit.net.ua (mail.terabit.net.ua [195.137.202.147]) by mx1.freebsd.org (Postfix) with ESMTP id 1BF8A8FC25; Thu, 25 Sep 2008 09:03:29 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from skuns.zoral.com.ua ([91.193.166.194] helo=mail.zoral.com.ua) by mail.terabit.net.ua with esmtp (Exim 4.63 (FreeBSD)) (envelope-from ) id 1Kimkv-0007ia-T9; Thu, 25 Sep 2008 12:03:25 +0300 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 m8P93IWS046462 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 25 Sep 2008 12:03:18 +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.2/8.14.2) with ESMTP id m8P93ISe082511; Thu, 25 Sep 2008 12:03:18 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.3/8.14.3/Submit) id m8P93Ipv082510; Thu, 25 Sep 2008 12:03:18 +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, 25 Sep 2008 12:03:18 +0300 From: Kostik Belousov To: David Xu Message-ID: <20080925090318.GK47828@deviant.kiev.zoral.com.ua> References: <48DAABAF.9030709@netapp.com> <48DB0950.3060405@freebsd.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="TXy4g9tqilp80iv6" Content-Disposition: inline In-Reply-To: <48DB0950.3060405@freebsd.org> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: ClamAV version 0.93.3, clamav-milter version 0.93.3 on skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua X-Virus-Scanned: mail.terabit.net.ua 1Kimkv-0007ia-T9 c32cfc9690d7367b0bf7b45060e18447 X-Terabit: YES Cc: freebsd-threads@freebsd.org, Amol Dixit Subject: Re: SIGTRAP during thr_new syscall 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: Thu, 25 Sep 2008 09:03:29 -0000 --TXy4g9tqilp80iv6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Sep 25, 2008 at 11:45:20AM +0800, David Xu wrote: > Amol Dixit wrote: > >Hi, > >I am seeing an unexpected SIGTRAP being reported to gdbserver when the= =20 > >debugged process creates a new thread via the _pthread_create() call of= =20 > >libthr library. [libthr/thread/thr_create.c,v 1.22.4.1, Freebsd 6.0] > >Gdbserver has internally set a breakpoint on address of=20 > >_thread_bp_create() so that it gets notified on thread creation and is= =20 > >expecting a SIGTRAP at address (stop pc) of _thread_bp_create(). But=20 > >instead SIGTRAP happens as a side-effect of thr_new() system call and=20 > >the stop pc at that point is that of routine thread_start() which is the= =20 > >starting function of new thread. So gdbserver cannot match expected=20 > >breakpoint (ie. _thread_bp_create) and is confused. > >For testing purpose, if I call _thread_bp_create() before thr_new() in= =20 > >_pthread_create(), I get the _expected_ SIGTRAP with address of=20 > >_thread_bp_create. But that is not the fix. > >Does anyone have any idea about this SIGTRAP being reported to tracing= =20 > >process gdbserver as part of thr_new? Where is it originating from and w= hy? > >Thanks, > >Amol > > >=20 > I found kernel clears trap flag for new process but not for new thread > in cpu_fork(), you may try following patch: >=20 > Index: i386/i386/vm_machdep.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- i386/i386/vm_machdep.c (revision 183337) > +++ i386/i386/vm_machdep.c (working copy) > @@ -413,6 +413,15 @@ > bcopy(td0->td_frame, td->td_frame, sizeof(struct trapframe)); >=20 > /* > + * If the current thread has the trap bit set (i.e. a debugger had > + * single stepped the process to the system call), we need to clear > + * the trap flag from the new frame. Otherwise, the new thread will > + * receive a (likely unexpected) SIGTRAP when it executes the first > + * instruction after returning to userland. > + */ > + td->td_frame->tf_eflags &=3D ~PSL_T; > + > + /* > * Set registers for trampoline to user mode. Leave space for the > * return address on stack. These are the kernel mode register=20 > values. > */ Should this be done for amd64 version of the cpu_set_upcall() as well ? --TXy4g9tqilp80iv6 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (FreeBSD) iEYEARECAAYFAkjbU9UACgkQC3+MBN1Mb4i9WwCgnoViT90RmMZWfWDut0g7TIMN 3BoAn2HgBS5mBYiy4GdDcFKVxUZP1HAd =zxDa -----END PGP SIGNATURE----- --TXy4g9tqilp80iv6--