NetBSD Problem Report #51635
From www@NetBSD.org Fri Nov 18 22:41:02 2016
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
by mollari.NetBSD.org (Postfix) with ESMTPS id 4EB757A2FF
for <gnats-bugs@gnats.NetBSD.org>; Fri, 18 Nov 2016 22:41:02 +0000 (UTC)
Message-Id: <20161118224101.3A9417A30C@mollari.NetBSD.org>
Date: Fri, 18 Nov 2016 22:41:01 +0000 (UTC)
From: n54@gmx.com
Reply-To: n54@gmx.com
To: gnats-bugs@NetBSD.org
Subject: td_thr_iter in <pthread_dbg.h> seems broken
X-Send-Pr-Version: www-1.0
>Number: 51635
>Category: lib
>Synopsis: td_thr_iter in <pthread_dbg.h> seems broken
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: lib-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Nov 18 22:45:00 +0000 2016
>Closed-Date: Sat Nov 19 15:15:31 +0000 2016
>Last-Modified: Sat Nov 19 15:15:31 +0000 2016
>Originator: Kamil Rytarowski
>Release: NetBSD 7.99.42 amd64
>Organization:
TNF
>Environment:
NetBSD chieftec 7.99.42 NetBSD 7.99.42 (GENERIC) #0: Thu Nov 17 17:11:44 CET 2016 root@chieftec:/tmp/netbsd-tmp/sys/arch/amd64/compile/GENERIC amd64
>Description:
I'm trying to use td_thr_iter() however it doesn't work for me.
Example test:
#include <sys/cdefs.h>
#include <dlfcn.h>
#include <pthread.h>
#include <pthread_dbg.h>
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include <string.h>
#define ATF_REQUIRE(a) assert(a)
#define ATF_REQUIRE_MSG(a,b,...) assert(a)
#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(addr, buf, 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;
}
static int exiting;
static void *
busyFunction1(void *arg)
{
while (exiting == 0)
usleep(50000);
return NULL;
}
static int
iterateThreads1(td_thread_t *thread, void *arg)
{
return TD_ERR_OK;
}
int
main(int argc, char **argv)
{
struct td_proc_callbacks_t dummy_callbacks;
td_proc_t *main_ta;
const size_t max_threads = 10;
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);
exiting = 1;
printf("Calling td_close(3)\n");
ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK);
}
Result in gdb(1), pointer ptqe_next is invalid.
(gdb) p ((pthread_t)next)->pt_allq
$7 = {ptqe_next = 0xfffff977e8004010, ptqe_prev = 0x10020077105c7}
(gdb) p ((pthread_t)next)->pt_allq.ptqe_next
$8 = (struct __pthread_st *) 0xfffff977e8004010
(gdb) p ((pthread_t)next)
$9 = (struct __pthread_st *) 0x400da1 <iterateThreads1>
>How-To-Repeat:
cd /usr/src/tests/lib/libpthread_dbg
atf-run t_threads | atf-report
>Fix:
N/A
>Release-Note:
>Audit-Trail:
From: "Kamil Rytarowski" <kamil@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/51635 CVS commit: src
Date: Fri, 18 Nov 2016 22:50:20 +0000
Module Name: src
Committed By: kamil
Date: Fri Nov 18 22:50:20 UTC 2016
Modified Files:
src/distrib/sets/lists/debug: mi
src/distrib/sets/lists/tests: mi
src/tests/lib/libpthread_dbg: Makefile t_dummy.c
Added Files:
src/tests/lib/libpthread_dbg: h_common.h t_threads.c
Log Message:
Add new test file lib/libpthread_dbg/t_threads
This test contains threads1 test that:
Asserts that td_thr_iter() call without extra logic works
This tests fails and is linked with gnats:
PR lib/51635: td_thr_iter in <pthread_dbg.h> seems broken
Sponsored by <The NetBSD Foundation>
To generate a diff of this commit:
cvs rdiff -u -r1.178 -r1.179 src/distrib/sets/lists/debug/mi
cvs rdiff -u -r1.701 -r1.702 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libpthread_dbg/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/libpthread_dbg/h_common.h \
src/tests/lib/libpthread_dbg/t_threads.c
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libpthread_dbg/t_dummy.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Kamil Rytarowski" <kamil@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/51635 CVS commit: src/tests/lib/libpthread_dbg
Date: Sat, 19 Nov 2016 02:30:54 +0000
Module Name: src
Committed By: kamil
Date: Sat Nov 19 02:30:54 UTC 2016
Modified Files:
src/tests/lib/libpthread_dbg: h_common.h
Log Message:
Fix basic_proc_read in pthread_dbg functions
Source and destination were swapped. The source of this confusion was that
running these tests under gdb(1) will generate false positives as it will
initialize pthread__dbg to PID of the debugger. This means that it is
currently not possible to debug pthread_dbg code under a full-stack
debugger using NetBSD debugging library for threads.
This should address:
PR lib/51633 tests/lib/libpthread_dbg/t_dummy unreliable
PR lib/51635: td_thr_iter in <pthread_dbg.h> seems broken
After applying the fix I'm able to run all pthread_dbg tests without
indeterminism. The indeterminism was caused by overwritting source of data
with trash.
Sponsored by <The NetBSD Foundation>
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libpthread_dbg/h_common.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: lib/51635: td_thr_iter in <pthread_dbg.h> seems broken
Date: Sat, 19 Nov 2016 10:10:47 +0700
Date: Fri, 18 Nov 2016 22:45:00 +0000 (UTC)
From: n54@gmx.com
Message-ID: <20161118224500.AFF407A305@mollari.NetBSD.org>
Perhaps because of ...
| /* Minimalistic basic implementation */
|
| static int __used
| basic_proc_read(void *arg, caddr_t addr, void *buf, size_t size)
| {
| memcpy(addr, buf, size);
|
| return TD_ERR_OK;
| }
Shouldn't that be
memcpy(buf, addr, size);
?
From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: lib/51635: td_thr_iter in <pthread_dbg.h> seems broken
Date: Sat, 19 Nov 2016 10:19:48 +0700
Oops, did not see that was already fixed... Should this PR not be closed?
kre
From: Kamil Rytarowski <n54@gmx.com>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: lib/51635: td_thr_iter in <pthread_dbg.h> seems broken
Date: Sat, 19 Nov 2016 05:12:32 +0100
This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
--WWaXSXr4sAsErD96ld8PU3U7uG2kv1kBc
Content-Type: multipart/mixed; boundary="dAmwdVvHu4Pbr2Uwfjp5K6rW7JfRUlAma"
From: Kamil Rytarowski <n54@gmx.com>
To: gnats-bugs@NetBSD.org
Message-ID: <4f3987b1-b366-e88a-78ed-be777d35806a@gmx.com>
Subject: Re: lib/51635: td_thr_iter in <pthread_dbg.h> seems broken
References: <pr-lib-51635@gnats.netbsd.org>
<20161118224101.3A9417A30C@mollari.NetBSD.org>
<20161119032001.4E0F47A30E@mollari.NetBSD.org>
In-Reply-To: <20161119032001.4E0F47A30E@mollari.NetBSD.org>
--dAmwdVvHu4Pbr2Uwfjp5K6rW7JfRUlAma
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
On 19.11.2016 04:20, Robert Elz wrote:
> The following reply was made to PR lib/51635; it has been noted by GNAT=
S.
>=20
> From: Robert Elz <kre@munnari.OZ.AU>
> To: gnats-bugs@NetBSD.org
> Cc:=20
> Subject: Re: lib/51635: td_thr_iter in <pthread_dbg.h> seems broken
> Date: Sat, 19 Nov 2016 10:19:48 +0700
>=20
> Oops, did not see that was already fixed... Should this PR not be cl=
osed?
> =20
> kre
> =20
>=20
Can you (or releng machines) reproduce that the pthread_dbg tests no
longer fail? The bug in the code was rather simple.. but I was misleaded
by gdb(1).
--dAmwdVvHu4Pbr2Uwfjp5K6rW7JfRUlAma--
--WWaXSXr4sAsErD96ld8PU3U7uG2kv1kBc
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQIcBAEBCAAGBQJYL9E+AAoJEEuzCOmwLnZsZgYQAJCxWdAQugvsRTPOHn5CkOih
EEhpbqgTdD+DTJA+g8kE+XyldPO6CHThvVZqjqKvlrb2+Ef2WNTTS9u79ERTTLIg
BA9fHQ4ZCvSvYAIpQIOXnKzqWyXPVms9taD8DjKgrVy60Svo9eRp2PadC1+GJYxM
DIRzts5qOK1+i+BGXbMr2GmG8QINhpozNFPXSWd04meij0u+sEx9WuUryVjtIb2y
NIDFQ8AlHHsZwTFL1KcFaikPsAE3rLe1umkrj4BH/gV1CwjRyfm7lMKZiDflPL1j
QUHr8437yHaGlxW10gXDS5txhsD8n7/vyikORHBZoJu1yykjbMnAf0a53NZ7Uxnz
ExGvcnzDRbYYed4Vf8xrPaVU1Cpd/uRgQ3D1kPkIMkkFVEl7dD9x4jC6aD8kn/RV
oaVB3tC4mC6D5YrdVI0AcKDGq3bXcZMycFVAjvuyIMIyDNpKAQCrDHGr/Td9AwHF
JRMaEjE+8++nDkmY7oCZC4ZqmQrvWfodB/dOXkpxmG/S1VMMdGKVgUaiKQRcsJF8
bV73bXOxFhnu4wqSZqDxVrf3TgIs4oCxG6gExr6f40uS5LEvJye+IjlilZknBlWQ
zDlzWdQZvu6zdJEkWT5CMGsiVG06keXQMNr335x/Q3s4SDoXHlYNFuNL1E986vh9
YXzkyUNoTeQIJRtsYsCg
=QDtB
-----END PGP SIGNATURE-----
--WWaXSXr4sAsErD96ld8PU3U7uG2kv1kBc--
From: "Kamil Rytarowski" <kamil@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/51635 CVS commit: src/tests/lib/libpthread_dbg
Date: Sat, 19 Nov 2016 15:13:46 +0000
Module Name: src
Committed By: kamil
Date: Sat Nov 19 15:13:46 UTC 2016
Modified Files:
src/tests/lib/libpthread_dbg: t_dummy.c t_threads.c
Log Message:
Remove atf_tx_expect_fail from lib/libpthread_dbg/ tests
The following PR are now resolved and are reported to be properly fixed:
PR lib/51635 td_thr_iter in <pthread_dbg.h> seems broken
PR lib/51633 tests/lib/libpthread_dbg/t_dummy unreliable
Sponsored by <The NetBSD Foundation>
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libpthread_dbg/t_dummy.c
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libpthread_dbg/t_threads.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->closed
State-Changed-By: kamil@NetBSD.org
State-Changed-When: Sat, 19 Nov 2016 16:15:31 +0100
State-Changed-Why:
Problem resolved.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.