From owner-freebsd-threads@FreeBSD.ORG Sun Oct 5 03:44:56 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 2A4F21065688; Sun, 5 Oct 2008 03:44:56 +0000 (UTC) (envelope-from dixit@netapp.com) Received: from mx2.netapp.com (mx2.netapp.com [216.240.18.37]) by mx1.freebsd.org (Postfix) with ESMTP id 130A98FC0A; Sun, 5 Oct 2008 03:44:55 +0000 (UTC) (envelope-from dixit@netapp.com) X-IronPort-AV: E=Sophos;i="4.33,362,1220252400"; d="scan'208";a="67197082" Received: from smtp1.corp.netapp.com ([10.57.156.124]) by mx2-out.netapp.com with ESMTP; 04 Oct 2008 20:44:55 -0700 Received: from dixit-lxp.nane.netapp.com ([10.30.32.59]) by smtp1.corp.netapp.com (8.13.1/8.13.1/NTAP-1.6) with ESMTP id m953isgZ001777; Sat, 4 Oct 2008 20:44:55 -0700 (PDT) Message-ID: <48E83836.6090305@netapp.com> Date: Sat, 04 Oct 2008 23:44:54 -0400 From: Amol Dixit User-Agent: Thunderbird 2.0.0.17 (X11/20080914) MIME-Version: 1.0 To: David Xu References: <48DAABAF.9030709@netapp.com> <48DB0950.3060405@freebsd.org> In-Reply-To: <48DB0950.3060405@freebsd.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-threads@freebsd.org 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: Sun, 05 Oct 2008 03:44:56 -0000 David, I tried your patch, but it doesn't seem to fix the problem because even though _pthread_create() calls thr_new(), this system call is never made for the first thread created. Breakpoint set in kernel code of thr_new is hit only for the initial_thread (_libpthread_init())...skips the first thread...and then is hit again for 2nd thread onwards. This patch may be necessary, but it doesn't fix my issue of SIGTRAP on thread_start(). Any clue why the first thread created using pthread_create() doesn't enter thr_new() syscall inside the kernel at all? I get the same SIGTRAP if I single-step through this thr_new() line in _pthread_create() using _local_ gdb. I am running freebsd6.0 configured for SYSTEM_SCOPE threading (1:1). Thanks, Amol David Xu wrote: > Amol Dixit wrote: >> Hi, >> I am seeing an unexpected SIGTRAP being reported to gdbserver when >> the debugged process creates a new thread via the _pthread_create() >> call of libthr library. [libthr/thread/thr_create.c,v 1.22.4.1, >> Freebsd 6.0] >> Gdbserver has internally set a breakpoint on address of >> _thread_bp_create() so that it gets notified on thread creation and >> is expecting a SIGTRAP at address (stop pc) of _thread_bp_create(). >> But instead SIGTRAP happens as a side-effect of thr_new() system call >> and the stop pc at that point is that of routine thread_start() which >> is the starting function of new thread. So gdbserver cannot match >> expected breakpoint (ie. _thread_bp_create) and is confused. >> For testing purpose, if I call _thread_bp_create() before thr_new() >> in _pthread_create(), I get the _expected_ SIGTRAP with address of >> _thread_bp_create. But that is not the fix. >> Does anyone have any idea about this SIGTRAP being reported to >> tracing process gdbserver as part of thr_new? Where is it originating >> from and why? >> Thanks, >> Amol >> > > I found kernel clears trap flag for new process but not for new thread > in cpu_fork(), you may try following patch: > > Index: i386/i386/vm_machdep.c > =================================================================== > --- 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)); > > /* > + * 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 &= ~PSL_T; > + > + /* > * Set registers for trampoline to user mode. Leave space for the > * return address on stack. These are the kernel mode register > values. > */