ddb: new 'show vmem' and 'show all vmems' commands.

Useful to inspect vmem(9) structures.
This commit is contained in:
cegger 2008-12-07 00:51:15 +00:00
parent 74bbb8ef72
commit 10de0e2b14
3 changed files with 80 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_command.c,v 1.124 2008/11/25 15:41:12 nakayama Exp $ */
/* $NetBSD: db_command.c,v 1.125 2008/12/07 00:51:15 cegger Exp $ */
/*
* Mach Operating System
* Copyright (c) 1991,1990 Carnegie Mellon University
@ -58,7 +58,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.124 2008/11/25 15:41:12 nakayama Exp $");
__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.125 2008/12/07 00:51:15 cegger Exp $");
#include "opt_aio.h"
#include "opt_ddb.h"
@ -215,6 +215,8 @@ static void db_uvmexp_print_cmd(db_expr_t, bool, db_expr_t, const char *);
static void db_uvmhist_print_cmd(db_expr_t, bool, db_expr_t, const char *);
#endif
static void db_vnode_print_cmd(db_expr_t, bool, db_expr_t, const char *);
static void db_vmem_print_cmd(db_expr_t, bool, db_expr_t, const char *);
static void db_show_all_vmems(db_expr_t, bool, db_expr_t, const char *);
static const struct db_command db_show_cmds[] = {
/*added from all sub cmds*/
@ -280,6 +282,10 @@ static const struct db_command db_show_cmds[] = {
#endif
{ DDB_ADD_CMD("vnode", db_vnode_print_cmd, 0,
"Print the vnode at address.", "[/f] address",NULL) },
{ DDB_ADD_CMD("vmem", db_vmem_print_cmd, 0,
"Print the vmem usage.", "[/a] address", NULL) },
{ DDB_ADD_CMD("vmems", db_show_all_vmems, 0,
"Show all vmems.", NULL, NULL) },
{ DDB_ADD_CMD("watches", db_listwatch_cmd, 0,
"Display all watchpoints.", NULL,NULL) },
{ DDB_ADD_CMD(NULL, NULL, 0,NULL,NULL,NULL) }
@ -1177,6 +1183,22 @@ db_vnode_print_cmd(db_expr_t addr, bool have_addr,
vfs_vnode_print((struct vnode *)(uintptr_t) addr, full, db_printf);
}
/*ARGSUSED*/
static void
db_vmem_print_cmd(db_expr_t addr, bool have_addr,
db_expr_t count, const char *modif)
{
vmem_print((uintptr_t) addr, modif, db_printf);
}
/*ARGSUSED*/
static void
db_show_all_vmems(db_expr_t addr, bool have_addr,
db_expr_t count, const char *modif)
{
vmem_print((uintptr_t)addr, "a", db_printf);
}
static void
db_mount_print_cmd(db_expr_t addr, bool have_addr,
db_expr_t count, const char *modif)

View File

@ -1,4 +1,4 @@
/* $NetBSD: subr_vmem.c,v 1.42 2008/03/17 08:27:50 yamt Exp $ */
/* $NetBSD: subr_vmem.c,v 1.43 2008/12/07 00:51:15 cegger Exp $ */
/*-
* Copyright (c)2006 YAMAMOTO Takashi,
@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: subr_vmem.c,v 1.42 2008/03/17 08:27:50 yamt Exp $");
__KERNEL_RCSID(0, "$NetBSD: subr_vmem.c,v 1.43 2008/12/07 00:51:15 cegger Exp $");
#define VMEM_DEBUG
#if defined(_KERNEL)
@ -1236,6 +1236,58 @@ vmem_whatis(uintptr_t addr, void (*pr)(const char *, ...))
(bt->bt_type == BT_TYPE_BUSY) ? "allocated" : "free");
}
}
static void
vmem_showall(void (*pr)(const char *, ...))
{
vmem_t *vm;
LIST_FOREACH(vm, &vmem_list, vm_alllist) {
(*pr)("VMEM '%s' at %p\n", vm->vm_name, vm);
if (vm->vm_source)
(*pr)(" VMEM backend '%s' at %p\n",
vm->vm_source->vm_name, vm->vm_source);
}
}
static void
vmem_show(uintptr_t addr, void (*pr)(const char *, ...))
{
vmem_t *vm;
bt_t *bt = NULL;
LIST_FOREACH(vm, &vmem_list, vm_alllist) {
if ((uintptr_t)vm == addr)
goto found;
bt = vmem_whatis_lookup(vm, addr);
if (bt != NULL)
goto found;
}
if (bt == NULL)
return;
found:
(*pr)("VMEM '%s' spans\n", vm->vm_name);
CIRCLEQ_FOREACH(bt, &vm->vm_seglist, bt_seglist) {
(*pr)(" 0x%"PRIx64" - 0x%"PRIx64" %s %s\n",
bt->bt_start, BT_END(bt),
(bt->bt_type == BT_TYPE_SPAN_STATIC) ? "static" : "",
(bt->bt_type == BT_TYPE_BUSY) ? "allocated" : "free");
}
}
void
vmem_print(uintptr_t addr, const char *modif, void (*pr)(const char *, ...))
{
if (modif[0] == 'a') {
vmem_showall(pr);
return;
}
vmem_show(addr, pr);
}
#endif /* defined(DDB) */
#if defined(VMEM_DEBUG)

View File

@ -1,4 +1,4 @@
/* $NetBSD: vmem.h,v 1.8 2007/12/13 02:45:10 yamt Exp $ */
/* $NetBSD: vmem.h,v 1.9 2008/12/07 00:51:15 cegger Exp $ */
/*-
* Copyright (c)2006 YAMAMOTO Takashi,
@ -58,6 +58,7 @@ vmem_size_t vmem_roundup_size(vmem_t *, vmem_size_t);
bool vmem_reap(vmem_t *);
void vmem_rehash_start(void);
void vmem_whatis(uintptr_t, void (*)(const char *, ...));
void vmem_print(uintptr_t, const char *, void (*)(const char *, ...));
/* vm_flag_t */
#define VM_SLEEP 0x00000001