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