From owner-freebsd-threads@FreeBSD.ORG Mon Jun 6 11:07:16 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 D000D106567D for ; Mon, 6 Jun 2011 11:07:16 +0000 (UTC) (envelope-from owner-bugmaster@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id BE3AF8FC24 for ; Mon, 6 Jun 2011 11:07:16 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p56B7GA4037769 for ; Mon, 6 Jun 2011 11:07:16 GMT (envelope-from owner-bugmaster@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p56B7G3D037767 for freebsd-threads@FreeBSD.org; Mon, 6 Jun 2011 11:07:16 GMT (envelope-from owner-bugmaster@FreeBSD.org) Date: Mon, 6 Jun 2011 11:07:16 GMT Message-Id: <201106061107.p56B7G3D037767@freefall.freebsd.org> X-Authentication-Warning: freefall.freebsd.org: gnats set sender to owner-bugmaster@FreeBSD.org using -f From: FreeBSD bugmaster To: freebsd-threads@FreeBSD.org Cc: Subject: Current problem reports assigned to freebsd-threads@FreeBSD.org 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: Mon, 06 Jun 2011 11:07:16 -0000 Note: to view an individual PR, use: http://www.freebsd.org/cgi/query-pr.cgi?pr=(number). The following is a listing of current problems submitted by FreeBSD users. These represent problem reports covering all versions including experimental development code and obsolete releases. S Tracker Resp. Description -------------------------------------------------------------------------------- o threa/157040 threads [libthr] valgrind detects leaks in libthr.so.3 o threa/154893 threads pthread_sigmask don't work if mask and oldmask are pas o threa/150959 threads [libc] Stub pthread_once in libc should call _libc_onc o threa/149366 threads pthread_cleanup_pop never runs the configured routine o threa/148515 threads Memory / syslog strangeness in FreeBSD 8.x ( possible o threa/141721 threads rtprio(1): (id|rt)prio priority resets when new thread o threa/136345 threads Recursive read rwlocks in thread A cause deadlock with o threa/135673 threads databases/mysql50-server - MySQL query lock-ups on 7.2 o threa/128922 threads threads hang with xorg running o threa/127225 threads bug in lib/libthr/thread/thr_init.c o threa/122923 threads 'nice' does not prevent background process from steali o threa/121336 threads lang/neko threading ok on UP, broken on SMP (FreeBSD 7 o threa/116668 threads can no longer use jdk15 with libthr on -stable SMP o threa/115211 threads pthread_atfork misbehaves in initial thread o threa/110636 threads [request] gdb(1): using gdb with multi thread applicat o threa/110306 threads apache 2.0 segmentation violation when calling gethost o threa/103975 threads Implicit loading/unloading of libpthread.so may crash o threa/101323 threads [patch] fork(2) in threaded programs broken. s threa/84483 threads problems with devel/nspr and -lc_r on 4.x o threa/80992 threads abort() sometimes not caught by gdb depending on threa o threa/79683 threads svctcp_create() fails if multiple threads call at the s threa/76694 threads fork cause hang in dup()/close() function in child (-l s threa/76690 threads fork hang in child for -lc_r s threa/69020 threads pthreads library leaks _gc_mutex s threa/48856 threads Setting SIGCHLD to SIG_IGN still leaves zombies under s threa/40671 threads pthread_cancel doesn't remove thread from condition qu s threa/34536 threads accept() blocks other threads s threa/30464 threads [patch] pthread mutex attributes -- pshared 28 problems total. From owner-freebsd-threads@FreeBSD.ORG Sat Jun 11 04:50:09 2011 Return-Path: Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9E7D3106566B for ; Sat, 11 Jun 2011 04:50:09 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 7A0128FC14 for ; Sat, 11 Jun 2011 04:50:09 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p5B4o9Eb039807 for ; Sat, 11 Jun 2011 04:50:09 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p5B4o9UF039806; Sat, 11 Jun 2011 04:50:09 GMT (envelope-from gnats) Resent-Date: Sat, 11 Jun 2011 04:50:09 GMT Resent-Message-Id: <201106110450.p5B4o9UF039806@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-threads@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, KUROSAWA Takahiro Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7066F106566B for ; Sat, 11 Jun 2011 04:43:26 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id 5EE088FC0A for ; Sat, 11 Jun 2011 04:43:26 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p5B4hQcc011458 for ; Sat, 11 Jun 2011 04:43:26 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.4/8.14.4/Submit) id p5B4hQ9M011452; Sat, 11 Jun 2011 04:43:26 GMT (envelope-from nobody) Message-Id: <201106110443.p5B4hQ9M011452@red.freebsd.org> Date: Sat, 11 Jun 2011 04:43:26 GMT From: KUROSAWA Takahiro To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: threads/157755: gdb hardware watchpoints do not work correctly in multi-threaded programs 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: Sat, 11 Jun 2011 04:50:09 -0000 >Number: 157755 >Category: threads >Synopsis: gdb hardware watchpoints do not work correctly in multi-threaded programs >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-threads >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Jun 11 04:50:09 UTC 2011 >Closed-Date: >Last-Modified: >Originator: KUROSAWA Takahiro >Release: 9-CURRENT >Organization: >Environment: FreeBSD amdk6 9.0-CURRENT FreeBSD 9.0-CURRENT #4: Fri Jun 3 19:18:20 JST 2011 kurosawa@amdk6:/usr/obj/.world/src/sys/AMDK7 i386 >Description: Hardware watchpoints are implemented on gdb in FreeBSD/i386 and FreeBSD/amd64 by setting debug registers with ptrace(PT_SETDBREGS). But watchpoints are effective only for one thread in the multi-threaded program because debug registers are only set per process. >How-To-Repeat: We can reproduce the problem by the following procedure: % cat watch.c #include #include #include #include static int watchpoint; void * thr_main(void *arg) { watchpoint = 2; return NULL; } int main(void) { pthread_t pt; int ret = 0; if ((ret = pthread_create(&pt, NULL, thr_main, NULL)) != 0) errx(1, "pthread_create: %s.\n", strerror(ret)); ret = 2; pthread_join(pt, NULL); watchpoint = 1; ret = 1; return 0; } % cc -pthread -g watch.c % gdb a.out GNU gdb 6.1.1 [FreeBSD] Copyright 2004 Free Software Foundation, Inc. .... # "break thr_main" sets a breakpoint at "watchpoint = 2" (gdb) x/i thr_main 0x8048540 : push %ebp (gdb) break *0x8048540 Breakpoint 1 at 0x8048540: file watch.c, line 10. (gdb) run Starting program: /home/kurosawa/a.out [New LWP 100260] [New Thread 28404300 (LWP 100260/initial thread)] [New Thread 28404900 (LWP 100693/a.out)] [Switching to Thread 28404900 (LWP 100693/a.out)] Breakpoint 1, thr_main (arg=0x0) at watch.c:10 10 { # set an watchpoint to the "watchpoint" variable (gdb) watch watchpoint Hardware watchpoint 2: watchpoint # watchpoint hit in thr_main (gdb) c Continuing. Hardware watchpoint 2: watchpoint Old value = 0 New value = 2 thr_main (arg=0x0) at watch.c:13 13 return NULL; (gdb) c Continuing. [Thread 28404900 (LWP 100693/a.out) exited] [New Thread 28404900 (LWP 100693/a.out)] Program exited normally. # watchpoint must be hit also in main, but program runs without stopping. >Fix: The attached patch fixes the problem. ---- (gdb) x/i thr_main 0x8048540 : push %ebp (gdb) break *0x8048540 Breakpoint 1 at 0x8048540: file watch.c, line 10. (gdb) run Starting program: /home/kurosawa/a.out [New LWP 100163] [New Thread 28404300 (LWP 100163/initial thread)] [New Thread 28404900 (LWP 100694/a.out)] [Switching to Thread 28404900 (LWP 100694/a.out)] Breakpoint 1, thr_main (arg=0x0) at watch.c:10 10 { (gdb) watch watchpoint Hardware watchpoint 2: watchpoint (gdb) c Continuing. Hardware watchpoint 2: watchpoint Old value = 0 New value = 2 thr_main (arg=0x0) at watch.c:13 13 return NULL; (gdb) c Continuing. [Thread 28404900 (LWP 100694/a.out) exited] [New Thread 28404900 (LWP 100694/a.out)] [Switching to Thread 28404300 (LWP 100163/initial thread)] Hardware watchpoint 2: watchpoint Old value = 2 New value = 1 main () at watch.c:28 28 ret = 1; (gdb) c Continuing. Program exited normally. ---- The patch only fixes FreeBSD/i386 but the same approach could be used for FreeBSD/amd64. Patch attached with submission follows: # HG changeset patch # Parent d95f240e861430967a2cd1ee93e8c1b0d5a3b6ef diff -r d95f240e8614 gnu/usr.bin/gdb/arch/i386/Makefile --- a/gnu/usr.bin/gdb/arch/i386/Makefile Fri Jun 03 15:58:48 2011 +0900 +++ b/gnu/usr.bin/gdb/arch/i386/Makefile Sat Jun 11 12:50:52 2011 +0900 @@ -9,7 +9,26 @@ LIBSRCS+= solib.c solib-svr4.c LIBSRCS+= i386-tdep.c i386bsd-tdep.c i386fbsd-tdep-fixed.c i387-tdep.c nm.h: - echo '#include "i386/nm-fbsd.h"' > ${.TARGET} + echo '#ifndef GENSRCS_NM_H' > ${.TARGET} + echo '#define GENSRCS_NM_H' >> ${.TARGET} + echo '#include "i386/nm-fbsd.h"' >> ${.TARGET} + echo '#undef I386_DR_LOW_SET_CONTROL' >> ${.TARGET} + echo '#undef I386_DR_LOW_SET_ADDR' >> ${.TARGET} + echo '#undef I386_DR_LOW_RESET_ADDR' >> ${.TARGET} + echo '#undef I386_DR_LOW_GET_STATUS' >> ${.TARGET} + echo '#define I386_DR_LOW_SET_CONTROL(c) \' >> ${.TARGET} + echo ' fbsd_thread_dr_set_control (c)' >> ${.TARGET} + echo 'void i386bsd_dr_set_control (unsigned long);' >> ${.TARGET} + echo '#define I386_DR_LOW_SET_ADDR(r, v) \' >> ${.TARGET} + echo ' fbsd_thread_dr_set_addr (r, v)' >> ${.TARGET} + echo 'void fbsd_thread_dr_set_addr (int, CORE_ADDR);' >> ${.TARGET} + echo '#define I386_DR_LOW_RESET_ADDR(r) \' >> ${.TARGET} + echo ' fbsd_thread_dr_reset_addr (r)' >> ${.TARGET} + echo 'void fbsd_thread_dr_reset_addr (int);' >> ${.TARGET} + echo '#define I386_DR_LOW_GET_STATUS() \' >> ${.TARGET} + echo ' fbsd_thread_dr_get_status ()' >> ${.TARGET} + echo 'unsigned long fbsd_thread_dr_get_status (void);' >> ${.TARGET} + echo '#endif /* GENSRCS_NM_H */' >> ${.TARGET} tm.h: echo '#include "i386/tm-fbsd.h"' > ${.TARGET} diff -r d95f240e8614 gnu/usr.bin/gdb/libgdb/fbsd-threads.c --- a/gnu/usr.bin/gdb/libgdb/fbsd-threads.c Fri Jun 03 15:58:48 2011 +0900 +++ b/gnu/usr.bin/gdb/libgdb/fbsd-threads.c Sat Jun 11 12:50:52 2011 +0900 @@ -1797,3 +1797,183 @@ ps_linfo(struct ps_prochandle *ph, lwpid return PS_ERR; return PS_OK; } + + +#if defined(HAVE_PT_GETDBREGS) && defined(I386_DR_LOW_SET_ADDR) +/* Hardware watchpoint support based on i386bsd-nat.c: */ +/* Native-dependent code for modern i386 BSD's. + Copyright 2000, 2001, 2002, 2003 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +/* + * We need to add threads support because debug registers need to be + * set per LWP to implement hardware watchpoints. + * + * We do not need to care user-level threads contexts for debug registers + * since they are not in mcontext. + */ + +/* Not all versions of FreeBSD/i386 that support the debug registers + have this macro. */ +#ifndef DBREG_DRX +#define DBREG_DRX(d, x) ((&d->dr0)[x]) +#endif + +static void +fbsd_lwp_dr_set (lwpid_t lwpid, int regnum, unsigned long value) +{ + struct dbreg dbregs; + + if (ptrace (PT_GETDBREGS, lwpid, + (PTRACE_ARG3_TYPE) &dbregs, 0) == -1) + perror_with_name ("Couldn't get debug registers"); + + /* For some mysterious reason, some of the reserved bits in the + debug control register get set. Mask these off, otherwise the + ptrace call below will fail. */ + DBREG_DRX ((&dbregs), 7) &= ~(0x0000fc00); + + DBREG_DRX ((&dbregs), regnum) = value; + + if (ptrace (PT_SETDBREGS, lwpid, + (PTRACE_ARG3_TYPE) &dbregs, 0) == -1) + perror_with_name ("Couldn't write debug registers"); +} + +struct dr_set_thr_arg { + int regnum; + unsigned long value; +}; + +static int +fbsd_thread_dr_set_callback (const td_thrhandle_t *th_p, void *data) +{ + struct dr_set_thr_arg *arg = data; + td_thrinfo_t ti; + td_err_e err; + + err = td_thr_get_info_p (th_p, &ti); + if (err != TD_OK) + error ("Cannot get thread info: %s", thread_db_err_str (err)); + + /* Ignore zombie */ + if (ti.ti_state == TD_THR_UNKNOWN || ti.ti_state == TD_THR_ZOMBIE) + return 0; + + fbsd_lwp_dr_set (ti.ti_lid, arg->regnum, arg->value); + return 0; +} + +static void +fbsd_thread_dr_set (int regnum, unsigned long value) +{ + struct dr_set_thr_arg arg; + td_err_e err; + + arg.regnum = regnum; + arg.value = value; + + /* Iterating over LWPs is sufficient actually. */ + err = td_ta_thr_iter_p (thread_agent, fbsd_thread_dr_set_callback, &arg, + TD_THR_ANY_STATE, TD_THR_LOWEST_PRIORITY, + TD_SIGNO_MASK, TD_THR_ANY_USER_FLAGS); + if (err != TD_OK) + error ("Cannot set debug registers: %s", thread_db_err_str (err)); +} + +void +fbsd_thread_dr_set_control (unsigned long control) +{ + if (fbsd_thread_active) + fbsd_thread_dr_set (7, control); + else + fbsd_lwp_dr_set (GET_PID (inferior_ptid), 7, control); +} + +void +fbsd_thread_dr_set_addr (int regnum, CORE_ADDR addr) +{ + gdb_assert (regnum >= 0 && regnum <= 4); + + if (fbsd_thread_active) + fbsd_thread_dr_set (regnum, addr); + else + fbsd_lwp_dr_set (GET_PID (inferior_ptid), regnum, addr); +} + +void +fbsd_thread_dr_reset_addr (int regnum) +{ + gdb_assert (regnum >= 0 && regnum <= 4); + + if (fbsd_thread_active) + fbsd_thread_dr_set (regnum, 0); + else + fbsd_lwp_dr_set (GET_PID (inferior_ptid), regnum, 0); +} + +unsigned long +fbsd_thread_dr_get_status (void) +{ + struct dbreg dbregs; + td_thrhandle_t th; + td_thrinfo_t ti; + td_err_e err; + lwpid_t lwpid; + + if (IS_THREAD (inferior_ptid)) + { + err = td_ta_map_id2thr_p (thread_agent, GET_THREAD (inferior_ptid), &th); + if (err != TD_OK) + error ("Cannot find thread %d: Thread ID=%ld, %s", + pid_to_thread_id (inferior_ptid), + GET_THREAD (inferior_ptid), thread_db_err_str (err)); + + err = td_thr_get_info_p (&th, &ti); + if (err != TD_OK) + error ("Cannot get thread info: %s", thread_db_err_str (err)); + + lwpid = ti.ti_lid; + } + else if (IS_LWP (inferior_ptid)) + { + lwpid = GET_LWP (inferior_ptid); + } + else + { + lwpid = GET_PID (inferior_ptid); + } + + /* FIXME: kettenis/2001-03-31: Calling perror_with_name if the + ptrace call fails breaks debugging remote targets. The correct + way to fix this is to add the hardware breakpoint and watchpoint + stuff to the target vector. For now, just return zero if the + ptrace call fails. */ + if (ptrace (PT_GETDBREGS, GET_PID (inferior_ptid), + (PTRACE_ARG3_TYPE) & dbregs, 0) == -1) +#if 0 + perror_with_name ("Couldn't read debug registers"); +#else + return 0; +#endif + + return DBREG_DRX ((&dbregs), 6); +} + +#endif /* PT_GETDBREGS && I386_DR_LOW_SET_ADDR */ >Release-Note: >Audit-Trail: >Unformatted: From owner-freebsd-threads@FreeBSD.ORG Sat Jun 11 06:25:41 2011 Return-Path: Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4C8661065670; Sat, 11 Jun 2011 06:25:41 +0000 (UTC) (envelope-from linimon@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 24D0F8FC14; Sat, 11 Jun 2011 06:25:41 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p5B6Pf6f034827; Sat, 11 Jun 2011 06:25:41 GMT (envelope-from linimon@freefall.freebsd.org) Received: (from linimon@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p5B6Pe7g034823; Sat, 11 Jun 2011 06:25:41 GMT (envelope-from linimon) Date: Sat, 11 Jun 2011 06:25:41 GMT Message-Id: <201106110625.p5B6Pe7g034823@freefall.freebsd.org> To: linimon@FreeBSD.org, freebsd-threads@FreeBSD.org, freebsd-bugs@FreeBSD.org From: linimon@FreeBSD.org Cc: Subject: Re: gnu/157755: [patch] gdb(1) hardware watchpoints do not work correctly in multi-threaded programs 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: Sat, 11 Jun 2011 06:25:41 -0000 Old Synopsis: gdb hardware watchpoints do not work correctly in multi-threaded programs New Synopsis: [patch] gdb(1) hardware watchpoints do not work correctly in multi-threaded programs Responsible-Changed-From-To: freebsd-threads->freebsd-bugs Responsible-Changed-By: linimon Responsible-Changed-When: Sat Jun 11 06:24:41 UTC 2011 Responsible-Changed-Why: Reclassify. http://www.freebsd.org/cgi/query-pr.cgi?pr=157755