libpthread_dbg(3) deletion from the base distribution

libpthread_dbg(3) is a remnant library from the M:N thread model
(pre-NetBSD-5.0) API to introspect threads within a process and for use
of debuggers.

Currently in the 1:1 model it's not used in GDB neither in LLDB and it's
not either planned to be used. It's current function to read pthread_t
structures is realizable within a regular debugger capable to
instrospect objects within a tracee (GDB, LLDB...).

Remaining users of this API can still use this library from
pkgsrc/devel/libpthread_dbg.

Sponsored by <The NetBSD Foundation>
This commit is contained in:
kamil 2017-02-08 03:44:40 +00:00
parent 7450df85ed
commit 0892a29a1a
31 changed files with 59 additions and 2444 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: shl.mi,v 1.799 2017/01/31 23:19:20 christos Exp $
# $NetBSD: shl.mi,v 1.800 2017/02/08 03:44:40 kamil Exp $
#
# Note: Don't delete entries from here - mark them as "obsolete" instead,
# unless otherwise stated below.
@ -451,9 +451,9 @@
./usr/lib/libpthread.so base-sys-shlib compatfile
./usr/lib/libpthread.so.1 base-sys-shlib compatfile
./usr/lib/libpthread.so.1.3 base-sys-shlib compatfile
./usr/lib/libpthread_dbg.so base-sys-shlib compatfile
./usr/lib/libpthread_dbg.so.2 base-sys-shlib compatfile
./usr/lib/libpthread_dbg.so.2.0 base-sys-shlib compatfile
./usr/lib/libpthread_dbg.so base-obsolete obsolete
./usr/lib/libpthread_dbg.so.2 base-obsolete obsolete
./usr/lib/libpthread_dbg.so.2.0 base-obsolete obsolete
./usr/lib/libpuffs.so base-puffs-shlib compatfile
./usr/lib/libpuffs.so.2 base-puffs-shlib compatfile
./usr/lib/libpuffs.so.2.0 base-puffs-shlib compatfile

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.2107 2017/02/01 12:33:58 christos Exp $
# $NetBSD: mi,v 1.2108 2017/02/08 03:44:40 kamil Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
./etc/mtree/set.comp comp-sys-root
@ -2620,7 +2620,7 @@
./usr/include/protocols/talkd.h comp-c-include
./usr/include/protocols/timed.h comp-c-include
./usr/include/pthread.h comp-c-include
./usr/include/pthread_dbg.h comp-c-include
./usr/include/pthread_dbg.h comp-obsolete obsolete
./usr/include/pthread_queue.h comp-c-include
./usr/include/pthread_types.h comp-c-include
./usr/include/puffs.h comp-puffs-include
@ -3384,8 +3384,8 @@
./usr/lib/libprop.a comp-c-lib compatfile
./usr/lib/libprop_p.a comp-c-proflib compatfile,profile
./usr/lib/libpthread.a comp-c-lib compatfile
./usr/lib/libpthread_dbg.a comp-c-lib compatfile
./usr/lib/libpthread_dbg_p.a comp-c-proflib compatfile,profile
./usr/lib/libpthread_dbg.a comp-obsolete obsolete
./usr/lib/libpthread_dbg_p.a comp-obsolete obsolete
./usr/lib/libpthread_p.a comp-c-proflib compatfile,profile
./usr/lib/libpuffs.a comp-puffs-lib compatfile
./usr/lib/libpuffs_p.a comp-puffs-proflib compatfile,profile
@ -3749,7 +3749,7 @@
./usr/libdata/lint/llib-lproc.ln comp-c-lintlib lint,dtrace
./usr/libdata/lint/llib-lprop.ln comp-c-lintlib lint
./usr/libdata/lint/llib-lpthread.ln comp-c-lintlib lint
./usr/libdata/lint/llib-lpthread_dbg.ln comp-c-lintlib lint
./usr/libdata/lint/llib-lpthread_dbg.ln comp-obsolete obsolete
./usr/libdata/lint/llib-lpuffs.ln comp-puffs-lintlib lint
./usr/libdata/lint/llib-lquota.ln comp-c-lintlib lint
./usr/libdata/lint/llib-lradius.ln comp-c-lintlib lint
@ -8465,7 +8465,7 @@
./usr/share/man/cat3/pthread_condattr_setpshared.0 comp-c-catman .cat
./usr/share/man/cat3/pthread_create.0 comp-c-catman .cat
./usr/share/man/cat3/pthread_curcpu_np.0 comp-c-catman .cat
./usr/share/man/cat3/pthread_dbg.0 comp-c-catman .cat
./usr/share/man/cat3/pthread_dbg.0 comp-obsolete obsolete
./usr/share/man/cat3/pthread_detach.0 comp-c-catman .cat
./usr/share/man/cat3/pthread_equal.0 comp-c-catman .cat
./usr/share/man/cat3/pthread_exit.0 comp-c-catman .cat
@ -9406,12 +9406,12 @@
./usr/share/man/cat3/tcsendbreak.0 comp-c-catman .cat
./usr/share/man/cat3/tcsetattr.0 comp-c-catman .cat
./usr/share/man/cat3/tcsetpgrp.0 comp-c-catman .cat
./usr/share/man/cat3/td_close.0 comp-c-catman .cat
./usr/share/man/cat3/td_map_pth2thr.0 comp-c-catman .cat
./usr/share/man/cat3/td_open.0 comp-c-catman .cat
./usr/share/man/cat3/td_thr_getname.0 comp-c-catman .cat
./usr/share/man/cat3/td_thr_info.0 comp-c-catman .cat
./usr/share/man/cat3/td_thr_iter.0 comp-c-catman .cat
./usr/share/man/cat3/td_close.0 comp-obsolete obsolete
./usr/share/man/cat3/td_map_pth2thr.0 comp-obsolete obsolete
./usr/share/man/cat3/td_open.0 comp-obsolete obsolete
./usr/share/man/cat3/td_thr_getname.0 comp-obsolete obsolete
./usr/share/man/cat3/td_thr_info.0 comp-obsolete obsolete
./usr/share/man/cat3/td_thr_iter.0 comp-obsolete obsolete
./usr/share/man/cat3/tdelete.0 comp-c-catman .cat
./usr/share/man/cat3/telldir.0 comp-c-catman .cat
./usr/share/man/cat3/tempnam.0 comp-c-catman .cat
@ -15838,7 +15838,7 @@
./usr/share/man/html3/pthread_condattr_setpshared.html comp-c-htmlman html
./usr/share/man/html3/pthread_create.html comp-c-htmlman html
./usr/share/man/html3/pthread_curcpu_np.html comp-c-htmlman html
./usr/share/man/html3/pthread_dbg.html comp-c-htmlman html
./usr/share/man/html3/pthread_dbg.html comp-obsolete obsolete
./usr/share/man/html3/pthread_detach.html comp-c-htmlman html
./usr/share/man/html3/pthread_equal.html comp-c-htmlman html
./usr/share/man/html3/pthread_exit.html comp-c-htmlman html
@ -16743,12 +16743,12 @@
./usr/share/man/html3/tcsendbreak.html comp-c-htmlman html
./usr/share/man/html3/tcsetattr.html comp-c-htmlman html
./usr/share/man/html3/tcsetpgrp.html comp-c-htmlman html
./usr/share/man/html3/td_close.html comp-c-htmlman html
./usr/share/man/html3/td_map_pth2thr.html comp-c-htmlman html
./usr/share/man/html3/td_open.html comp-c-htmlman html
./usr/share/man/html3/td_thr_getname.html comp-c-htmlman html
./usr/share/man/html3/td_thr_info.html comp-c-htmlman html
./usr/share/man/html3/td_thr_iter.html comp-c-htmlman html
./usr/share/man/html3/td_close.html comp-obsolete obsolete
./usr/share/man/html3/td_map_pth2thr.html comp-obsolete obsolete
./usr/share/man/html3/td_open.html comp-obsolete obsolete
./usr/share/man/html3/td_thr_getname.html comp-obsolete obsolete
./usr/share/man/html3/td_thr_info.html comp-obsolete obsolete
./usr/share/man/html3/td_thr_iter.html comp-obsolete obsolete
./usr/share/man/html3/tdelete.html comp-c-htmlman html
./usr/share/man/html3/telldir.html comp-c-htmlman html
./usr/share/man/html3/tempnam.html comp-c-htmlman html
@ -23204,7 +23204,7 @@
./usr/share/man/man3/pthread_condattr_setpshared.3 comp-c-man .man
./usr/share/man/man3/pthread_create.3 comp-c-man .man
./usr/share/man/man3/pthread_curcpu_np.3 comp-c-man .man
./usr/share/man/man3/pthread_dbg.3 comp-c-man .man
./usr/share/man/man3/pthread_dbg.3 comp-obsolete obsolete
./usr/share/man/man3/pthread_detach.3 comp-c-man .man
./usr/share/man/man3/pthread_equal.3 comp-c-man .man
./usr/share/man/man3/pthread_exit.3 comp-c-man .man
@ -24141,12 +24141,12 @@
./usr/share/man/man3/tcsendbreak.3 comp-c-man .man
./usr/share/man/man3/tcsetattr.3 comp-c-man .man
./usr/share/man/man3/tcsetpgrp.3 comp-c-man .man
./usr/share/man/man3/td_close.3 comp-c-man .man
./usr/share/man/man3/td_map_pth2thr.3 comp-c-man .man
./usr/share/man/man3/td_open.3 comp-c-man .man
./usr/share/man/man3/td_thr_getname.3 comp-c-man .man
./usr/share/man/man3/td_thr_info.3 comp-c-man .man
./usr/share/man/man3/td_thr_iter.3 comp-c-man .man
./usr/share/man/man3/td_close.3 comp-obsolete obsolete
./usr/share/man/man3/td_map_pth2thr.3 comp-obsolete obsolete
./usr/share/man/man3/td_open.3 comp-obsolete obsolete
./usr/share/man/man3/td_thr_getname.3 comp-obsolete obsolete
./usr/share/man/man3/td_thr_info.3 comp-obsolete obsolete
./usr/share/man/man3/td_thr_iter.3 comp-obsolete obsolete
./usr/share/man/man3/tdelete.3 comp-c-man .man
./usr/share/man/man3/telldir.3 comp-c-man .man
./usr/share/man/man3/tempnam.3 comp-c-man .man

View File

