xref: /titanic_44/usr/src/cmd/mdb/i86pc/modules/unix/unix.c (revision fb3fb4f3d76d55b64440afd0af72775dfad3bd1d)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <mdb/mdb_modapi.h>
30 #include <mdb/mdb_ctf.h>
31 #include <sys/cpuvar.h>
32 #include <sys/systm.h>
33 #include <sys/traptrace.h>
34 #include <sys/avintr.h>
35 #include <sys/systm.h>
36 #include <sys/trap.h>
37 #include <sys/mutex.h>
38 #include <sys/mutex_impl.h>
39 #include "i86mmu.h"
40 
41 #define	TT_HDLR_WIDTH	17
42 
43 static int
44 ttrace_ttr_size_check(void)
45 {
46 	mdb_ctf_id_t ttrtid;
47 	ssize_t ttr_size;
48 
49 	if (mdb_ctf_lookup_by_name("trap_trace_rec_t", &ttrtid) != 0 ||
50 	    mdb_ctf_type_resolve(ttrtid, &ttrtid) != 0) {
51 		mdb_warn("failed to determine size of trap_trace_rec_t; "
52 		    "non-TRAPTRACE kernel?\n");
53 		return (0);
54 	}
55 
56 	if ((ttr_size = mdb_ctf_type_size(ttrtid)) !=
57 	    sizeof (trap_trace_rec_t)) {
58 		/*
59 		 * On Intel machines, this will happen when TTR_STACK_DEPTH
60 		 * is changed.  This code could be smarter, and could
61 		 * dynamically adapt to different depths, but not until a
62 		 * need for such adaptation is demonstrated.
63 		 */
64 		mdb_warn("size of trap_trace_rec_t (%d bytes) doesn't "
65 		    "match expected %d\n", ttr_size, sizeof (trap_trace_rec_t));
66 		return (0);
67 	}
68 
69 	return (1);
70 }
71 
72 int
73 ttrace_walk_init(mdb_walk_state_t *wsp)
74 {
75 	trap_trace_ctl_t *ttcp;
76 	size_t ttc_size = sizeof (trap_trace_ctl_t) * NCPU;
77 	int i;
78 
79 	if (!ttrace_ttr_size_check())
80 		return (WALK_ERR);
81 
82 	ttcp = mdb_zalloc(ttc_size, UM_SLEEP);
83 
84 	if (wsp->walk_addr != NULL) {
85 		mdb_warn("ttrace only supports global walks\n");
86 		return (WALK_ERR);
87 	}
88 
89 	if (mdb_readsym(ttcp, ttc_size, "trap_trace_ctl") == -1) {
90 		mdb_warn("symbol 'trap_trace_ctl' not found; "
91 		    "non-TRAPTRACE kernel?\n");
92 		mdb_free(ttcp, ttc_size);
93 		return (WALK_ERR);
94 	}
95 
96 	/*
97 	 * We'll poach the ttc_current pointer (which isn't used for
98 	 * anything) to store a pointer to our current TRAPTRACE record.
99 	 * This allows us to only keep the array of trap_trace_ctl structures
100 	 * as our walker state (ttc_current may be the only kernel data
101 	 * structure member added exclusively to make writing the mdb walker
102 	 * a little easier).
103 	 */
104 	for (i = 0; i < NCPU; i++) {
105 		trap_trace_ctl_t *ttc = &ttcp[i];
106 
107 		if (ttc->ttc_first == NULL)
108 			continue;
109 
110 		/*
111 		 * Assign ttc_current to be the last completed record.
112 		 * Note that the error checking (i.e. in the ttc_next ==
113 		 * ttc_first case) is performed in the step function.
114 		 */
115 		ttc->ttc_current = ttc->ttc_next - sizeof (trap_trace_rec_t);
116 	}
117 
118 	wsp->walk_data = ttcp;
119 	return (WALK_NEXT);
120 }
121 
122 int
123 ttrace_walk_step(mdb_walk_state_t *wsp)
124 {
125 	trap_trace_ctl_t *ttcp = wsp->walk_data, *ttc, *latest_ttc;
126 	trap_trace_rec_t rec;
127 	int rval, i, recsize = sizeof (trap_trace_rec_t);
128 	hrtime_t latest = 0;
129 
130 	/*
131 	 * Loop through the CPUs, looking for the latest trap trace record
132 	 * (we want to walk through the trap trace records in reverse
133 	 * chronological order).
134 	 */
135 	for (i = 0; i < NCPU; i++) {
136 		ttc = &ttcp[i];
137 
138 		if (ttc->ttc_current == NULL)
139 			continue;
140 
141 		if (ttc->ttc_current < ttc->ttc_first)
142 			ttc->ttc_current = ttc->ttc_limit - recsize;
143 
144 		if (mdb_vread(&rec, sizeof (rec), ttc->ttc_current) == -1) {
145 			mdb_warn("couldn't read rec at %p", ttc->ttc_current);
146 			return (WALK_ERR);
147 		}
148 
149 		if (rec.ttr_stamp > latest) {
150 			latest = rec.ttr_stamp;
151 			latest_ttc = ttc;
152 		}
153 	}
154 
155 	if (latest == 0)
156 		return (WALK_DONE);
157 
158 	ttc = latest_ttc;
159 
160 	if (mdb_vread(&rec, sizeof (rec), ttc->ttc_current) == -1) {
161 		mdb_warn("couldn't read rec at %p", ttc->ttc_current);
162 		return (WALK_ERR);
163 	}
164 
165 	rval = wsp->walk_callback(ttc->ttc_current, &rec, wsp->walk_cbdata);
166 
167 	if (ttc->ttc_current == ttc->ttc_next)
168 		ttc->ttc_current = NULL;
169 	else
170 		ttc->ttc_current -= sizeof (trap_trace_rec_t);
171 
172 	return (rval);
173 }
174 
175 void
176 ttrace_walk_fini(mdb_walk_state_t *wsp)
177 {
178 	mdb_free(wsp->walk_data, sizeof (trap_trace_ctl_t) * NCPU);
179 }
180 
181 static int
182 ttrace_syscall(trap_trace_rec_t *rec)
183 {
184 	GElf_Sym sym;
185 	int sysnum = rec->ttr_sysnum;
186 	uintptr_t addr;
187 	struct sysent sys;
188 
189 	mdb_printf("%s%-*x", sysnum < 0x10 ? " " : "",
190 	    sysnum < 0x10 ? 2 : 3, sysnum);
191 
192 	if (rec->ttr_sysnum > NSYSCALL) {
193 		mdb_printf("%-*d", TT_HDLR_WIDTH, rec->ttr_sysnum);
194 		return (0);
195 	}
196 
197 	if (mdb_lookup_by_name("sysent", &sym) == -1) {
198 		mdb_warn("\ncouldn't find 'sysent'");
199 		return (-1);
200 	}
201 
202 	addr = (uintptr_t)sym.st_value + sysnum * sizeof (struct sysent);
203 
204 	if (addr >= (uintptr_t)sym.st_value + sym.st_size) {
205 		mdb_warn("\nsysnum %d out-of-range\n", sysnum);
206 		return (-1);
207 	}
208 
209 	if (mdb_vread(&sys, sizeof (sys), addr) == -1) {
210 		mdb_warn("\nfailed to read sysent at %p", addr);
211 		return (-1);
212 	}
213 
214 	mdb_printf("%-*a", TT_HDLR_WIDTH, sys.sy_callc);
215 
216 	return (0);
217 }
218 
219 static int
220 ttrace_interrupt(trap_trace_rec_t *rec)
221 {
222 	GElf_Sym sym;
223 	uintptr_t addr;
224 	struct av_head hd;
225 	struct autovec av;
226 
227 	if (rec->ttr_regs.r_trapno == T_SOFTINT) {
228 		mdb_printf("%2s %-*s", "-", TT_HDLR_WIDTH, "(fakesoftint)");
229 		return (0);
230 	}
231 
232 	mdb_printf("%2x ", rec->ttr_vector);
233 
234 	if (mdb_lookup_by_name("autovect", &sym) == -1) {
235 		mdb_warn("\ncouldn't find 'autovect'");
236 		return (-1);
237 	}
238 
239 	addr = (uintptr_t)sym.st_value +
240 	    rec->ttr_vector * sizeof (struct av_head);
241 
242 	if (addr >= (uintptr_t)sym.st_value + sym.st_size) {
243 		mdb_warn("\nav_head for vec %x is corrupt\n", rec->ttr_vector);
244 		return (-1);
245 	}
246 
247 	if (mdb_vread(&hd, sizeof (hd), addr) == -1) {
248 		mdb_warn("\ncouldn't read av_head for vec %x", rec->ttr_vector);
249 		return (-1);
250 	}
251 
252 	if (hd.avh_link == NULL) {
253 		mdb_printf("%-*s", TT_HDLR_WIDTH, "(spurious)");
254 	} else {
255 		if (mdb_vread(&av, sizeof (av), (uintptr_t)hd.avh_link) == -1) {
256 			mdb_warn("couldn't read autovec at %p",
257 			    (uintptr_t)hd.avh_link);
258 		}
259 
260 		mdb_printf("%-*a", TT_HDLR_WIDTH, av.av_vector);
261 	}
262 
263 	return (0);
264 }
265 
266 static struct {
267 	int tt_trapno;
268 	char *tt_name;
269 } ttrace_traps[] = {
270 	{ T_ZERODIV,	"divide-error" },
271 	{ T_SGLSTP,	"debug-exception" },
272 	{ T_NMIFLT,	"nmi-interrupt" },
273 	{ T_BPTFLT,	"breakpoint" },
274 	{ T_OVFLW,	"into-overflow" },
275 	{ T_BOUNDFLT,	"bound-exceeded" },
276 	{ T_ILLINST,	"invalid-opcode" },
277 	{ T_NOEXTFLT,	"device-not-avail" },
278 	{ T_DBLFLT,	"double-fault" },
279 	{ T_EXTOVRFLT,	"segment-overrun" },
280 	{ T_TSSFLT,	"invalid-tss" },
281 	{ T_SEGFLT,	"segment-not-pres" },
282 	{ T_STKFLT,	"stack-fault" },
283 	{ T_GPFLT,	"general-protectn" },
284 	{ T_PGFLT,	"page-fault" },
285 	{ T_EXTERRFLT,	"error-fault" },
286 	{ T_ALIGNMENT,	"alignment-check" },
287 	{ T_MCE,	"machine-check" },
288 	{ T_SIMDFPE,	"sse-exception" },
289 	{ 0,		NULL }
290 };
291 
292 static int
293 ttrace_trap(trap_trace_rec_t *rec)
294 {
295 	int i;
296 
297 	mdb_printf("%2x ", rec->ttr_regs.r_trapno);
298 
299 	for (i = 0; ttrace_traps[i].tt_name != NULL; i++) {
300 		if (rec->ttr_regs.r_trapno == ttrace_traps[i].tt_trapno)
301 			break;
302 	}
303 
304 	if (ttrace_traps[i].tt_name == NULL)
305 		mdb_printf("%-*s", TT_HDLR_WIDTH, "(unknown)");
306 	else
307 		mdb_printf("%-*s", TT_HDLR_WIDTH, ttrace_traps[i].tt_name);
308 
309 	return (0);
310 }
311 
312 static struct {
313 	uchar_t t_marker;
314 	char *t_name;
315 	int (*t_hdlr)(trap_trace_rec_t *);
316 } ttrace_hdlr[] = {
317 	{ TT_SYSCALL, "sysc", ttrace_syscall },
318 	{ TT_SYSENTER, "syse", ttrace_syscall },
319 	{ TT_SYSC, "asys", ttrace_syscall },
320 	{ TT_SYSC64, "sc64", ttrace_syscall },
321 	{ TT_INTERRUPT, "intr", ttrace_interrupt },
322 	{ TT_TRAP, "trap", ttrace_trap },
323 	{ 0, NULL, NULL }
324 };
325 
326 typedef struct ttrace_dcmd {
327 	processorid_t ttd_cpu;
328 	uint_t ttd_extended;
329 	trap_trace_ctl_t ttd_ttc[NCPU];
330 } ttrace_dcmd_t;
331 
332 #if defined(__amd64)
333 
334 #define	DUMP(reg) #reg, regs->r_##reg
335 #define	THREEREGS	"         %3s: %16lx %3s: %16lx %3s: %16lx\n"
336 #define	TWOREGS		"         %3s: %16lx %3s: %16lx\n"
337 
338 static void
339 ttrace_dumpregs(trap_trace_rec_t *rec)
340 {
341 	struct regs *regs = &rec->ttr_regs;
342 
343 	mdb_printf(THREEREGS, DUMP(rdi), DUMP(rsi), DUMP(rdx));
344 	mdb_printf(THREEREGS, DUMP(rcx), DUMP(r8), DUMP(r9));
345 	mdb_printf(THREEREGS, DUMP(rax), DUMP(rbx), DUMP(rbp));
346 	mdb_printf(THREEREGS, DUMP(r10), DUMP(r11), DUMP(r12));
347 	mdb_printf(THREEREGS, DUMP(r13), DUMP(r14), DUMP(r15));
348 	mdb_printf(THREEREGS, "fsb", regs->r_fsbase, "gsb", regs->r_gsbase,
349 	    DUMP(ds));
350 	mdb_printf(THREEREGS, DUMP(es), DUMP(fs), DUMP(gs));
351 	mdb_printf(THREEREGS, "trp", regs->r_trapno, DUMP(err), DUMP(rip));
352 	mdb_printf(THREEREGS, DUMP(cs), DUMP(rfl), DUMP(rsp));
353 	mdb_printf(TWOREGS, DUMP(ss), "cr2", rec->ttr_cr2);
354 	mdb_printf("\n");
355 }
356 
357 #else
358 
359 #define	DUMP(reg) #reg, regs->r_##reg
360 #define	FOURREGS	"         %3s: %08x %3s: %08x %3s: %08x %3s: %08x\n"
361 
362 static void
363 ttrace_dumpregs(trap_trace_rec_t *rec)
364 {
365 	struct regs *regs = &rec->ttr_regs;
366 
367 	mdb_printf(FOURREGS, DUMP(gs), DUMP(fs), DUMP(es), DUMP(ds));
368 	mdb_printf(FOURREGS, DUMP(edi), DUMP(esi), DUMP(ebp), DUMP(esp));
369 	mdb_printf(FOURREGS, DUMP(ebx), DUMP(edx), DUMP(ecx), DUMP(eax));
370 	mdb_printf(FOURREGS, "trp", regs->r_trapno, DUMP(err),
371 	    DUMP(pc), DUMP(cs));
372 	mdb_printf(FOURREGS, DUMP(efl), "usp", regs->r_uesp, DUMP(ss),
373 	    "cr2", rec->ttr_cr2);
374 	mdb_printf("\n");
375 }
376 
377 #endif	/* __amd64 */
378 
379 int
380 ttrace_walk(uintptr_t addr, trap_trace_rec_t *rec, ttrace_dcmd_t *dcmd)
381 {
382 	struct regs *regs = &rec->ttr_regs;
383 	processorid_t cpu = -1, i;
384 
385 	for (i = 0; i < NCPU; i++) {
386 		if (addr >= dcmd->ttd_ttc[i].ttc_first &&
387 		    addr < dcmd->ttd_ttc[i].ttc_limit) {
388 			cpu = i;
389 			break;
390 		}
391 	}
392 
393 	if (cpu == -1) {
394 		mdb_warn("couldn't find %p in any trap trace ctl\n", addr);
395 		return (WALK_ERR);
396 	}
397 
398 	if (dcmd->ttd_cpu != -1 && cpu != dcmd->ttd_cpu)
399 		return (WALK_NEXT);
400 
401 	mdb_printf("%3d %15llx ", cpu, rec->ttr_stamp);
402 
403 	for (i = 0; ttrace_hdlr[i].t_hdlr != NULL; i++) {
404 		if (rec->ttr_marker != ttrace_hdlr[i].t_marker)
405 			continue;
406 		mdb_printf("%4s ", ttrace_hdlr[i].t_name);
407 		if (ttrace_hdlr[i].t_hdlr(rec) == -1)
408 			return (WALK_ERR);
409 	}
410 
411 	mdb_printf("%a\n", regs->r_pc);
412 
413 	if (dcmd->ttd_extended == FALSE)
414 		return (WALK_NEXT);
415 
416 	ttrace_dumpregs(rec);
417 
418 	if (rec->ttr_sdepth > 0) {
419 		for (i = 0; i < rec->ttr_sdepth; i++) {
420 			if (i >= TTR_STACK_DEPTH) {
421 				mdb_printf("%17s*** invalid ttr_sdepth (is %d, "
422 				    "should be <= %d)\n", " ", rec->ttr_sdepth,
423 				    TTR_STACK_DEPTH);
424 				break;
425 			}
426 
427 			mdb_printf("%17s %a()\n", " ", rec->ttr_stack[i]);
428 		}
429 		mdb_printf("\n");
430 	}
431 
432 	return (WALK_NEXT);
433 }
434 
435 int
436 ttrace(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
437 {
438 	ttrace_dcmd_t dcmd;
439 	trap_trace_ctl_t *ttc = dcmd.ttd_ttc;
440 	trap_trace_rec_t rec;
441 	size_t ttc_size = sizeof (trap_trace_ctl_t) * NCPU;
442 
443 	if (!ttrace_ttr_size_check())
444 		return (WALK_ERR);
445 
446 	bzero(&dcmd, sizeof (dcmd));
447 	dcmd.ttd_cpu = -1;
448 	dcmd.ttd_extended = FALSE;
449 
450 	if (mdb_readsym(ttc, ttc_size, "trap_trace_ctl") == -1) {
451 		mdb_warn("symbol 'trap_trace_ctl' not found; "
452 		    "non-TRAPTRACE kernel?\n");
453 		return (DCMD_ERR);
454 	}
455 
456 	if (mdb_getopts(argc, argv,
457 	    'x', MDB_OPT_SETBITS, TRUE, &dcmd.ttd_extended, NULL) != argc)
458 		return (DCMD_USAGE);
459 
460 	if (DCMD_HDRSPEC(flags)) {
461 		mdb_printf("%3s %15s %4s %2s %-*s%s\n", "CPU",
462 		    "TIMESTAMP", "TYPE", "VC", TT_HDLR_WIDTH, "HANDLER",
463 		    "EIP");
464 	}
465 
466 	if (flags & DCMD_ADDRSPEC) {
467 		if (addr >= NCPU) {
468 			if (mdb_vread(&rec, sizeof (rec), addr) == -1) {
469 				mdb_warn("couldn't read trap trace record "
470 				    "at %p", addr);
471 				return (DCMD_ERR);
472 			}
473 
474 			if (ttrace_walk(addr, &rec, &dcmd) == WALK_ERR)
475 				return (DCMD_ERR);
476 
477 			return (DCMD_OK);
478 		}
479 		dcmd.ttd_cpu = addr;
480 	}
481 
482 	if (mdb_walk("ttrace", (mdb_walk_cb_t)ttrace_walk, &dcmd) == -1) {
483 		mdb_warn("couldn't walk 'ttrace'");
484 		return (DCMD_ERR);
485 	}
486 
487 	return (DCMD_OK);
488 }
489 
490 /*ARGSUSED*/
491 int
492 mutex_owner_init(mdb_walk_state_t *wsp)
493 {
494 	return (WALK_NEXT);
495 }
496 
497 int
498 mutex_owner_step(mdb_walk_state_t *wsp)
499 {
500 	uintptr_t addr = wsp->walk_addr;
501 	mutex_impl_t mtx;
502 	uintptr_t owner;
503 	kthread_t thr;
504 
505 	if (mdb_vread(&mtx, sizeof (mtx), addr) == -1)
506 		return (WALK_ERR);
507 
508 	if (!MUTEX_TYPE_ADAPTIVE(&mtx))
509 		return (WALK_DONE);
510 
511 	if ((owner = (uintptr_t)MUTEX_OWNER(&mtx)) == NULL)
512 		return (WALK_DONE);
513 
514 	if (mdb_vread(&thr, sizeof (thr), owner) != -1)
515 		(void) wsp->walk_callback(owner, &thr, wsp->walk_cbdata);
516 
517 	return (WALK_DONE);
518 }
519 
520 static void
521 gate_desc_dump(gate_desc_t *gate, const char *label, int header)
522 {
523 	const char *lastnm;
524 	uint_t lastval;
525 	char type[4];
526 
527 	switch (gate->sgd_type) {
528 	case SDT_SYSIGT:
529 		strcpy(type, "int");
530 		break;
531 	case SDT_SYSTGT:
532 		strcpy(type, "trp");
533 		break;
534 	case SDT_SYSTASKGT:
535 		strcpy(type, "tsk");
536 		break;
537 	default:
538 		(void) mdb_snprintf(type, sizeof (type), "%3x", gate->sgd_type);
539 	}
540 
541 #if defined(__amd64)
542 	lastnm = "IST";
543 	lastval = gate->sgd_ist;
544 #else
545 	lastnm = "STK";
546 	lastval = gate->sgd_stkcpy;
547 #endif
548 
549 	if (header) {
550 		mdb_printf("%*s%<u>%-30s%</u> %<u>%-4s%</u> %<u>%3s%</u> "
551 		    "%<u>%1s%</u> %<u>%3s%</u> %<u>%3s%</u>\n", strlen(label),
552 		    "", "HANDLER", "SEL", "DPL", "P", "TYP", lastnm);
553 	}
554 
555 	mdb_printf("%s", label);
556 
557 	if (gate->sgd_type == SDT_SYSTASKGT)
558 		mdb_printf("%-30s ", "-");
559 	else
560 		mdb_printf("%-30a ", GATESEG_GETOFFSET(gate));
561 
562 	mdb_printf("%4x  %d  %c %3s %2x\n", gate->sgd_selector,
563 	    gate->sgd_dpl, (gate->sgd_p ? '+' : ' '), type, lastval);
564 }
565 
566 /*ARGSUSED*/
567 static int
568 gate_desc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
569 {
570 	gate_desc_t gate;
571 
572 	if (argc != 0 || !(flags & DCMD_ADDRSPEC))
573 		return (DCMD_USAGE);
574 
575 	if (mdb_vread(&gate, sizeof (gate_desc_t), addr) !=
576 	    sizeof (gate_desc_t)) {
577 		mdb_warn("failed to read gate descriptor at %p\n", addr);
578 		return (DCMD_ERR);
579 	}
580 
581 	gate_desc_dump(&gate, "", DCMD_HDRSPEC(flags));
582 
583 	return (DCMD_OK);
584 }
585 
586 /*ARGSUSED*/
587 static int
588 idt(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
589 {
590 	int i;
591 
592 	if (!(flags & DCMD_ADDRSPEC)) {
593 		GElf_Sym idt;
594 
595 		if (mdb_lookup_by_name("idt0", &idt) < 0) {
596 			mdb_warn("failed to find idt0");
597 			return (DCMD_ERR);
598 		}
599 
600 		addr = idt.st_value;
601 	}
602 
603 	for (i = 0; i < NIDT; i++, addr += sizeof (gate_desc_t)) {
604 		gate_desc_t gate;
605 		char label[6];
606 
607 		if (mdb_vread(&gate, sizeof (gate_desc_t), addr) !=
608 		    sizeof (gate_desc_t)) {
609 			mdb_warn("failed to read gate descriptor at %p\n",
610 			    addr);
611 			return (DCMD_ERR);
612 		}
613 
614 		(void) mdb_snprintf(label, sizeof (label), "%3d: ", i);
615 		gate_desc_dump(&gate, label, i == 0);
616 	}
617 
618 	return (DCMD_OK);
619 }
620 
621 static const mdb_dcmd_t dcmds[] = {
622 	{ "gate_desc", ":", "dump a gate descriptor", gate_desc },
623 	{ "idt", ":[-v]", "dump an IDT", idt },
624 	{ "ttrace", "[-x]", "dump trap trace buffers", ttrace },
625 	{ "vatopfn", ":[-a as]", "translate address to physical page",
626 	    va2pfn_dcmd },
627 	{ "report_maps", "", "Given PFN, report mappings / page table usage",
628 	    report_maps_dcmd },
629 	{ "ptable", "", "Dump contents of a page table", ptable_dcmd },
630 	{ "pte", ":[-p XXXXX] [-l N]", "print human readable page table entry",
631 	    pte_dcmd },
632 	{ "page_num2pp", ":", "page frame number to page structure",
633 	    page_num2pp },
634 	{ "memseg_list", ":", "show memseg list", memseg_list },
635 	{ NULL }
636 };
637 
638 static const mdb_walker_t walkers[] = {
639 	{ "ttrace", "walks trap trace buffers in reverse chronological order",
640 		ttrace_walk_init, ttrace_walk_step, ttrace_walk_fini },
641 	{ "mutex_owner", "walks the owner of a mutex",
642 		mutex_owner_init, mutex_owner_step },
643 	{ "memseg", "walk the memseg structures",
644 		memseg_walk_init, memseg_walk_step, memseg_walk_fini },
645 	{ NULL }
646 };
647 
648 static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, walkers };
649 
650 const mdb_modinfo_t *
651 _mdb_init(void)
652 {
653 	return (&modinfo);
654 }
655