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.h> 30 #include <mdb/mdb_conf.h> 31 #include <mdb/mdb_module.h> 32 33 #include <sys/types.h> 34 #include <limits.h> 35 36 #include <dirent.h> 37 38 void 39 mdb_create_builtin_tgts(void) 40 { 41 mdb_module_t *mp; 42 43 if ((mp = mdb_module_load_builtin("mdb_kvm")) != NULL) 44 mp->mod_tgt_ctor = mdb_kvm_tgt_create; 45 46 if ((mp = mdb_module_load_builtin("mdb_proc")) != NULL) 47 mp->mod_tgt_ctor = mdb_proc_tgt_create; 48 49 if ((mp = mdb_module_load_builtin("mdb_kproc")) != NULL) 50 mp->mod_tgt_ctor = mdb_kproc_tgt_create; 51 52 if ((mp = mdb_module_load_builtin("mdb_raw")) != NULL) 53 mp->mod_tgt_ctor = mdb_rawfile_tgt_create; 54 } 55 56 void 57 mdb_create_loadable_disasms(void) 58 { 59 DIR *dir; 60 struct dirent *dp; 61 char buf[PATH_MAX], *p, *q; 62 size_t len; 63 64 #ifdef _LP64 65 len = mdb_snprintf(buf, sizeof (buf), "%s/usr/lib/mdb/disasm/%s", 66 mdb.m_root, mdb_conf_isa()); 67 #else 68 len = mdb_snprintf(buf, sizeof (buf), "%s/usr/lib/mdb/disasm", 69 mdb.m_root); 70 #endif 71 p = &buf[len]; 72 73 if ((dir = opendir(buf)) == NULL) 74 return; 75 76 while ((dp = readdir(dir)) != NULL) { 77 if (dp->d_name[0] == '.') 78 continue; /* skip "." and ".." */ 79 if ((q = strrchr(dp->d_name, '.')) == NULL || 80 strcmp(q, ".so") != 0) 81 continue; 82 83 (void) mdb_snprintf(p, sizeof (buf) - len, "/%s", dp->d_name); 84 85 (void) mdb_module_load(buf, MDB_MOD_SILENT); 86 } 87 88 (void) closedir(dir); 89 } 90