@ -1,4 +1,4 @@
# $NetBSD: shl.mi,v 1.299 2017/01/05 13:45:51 wiz Exp $
# $NetBSD: shl.mi,v 1.300 2017/02/08 03:44:40 kamil Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@ -133,7 +133,7 @@
./usr/lib/libproc.so.0 comp-c-shlib compatfile,dtrace
./usr/lib/libproc_pic.a comp-c-piclib compatfile,dtrace,picinstall
./usr/lib/libprop_pic.a comp-c-piclib compatfile,picinstall
./usr/lib/libpthread_dbg_pic.a comp-c-piclib compatfile,picinstall
./usr/lib/libpthread_dbg_pic.a comp-obsolete obsolete
./usr/lib/libpthread_pic.a comp-c-piclib compatfile,picinstall
./usr/lib/libpuffs_pic.a comp-puffs-piclib compatfile,picinstall
./usr/lib/libquota_pic.a comp-c-piclib compatfile,picinstall

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.196 2017/02/06 19:45:17 kre Exp $
# $NetBSD: mi,v 1.197 2017/02/08 03:44:41 kamil Exp $
./etc/mtree/set.debug comp-sys-root
./usr/lib comp-sys-usr compatdir
./usr/lib/i18n/libBIG5_g.a comp-c-debuglib debuglib,compatfile
@ -126,7 +126,7 @@
./usr/lib/libproc_g.a comp-c-libdebug debuglib,compatfile,dtrace
./usr/lib/libproc_p.a comp-c-debuglib debuglib,compatfile,dtrace
./usr/lib/libprop_g.a comp-c-debuglib debuglib,compatfile
./usr/lib/libpthread_dbg_g.a comp-c-debuglib debuglib,compatfile
./usr/lib/libpthread_dbg_g.a comp-obsolete obsolete
./usr/lib/libpthread_g.a comp-c-debuglib debuglib,compatfile
./usr/lib/libpuffs_g.a comp-c-debuglib debuglib,compatfile
./usr/lib/libquota_g.a comp-c-debuglib debuglib,compatfile
@ -2197,8 +2197,8 @@
./usr/libdata/debug/usr/tests/lib/libpthread/t_status.debug tests-obsolete obsolete,compattestfile
./usr/libdata/debug/usr/tests/lib/libpthread/t_swapcontext.debug tests-lib-tests debug,atf,compattestfile
./usr/libdata/debug/usr/tests/lib/libpthread/t_timedmutex.debug tests-lib-tests debug,atf,compattestfile
./usr/libdata/debug/usr/tests/lib/libpthread_dbg/t_dummy.debug tests-lib-tests debug,atf,compattestfile
./usr/libdata/debug/usr/tests/lib/libpthread_dbg/t_threads.debug tests-lib-tests debug,atf,compattestfile
./usr/libdata/debug/usr/tests/lib/libpthread_dbg/t_dummy.debug tests-obsolete obsolete
./usr/libdata/debug/usr/tests/lib/libpthread_dbg/t_threads.debug tests-obsolete obsolete
./usr/libdata/debug/usr/tests/lib/librefuse/t_refuse_opt.debug tests-lib-debug debug,atf,compattestfile
./usr/libdata/debug/usr/tests/lib/librt/t_sched.debug tests-lib-debug debug,atf,compattestfile
./usr/libdata/debug/usr/tests/lib/librt/t_sem.debug tests-lib-debug debug,atf,compattestfile

View File

@ -1,4 +1,4 @@
# $NetBSD: shl.mi,v 1.158 2017/01/31 23:19:20 christos Exp $
# $NetBSD: shl.mi,v 1.159 2017/02/08 03:44:41 kamil Exp $
./usr/libdata/debug/lib base-sys-usr debug,dynamicroot,compatdir
./usr/libdata/debug/lib/libblacklist.so.0.0.debug comp-sys-debug debug,dynamicroot
./usr/libdata/debug/lib/libc.so.12.205.debug comp-sys-debug debug,dynamicroot
@ -160,7 +160,7 @@
./usr/libdata/debug/usr/lib/libproc.so.0.0.debug comp-sys-debug debug,dtrace
./usr/libdata/debug/usr/lib/libprop.so.1.1.debug comp-sys-debug debug,compatfile
./usr/libdata/debug/usr/lib/libpthread.so.1.3.debug comp-sys-debug debug,compatfile
./usr/libdata/debug/usr/lib/libpthread_dbg.so.2.0.debug comp-sys-debug debug,compatfile
./usr/libdata/debug/usr/lib/libpthread_dbg.so.2.0.debug comp-obsolete obsolete
./usr/libdata/debug/usr/lib/libpuffs.so.2.0.debug comp-puffs-debug debug,compatfile
./usr/libdata/debug/usr/lib/libquota.so.1.0.debug comp-sys-debug debug,compatfile
./usr/libdata/debug/usr/lib/libradius.so.4.0.debug comp-net-debug debug,compatfile

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.716 2017/02/02 22:07:33 martin Exp $
# $NetBSD: mi,v 1.717 2017/02/08 03:44:41 kamil Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@ -132,7 +132,7 @@
./usr/libdata/debug/usr/tests/lib/libprop tests-lib-debug compattestfile,atf
./usr/libdata/debug/usr/tests/lib/libpthread tests-lib-debug compattestfile,atf
./usr/libdata/debug/usr/tests/lib/libpthread/dlopen tests-lib-debug compattestfile,atf
./usr/libdata/debug/usr/tests/lib/libpthread_dbg tests-lib-debug compattestfile,atf
./usr/libdata/debug/usr/tests/lib/libpthread_dbg tests-obsolete obsolete
./usr/libdata/debug/usr/tests/lib/librefuse tests-lib-debug compattestfile,atf
./usr/libdata/debug/usr/tests/lib/librt tests-lib-debug compattestfile,atf
./usr/libdata/debug/usr/tests/lib/librumpclient tests-lib-debug compattestfile,atf
@ -3049,11 +3049,11 @@
./usr/tests/lib/libpthread/t_status tests-obsolete obsolete
./usr/tests/lib/libpthread/t_swapcontext tests-lib-tests compattestfile,atf
./usr/tests/lib/libpthread/t_timedmutex tests-lib-tests compattestfile,atf
./usr/tests/lib/libpthread_dbg tests-lib-tests compattestfile,atf
./usr/tests/lib/libpthread_dbg/Atffile tests-lib-tests compattestfile,atf
./usr/tests/lib/libpthread_dbg/Kyuafile tests-lib-tests compattestfile,atf,kyua
./usr/tests/lib/libpthread_dbg/t_dummy tests-lib-tests compattestfile,atf
./usr/tests/lib/libpthread_dbg/t_threads tests-lib-tests compattestfile,atf
./usr/tests/lib/libpthread_dbg tests-obsolete obsolete
./usr/tests/lib/libpthread_dbg/Atffile tests-obsolete obsolete
./usr/tests/lib/libpthread_dbg/Kyuafile tests-obsolete obsolete
./usr/tests/lib/libpthread_dbg/t_dummy tests-obsolete obsolete
./usr/tests/lib/libpthread_dbg/t_threads tests-obsolete obsolete
./usr/tests/lib/librefuse tests-lib-tests compattestfile,atf
./usr/tests/lib/librefuse/Atffile tests-lib-tests compattestfile,atf
./usr/tests/lib/librefuse/t_refuse_opt tests-lib-tests compattestfile,atf

View File

@ -1,4 +1,4 @@
$NetBSD: TODO.ptrace,v 1.14 2017/02/07 16:15:05 kamil Exp $
$NetBSD: TODO.ptrace,v 1.15 2017/02/08 03:44:41 kamil Exp $
Items we (currently) plan to finish in the ptrace(2) field:
@ -16,7 +16,6 @@ Items we (currently) plan to finish in the ptrace(2) field:
in all ports
- add proper implementation of PTRACE_VFORK for vfork(2)-like events
- remove exect(3) from libc - there is no usecase for it
- remove pthread_dbg(3) from the base distribution
- research what happens when a tracee masks signals (including SIGTRAP) and a
breakpoint is triggered
- add ATF tests for SIGCHLD

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.248 2016/10/14 17:29:29 macallan Exp $
# $NetBSD: Makefile,v 1.249 2017/02/08 03:44:41 kamil Exp $
# from: @(#)Makefile 5.25.1.1 (Berkeley) 5/7/91
.include <bsd.own.mk>
@ -25,7 +25,7 @@ SUBDIR+= libarch \
libcompat libcrypt \
libintl libipsec libkvm libm \
libossaudio libpci libpmc libposix libprop libpthread \
libpthread_dbg libpuffs libresolv librmt librpcsvc librt \
libpuffs libresolv librmt librpcsvc librt \
libtelnet libterminfo \
libusbhid libutil libwrap liby libz

View File

@ -1,7 +1,4 @@
$NetBSD: README,v 1.6 2009/04/16 18:37:30 wiz Exp $
When making changes to libpthread, please ensure that libpthread_dbg
still compiles.
$NetBSD: README,v 1.7 2017/02/08 03:44:41 kamil Exp $
Due to limitations in the current pthread implementation, makecontext(3)
and sigaltstack(2) should not be used in programs which link against

View File

@ -1,4 +1,4 @@
$NetBSD: TODO,v 1.17 2012/02/03 21:11:17 joerg Exp $
$NetBSD: TODO,v 1.18 2017/02/08 03:44:41 kamil Exp $
Interfaces/features to implement:
@ -10,3 +10,5 @@ Interfaces/features to implement:
- Keep a pool of dead LWPs so that we do not have take the full hit of
_lwp_create() every time pthread_create() is called.
- kill pthread__dbg (pthread_dbg(3) has been removed from base)

View File

@ -1,4 +1,4 @@
.\" $NetBSD: pthread.3,v 1.16 2016/11/24 12:19:28 wiz Exp $
.\" $NetBSD: pthread.3,v 1.17 2017/02/08 03:44:41 kamil Exp $
.\"
.\" Copyright (c) 2003, 2007, 2009 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -157,7 +157,6 @@ for
.Xr sh 1 ) .
.El
.Sh SEE ALSO
.Xr pthread_dbg 3
.Rs
.%A David R. Butenhof
.%T Programming with POSIX(R) Threads

View File

@ -1,4 +1,4 @@
/* $NetBSD: pthread_int.h,v 1.92 2015/05/29 16:05:13 christos Exp $ */
/* $NetBSD: pthread_int.h,v 1.93 2017/02/08 03:44:41 kamil Exp $ */
/*-
* Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@ -29,11 +29,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* NOTE: when changing anything in this file, please ensure that
* libpthread_dbg still compiles.
*/
#ifndef _LIB_PTHREAD_INT_H
#define _LIB_PTHREAD_INT_H

View File

