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 #pragma ident "%Z%%M% %I% %E% SMI"
28*7c478bd9Sstevel@tonic-gate
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate * (k)adb Macro Aliases
31*7c478bd9Sstevel@tonic-gate *
32*7c478bd9Sstevel@tonic-gate * Provides aliases for popular ADB macros. These macros, which have been
33*7c478bd9Sstevel@tonic-gate * removed from the workspace, were documented in various locations, and need
34*7c478bd9Sstevel@tonic-gate * continued support. While we don't provide the same output format that was
35*7c478bd9Sstevel@tonic-gate * provided by the original macros, we do map the macro names to the equivalent
36*7c478bd9Sstevel@tonic-gate * MDB functionality.
37*7c478bd9Sstevel@tonic-gate */
38*7c478bd9Sstevel@tonic-gate
39*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_debug.h>
40*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_nv.h>
41*7c478bd9Sstevel@tonic-gate #include <mdb/mdb.h>
42*7c478bd9Sstevel@tonic-gate
43*7c478bd9Sstevel@tonic-gate typedef struct mdb_macalias {
44*7c478bd9Sstevel@tonic-gate const char *ma_name;
45*7c478bd9Sstevel@tonic-gate const char *ma_defn;
46*7c478bd9Sstevel@tonic-gate } mdb_macalias_t;
47*7c478bd9Sstevel@tonic-gate
48*7c478bd9Sstevel@tonic-gate static const mdb_macalias_t mdb_macaliases[] = {
49*7c478bd9Sstevel@tonic-gate { "bufctl", "::bufctl" },
50*7c478bd9Sstevel@tonic-gate { "bufctl_audit", "::bufctl -v" },
51*7c478bd9Sstevel@tonic-gate { "cpu", "::cpuinfo -v" },
52*7c478bd9Sstevel@tonic-gate { "cpun", "::cpuinfo -v" },
53*7c478bd9Sstevel@tonic-gate { "cpus", "::walk cpu |::cpuinfo -v" },
54*7c478bd9Sstevel@tonic-gate { "devinfo", "::print struct dev_info" },
55*7c478bd9Sstevel@tonic-gate { "devinfo.minor", "::minornodes" },
56*7c478bd9Sstevel@tonic-gate { "devinfo.next", "::walk devi_next |::devinfo -s" },
57*7c478bd9Sstevel@tonic-gate { "devinfo.parent", "::walk devinfo_parents |::devinfo -s" },
58*7c478bd9Sstevel@tonic-gate { "devinfo.prop", "::devinfo" },
59*7c478bd9Sstevel@tonic-gate { "devinfo.sibling", "::walk devinfo_siblings |::devinfo -s" },
60*7c478bd9Sstevel@tonic-gate { "devinfo_brief", "::devinfo -s" },
61*7c478bd9Sstevel@tonic-gate { "devinfo_major", "::devbindings -s" },
62*7c478bd9Sstevel@tonic-gate { "devnames_major", "::devnames -m" },
63*7c478bd9Sstevel@tonic-gate { "devt", "::devt" },
64*7c478bd9Sstevel@tonic-gate { "devt2snode", "::dev2snode" },
65*7c478bd9Sstevel@tonic-gate { "findthreads", "::walk thread |::thread" },
66*7c478bd9Sstevel@tonic-gate { "major2snode", "::major2snode" },
67*7c478bd9Sstevel@tonic-gate { "mblk", "::mblk -v" },
68*7c478bd9Sstevel@tonic-gate { "modctl.brief", "::modctl" },
69*7c478bd9Sstevel@tonic-gate { "modules", "::modinfo" },
70*7c478bd9Sstevel@tonic-gate { "mount", "::fsinfo" },
71*7c478bd9Sstevel@tonic-gate { "msgbuf", "::msgbuf" },
72*7c478bd9Sstevel@tonic-gate { "mutex", "::mutex" },
73*7c478bd9Sstevel@tonic-gate { "panicbuf", "::panicinfo" },
74*7c478bd9Sstevel@tonic-gate { "pid2proc", "::pid2proc |::print proc_t" },
75*7c478bd9Sstevel@tonic-gate { "proc2u", "::print proc_t p_user" },
76*7c478bd9Sstevel@tonic-gate { "procargs", "::print proc_t p_user.u_psargs" },
77*7c478bd9Sstevel@tonic-gate { "queue", "::queue -v" },
78*7c478bd9Sstevel@tonic-gate { "sema", "::print sema_impl_t" },
79*7c478bd9Sstevel@tonic-gate { "stackregs", "::stackregs" },
80*7c478bd9Sstevel@tonic-gate { "stacktrace", "::stackregs" },
81*7c478bd9Sstevel@tonic-gate #if defined(__sparc)
82*7c478bd9Sstevel@tonic-gate { "systemdump", "0>pc;0>npc;nopanicdebug/W 1;:c" },
83*7c478bd9Sstevel@tonic-gate #elif defined(__i386)
84*7c478bd9Sstevel@tonic-gate { "systemdump", "0>eip;nopanicdebug/W 1;:c" },
85*7c478bd9Sstevel@tonic-gate #else
86*7c478bd9Sstevel@tonic-gate { "systemdump", "0>rip;nopanicdebug/W 1;:c" },
87*7c478bd9Sstevel@tonic-gate #endif
88*7c478bd9Sstevel@tonic-gate { "thread", "::print kthread_t" },
89*7c478bd9Sstevel@tonic-gate { "threadlist", "::threadlist -v" },
90*7c478bd9Sstevel@tonic-gate { "u", "::print user_t" },
91*7c478bd9Sstevel@tonic-gate { "utsname", "utsname::print" },
92*7c478bd9Sstevel@tonic-gate { NULL }
93*7c478bd9Sstevel@tonic-gate };
94*7c478bd9Sstevel@tonic-gate
95*7c478bd9Sstevel@tonic-gate void
mdb_macalias_create(void)96*7c478bd9Sstevel@tonic-gate mdb_macalias_create(void)
97*7c478bd9Sstevel@tonic-gate {
98*7c478bd9Sstevel@tonic-gate int i;
99*7c478bd9Sstevel@tonic-gate
100*7c478bd9Sstevel@tonic-gate (void) mdb_nv_create(&mdb.m_macaliases, UM_SLEEP);
101*7c478bd9Sstevel@tonic-gate
102*7c478bd9Sstevel@tonic-gate for (i = 0; mdb_macaliases[i].ma_name != NULL; i++) {
103*7c478bd9Sstevel@tonic-gate const mdb_macalias_t *ma = &mdb_macaliases[i];
104*7c478bd9Sstevel@tonic-gate (void) mdb_nv_insert(&mdb.m_macaliases, ma->ma_name, NULL,
105*7c478bd9Sstevel@tonic-gate (uintptr_t)ma->ma_defn, MDB_NV_RDONLY | MDB_NV_EXTNAME |
106*7c478bd9Sstevel@tonic-gate MDB_NV_PERSIST);
107*7c478bd9Sstevel@tonic-gate }
108*7c478bd9Sstevel@tonic-gate }
109*7c478bd9Sstevel@tonic-gate
110*7c478bd9Sstevel@tonic-gate const char *
mdb_macalias_lookup(const char * name)111*7c478bd9Sstevel@tonic-gate mdb_macalias_lookup(const char *name)
112*7c478bd9Sstevel@tonic-gate {
113*7c478bd9Sstevel@tonic-gate mdb_var_t *v;
114*7c478bd9Sstevel@tonic-gate
115*7c478bd9Sstevel@tonic-gate if ((v = mdb_nv_lookup(&mdb.m_macaliases, name)) == NULL)
116*7c478bd9Sstevel@tonic-gate return (NULL);
117*7c478bd9Sstevel@tonic-gate
118*7c478bd9Sstevel@tonic-gate return (MDB_NV_COOKIE(v));
119*7c478bd9Sstevel@tonic-gate }
120*7c478bd9Sstevel@tonic-gate
121*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
122*7c478bd9Sstevel@tonic-gate int
cmd_macalias_list(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)123*7c478bd9Sstevel@tonic-gate cmd_macalias_list(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
124*7c478bd9Sstevel@tonic-gate {
125*7c478bd9Sstevel@tonic-gate int i;
126*7c478bd9Sstevel@tonic-gate
127*7c478bd9Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC || argc != 0)
128*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
129*7c478bd9Sstevel@tonic-gate
130*7c478bd9Sstevel@tonic-gate mdb_printf("%<u>%-20s%</u> %<u>%-59s%</u>\n",
131*7c478bd9Sstevel@tonic-gate "MACRO", "NATIVE EQUIVALENT");
132*7c478bd9Sstevel@tonic-gate
133*7c478bd9Sstevel@tonic-gate for (i = 0; mdb_macaliases[i].ma_name != NULL; i++) {
134*7c478bd9Sstevel@tonic-gate const mdb_macalias_t *ma = &mdb_macaliases[i];
135*7c478bd9Sstevel@tonic-gate mdb_printf("%-20s %s\n", ma->ma_name, ma->ma_defn);
136*7c478bd9Sstevel@tonic-gate }
137*7c478bd9Sstevel@tonic-gate
138*7c478bd9Sstevel@tonic-gate return (DCMD_OK);
139*7c478bd9Sstevel@tonic-gate }
140*7c478bd9Sstevel@tonic-gate
141*7c478bd9Sstevel@tonic-gate void
mdb_macalias_destroy(void)142*7c478bd9Sstevel@tonic-gate mdb_macalias_destroy(void)
143*7c478bd9Sstevel@tonic-gate {
144*7c478bd9Sstevel@tonic-gate mdb_nv_destroy(&mdb.m_macaliases);
145*7c478bd9Sstevel@tonic-gate }
146