diff options
author | 2002-12-11 23:21:19 +0000 | |
---|---|---|
committer | 2002-12-11 23:21:19 +0000 | |
commit | 701d45da4fcb8a6312f3fffb79a4de78c2c05777 (patch) | |
tree | 3ceeabce38f179af566d7335cf7c3c806fcfe843 /lib/libpthread | |
parent | Convert ctype.h macros into inline functions. This fixes the issues we (diff) | |
download | wireguard-openbsd-701d45da4fcb8a6312f3fffb79a4de78c2c05777.tar.xz wireguard-openbsd-701d45da4fcb8a6312f3fffb79a4de78c2c05777.zip |
add a debugging function not normally called
Diffstat (limited to 'lib/libpthread')
-rw-r--r-- | lib/libpthread/uthread/pthread_private.h | 3 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_info_openbsd.c | 63 |
2 files changed, 63 insertions, 3 deletions
diff --git a/lib/libpthread/uthread/pthread_private.h b/lib/libpthread/uthread/pthread_private.h index a4ab5f48044..83389b6008b 100644 --- a/lib/libpthread/uthread/pthread_private.h +++ b/lib/libpthread/uthread/pthread_private.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pthread_private.h,v 1.39 2002/12/08 04:06:01 marc Exp $ */ +/* $OpenBSD: pthread_private.h,v 1.40 2002/12/11 23:21:19 marc Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>. * All rights reserved. @@ -1095,6 +1095,7 @@ void _waitq_clearactive(void); __dead void _thread_exit(const char *, int, const char *) __attribute__((__noreturn__)); void *_thread_cleanup(pthread_t); void _thread_cleanupspecific(void); +void _thread_dump_data(const void *, int); void _thread_dump_info(void); void _thread_init(void); void _thread_kern_sched(struct sigcontext *); diff --git a/lib/libpthread/uthread/uthread_info_openbsd.c b/lib/libpthread/uthread/uthread_info_openbsd.c index be3423b9ba7..0b7881d6477 100644 --- a/lib/libpthread/uthread/uthread_info_openbsd.c +++ b/lib/libpthread/uthread/uthread_info_openbsd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_info_openbsd.c,v 1.6 2002/10/21 23:10:30 marc Exp $ */ +/* $OpenBSD: uthread_info_openbsd.c,v 1.7 2002/12/11 23:21:19 marc Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> @@ -286,7 +286,7 @@ _thread_dump_entry(pthread, fd, verbose) } break; default: - /* Nothing to do here. */ + /* Nothing to do here. */ break; } } @@ -402,6 +402,65 @@ _thread_dump_info(void) return; } +/* + * Generic "dump some data to /dev/tty in hex format" function + * output format is: + * 0 22 48 + * 0x0123456789abcdef: 00 11 22 33 44 55 66 77 01234567 + */ +#define DUMP_BUFLEN 84 +#define DUMP_HEX_OFF 22 +#define DUMP_ASCII_OFF 48 + +void +_thread_dump_data(const void *addr, int len) +{ + int fd = -1; + unsigned char data[ DUMP_BUFLEN ]; + + if (getenv("PTHREAD_DEBUG") != NULL) + fd = _thread_sys_open(_PATH_TTY, O_WRONLY | O_APPEND); + if (fd != -1) { + memset(data, ' ', DUMP_BUFLEN); + while (len) { + const unsigned char *d; + unsigned char *h; + unsigned char *a; + int count; + + d = addr; + h = &data[DUMP_HEX_OFF]; + a = &data[DUMP_ASCII_OFF]; + + if (len > 8) { + count = 8; + len -= 8; + } else { + count = len; + len = 0; + memset(data, ' ', DUMP_BUFLEN); + } + addr += 8; + + sprintf( data, "%18p: ", d ); + while (count--) { + if (isprint(*d)) + *a++ = *d; + else + *a++ = '.'; + *h++ = "0123456789abcdef"[(*d >> 4) & 0xf]; + *h++ = "0123456789abcdef"[*d++ & 0xf]; + *h++ = ' '; + } + *a++ = '\n'; + *a = 0; + _thread_sys_write(fd, data, a - data); + } + writestring(fd, "\n"); + _thread_sys_close(fd); + } +} + /* Set the thread name for debug: */ void pthread_set_name_np(pthread_t thread, char *name) |