@ -1,58 +0,0 @@
# $NetBSD: Makefile,v 1.16 2016/11/22 03:52:01 kamil Exp $
#
WARNS?= 5
.include <bsd.own.mk>
LIBPDIR= ${.CURDIR}/../libpthread
.if defined(PTHREAD_MACHINE_ARCH) && !empty(PTHREAD_MACHINE_ARCH) && \
exists(${LIBPDIR}/arch/${PTHREAD_MACHINE_ARCH})
ARCHSUBDIR= ${PTHREAD_MACHINE_ARCH}
.elif exists(${LIBPDIR}/arch/${MACHINE_ARCH})
ARCHSUBDIR= ${MACHINE_ARCH}
.elif exists(${LIBPDIR}/arch/${MACHINE_CPU})
ARCHSUBDIR= ${MACHINE_CPU}
.else
.BEGIN:
@echo "no ARCHSUBDIR for ${MACHINE_ARCH}/${MACHINE_CPU}; skipping..."
.endif
.if defined(ARCHSUBDIR)
LIB= pthread_dbg
ARCHDIR= ${LIBPDIR}/arch/${ARCHSUBDIR}
.PATH: ${ARCHDIR}
CPPFLAGS+= -I${ARCHDIR} -I${LIBPDIR} -I${.CURDIR}
assym.h: genassym.sh ${ARCHDIR}/genassym.cf
${TOOL_GENASSYM} -- ${CC} ${CFLAGS:N-Wa,*} ${CPPFLAGS} ${PROF} \
${GENASSYM_CPPFLAGS} < ${ARCHDIR}/genassym.cf > assym.h.tmp && \
mv -f assym.h.tmp assym.h
SRCS= pthread_dbg.c
CPPFLAGS+= -D__LIBPTHREAD_SOURCE__
INCS= pthread_dbg.h
INCSDIR=/usr/include
MAN+= pthread_dbg.3
MAN+= td_open.3
MAN+= td_map_pth2thr.3
MAN+= td_thr_getname.3
MAN+= td_thr_info.3
MAN+= td_thr_iter.3
MLINKS+= td_open.3 td_close.3
.include <bsd.lib.mk>
.else
.include <bsd.man.mk>
.endif

View File

@ -1,148 +0,0 @@
.\" $NetBSD: pthread_dbg.3,v 1.4 2016/11/24 12:18:02 wiz Exp $
.\"
.\"
.\" Copyright (c) 2016 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd November 21, 2016
.Dt PTHREAD_DBG 3
.Os
.Sh NAME
.Nm pthread_dbg
.Nd POSIX Debug Threads Library
.Sh LIBRARY
.Lb libpthread_dbg
.Sh SYNOPSIS
.In pthread_dbg.h
.Pp
.Nm cc
.Op Ar flags
.Ar files
.Fl lpthread_dbg
.Op Ar libraries
.Sh DESCRIPTION
The
.Nm
library provides an implementation of the standard
.Tn POSIX
threads library debugging facilities.
.Pp
The
.Nx
implementation is based on 1:1 thread model, therefore each
.Xr pthread 3
has a kernel thread, called a light-weight process (LWP).
.Pp
Note that the system private thread interfaces upon which the
.Xr pthread 3
library is built are subject to change without notice.
In order to remain compatible with future
.Nx
releases, programs must be linked against the dynamic version of the
thread library.
Statically linked programs using the
.Tn POSIX
threads framework may not work when run on a future version of the system.
.Pp
The
.Nm
library is designed to be used in debuggers and to control and introspect the
.Nx
implementation of the
.Tn POSIX
threads.
Software may use native
.Tn LWP
threads without
.Xr pthread 3
layer,
in that case
.Nm
cannot be used.
.Ss Error codes
The following error codes are defined in
.Nm
functions:
.Pp
.Bl -column ".Sy TD_ERR_BADTHREAD" "Request is not meaningful for that thread" -compact
.\".It Sy "Symbol" Ta Sy "Descriptive name"
.It Dv TD_ERR_OK Ta "Success"
.It Dv TD_ERR_ERR Ta "Generic error"
.It Dv TD_ERR_NOSYM Ta "Symbol not found (proc_lookup)"
.It Dv TD_ERR_NOOBJ Ta "No object matched the request"
.It Dv TD_ERR_BADTHREAD Ta "Request is not meaningful for that thread"
.It Dv TD_ERR_INUSE Ta "The process is already being debugged"
.It Dv TD_ERR_NOLIB Ta "The process is not using libpthread"
.It Dv TD_ERR_NOMEM Ta "Memory allocation failed"
.It Dv TD_ERR_IO Ta "A callback failed to read or write"
.It Dv TD_ERR_INVAL Ta "Invalid parameter"
.El
.Sh FUNCTIONS
The following functions comprise the core of the
.Nm
library:
.Bl -column -offset indent "td_thr_getname(3)" "convert the pthread_t to a thread handle"
.It Sy Function Ta Sy Description
.It Xr td_close 3 Ta close connection to a threaded process
.It Xr td_map_pth2thr 3 Ta convert a pthread_t to a thread handle
.It Xr td_open 3 Ta make connection to a threaded process
.It Xr td_thr_getname 3 Ta get the user-assigned name of a thread
.It Xr td_thr_info 3 Ta get information on a thread
.It Xr td_thr_iter 3 Ta iterate over the threads in the process
.El
.Sh SEE ALSO
.Xr pthread 3
.Sh STANDARDS
The
.Nm
library is a
.Nx
extension.
.Sh HISTORY
The
.Nm
library first appeared in
.Nx 2.0
along with the Scheduler Activation thread interface.
This interface was authored by
.An Nathan J. Williams
and merged by
.An Jason R. Thorpe .
In
.Nx 5.0
the
.Nm
library was moved to the new 1:1 thread model.
.Sh AUTHORS
.An -nosplit
.An Nathan J. Williams Aq Mt nathanw@NetBSD.org
.Pp
This manual page was written by
.An Kamil Rytarowski Aq Mt kamil@NetBSD.org .
.Sh BUGS
It is not possible to debug the
.Nx
library with a debugger that is using
.Nm
internally.

View File

