1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*
28*7c478bd9Sstevel@tonic-gate  * (k)adb Macro Aliases
29*7c478bd9Sstevel@tonic-gate  *
30*7c478bd9Sstevel@tonic-gate  * Provides aliases for popular ADB macros.  These macros, which have been
31*7c478bd9Sstevel@tonic-gate  * removed from the workspace, were documented in various locations, and need
32*7c478bd9Sstevel@tonic-gate  * continued support.  While we don't provide the same output format that was
33*7c478bd9Sstevel@tonic-gate  * provided by the original macros, we do map the macro names to the equivalent
34*7c478bd9Sstevel@tonic-gate  * MDB functionality.
35*7c478bd9Sstevel@tonic-gate  */
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_debug.h>
38*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_nv.h>
39*7c478bd9Sstevel@tonic-gate #include <mdb/mdb.h>
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate typedef struct mdb_macalias {
42*7c478bd9Sstevel@tonic-gate 	const char *ma_name;
43*7c478bd9Sstevel@tonic-gate 	const char *ma_defn;
44*7c478bd9Sstevel@tonic-gate } mdb_macalias_t;
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate static const mdb_macalias_t mdb_macaliases[] = {
47*7c478bd9Sstevel@tonic-gate 	{ "bufctl",		"::bufctl" },
48*7c478bd9Sstevel@tonic-gate 	{ "bufctl_audit",	"::bufctl -v" },
49*7c478bd9Sstevel@tonic-gate 	{ "cpu",		"::cpuinfo -v" },
50*7c478bd9Sstevel@tonic-gate 	{ "cpun",		"::cpuinfo -v" },
51*7c478bd9Sstevel@tonic-gate 	{ "cpus",		"::walk cpu |::cpuinfo -v" },
52*7c478bd9Sstevel@tonic-gate 	{ "devinfo",		"::print struct dev_info" },
53*7c478bd9Sstevel@tonic-gate 	{ "devinfo.minor",	"::minornodes" },
54*7c478bd9Sstevel@tonic-gate 	{ "devinfo.next",	"::walk devi_next |::devinfo -s" },
55*7c478bd9Sstevel@tonic-gate 	{ "devinfo.parent",	"::walk devinfo_parents |::devinfo -s" },
56*7c478bd9Sstevel@tonic-gate 	{ "devinfo.prop",	"::devinfo" },
57*7c478bd9Sstevel@tonic-gate 	{ "devinfo.sibling",	"::walk devinfo_siblings |::devinfo -s" },
58*7c478bd9Sstevel@tonic-gate 	{ "devinfo_brief",	"::devinfo -s" },
59*7c478bd9Sstevel@tonic-gate 	{ "devinfo_major",	"::devbindings -s" },
60*7c478bd9Sstevel@tonic-gate 	{ "devnames_major",	"::devnames -m" },
61*7c478bd9Sstevel@tonic-gate 	{ "devt",		"::devt" },
62*7c478bd9Sstevel@tonic-gate 	{ "devt2snode",		"::dev2snode" },
63*7c478bd9Sstevel@tonic-gate 	{ "findthreads",	"::walk thread |::thread" },
64*7c478bd9Sstevel@tonic-gate 	{ "major2snode",	"::major2snode" },
65*7c478bd9Sstevel@tonic-gate 	{ "mblk",		"::mblk -v" },
66*7c478bd9Sstevel@tonic-gate 	{ "modctl.brief",	"::modctl" },
67*7c478bd9Sstevel@tonic-gate 	{ "modules",		"::modinfo" },
68*7c478bd9Sstevel@tonic-gate 	{ "mount",		"::fsinfo" },
69*7c478bd9Sstevel@tonic-gate 	{ "msgbuf",		"::msgbuf" },
70*7c478bd9Sstevel@tonic-gate 	{ "mutex",		"::mutex" },
71*7c478bd9Sstevel@tonic-gate 	{ "panicbuf",		"::panicinfo" },
72*7c478bd9Sstevel@tonic-gate 	{ "pid2proc",		"::pid2proc |::print proc_t" },
73*7c478bd9Sstevel@tonic-gate 	{ "proc2u",		"::print proc_t p_user" },
74*7c478bd9Sstevel@tonic-gate 	{ "procargs",		"::print proc_t p_user.u_psargs" },
75*7c478bd9Sstevel@tonic-gate 	{ "queue",		"::queue -v" },
76*7c478bd9Sstevel@tonic-gate 	{ "sema",		"::print sema_impl_t" },
77*7c478bd9Sstevel@tonic-gate 	{ "stackregs",		"::stackregs" },
78*7c478bd9Sstevel@tonic-gate 	{ "stacktrace",		"::stackregs" },
79*7c478bd9Sstevel@tonic-gate #if defined(__sparc)
80*7c478bd9Sstevel@tonic-gate 	{ "systemdump",		"0>pc;0>npc;nopanicdebug/W 1;:c" },
81*7c478bd9Sstevel@tonic-gate #elif defined(__i386)
82*7c478bd9Sstevel@tonic-gate 	{ "systemdump",		"0>eip;nopanicdebug/W 1;:c" },
83*7c478bd9Sstevel@tonic-gate #else
84*7c478bd9Sstevel@tonic-gate 	{ "systemdump",		"0>rip;nopanicdebug/W 1;:c" },
85*7c478bd9Sstevel@tonic-gate #endif
86*7c478bd9Sstevel@tonic-gate 	{ "thread",		"::print kthread_t" },
87*7c478bd9Sstevel@tonic-gate 	{ "threadlist",		"::threadlist -v" },
88*7c478bd9Sstevel@tonic-gate 	{ "u",			"::print user_t" },
89*7c478bd9Sstevel@tonic-gate 	{ "utsname",		"utsname::print" },
90*7c478bd9Sstevel@tonic-gate 	{ NULL }
91*7c478bd9Sstevel@tonic-gate };
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate void
mdb_macalias_create(void)94*7c478bd9Sstevel@tonic-gate mdb_macalias_create(void)
95*7c478bd9Sstevel@tonic-gate {
96*7c478bd9Sstevel@tonic-gate 	int i;
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate 	(void) mdb_nv_create(&mdb.m_macaliases, UM_SLEEP);
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate 	for (i = 0; mdb_macaliases[i].ma_name != NULL; i++) {
101*7c478bd9Sstevel@tonic-gate 		const mdb_macalias_t *ma = &mdb_macaliases[i];
102*7c478bd9Sstevel@tonic-gate 		(void) mdb_nv_insert(&mdb.m_macaliases, ma->ma_name, NULL,
103*7c478bd9Sstevel@tonic-gate 		    (uintptr_t)ma->ma_defn, MDB_NV_RDONLY | MDB_NV_EXTNAME |
104*7c478bd9Sstevel@tonic-gate 		    MDB_NV_PERSIST);
105*7c478bd9Sstevel@tonic-gate 	}
106*7c478bd9Sstevel@tonic-gate }
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate const char *
mdb_macalias_lookup(const char * name)109*7c478bd9Sstevel@tonic-gate mdb_macalias_lookup(const char *name)
110*7c478bd9Sstevel@tonic-gate {
111*7c478bd9Sstevel@tonic-gate 	mdb_var_t *v;
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate 	if ((v = mdb_nv_lookup(&mdb.m_macaliases, name)) == NULL)
114*7c478bd9Sstevel@tonic-gate 		return (NULL);
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate 	return (MDB_NV_COOKIE(v));
117*7c478bd9Sstevel@tonic-gate }
118*7c478bd9Sstevel@tonic-gate 
119*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
120*7c478bd9Sstevel@tonic-gate int
cmd_macalias_list(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)121*7c478bd9Sstevel@tonic-gate cmd_macalias_list(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
122*7c478bd9Sstevel@tonic-gate {
123*7c478bd9Sstevel@tonic-gate 	int i;
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC || argc != 0)
126*7c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 	mdb_printf("%<u>%-20s%</u> %<u>%-59s%</u>\n",
129*7c478bd9Sstevel@tonic-gate 	    "MACRO", "NATIVE EQUIVALENT");
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate 	for (i = 0; mdb_macaliases[i].ma_name != NULL; i++) {
132*7c478bd9Sstevel@tonic-gate 		const mdb_macalias_t *ma = &mdb_macaliases[i];
133*7c478bd9Sstevel@tonic-gate 		mdb_printf("%-20s %s\n", ma->ma_name, ma->ma_defn);
134*7c478bd9Sstevel@tonic-gate 	}
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
137*7c478bd9Sstevel@tonic-gate }
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate void
mdb_macalias_destroy(void)140*7c478bd9Sstevel@tonic-gate mdb_macalias_destroy(void)
141*7c478bd9Sstevel@tonic-gate {
142*7c478bd9Sstevel@tonic-gate 	mdb_nv_destroy(&mdb.m_macaliases);
143*7c478bd9Sstevel@tonic-gate }
144