Sun Nov 20 02:27:56 2016 UTC ()
Fix pt_magic (part of pthread_t) read in td_thr_info()

The pt_magic field is not the first one in the pthread_t structure.
After this fix, this code is confirmed to work and function td_thr_info()
is functional.

Sponsored by <The NetBSD Foundation>


(kamil)
diff -r1.44 -r1.45 src/lib/libpthread_dbg/pthread_dbg.c

cvs diff -r1.44 -r1.45 src/lib/libpthread_dbg/Attic/pthread_dbg.c (expand / switch to unified diff)

--- src/lib/libpthread_dbg/Attic/pthread_dbg.c 2016/01/23 14:02:21 1.44
+++ src/lib/libpthread_dbg/Attic/pthread_dbg.c 2016/11/20 02:27:56 1.45
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pthread_dbg.c,v 1.44 2016/01/23 14:02:21 christos Exp $ */ 1/* $NetBSD: pthread_dbg.c,v 1.45 2016/11/20 02:27:56 kamil Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2002 Wasabi Systems, Inc. 4 * Copyright (c) 2002 Wasabi Systems, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Written by Nathan J. Williams for Wasabi Systems, Inc. 7 * Written by Nathan J. Williams for Wasabi Systems, Inc.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -26,27 +26,27 @@ @@ -26,27 +26,27 @@
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE. 35 * POSSIBILITY OF SUCH DAMAGE.
36 */ 36 */
37 37
38#include <sys/cdefs.h> 38#include <sys/cdefs.h>
39__RCSID("$NetBSD: pthread_dbg.c,v 1.44 2016/01/23 14:02:21 christos Exp $"); 39__RCSID("$NetBSD: pthread_dbg.c,v 1.45 2016/11/20 02:27:56 kamil Exp $");
40 40
41#define __EXPOSE_STACK 1 41#define __EXPOSE_STACK 1
42 42
43#include <sys/param.h> 43#include <sys/param.h>
44#include <sys/types.h> 44#include <sys/types.h>
45#include <sys/lock.h> 45#include <sys/lock.h>
46 46
47#include <stddef.h> 47#include <stddef.h>
48#include <stdlib.h> 48#include <stdlib.h>
49#include <string.h> 49#include <string.h>
50#include <errno.h> 50#include <errno.h>
51#include <unistd.h> 51#include <unistd.h>
52#include <lwp.h> 52#include <lwp.h>
@@ -200,27 +200,27 @@ td_thr_iter(td_proc_t *proc, int (*call) @@ -200,27 +200,27 @@ td_thr_iter(td_proc_t *proc, int (*call)
200 next + offsetof(struct __pthread_st, pt_allq.ptqe_next),  200 next + offsetof(struct __pthread_st, pt_allq.ptqe_next),
201 &next, sizeof(next)); 201 &next, sizeof(next));
202 if (val != 0) 202 if (val != 0)
203 return val; 203 return val;
204 } 204 }
205 return 0; 205 return 0;
206} 206}
207 207
208int 208int
209td_thr_info(td_thread_t *thread, td_thread_info_t *info) 209td_thr_info(td_thread_t *thread, td_thread_info_t *info)
210{ 210{
211 int tmp, val; 211 int tmp, val;
212 212
213 val = READ(thread->proc, thread->addr, &tmp, sizeof(tmp)); 213 val = READ(thread->proc, OFFSET(thread, pt_magic), &tmp, sizeof(tmp));
214 if (val != 0) 214 if (val != 0)
215 return val; 215 return val;
216 216
217 if (tmp != PT_MAGIC) 217 if (tmp != PT_MAGIC)
218 return TD_ERR_BADTHREAD; 218 return TD_ERR_BADTHREAD;
219 219
220 info->thread_addr = thread->addr; 220 info->thread_addr = thread->addr;
221 if ((val = READ(thread->proc, 221 if ((val = READ(thread->proc,
222 OFFSET(thread, pt_state), &tmp, sizeof(tmp))) != 0) 222 OFFSET(thread, pt_state), &tmp, sizeof(tmp))) != 0)
223 return val; 223 return val;
224 switch (tmp) { 224 switch (tmp) {
225 case PT_STATE_RUNNING: 225 case PT_STATE_RUNNING:
226 info->thread_state = TD_STATE_RUNNING; 226 info->thread_state = TD_STATE_RUNNING;