@ -1,520 +0,0 @@
/* $NetBSD: pthread_dbg.c,v 1.51 2016/11/22 04:51:06 kamil Exp $ */
/*-
* Copyright (c) 2002 Wasabi Systems, Inc.
* All rights reserved.
*
* Written by Nathan J. Williams for Wasabi Systems, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed for the NetBSD Project by
* Wasabi Systems, Inc.
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
* or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pthread_dbg.c,v 1.51 2016/11/22 04:51:06 kamil Exp $");
#define __EXPOSE_STACK 1
#include <sys/param.h>
#include <sys/types.h>
#include <sys/lock.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <lwp.h>
#include <machine/reg.h>
#include <pthread.h>
#include <pthread_int.h>
#include <pthread_dbg.h>
#include <pthread_dbg_int.h>
#define PT_STACKMASK (proc->stackmask)
#define OFFSET(thread, field) \
(((char *)(thread)->addr) + offsetof(struct __pthread_st, field))
/* Compensate for debuggers that want a zero ID to be a sentinel */
#define TN_OFFSET 1
static int td__getthread(td_proc_t *proc, caddr_t addr, td_thread_t **threadp);
int
td_open(struct td_proc_callbacks_t *cb, void *arg, td_proc_t **procp)
{
td_proc_t *proc;
caddr_t addr;
int dbg;
int val;
proc = malloc(sizeof(*proc));
if (proc == NULL)
return TD_ERR_NOMEM;
proc->cb = cb;
proc->arg = arg;
val = LOOKUP(proc, "pthread__dbg", &addr);
if (val != 0) {
if (val == TD_ERR_NOSYM)
val = TD_ERR_NOLIB;
goto error;
}
proc->dbgaddr = addr;
val = LOOKUP(proc, "pthread__allqueue", &addr);
if (val != 0)
goto error;
proc->allqaddr = addr;
val = LOOKUP(proc, "pthread__tsd_list", &addr);
if (val != 0)
goto error;
proc->tsdlistaddr = addr;
val = LOOKUP(proc, "pthread__tsd_destructors", &addr);
if (val != 0)
goto error;
proc->tsddestaddr = addr;
val = READ(proc, proc->dbgaddr, &dbg, sizeof(int));
if (val != 0)
goto error;
if (dbg != 0) {
/* Another instance of libpthread_dbg is already attached. */
val = TD_ERR_INUSE;
goto error;
}
val = LOOKUP(proc, "pthread__stacksize_lg", &addr);
if (val == 0)
proc->stacksizeaddr = addr;
else
proc->stacksizeaddr = NULL;
proc->stacksizelg = -1;
proc->stacksize = 0;
proc->stackmask = 0;
proc->regbuf = NULL;
proc->fpregbuf = NULL;
dbg = getpid();
/*
* If this fails it probably means we're debugging a core file and
* can't write to it.
* If it's something else we'll lose the next time we hit WRITE,
* but not before, and that's OK.
*/
WRITE(proc, proc->dbgaddr, &dbg, sizeof(int));
PTQ_INIT(&proc->threads);
*procp = proc;
return 0;
error:
free(proc);
return val;
}
int
td_close(td_proc_t *proc)
{
int dbg;
td_thread_t *t, *next;
dbg = 0;
/*
* Error returns from this write are mot really a problem;
* the process doesn't exist any more.
*/
WRITE(proc, proc->dbgaddr, &dbg, sizeof(int));
/* Deallocate the list of thread structures */
for (t = PTQ_FIRST(&proc->threads); t; t = next) {
next = PTQ_NEXT(t, list);
PTQ_REMOVE(&proc->threads, t, list);
free(t);
}
if (proc->regbuf != NULL) {
free(proc->regbuf);
free(proc->fpregbuf);
}
free(proc);
return 0;
}
int
td_thr_iter(td_proc_t *proc, int (*call)(td_thread_t *, void *), void *callarg)
{
int val;
caddr_t next;
pthread_queue_t allq;
td_thread_t *thread;
val = READ(proc, proc->allqaddr, &allq, sizeof(allq));
if (val != 0)
return val;
next = (void *)allq.ptqh_first;
while (next != NULL) {
val = td__getthread(proc, next, &thread);
if (val != 0)
return val;
val = (*call)(thread, callarg);
if (val != 0)
return 0;
val = READ(proc,
next + offsetof(struct __pthread_st, pt_allq.ptqe_next),
&next, sizeof(next));
if (val != 0)
return val;
}
return 0;
}
int
td_thr_info(td_thread_t *thread, td_thread_info_t *info)
{
int tmp, val;
val = READ(thread->proc, OFFSET(thread, pt_magic), &tmp, sizeof(tmp));
if (val != 0)
return val;
if (tmp != PT_MAGIC)
return TD_ERR_BADTHREAD;
info->thread_addr = thread->addr;
if ((val = READ(thread->proc,
OFFSET(thread, pt_state), &tmp, sizeof(tmp))) != 0)
return val;
switch (tmp) {
case PT_STATE_RUNNING:
info->thread_state = TD_STATE_RUNNING;
break;
case PT_STATE_ZOMBIE:
info->thread_state = TD_STATE_ZOMBIE;
break;
case PT_STATE_DEAD:
info->thread_state = TD_STATE_DEAD;
break;
default:
info->thread_state = TD_STATE_UNKNOWN;
}
if ((val = READ(thread->proc, OFFSET(thread, pt_stack),
&info->thread_stack, sizeof(stack_t))) != 0)
return val;
if ((val = READ(thread->proc, OFFSET(thread, pt_errno),
&info->thread_errno, sizeof(info->thread_errno))) != 0)
return val;
if ((val = READ(thread->proc, OFFSET(thread, pt_lid),
&info->thread_id, sizeof(info->thread_id))) != 0)
return val;
info->thread_id += TN_OFFSET;
return 0;
}
int
td_thr_getname(td_thread_t *thread, char *name, int len)
{
int val, tmp;
caddr_t nameaddr;
val = READ(thread->proc, OFFSET(thread, pt_magic), &tmp, sizeof(tmp));
if (val != 0)
return val;
if (tmp != PT_MAGIC)
return TD_ERR_BADTHREAD;
if ((val = READ(thread->proc, OFFSET(thread, pt_name),
&nameaddr, sizeof(nameaddr))) != 0)
return val;
if (nameaddr == 0)
name[0] = '\0';
else if ((val = READ(thread->proc, nameaddr,
name, (size_t)MIN(PTHREAD_MAX_NAMELEN_NP, len))) != 0)
return val;
if (len < PTHREAD_MAX_NAMELEN_NP)
name[len - 1] = '\0';
return 0;
}
int
td_thr_getregs(td_thread_t *thread, int regset, void *buf)
{
int tmp, val;
if ((val = READ(thread->proc, OFFSET(thread, pt_state),
&tmp, sizeof(tmp))) != 0)
return val;
switch (tmp) {
case PT_STATE_RUNNING:
/*
* The register state of the thread is live in the
* inferior process's register state.
*/
val = GETREGS(thread->proc, regset, thread->lwp, buf);
if (val != 0)
return val;
break;
case PT_STATE_ZOMBIE:
case PT_STATE_DEAD:
default:
return TD_ERR_BADTHREAD;
}
return 0;
}
int
td_thr_setregs(td_thread_t *thread, int regset, void *buf)
{
int val, tmp;
if ((val = READ(thread->proc, OFFSET(thread, pt_state),
&tmp, sizeof(tmp))) != 0)
return val;
switch (tmp) {
case PT_STATE_RUNNING:
/*
* The register state of the thread is live in the
* inferior process's register state.
*/
val = SETREGS(thread->proc, regset, thread->lwp, buf);
if (val != 0)
return val;
break;
case PT_STATE_ZOMBIE:
case PT_STATE_DEAD:
default:
return TD_ERR_BADTHREAD;
}
return 0;
}
int
td_map_pth2thr(td_proc_t *proc, pthread_t thread, td_thread_t **threadp)
{
int magic, val;
val = READ(proc, (caddr_t)&thread->pt_magic, &magic, sizeof(magic));
if (val != 0)
return val;
if (magic != PT_MAGIC)
return TD_ERR_NOOBJ;
val = td__getthread(proc, (void *)thread, threadp);
if (val != 0)
return val;
return 0;
}
int
td_map_id2thr(td_proc_t *proc, int threadid, td_thread_t **threadp)
{
int val, num;
caddr_t next;
pthread_queue_t allq;
td_thread_t *thread;
val = READ(proc, proc->allqaddr, &allq, sizeof(allq));
if (val != 0)
return val;
/* Correct for offset */
threadid -= TN_OFFSET;
next = (void *)allq.ptqh_first;
while (next != NULL) {
val = READ(proc, next + offsetof(struct __pthread_st, pt_lid),
&num, sizeof(num));
if (num == threadid)
break;
val = READ(proc,
next + offsetof(struct __pthread_st, pt_allq.ptqe_next),
&next, sizeof(next));
if (val != 0)
return val;
}
if (next == 0) {
/* A matching thread was not found. */
return TD_ERR_NOOBJ;
}
val = td__getthread(proc, next, &thread);
if (val != 0)
return val;
*threadp = thread;
return 0;
}
int
td_tsd_iter(td_proc_t *proc,
int (*call)(pthread_key_t, void (*)(void *), void *), void *arg)
{
#ifdef notyet
int val;
int i;
void *allocated;
void (*destructor)(void *);
for (i = 0; i < pthread_keys_max; i++) {
val = READ(proc, proc->tsdlistaddr + i * sizeof(allocated),
&allocated, sizeof(allocated));
if (val != 0)
return val;
if ((uintptr_t)allocated) {
val = READ(proc, proc->tsddestaddr +
i * sizeof(destructor),
&destructor, sizeof(destructor));
if (val != 0)
return val;
val = (call)(i, destructor, arg);
if (val != 0)
return val;
}
}
#else
abort();
#endif
return 0;
}
/* Suspend a thread from running */
int
td_thr_suspend(td_thread_t *thread)
{
int tmp, val;
/* validate the thread */
val = READ(thread->proc, OFFSET(thread, pt_magic), &tmp, sizeof(tmp));
if (val != 0)
return val;
if (tmp != PT_MAGIC)
return TD_ERR_BADTHREAD;
val = READ(thread->proc, OFFSET(thread, pt_lid), &tmp, sizeof(tmp));
if (val != 0)
return val;
/* XXXLWP continue the sucker */;
return 0;
}
/* Restore a suspended thread to its previous state */
int
td_thr_resume(td_thread_t *thread)
{
int tmp, val;
/* validate the thread */
val = READ(thread->proc, OFFSET(thread, pt_magic), &tmp, sizeof(tmp));
if (val != 0)
return val;
if (tmp != PT_MAGIC)
return TD_ERR_BADTHREAD;
val = READ(thread->proc, OFFSET(thread, pt_lid), &tmp, sizeof(tmp));
if (val != 0)
return val;
/* XXXLWP continue the sucker */;
return 0;
}
static int
td__getthread(td_proc_t *proc, caddr_t addr, td_thread_t **threadp)
{
td_thread_t *thread;
/*
* Check if we've allocated a descriptor for this thread.
* Sadly, this makes iterating over a set of threads O(N^2)
* in the number of threads. More sophisticated data structures
* can wait.
*/
PTQ_FOREACH(thread, &proc->threads, list) {
if (thread->addr == addr)
break;
}
if (thread == NULL) {
thread = malloc(sizeof(*thread));
if (thread == NULL)
return TD_ERR_NOMEM;
thread->proc = proc;
thread->addr = addr;
thread->lwp = 0;
PTQ_INSERT_HEAD(&proc->threads, thread, list);
}
*threadp = thread;
return 0;
}
int
td_thr_tsd(td_thread_t *thread, pthread_key_t key, void **value)
{
int val;
val = READ(thread->proc, OFFSET(thread, pt_specific) +
key * sizeof(void *), value, sizeof(*value));
return val;
}

View File

@ -1,200 +0,0 @@
/* $NetBSD: pthread_dbg.h,v 1.9 2016/11/22 04:51:06 kamil Exp $ */
/*-
* Copyright (c) 2002 Wasabi Systems, Inc.
* All rights reserved.
*
* Written by Nathan J. Williams for Wasabi Systems, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed for the NetBSD Project by
* Wasabi Systems, Inc.
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
* or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LIB_PTHREAD_DBG_H
#define _LIB_PTHREAD_DBG_H
#include <sys/types.h>
#include <signal.h>
__BEGIN_DECLS
struct td_proc_st;
struct td_thread_st;
struct td_sync_st;
typedef struct td_proc_st td_proc_t;
typedef struct td_thread_st td_thread_t;
typedef struct td_sync_st td_sync_t;
struct td_proc_callbacks_t {
int (*proc_read)(void *arg, caddr_t addr, void *buf, size_t size);
int (*proc_write)(void *arg, caddr_t addr, void *buf, size_t size);
int (*proc_lookup)(void *arg, const char *sym, caddr_t *addr);
int (*proc_regsize)(void *arg, int regset, size_t *size);
int (*proc_getregs)(void *arg, int regset, int lwp, void *buf);
int (*proc_setregs)(void *arg, int regset, int lwp, void *buf);
};
typedef struct td_thread_info_st {
caddr_t thread_addr; /* Address of data structure */
int thread_state; /* TD_STATE_*; see below */
int thread_type; /* TD_TYPE_*; see below */
int thread_id;
stack_t thread_stack;
int thread_hasjoiners; /* 1 if threads are waiting */
caddr_t thread_tls;
int thread_errno;
sigset_t thread_sigmask;
sigset_t thread_sigpending;
long pad[32];
} td_thread_info_t;
#define TD_STATE_UNKNOWN 0
#define TD_STATE_RUNNING 1 /* On a processor */
#define TD_STATE_UNUSED2 2 /* former TD_STATE_RUNNABLE for SA */
#define TD_STATE_UNUSED3 3 /* former TD_STATE_BLOCKED for SA */
#define TD_STATE_UNUSED4 4 /* former TD_STATE_SLEEPING for SA */
#define TD_STATE_ZOMBIE 5
#define TD_STATE_UNUSED6 6 /* former TD_STATE_SUSPENDED for SA */
#define TD_STATE_DEAD 7
#define TD_TYPE_UNUSED0 0
#define TD_TYPE_UNUSED1 1
#define TD_TYPE_UNUSED2 2
typedef struct {
caddr_t sync_addr; /* Address within the process */
int sync_type; /* TD_SYNC_*; see below */
size_t sync_size;
int sync_haswaiters; /* 1 if threads are known to be waiting */
union {
struct {
int locked;
td_thread_t *owner;
} mutex;
struct {
int locked;
} spin;
struct {
td_thread_t *thread;
} join;
struct {
int locked;
int readlocks;
td_thread_t *writeowner;
} rwlock;
long pad[8];
} sync_data;
} td_sync_info_t;
#define TD_SYNC_UNKNOWN 0
#define TD_SYNC_MUTEX 1 /* pthread_mutex_t */
#define TD_SYNC_COND 2 /* pthread_cond_t */
#define TD_SYNC_SPIN 3 /* pthread_spinlock_t */
#define TD_SYNC_JOIN 4 /* thread being joined */
#define TD_SYNC_RWLOCK 5 /* pthread_rwlock_t */
/* Error return codes */
#define TD_ERR_OK 0
#define TD_ERR_ERR 1 /* Generic error */
#define TD_ERR_NOSYM 2 /* Symbol not found (proc_lookup) */
#define TD_ERR_NOOBJ 3 /* No object matched the request */
#define TD_ERR_BADTHREAD 4 /* Request is not meaningful for that thread */
#define TD_ERR_INUSE 5 /* The process is already being debugged */
#define TD_ERR_NOLIB 6 /* The process is not using libpthread */
#define TD_ERR_NOMEM 7 /* malloc() failed */
#define TD_ERR_IO 8 /* A callback failed to read or write */
#define TD_ERR_INVAL 9 /* Invalid parameter */
/* Make a connection to a threaded process */
int td_open(struct td_proc_callbacks_t *, void *arg, td_proc_t **);
int td_close(td_proc_t *);
/* Iterate over the threads in the process */
int td_thr_iter(td_proc_t *, int (*)(td_thread_t *, void *), void *);
/* Get information on a thread */
int td_thr_info(td_thread_t *, td_thread_info_t *);
/* Get the user-assigned name of a thread */
int td_thr_getname(td_thread_t *, char *, int);
/* Get register state of a thread */
int td_thr_getregs(td_thread_t *, int, void *);
/* Set register state of a thread */
int td_thr_setregs(td_thread_t *, int, void *);
/* Iterate over the set of threads that are joining with the given thread */
int td_thr_join_iter(td_thread_t *, int (*)(td_thread_t *, void *), void *);
/* Get the synchronization object that the thread is sleeping on */
int td_thr_sleepinfo(td_thread_t *, td_sync_t **);
/* Get information on a synchronization object */
int td_sync_info(td_sync_t *, td_sync_info_t *);
/* Iterate over the set of threads waiting on a synchronization object */
int td_sync_waiters_iter(td_sync_t *, int (*)(td_thread_t *, void *), void *);
/* Convert the process address to a synchronization handle, if possible */
int td_map_addr2sync(td_proc_t *, caddr_t addr, td_sync_t **);
/* Convert the pthread_t to a thread handle, if possible */
int td_map_pth2thr(td_proc_t *, pthread_t, td_thread_t **);
/* Convert the thread ID to a thread handle, if possible */
int td_map_id2thr(td_proc_t *, int, td_thread_t **);
/* Return the thread handle of the thread running on the given LWP */
int td_map_lwp2thr(td_proc_t *, int, td_thread_t **);
/*
* Establish a mapping between threads and LWPs. Must be called
* every time a live process runs before calling td_thr_getregs() or
* td_thr_setregs().
*/
int td_map_lwps(td_proc_t *);
/* Iterate over the set of TSD keys in the process */
int td_tsd_iter(td_proc_t *, int (*)(pthread_key_t, void (*)(void *), void *),
void *);
/* Get a TSD value from a thread */
int td_thr_tsd(td_thread_t *, pthread_key_t, void **);
/* Suspend a thread from running */
int td_thr_suspend(td_thread_t *);
/* Restore a suspended thread to its previous state */
int td_thr_resume(td_thread_t *);
__END_DECLS
#endif /* _LIB_PTHREAD_DBG_H */

