diff options
author | 2000-06-07 11:21:39 +0000 | |
---|---|---|
committer | 2000-06-07 11:21:39 +0000 | |
commit | e37c6774de708ece1600456f420eea22d75979b9 (patch) | |
tree | 808742f62ca229e772b77be32a4cf39b37d9617f /sys/kern/kern_malloc_debug.c | |
parent | Document how 'show malloc' in ddb can be used to find out what went wrong. (diff) | |
download | wireguard-openbsd-e37c6774de708ece1600456f420eea22d75979b9.tar.xz wireguard-openbsd-e37c6774de708ece1600456f420eea22d75979b9.zip |
Allow passing an address to 'show malloc' and print out some information about
that address.
Diffstat (limited to 'sys/kern/kern_malloc_debug.c')
-rw-r--r-- | sys/kern/kern_malloc_debug.c | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/sys/kern/kern_malloc_debug.c b/sys/kern/kern_malloc_debug.c index 318fd87d5e6..30f06cafbab 100644 --- a/sys/kern/kern_malloc_debug.c +++ b/sys/kern/kern_malloc_debug.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_malloc_debug.c,v 1.4 2000/06/07 09:38:46 art Exp $ */ +/* $OpenBSD: kern_malloc_debug.c,v 1.5 2000/06/07 11:21:40 art Exp $ */ /* * Copyright (c) 1999, 2000 Artur Grabowski <art@openbsd.org> @@ -92,7 +92,7 @@ void debug_malloc_init __P((void)); void malloc_deb_allocate_free __P((int)); void debug_malloc_print __P((void)); -void debug_malloc_printit __P((int (*) __P((const char *, ...)))); +void debug_malloc_printit __P((int (*) __P((const char *, ...)), vaddr_t)); struct malloc_deb_entry { TAILQ_ENTRY(malloc_deb_entry) md_list; @@ -294,15 +294,39 @@ malloc_deb_allocate_free(wait) void debug_malloc_print() { - debug_malloc_printit(printf); + debug_malloc_printit(printf, NULL); } void -debug_malloc_printit(pr) +debug_malloc_printit(pr, addr) int (*pr) __P((const char *, ...)); + vaddr_t addr; { struct malloc_deb_entry *md; + if (addr) { + TAILQ_FOREACH(md, &malloc_deb_free, md_list) { + if (addr >= md->md_va && + addr < md->md_va + 2 * PAGE_SIZE) { + (*pr)("Memory at address 0x%x is in a freed " + "area. type %d, size: %d\n ", + addr, md->md_type, md->md_size); + return; + } + } + TAILQ_FOREACH(md, &malloc_deb_used, md_list) { + if (addr >= md->md_va + PAGE_SIZE && + addr < md->md_va + 2 * PAGE_SIZE) { + (*pr)("Memory at address 0x%x is just outside " + "an allocated area. type %d, size: %d\n", + addr, md->md_type, md->md_size); + return; + } + } + (*pr)("Memory at address 0x%x is outside debugged malloc.\n"); + return; + } + (*pr)("allocs: %d\n", malloc_deb_allocs); (*pr)("frees: %d\n", malloc_deb_frees); (*pr)("pages used: %d\n", malloc_deb_pages); @@ -311,10 +335,12 @@ debug_malloc_printit(pr) (*pr)("\taddr:\tsize:\n"); (*pr)("free chunks:\n"); TAILQ_FOREACH(md, &malloc_deb_free, md_list) - (*pr)("\t0x%x\t0x%x\t%d\n", md->md_va, md->md_size, md->md_type); + (*pr)("\t0x%x\t0x%x\t%d\n", md->md_va, md->md_size, + md->md_type); (*pr)("used chunks:\n"); TAILQ_FOREACH(md, &malloc_deb_used, md_list) - (*pr)("\t0x%x\t0x%x\t%d\n", md->md_va, md->md_size, md->md_type); + (*pr)("\t0x%x\t0x%x\t%d\n", md->md_va, md->md_size, + md->md_type); } |