From 3ea968582de7b7ba19dc2d93dc3b8c459a6667f7 Mon Sep 17 00:00:00 2001 From: Marco S Hyman Date: Wed, 11 Dec 2002 23:21:20 +0000 Subject: add a debugging function not normally called --- lib/libc_r/uthread/pthread_private.h | 3 +- lib/libc_r/uthread/uthread_info_openbsd.c | 63 ++++++++++++++++++++++++++- lib/libpthread/uthread/pthread_private.h | 3 +- lib/libpthread/uthread/uthread_info_openbsd.c | 63 ++++++++++++++++++++++++++- 4 files changed, 126 insertions(+), 6 deletions(-) diff --git a/lib/libc_r/uthread/pthread_private.h b/lib/libc_r/uthread/pthread_private.h index a4ab5f48044..83389b6008b 100644 --- a/lib/libc_r/uthread/pthread_private.h +++ b/lib/libc_r/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 . * 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/libc_r/uthread/uthread_info_openbsd.c b/lib/libc_r/uthread/uthread_info_openbsd.c index be3423b9ba7..0b7881d6477 100644 --- a/lib/libc_r/uthread/uthread_info_openbsd.c +++ b/lib/libc_r/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 @@ -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) 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 . * 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 @@ -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) -- cgit v1.2.3