View File

@ -1,48 +0,0 @@
PTQ_HEAD(thread_queue_t, td_thread_st);
PTQ_HEAD(sync_queue_t, td_sync_st);
struct td_proc_st {
struct td_proc_callbacks_t *cb;
void *arg;
void *dbgaddr;
void *allqaddr;
void *runqaddr;
void *idleqaddr;
void *suspqaddr;
void *maxlwpsaddr;
void *tsdlistaddr;
void *tsddestaddr;
void *stacksizeaddr;
int stacksizelg;
size_t stacksize;
uintptr_t stackmask;
struct reg *regbuf;
struct fpreg *fpregbuf;
struct thread_queue_t threads;
};
struct td_thread_st {
td_proc_t *proc;
void *addr;
lwpid_t lwp;
PTQ_ENTRY(td_thread_st) list;
};
struct td_sync_st {
td_proc_t *proc;
void *addr;
PTQ_ENTRY(td_sync_st) list;
};
#define READ(proc, addr, buf, size) ((proc)->cb->proc_read((proc)->arg, (addr), (buf), (size)))
#define WRITE(proc, addr, buf, size) ((proc)->cb->proc_write((proc)->arg, (addr), (buf), (size)))
#define LOOKUP(proc, sym, addr) ((proc)->cb->proc_lookup((proc)->arg, (sym), (addr)))
#define REGSIZE(proc, regset, size) ((proc)->cb->proc_regsize((proc)->arg, (regset), (size)))
#define GETREGS(proc, regset, lwp, buf) ((proc)->cb->proc_getregs((proc)->arg, (regset), (lwp), (buf)))
#define SETREGS(proc, regset, lwp, buf) ((proc)->cb->proc_setregs((proc)->arg, (regset), (lwp), (buf)))

View File

@ -1,5 +0,0 @@
# $NetBSD: shlib_version,v 1.5 2009/01/11 03:07:49 christos Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
major=2
minor=0

View File

@ -1,71 +0,0 @@
.\" $NetBSD: td_map_pth2thr.3,v 1.2 2016/11/24 12:18:02 wiz Exp $
.\"
.\" Copyright (c) 2016 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd November 22, 2016
.Dt TD_MAP_PTH2THR 3
.Os
.Sh NAME
.Nm td_map_pth2thr
.Nd convert a pthread_t to a thread handle
.Sh LIBRARY
.Lb libpthread_dbg
.Sh SYNOPSIS
.In pthread_dbg.h
.Ft int
.Fn td_thr_getname "td_proc_t *proc" "pthread_t thread" "td_thread_t **threadp"
.Sh DESCRIPTION
The
.Nm
function converts a
.Ta POSIX
thread
.Fa thread
to a
.Xr pthread_dbg 3
specific thread passed in the
.Fa threadp
argument.
.Sh RETURN VALUES
If successful, the
.Nm
function will return
.Dv TD_ERR_OK .
Otherwise an error number will be returned to indicate failure as described in
.Xr pthread_dbg 3 .
.Sh SEE ALSO
.Xr pthread 3 ,
.Xr pthread_dbg 3
.Sh HISTORY
The
.Nm
function first appeared in
.Nx 2.0 .
.Sh AUTHORS
.An -nosplit
.An Nathan J. Williams Aq Mt nathanw@NetBSD.org
.Pp
This manual page was written by
.An Kamil Rytarowski Aq Mt kamil@NetBSD.org .

View File

@ -1,79 +0,0 @@
.\" $NetBSD: td_open.3,v 1.2 2016/11/24 12:18:02 wiz Exp $
.\"
.\" Copyright (c) 2016 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd November 21, 2016
.Dt TD_OPEN 3
.Os
.Sh NAME
.Nm td_open ,
.Nm td_close
.Nd make or close a connection to a threaded process
.Sh LIBRARY
.Lb libpthread_dbg
.Sh SYNOPSIS
.In pthread_dbg.h
.Ft int
.Fn td_open "struct td_proc_callbacks_t *cb" "void *arg" "td_proc_t **procp"
.Ft int
.Fn td_close "td_proc_t *proc"
.Sh DESCRIPTION
The
.Fn td_open
function makes a connection to a threaded process.
That program must be a consumer of the
.Tn POSIX
threads implementation using the
.Xr pthread 3
library.
.Pp
The
.Fn td_close
function closes a connection to a threaded process.
.Sh RETURN VALUES
If successful, the
.Fn td_open
and
.Fn td_close
functions will return
.Dv TD_ERR_OK .
Otherwise an error number will be returned to indicate failure as described in
.Xr pthread_dbg 3 .
.Sh SEE ALSO
.Xr pthread 3 ,
.Xr pthread_dbg 3
.Sh HISTORY
The
.Fn td_open
and
.Fn td_close
functions first appeared in
.Nx 2.0 .
.Sh AUTHORS
.An -nosplit
.An Nathan J. Williams Aq Mt nathanw@NetBSD.org
.Pp
This manual page was written by
.An Kamil Rytarowski Aq Mt kamil@NetBSD.org .

View File

@ -1,75 +0,0 @@
.\" $NetBSD: td_thr_getname.3,v 1.2 2016/11/24 12:18:02 wiz Exp $
.\"
.\" Copyright (c) 2016 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd November 22, 2016
.Dt TD_THR_GETNAME 3
.Os
.Sh NAME
.Nm td_thr_getname
.Nd get the user-assigned name of a thread
.Sh LIBRARY
.Lb libpthread_dbg
.Sh SYNOPSIS
.In pthread_dbg.h
.Ft int
.Fn td_thr_getname "td_thread_t *thread" "char *name" "int len"
.Sh DESCRIPTION
The
.Nm
function retrieves the user-assigned name of a thread
.Fa thread
and stores it in the buffer
.Fa name
of length
.Fa len .
If the name is longer than the buffer size, the result will be truncated.
The returned string always terminates with a
.Dv NUL
byte.
The maximum length of a thread's name,
including terminating character, is defined by
.Dv PTHREAD_MAX_NAMELEN_NP .
.Sh RETURN VALUES
If successful, the
.Nm
function will return
.Dv TD_ERR_OK .
Otherwise an error number will be returned to indicate failure as described in
.Xr pthread_dbg 3 .
.Sh SEE ALSO
.Xr pthread 3 ,
.Xr pthread_dbg 3
.Sh HISTORY
The
.Nm
function first appeared in
.Nx 2.0 .
.Sh AUTHORS
.An -nosplit
.An Nathan J. Williams Aq Mt nathanw@NetBSD.org
.Pp
This manual page was written by
.An Kamil Rytarowski Aq Mt kamil@NetBSD.org .

View File

