Exemplo n.º 1
0
static void
print_modules(mdb_nv_t *mods)
{
	mdb_var_t *v;

	mdb_nv_rewind(mods);
	while ((v = mdb_nv_advance(mods)) != NULL)
		mdb_printf(" %s", mdb_nv_get_name(v));
}
Exemplo n.º 2
0
/*
 * Called by the kmdb_kvm target upon debugger reentry, this routine checks
 * to see if the loaded dmods have changed.  Of particular interest is the
 * exportation of dmod symbol tables, which will happen during the boot
 * process for dmods that were loaded prior to kernel startup.  If this
 * has occurred, we'll need to reconstruct our view of the symbol tables for
 * the affected dmods, since the old symbol tables lived in bootmem
 * and have been moved during the kobj_export_module().
 *
 * Also, any ctf_file_t we might have opened is now invalid, since it
 * has internal pointers to the old data as well.
 */
void
kmdb_module_sync(void)
{
    mdb_var_t *v;

    mdb_nv_rewind(&mdb.m_dmodctl);
    while ((v = mdb_nv_advance(&mdb.m_dmodctl)) != NULL) {
        kmdb_modctl_t *kmc = MDB_NV_COOKIE(v);
        struct module *mp;

        if (kmc->kmc_state != KMDB_MC_STATE_LOADED)
            continue;

        mp = kmc->kmc_modctl->mod_mp;

        if ((mp->flags & (KOBJ_PRIM | KOBJ_EXPORTED)) &&
                !kmc->kmc_exported) {
            /*
             * The exporting process moves the symtab from boot
             * scratch memory to vmem.
             */
            if (kmc->kmc_symtab != NULL)
                mdb_gelf_symtab_destroy(kmc->kmc_symtab);

            kmc->kmc_symtab = mdb_gelf_symtab_create_raw(
                                  &kmc->kmc_ehdr, mp->symhdr, mp->symtbl, mp->strhdr,
                                  mp->strings, MDB_TGT_SYMTAB);

            if (kmc->kmc_mod->mod_ctfp != NULL) {
                ctf_close(kmc->kmc_mod->mod_ctfp);
                kmc->kmc_mod->mod_ctfp =
                    mdb_ctf_open(kmc->kmc_modname, NULL);
            }
            kmc->kmc_exported = TRUE;
        }
    }
}
Exemplo n.º 3
0
void
mdb_destroy(void)
{
	const mdb_dcmd_t *dcp;
	mdb_var_t *v;
	int unload_mode = MDB_MOD_SILENT;

#ifdef _KMDB
	unload_mode |= MDB_MOD_DEFER;
#endif

	mdb_intr_disable();

	mdb_macalias_destroy();

	/*
	 * Some targets use modules during ->t_destroy, so do it first.
	 */
	if (mdb.m_target != NULL)
		(void) mdb_tgt_destroy(mdb.m_target);

	/*
	 * Unload modules _before_ destroying the disassemblers since a
	 * module that installs a disassembler should try to clean up after
	 * itself.
	 */
	mdb_module_unload_all(unload_mode);

	mdb_nv_rewind(&mdb.m_disasms);
	while ((v = mdb_nv_advance(&mdb.m_disasms)) != NULL)
		mdb_dis_destroy(mdb_nv_get_cookie(v));

	mdb_callb_remove_all();

	if (mdb.m_defdisasm != NULL)
		strfree(mdb.m_defdisasm);

	if (mdb.m_prsym != NULL)
		mdb_gelf_symtab_destroy(mdb.m_prsym);

	for (dcp = &mdb_dcmd_builtins[0]; dcp->dc_name != NULL; dcp++)
		(void) mdb_module_remove_dcmd(&mdb.m_rmod, dcp->dc_name);

	mdb_nv_destroy(&mdb.m_nv);
	mdb_nv_destroy(&mdb.m_walkers);
	mdb_nv_destroy(&mdb.m_dcmds);
	mdb_nv_destroy(&mdb.m_modules);
	mdb_nv_destroy(&mdb.m_disasms);

	mdb_free(mdb.m_ipathstr, MAXPATHLEN);
	mdb_free(mdb.m_lpathstr, MAXPATHLEN);

	if (mdb.m_ipath != NULL)
		mdb_path_free(mdb.m_ipath, mdb.m_ipathlen);

	if (mdb.m_lpath != NULL)
		mdb_path_free(mdb.m_lpath, mdb.m_lpathlen);

	if (mdb.m_in != NULL)
		mdb_iob_destroy(mdb.m_in);

	mdb_iob_destroy(mdb.m_out);
	mdb.m_out = NULL;
	mdb_iob_destroy(mdb.m_err);
	mdb.m_err = NULL;

	if (mdb.m_log != NULL)
		mdb_io_rele(mdb.m_log);

	mdb_lex_state_destroy(&frame0);
}
Exemplo n.º 4
0
int
kt_symbol_iter(mdb_tgt_t *t, const char *obj, uint_t which, uint_t type,
    mdb_tgt_sym_f *cb, void *data)
{
	kt_data_t *kt = t->t_data;
	kt_module_t *km;

	mdb_gelf_symtab_t *symtab = NULL;
	mdb_var_t *v;

	switch ((uintptr_t)obj) {
	case (uintptr_t)MDB_TGT_OBJ_EXEC:
		if (which == MDB_TGT_SYMTAB)
			symtab = kt->k_symtab;
		else
			symtab = kt->k_dynsym;
		break;

	case (uintptr_t)MDB_TGT_OBJ_EVERY:
		if (which == MDB_TGT_DYNSYM) {
			symtab = kt->k_dynsym;
			obj = MDB_TGT_OBJ_EXEC;
			break;
		}

		mdb_nv_rewind(&kt->k_modules);
		while ((v = mdb_nv_advance(&kt->k_modules)) != NULL) {
			km = mdb_nv_get_cookie(v);

			if (km->km_symtab == NULL)
				kt_load_module(kt, t, km);

			if (km->km_symtab != NULL)
				kt_symtab_iter(km->km_symtab, type,
				    km->km_name, cb, data);
		}
		break;

	case (uintptr_t)MDB_TGT_OBJ_RTLD:
		obj = KT_RTLD_NAME;
		/*FALLTHRU*/

	default:
		v = mdb_nv_lookup(&kt->k_modules, obj);

		if (v == NULL)
			return (set_errno(EMDB_NOOBJ));

		km = mdb_nv_get_cookie(v);

		if (km->km_symtab == NULL)
			kt_load_module(kt, t, km);

		symtab = km->km_symtab;
	}

	if (symtab)
		kt_symtab_iter(symtab, type, obj, cb, data);

	return (0);
}