summaryrefslogtreecommitdiff
path: root/lib/libc_r
diff options
context:
space:
mode:
authorMarco S Hyman <marc@cvs.openbsd.org>2002-12-11 23:21:20 +0000
committerMarco S Hyman <marc@cvs.openbsd.org>2002-12-11 23:21:20 +0000
commit3ea968582de7b7ba19dc2d93dc3b8c459a6667f7 (patch)
tree2d59d536466e46caab27ac2eda1826e2890d4e23 /lib/libc_r
parent3d2d0dd6e38a4a646756782494ce94ec825fd594 (diff)
add a debugging function not normally called
Diffstat (limited to 'lib/libc_r')
-rw-r--r--lib/libc_r/uthread/pthread_private.h3
-rw-r--r--lib/libc_r/uthread/uthread_info_openbsd.c63
2 files changed, 63 insertions, 3 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 <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/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 <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)