@ -1,109 +0,0 @@
.\" $NetBSD: td_thr_info.3,v 1.2 2016/11/24 12:18:02 wiz Exp $
.\"
.\" Copyright (c) 2016 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd November 21, 2016
.Dt TD_THR_INFO 3
.Os
.Sh NAME
.Nm td_thr_info
.Nd get information on a thread
.Sh LIBRARY
.Lb libpthread_dbg
.Sh SYNOPSIS
.In pthread_dbg.h
.Ft int
.Fn td_thr_info "td_thread_t *thread" "td_thread_info_t *info"
.Sh DESCRIPTION
The
.Fn td_thr_info
function retrieves information on a thread specified in the
.Fa thread
argument and saves the result in
.Fa info .
.Pp
The following members are defined in the
.Dv td_thread_info_t
structure:
.Bl -column "thread_state" "caddr_t" "Pointer to underlaying Dv pthread_t object"
.It Sy Name Ta Sy Type Ta Sy Description
.It thread_addr Ta Dv caddr_t Ta Points to underlaying Dv pthread_t object
.It thread_state Ta Dv int Ta Defines Dv TD_STATE of the thread
.\" TODO: Add ATF tests, verify and document:
.\" thread_type
.\" thread_id
.\" thread_stack
.\" thread_hasjoiners
.\" thread_tls
.\" thread_errno
.\" thread_sigmask
.\" thread_sigpending
.El
.Ss Thread State types
The following state types are possible in
.Dv thread_state :
.Pp
.Bl -column ".Sy TD_STATE_RUNNING" "Thread is alive" -compact
.It Dv TD_STATE_UNKNOWN Ta "Unknown state"
.It Dv TD_STATE_RUNNING Ta "Thread is alive"
.It Dv TD_STATE_ZOMBIE Ta "Thread is in the zombie state"
.It Dv TD_STATE_DEAD Ta "Thread is dead"
.El
.Pp
It is not possible to retrieve information whether a thread
is suspended or resumed using this interface,
as this data is stored only inside the kernel and not in the
.Dv pthread_t
object.
The
.Dv TD_STATE_RUNNING
name is kept for backwards compatibility with old Scheduler Activation threads.
The
.Dv TD_STATE_RUNNING
state might only be returned for a mismatch between the versions of
.Xr pthread 3
and
.Xr pthread_dbg 3 .
.Sh RETURN VALUES
If successful, the
.Nm
function will return
.Dv TD_ERR_OK .
Otherwise an error number will be returned to indicate failure as described in
.Xr pthread_dbg 3 .
.Sh SEE ALSO
.Xr pthread 3 ,
.Xr pthread_dbg 3
.Sh HISTORY
The
.Nm
function first appeared in
.Nx 2.0 .
.Sh AUTHORS
.An -nosplit
.An Nathan J. Williams Aq Mt nathanw@NetBSD.org
.Pp
This manual page was written by
.An Kamil Rytarowski Aq Mt kamil@NetBSD.org .

View File

@ -1,69 +0,0 @@
.\" $NetBSD: td_thr_iter.3,v 1.2 2016/11/24 12:18:02 wiz Exp $
.\"
.\" Copyright (c) 2016 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd November 21, 2016
.Dt TD_THR_ITER 3
.Os
.Sh NAME
.Nm td_thr_iter
.Nd iterate over the threads in a process
.Sh LIBRARY
.Lb libpthread_dbg
.Sh SYNOPSIS
.In pthread_dbg.h
.Ft int
.Fn td_thr_iter "td_proc_t *proc" "int (*call)(td_thread_t *, void *)" "void *callarg"
.Sh DESCRIPTION
The
.Fn td_thr_iter
function iterates over all threads in the
.Fa proc
process and calls the
.Fa call
function for each of them with the
.Fa callarg
argument.
.Sh RETURN VALUES
If successful, the
.Nm
function will return
.Dv TD_ERR_OK .
Otherwise an error number will be returned to indicate failure as described in
.Xr pthread_dbg 3 .
.Sh SEE ALSO
.Xr pthread 3 ,
.Xr pthread_dbg 3
.Sh HISTORY
The
.Nm
function first appeared in
.Nx 2.0 .
.Sh AUTHORS
.An -nosplit
.An Nathan J. Williams Aq Mt nathanw@NetBSD.org
.Pp
This manual page was written by
.An Kamil Rytarowski Aq Mt kamil@NetBSD.org .

View File

@ -1,4 +1,4 @@
# $NetBSD: bsd.README,v 1.357 2017/01/07 22:27:36 christos Exp $
# $NetBSD: bsd.README,v 1.358 2017/02/08 03:44:41 kamil Exp $
# @(#)bsd.README 8.2 (Berkeley) 4/2/94
This is the README file for the make "include" files for the NetBSD
@ -1611,7 +1611,6 @@ DPADD Additional dependencies for the program. Usually used for
LIBPMC?= ${DESTDIR}/usr/lib/libpmc.a
LIBPOSIX?= ${DESTDIR}/usr/lib/libposix.a
LIBPTHREAD?= ${DESTDIR}/usr/lib/libpthread.a
LIBPTHREAD_DBG?=${DESTDIR}/usr/lib/libpthread_dbg.a
LIBPUFFS?= ${DESTDIR}/usr/lib/libpuffs.a
LIBQUOTA?= ${DESTDIR}/usr/lib/libquota.a
LIBRADIUS?= ${DESTDIR}/usr/lib/libradius.a

View File

@ -1,4 +1,4 @@
# $NetBSD: bsd.hostprog.mk,v 1.76 2016/01/01 17:06:21 christos Exp $
# $NetBSD: bsd.hostprog.mk,v 1.77 2017/02/08 03:44:41 kamil Exp $
# @(#)bsd.prog.mk 8.2 (Berkeley) 4/2/94
.include <bsd.init.mk>
@ -48,7 +48,6 @@ LIBPCI?= /usr/lib/libpci.a
LIBPLOT?= /usr/lib/libplot.a
LIBPOSIX?= /usr/lib/libposix.a
LIBPTHREAD?= /usr/lib/libpthread.a
LIBPTHREAD_DBG?=/usr/lib/libpthread_dbg.a
LIBPUFFS?= /usr/lib/libpuffs.a
LIBQUOTA?= /usr/lib/libquota.a
LIBRESOLV?= /usr/lib/libresolv.a

View File

@ -1,4 +1,4 @@
# $NetBSD: bsd.prog.mk,v 1.301 2017/01/29 21:43:56 christos Exp $
# $NetBSD: bsd.prog.mk,v 1.302 2017/02/08 03:44:41 kamil Exp $
# @(#)bsd.prog.mk 8.2 (Berkeley) 4/2/94
.ifndef HOSTPROG
@ -163,7 +163,6 @@ LIBCRTI= ${DESTDIR}/usr/lib/${MLIBDIR:D${MLIBDIR}/}crti.o
pmc \
posix \
pthread \
pthread_dbg \
puffs \
quota \
radius \

View File

@ -1,10 +1,10 @@
# $NetBSD: Makefile,v 1.27 2016/11/16 21:36:23 kamil Exp $
# $NetBSD: Makefile,v 1.28 2017/02/08 03:44:41 kamil Exp $
.include <bsd.own.mk>
TESTS_SUBDIRS= csu libbluetooth libc libcrypt libcurses libevent libexecinfo \
libm libobjc libposix libppath libprop libpthread \
libpthread_dbg librefuse librt libtre libusbhid libutil \
librefuse librt libtre libusbhid libutil \
semaphore
.if (${MKRUMP} != "no") && !defined(BSD_MK_COMPAT_FILE)

View File

@ -1,14 +0,0 @@
# $NetBSD: Makefile,v 1.2 2016/11/18 22:50:19 kamil Exp $
NOMAN= # defined
.include <bsd.own.mk>
TESTSDIR= ${TESTSBASE}/lib/libpthread_dbg
LDADD+= -lpthread
LDADD+= -lpthread_dbg
TESTS_C+= t_dummy
TESTS_C+= t_threads
.include <bsd.test.mk>

View File

@ -1,128 +0,0 @@
/* $NetBSD: h_common.h,v 1.2 2016/11/19 02:30:54 kamil Exp $ */
/*-
* Copyright (c) 2016 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef H_COMMON_H
#define H_COMMON_H
#include <sys/cdefs.h>
#include <dlfcn.h>
#include <pthread_dbg.h>
#include <string.h>
#include <atf-c.h>
#define PTHREAD_REQUIRE(x) \
do { \
int ret = (x); \
ATF_REQUIRE_MSG(ret == 0, "%s: %s", #x, strerror(ret)); \
} while (0)
#define PTHREAD_REQUIRE_STATUS(x, v) \
do { \
int ret = (x); \
ATF_REQUIRE_MSG(ret == (v), "%s: %s", #x, strerror(ret)); \
} while (0)
static int __used
dummy_proc_read(void *arg, caddr_t addr, void *buf, size_t size)
{
return TD_ERR_ERR;
}
static int __used
dummy_proc_write(void *arg, caddr_t addr, void *buf, size_t size)
{
return TD_ERR_ERR;
}
static int __used
dummy_proc_lookup(void *arg, const char *sym, caddr_t *addr)
{
return TD_ERR_ERR;
}
static int __used
dummy_proc_regsize(void *arg, int regset, size_t *size)
{
return TD_ERR_ERR;
}
static int __used
dummy_proc_getregs(void *arg, int regset, int lwp, void *buf)
{
return TD_ERR_ERR;
}
static int __used
dummy_proc_setregs(void *arg, int regset, int lwp, void *buf)
{
return TD_ERR_ERR;
}
/* Minimalistic basic implementation */
static int __used
basic_proc_read(void *arg, caddr_t addr, void *buf, size_t size)
{
memcpy(buf, addr, size);
return TD_ERR_OK;
}
static int __used
basic_proc_write(void *arg, caddr_t addr, void *buf, size_t size)
{
memcpy(addr, buf, size);
return TD_ERR_OK;
}
static int __used
basic_proc_lookup(void *arg, const char *sym, caddr_t *addr)
{
void *handle;
void *symbol;
ATF_REQUIRE_MSG((handle = dlopen(NULL, RTLD_LOCAL | RTLD_LAZY))
!= NULL, "dlopen(3) failed: %s", dlerror());
symbol = dlsym(handle, sym);
ATF_REQUIRE_MSG(dlclose(handle) == 0, "dlclose(3) failed: %s",
dlerror());
if (!symbol)
return TD_ERR_NOSYM;
*addr = (caddr_t)(uintptr_t)symbol;
return TD_ERR_OK;
}
#endif // H_COMMON_H

View File

