diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 2000-06-07 11:21:41 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 2000-06-07 11:21:41 +0000 |
commit | 3ffe6ff5a6808c0fecd79ee4aaac31ad54e81cd4 (patch) | |
tree | 235afa9354c0592848f84b10de4b06368e329dba | |
parent | d5c249313af9993f2ab7eab93a410fbd8d3422d9 (diff) |
Allow passing an address to 'show malloc' and print out some information about
that address.
-rw-r--r-- | sys/ddb/db_command.c | 9 | ||||
-rw-r--r-- | sys/kern/kern_malloc_debug.c | 38 |
2 files changed, 38 insertions, 9 deletions
diff --git a/sys/ddb/db_command.c b/sys/ddb/db_command.c index dbde7a1ffed..d9c38757241 100644 --- a/sys/ddb/db_command.c +++ b/sys/ddb/db_command.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_command.c,v 1.18 2000/06/07 09:40:02 art Exp $ */ +/* $OpenBSD: db_command.c,v 1.19 2000/06/07 11:21:39 art Exp $ */ /* $NetBSD: db_command.c,v 1.20 1996/03/30 22:30:05 christos Exp $ */ /* @@ -310,9 +310,12 @@ db_malloc_print_cmd(addr, have_addr, count, modif) char * modif; { #if defined(MALLOC_DEBUG) - extern void debug_malloc_printit __P((int (*) __P((const char *, ...)))); + extern void debug_malloc_printit __P((int (*) __P((const char *, ...)), vaddr_t)); - debug_malloc_printit(db_printf); + if (!have_addr) + addr = 0; + + debug_malloc_printit(db_printf, (vaddr_t)addr); #else db_printf("Malloc debugging not enabled.\n"); #endif 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); } |