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