@ -1,131 +0,0 @@
/* $NetBSD: t_dummy.c,v 1.6 2016/11/19 15:13:46 kamil Exp $ */
/*-
* Copyright (c) 2016 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_dummy.c,v 1.6 2016/11/19 15:13:46 kamil Exp $");
#include "h_common.h"
#include <pthread_dbg.h>
#include <stdio.h>
#include <atf-c.h>
ATF_TC(dummy1);
ATF_TC_HEAD(dummy1, tc)
{
atf_tc_set_md_var(tc, "descr",
"Asserts that dummy lookup functions stop td_open() with failure");
}
ATF_TC_BODY(dummy1, tc)
{
struct td_proc_callbacks_t dummy_callbacks;
td_proc_t *main_ta;
dummy_callbacks.proc_read = dummy_proc_read;
dummy_callbacks.proc_write = dummy_proc_write;
dummy_callbacks.proc_lookup = dummy_proc_lookup;
dummy_callbacks.proc_regsize = dummy_proc_regsize;
dummy_callbacks.proc_getregs = dummy_proc_getregs;
dummy_callbacks.proc_setregs = dummy_proc_setregs;
ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_ERR);
}
ATF_TC(dummy2);
ATF_TC_HEAD(dummy2, tc)
{
atf_tc_set_md_var(tc, "descr",
"Asserts that td_open() for basic proc_{read,write,lookup} works");
}
ATF_TC_BODY(dummy2, tc)
{
struct td_proc_callbacks_t dummy_callbacks;
td_proc_t *main_ta;
dummy_callbacks.proc_read = basic_proc_read;
dummy_callbacks.proc_write = basic_proc_write;
dummy_callbacks.proc_lookup = basic_proc_lookup;
dummy_callbacks.proc_regsize = dummy_proc_regsize;
dummy_callbacks.proc_getregs = dummy_proc_getregs;
dummy_callbacks.proc_setregs = dummy_proc_setregs;
printf("Calling td_open(3)\n");
ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_OK);
printf("Calling td_close(3)\n");
ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK);
}
ATF_TC(dummy3);
ATF_TC_HEAD(dummy3, tc)
{
atf_tc_set_md_var(tc, "descr",
"Asserts that calling twice td_open() for the same process fails");
}
ATF_TC_BODY(dummy3, tc)
{
struct td_proc_callbacks_t dummy_callbacks;
td_proc_t *main_ta1;
td_proc_t *main_ta2;
dummy_callbacks.proc_read = basic_proc_read;
dummy_callbacks.proc_write = basic_proc_write;
dummy_callbacks.proc_lookup = basic_proc_lookup;
dummy_callbacks.proc_regsize = dummy_proc_regsize;
dummy_callbacks.proc_getregs = dummy_proc_getregs;
dummy_callbacks.proc_setregs = dummy_proc_setregs;
printf("Calling td_open(3) for the first time - expecting success\n");
ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta1) == TD_ERR_OK);
printf("Calling td_open(3) for the first time - expecting in-use\n");
ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta2) ==
TD_ERR_INUSE);
printf("Calling td_close(3) for the first successful call\n");
ATF_REQUIRE(td_close(main_ta1) == TD_ERR_OK);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, dummy1);
ATF_TP_ADD_TC(tp, dummy2);
ATF_TP_ADD_TC(tp, dummy3);
return atf_no_error();
}

View File

@ -1,719 +0,0 @@
/* $NetBSD: t_threads.c,v 1.9 2017/01/13 05:18:22 christos Exp $ */
/*-
* Copyright (c) 2016 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_threads.c,v 1.9 2017/01/13 05:18:22 christos Exp $");
#include <dlfcn.h>
#include <pthread.h>
#include <pthread_dbg.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <atf-c.h>
#include "h_common.h"
#define MAX_THREADS (size_t)10
ATF_TC(threads1);
ATF_TC_HEAD(threads1, tc)
{
atf_tc_set_md_var(tc, "descr",
"Asserts that td_thr_iter() call without extra logic works");
}
static volatile int exiting1;
static void *
busyFunction1(void *arg)
{
while (exiting1 == 0)
usleep(50000);
return NULL;
}
static int
iterateThreads1(td_thread_t *thread, void *arg)
{
return TD_ERR_OK;
}
ATF_TC_BODY(threads1, tc)
{
struct td_proc_callbacks_t dummy_callbacks;
td_proc_t *main_ta;
size_t i;
pthread_t threads[MAX_THREADS];
dummy_callbacks.proc_read = basic_proc_read;
dummy_callbacks.proc_write = basic_proc_write;
dummy_callbacks.proc_lookup = basic_proc_lookup;
dummy_callbacks.proc_regsize = dummy_proc_regsize;
dummy_callbacks.proc_getregs = dummy_proc_getregs;
dummy_callbacks.proc_setregs = dummy_proc_setregs;
for (i = 0; i < MAX_THREADS; i++) {
printf("Creating thread %zu\n", i);
PTHREAD_REQUIRE
(pthread_create(&threads[i], NULL, busyFunction1, NULL));
}
printf("Calling td_open(3)\n");
ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_OK);
ATF_REQUIRE(td_thr_iter(main_ta, iterateThreads1, NULL) == TD_ERR_OK);
exiting1 = 1;
printf("Calling td_close(3)\n");
ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK);
}
ATF_TC(threads2);
ATF_TC_HEAD(threads2, tc)
{
atf_tc_set_md_var(tc, "descr",
"Asserts that td_thr_iter() call is executed for each thread once");
}
static volatile int exiting2;
static void *
busyFunction2(void *arg)
{
while (exiting2 == 0)
usleep(50000);
return NULL;
}
static int
iterateThreads2(td_thread_t *thread, void *arg)
{
int *counter = (int *)arg;
++(*counter);
return TD_ERR_OK;
}
ATF_TC_BODY(threads2, tc)
{
struct td_proc_callbacks_t dummy_callbacks;
td_proc_t *main_ta;
size_t i;
pthread_t threads[MAX_THREADS];
int count = 0;
dummy_callbacks.proc_read = basic_proc_read;
dummy_callbacks.proc_write = basic_proc_write;
dummy_callbacks.proc_lookup = basic_proc_lookup;
dummy_callbacks.proc_regsize = dummy_proc_regsize;
dummy_callbacks.proc_getregs = dummy_proc_getregs;
dummy_callbacks.proc_setregs = dummy_proc_setregs;
for (i = 0; i < MAX_THREADS; i++) {
printf("Creating thread %zu\n", i);
PTHREAD_REQUIRE
(pthread_create(&threads[i], NULL, busyFunction2, NULL));
}
printf("Calling td_open(3)\n");
ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_OK);
ATF_REQUIRE(td_thr_iter(main_ta, iterateThreads2, &count) == TD_ERR_OK);
exiting2 = 1;
printf("Calling td_close(3)\n");
ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK);
ATF_REQUIRE_EQ_MSG(count, MAX_THREADS + 1,
"counted threads (%d) != expected threads (%zu)",
count, MAX_THREADS + 1);
}
ATF_TC(threads3);
ATF_TC_HEAD(threads3, tc)
{
atf_tc_set_md_var(tc, "descr",
"Asserts that for each td_thr_iter() call td_thr_info() is valid");
}
static volatile int exiting3;
static void *
busyFunction3(void *arg)
{
while (exiting3 == 0)
usleep(50000);
return NULL;
}
static int
iterateThreads3(td_thread_t *thread, void *arg)
{
int *counter = (int *)arg;
td_thread_info_t info;
ATF_REQUIRE(td_thr_info(thread, &info) == TD_ERR_OK);
++(*counter);
return TD_ERR_OK;
}
ATF_TC_BODY(threads3, tc)
{
struct td_proc_callbacks_t dummy_callbacks;
td_proc_t *main_ta;
size_t i;
pthread_t threads[MAX_THREADS];
int count = 0;
dummy_callbacks.proc_read = basic_proc_read;
dummy_callbacks.proc_write = basic_proc_write;
dummy_callbacks.proc_lookup = basic_proc_lookup;
dummy_callbacks.proc_regsize = dummy_proc_regsize;
dummy_callbacks.proc_getregs = dummy_proc_getregs;
dummy_callbacks.proc_setregs = dummy_proc_setregs;
for (i = 0; i < MAX_THREADS; i++) {
printf("Creating thread %zu\n", i);
PTHREAD_REQUIRE
(pthread_create(&threads[i], NULL, busyFunction3, NULL));
}
printf("Calling td_open(3)\n");
ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_OK);
ATF_REQUIRE(td_thr_iter(main_ta, iterateThreads3, &count) == TD_ERR_OK);
exiting3 = 1;
printf("Calling td_close(3)\n");
ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK);
ATF_REQUIRE_EQ_MSG(count, MAX_THREADS + 1,
"counted threads (%d) != expected threads (%zu)",
count, MAX_THREADS + 1);
}
ATF_TC(threads4);
ATF_TC_HEAD(threads4, tc)
{
atf_tc_set_md_var(tc, "descr",
"Asserts that for each td_thr_iter() call td_thr_getname() is "
"valid");
}
static volatile int exiting4;
static void *
busyFunction4(void *arg)
{
while (exiting4 == 0)
usleep(50000);
return NULL;
}
static int
iterateThreads4(td_thread_t *thread, void *arg)
{
int *counter = (int *)arg;
char name[PTHREAD_MAX_NAMELEN_NP];
ATF_REQUIRE(td_thr_getname(thread, name, sizeof(name)) == TD_ERR_OK);
printf("Thread name: %s\n", name);
++(*counter);
return TD_ERR_OK;
}
ATF_TC_BODY(threads4, tc)
{
struct td_proc_callbacks_t dummy_callbacks;
td_proc_t *main_ta;
size_t i;
pthread_t threads[MAX_THREADS];
int count = 0;
dummy_callbacks.proc_read = basic_proc_read;
dummy_callbacks.proc_write = basic_proc_write;
dummy_callbacks.proc_lookup = basic_proc_lookup;
dummy_callbacks.proc_regsize = dummy_proc_regsize;
dummy_callbacks.proc_getregs = dummy_proc_getregs;
dummy_callbacks.proc_setregs = dummy_proc_setregs;
for (i = 0; i < MAX_THREADS; i++) {
printf("Creating thread %zu\n", i);
PTHREAD_REQUIRE
(pthread_create(&threads[i], NULL, busyFunction4, NULL));
}
for (i = 0; i < MAX_THREADS; i++) {
PTHREAD_REQUIRE
(pthread_setname_np(threads[i], "test_%d", (void*)i));
}
printf("Calling td_open(3)\n");
ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_OK);
ATF_REQUIRE(td_thr_iter(main_ta, iterateThreads4, &count) == TD_ERR_OK);
exiting4 = 1;
printf("Calling td_close(3)\n");
ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK);
ATF_REQUIRE_EQ_MSG(count, MAX_THREADS + 1,
"counted threads (%d) != expected threads (%zu)",
count, MAX_THREADS + 1);
}
ATF_TC(threads5);
ATF_TC_HEAD(threads5, tc)
{
atf_tc_set_md_var(tc, "descr",
"Asserts that td_thr_getname() handles shorter buffer parameter "
"and the result is properly truncated");
}
static volatile int exiting5;
static void *
busyFunction5(void *arg)
{
while (exiting5 == 0)
usleep(50000);
return NULL;
}
static int
iterateThreads5(td_thread_t *thread, void *arg)
{
int *counter = (int *)arg;
/* Arbitrarily short string buffer */
char name[3];
ATF_REQUIRE(td_thr_getname(thread, name, sizeof(name)) == TD_ERR_OK);
printf("Thread name: %s\n", name);
/* strlen(3) does not count including a '\0' character */
ATF_REQUIRE(strlen(name) < sizeof(name));
++(*counter);
return TD_ERR_OK;
}
ATF_TC_BODY(threads5, tc)
{
struct td_proc_callbacks_t dummy_callbacks;
td_proc_t *main_ta;
size_t i;
pthread_t threads[MAX_THREADS];
int count = 0;
dummy_callbacks.proc_read = basic_proc_read;
dummy_callbacks.proc_write = basic_proc_write;
dummy_callbacks.proc_lookup = basic_proc_lookup;
dummy_callbacks.proc_regsize = dummy_proc_regsize;
dummy_callbacks.proc_getregs = dummy_proc_getregs;
dummy_callbacks.proc_setregs = dummy_proc_setregs;
for (i = 0; i < MAX_THREADS; i++) {
printf("Creating thread %zu\n", i);
PTHREAD_REQUIRE
(pthread_create(&threads[i], NULL, busyFunction5, NULL));
}
for (i = 0; i < MAX_THREADS; i++) {
PTHREAD_REQUIRE
(pthread_setname_np(threads[i], "test_%d", (void*)i));
}
printf("Calling td_open(3)\n");
ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_OK);
ATF_REQUIRE(td_thr_iter(main_ta, iterateThreads5, &count) == TD_ERR_OK);
exiting5 = 1;
printf("Calling td_close(3)\n");
ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK);
ATF_REQUIRE_EQ_MSG(count, MAX_THREADS + 1,
"counted threads (%d) != expected threads (%zu)",
count, MAX_THREADS + 1);
}
ATF_TC(threads6);
ATF_TC_HEAD(threads6, tc)
{
atf_tc_set_md_var(tc, "descr",
"Asserts that pthread_t can be translated with td_map_pth2thr() "
"to td_thread_t -- and assert earlier that td_thr_iter() call is "
"valid");
}
static volatile int exiting6;
static void *
busyFunction6(void *arg)
{
while (exiting6 == 0)
usleep(50000);
return NULL;
}
static int
iterateThreads6(td_thread_t *thread, void *arg)
{
int *counter = (int *)arg;
++(*counter);
return TD_ERR_OK;
}
ATF_TC_BODY(threads6, tc)
{
struct td_proc_callbacks_t dummy_callbacks;
td_proc_t *main_ta;
size_t i;
pthread_t threads[MAX_THREADS];
int count = 0;
dummy_callbacks.proc_read = basic_proc_read;
dummy_callbacks.proc_write = basic_proc_write;
dummy_callbacks.proc_lookup = basic_proc_lookup;
dummy_callbacks.proc_regsize = dummy_proc_regsize;
dummy_callbacks.proc_getregs = dummy_proc_getregs;
dummy_callbacks.proc_setregs = dummy_proc_setregs;
for (i = 0; i < MAX_THREADS; i++) {
printf("Creating thread %zu\n", i);
PTHREAD_REQUIRE
(pthread_create(&threads[i], NULL, busyFunction6, NULL));
}
printf("Calling td_open(3)\n");
ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_OK);
ATF_REQUIRE(td_thr_iter(main_ta, iterateThreads6, &count) == TD_ERR_OK);
for (i = 0; i < MAX_THREADS; i++) {
td_thread_t *td_thread;
ATF_REQUIRE(td_map_pth2thr(main_ta, threads[i], &td_thread)
== TD_ERR_OK);
}
exiting6 = 1;
printf("Calling td_close(3)\n");
ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK);
ATF_REQUIRE_EQ_MSG(count, MAX_THREADS + 1,
"counted threads (%d) != expected threads (%zu)",
count, MAX_THREADS + 1);
}
ATF_TC(threads7);
ATF_TC_HEAD(threads7, tc)
{
atf_tc_set_md_var(tc, "descr",
"Asserts that pthread_t can be translated with td_map_pth2thr() "
"to td_thread_t -- and assert later that td_thr_iter() call is "
"valid");
}
static volatile int exiting7;
static void *
busyFunction7(void *arg)
{
while (exiting7 == 0)
usleep(50000);
return NULL;
}
static int
iterateThreads7(td_thread_t *thread, void *arg)
{
int *counter = (int *)arg;
++(*counter);
return TD_ERR_OK;
}
ATF_TC_BODY(threads7, tc)
{
struct td_proc_callbacks_t dummy_callbacks;
td_proc_t *main_ta;
size_t i;
pthread_t threads[MAX_THREADS];
int count = 0;
dummy_callbacks.proc_read = basic_proc_read;
dummy_callbacks.proc_write = basic_proc_write;
dummy_callbacks.proc_lookup = basic_proc_lookup;
dummy_callbacks.proc_regsize = dummy_proc_regsize;
dummy_callbacks.proc_getregs = dummy_proc_getregs;
dummy_callbacks.proc_setregs = dummy_proc_setregs;
for (i = 0; i < MAX_THREADS; i++) {
printf("Creating thread %zu\n", i);
PTHREAD_REQUIRE
(pthread_create(&threads[i], NULL, busyFunction7, NULL));
}
printf("Calling td_open(3)\n");
ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_OK);
for (i = 0; i < MAX_THREADS; i++) {
td_thread_t *td_thread;
ATF_REQUIRE(td_map_pth2thr(main_ta, threads[i], &td_thread)
== TD_ERR_OK);
}
ATF_REQUIRE(td_thr_iter(main_ta, iterateThreads7, &count) == TD_ERR_OK);
exiting7 = 1;
printf("Calling td_close(3)\n");
ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK);
ATF_REQUIRE_EQ_MSG(count, MAX_THREADS + 1,
"counted threads (%d) != expected threads (%zu)",
count, MAX_THREADS + 1);
}
ATF_TC(threads8);
ATF_TC_HEAD(threads8, tc)
{
atf_tc_set_md_var(tc, "descr",
"Asserts that pthread_t can be translated with td_map_pth2thr() "
"to td_thread_t -- compare thread's name of pthread_t and "
"td_thread_t");
}
static volatile int exiting8;
static void *
busyFunction8(void *arg)
{
while (exiting8 == 0)
usleep(50000);
return NULL;
}
static int
iterateThreads8(td_thread_t *thread, void *arg)
{
int *counter = (int *)arg;
++(*counter);
return TD_ERR_OK;
}
ATF_TC_BODY(threads8, tc)
{
struct td_proc_callbacks_t dummy_callbacks;
td_proc_t *main_ta;
size_t i;
pthread_t threads[MAX_THREADS];
int count = 0;
dummy_callbacks.proc_read = basic_proc_read;
dummy_callbacks.proc_write = basic_proc_write;
dummy_callbacks.proc_lookup = basic_proc_lookup;
dummy_callbacks.proc_regsize = dummy_proc_regsize;
dummy_callbacks.proc_getregs = dummy_proc_getregs;
dummy_callbacks.proc_setregs = dummy_proc_setregs;
for (i = 0; i < MAX_THREADS; i++) {
printf("Creating thread %zu\n", i);
PTHREAD_REQUIRE
(pthread_create(&threads[i], NULL, busyFunction8, NULL));
}
printf("Calling td_open(3)\n");
ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_OK);
ATF_REQUIRE(td_thr_iter(main_ta, iterateThreads8, &count) == TD_ERR_OK);
for (i = 0; i < MAX_THREADS; i++) {
td_thread_t *td_thread;
char td_threadname[PTHREAD_MAX_NAMELEN_NP];
char pth_threadname[PTHREAD_MAX_NAMELEN_NP];
ATF_REQUIRE(td_map_pth2thr(main_ta, threads[i], &td_thread)
== TD_ERR_OK);
ATF_REQUIRE(td_thr_getname(td_thread, td_threadname,
sizeof(td_threadname)) == TD_ERR_OK);
PTHREAD_REQUIRE(pthread_getname_np(threads[i], pth_threadname,
sizeof(pth_threadname)));
ATF_REQUIRE(strcmp(td_threadname, pth_threadname) == 0);
}
exiting8 = 1;
printf("Calling td_close(3)\n");
ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK);
ATF_REQUIRE_EQ_MSG(count, MAX_THREADS + 1,
"counted threads (%d) != expected threads (%zu)",
count, MAX_THREADS + 1);
}
ATF_TC(threads9);
ATF_TC_HEAD(threads9, tc)
{
atf_tc_set_md_var(tc, "descr",
"Asserts that pthread_t can be translated with td_map_pth2thr() "
"to td_thread_t -- assert that thread is in the TD_STATE_RUNNING "
"state");
}
static volatile int exiting9;
static void *
busyFunction9(void *arg)
{
while (exiting9 == 0)
usleep(50000);
return NULL;
}
static int
iterateThreads9(td_thread_t *thread, void *arg)
{
int *counter = (int *)arg;
++(*counter);
return TD_ERR_OK;
}
ATF_TC_BODY(threads9, tc)
{
struct td_proc_callbacks_t dummy_callbacks;
td_proc_t *main_ta;
size_t i;
pthread_t threads[MAX_THREADS];
int count = 0;
dummy_callbacks.proc_read = basic_proc_read;
dummy_callbacks.proc_write = basic_proc_write;
dummy_callbacks.proc_lookup = basic_proc_lookup;
dummy_callbacks.proc_regsize = dummy_proc_regsize;
dummy_callbacks.proc_getregs = dummy_proc_getregs;
dummy_callbacks.proc_setregs = dummy_proc_setregs;
for (i = 0; i < MAX_THREADS; i++) {
printf("Creating thread %zu\n", i);
PTHREAD_REQUIRE
(pthread_create(&threads[i], NULL, busyFunction9, NULL));
}
printf("Calling td_open(3)\n");
ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_OK);
for (i = 0; i < MAX_THREADS; i++) {
td_thread_t *td_thread;
td_thread_info_t info;
ATF_REQUIRE(td_map_pth2thr(main_ta, threads[i], &td_thread)
== TD_ERR_OK);
ATF_REQUIRE(td_thr_info(td_thread, &info) == TD_ERR_OK);
ATF_REQUIRE_EQ(info.thread_state, TD_STATE_RUNNING);
}
ATF_REQUIRE(td_thr_iter(main_ta, iterateThreads9, &count) == TD_ERR_OK);
exiting9 = 1;
printf("Calling td_close(3)\n");
ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK);
ATF_REQUIRE_EQ_MSG(count, MAX_THREADS + 1,
"counted threads (%d) != expected threads (%zu)",
count, MAX_THREADS + 1);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, threads1);
ATF_TP_ADD_TC(tp, threads2);
ATF_TP_ADD_TC(tp, threads3);
ATF_TP_ADD_TC(tp, threads4);
ATF_TP_ADD_TC(tp, threads5);
ATF_TP_ADD_TC(tp, threads6);
ATF_TP_ADD_TC(tp, threads7);
ATF_TP_ADD_TC(tp, threads8);
ATF_TP_ADD_TC(tp, threads9);
return atf_no_error();
}