Date: Thu, 25 Sep 2008 12:03:18 +0300 From: Kostik Belousov <kostikbel@gmail.com> To: David Xu <davidxu@freebsd.org> Cc: freebsd-threads@freebsd.org, Amol Dixit <dixit@netapp.com> Subject: Re: SIGTRAP during thr_new syscall Message-ID: <20080925090318.GK47828@deviant.kiev.zoral.com.ua> In-Reply-To: <48DB0950.3060405@freebsd.org> References: <48DAABAF.9030709@netapp.com> <48DB0950.3060405@freebsd.org>
index | next in thread | previous in thread | raw e-mail
[-- Attachment #1 --] 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 > >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. > */ Should this be done for amd64 version of the cpu_set_upcall() as well ? [-- Attachment #2 --] -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (FreeBSD) iEYEARECAAYFAkjbU9UACgkQC3+MBN1Mb4i9WwCgnoViT90RmMZWfWDut0g7TIMN 3BoAn2HgBS5mBYiy4GdDcFKVxUZP1HAd =zxDa -----END PGP SIGNATURE-----help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080925090318.GK47828>
