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