Date: Wed, 19 Apr 2006 00:43:11 GMT From: John Birrell <jb@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 95568 for review Message-ID: <200604190043.k3J0hBAb009462@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=95568 Change 95568 by jb@jb_freebsd2 on 2006/04/19 00:42:37 FreeBSD doesn't have an object file system, so use the kernel loader interface to get the names of the loaded modules. There are still a few parts of this file that need to be looked at, but mostly the code should work. Affected files ... .. //depot/projects/dtrace/src/contrib/opensolaris/lib/libdtrace/common/dt_module.c#4 edit Differences ... ==== //depot/projects/dtrace/src/contrib/opensolaris/lib/libdtrace/common/dt_module.c#4 (text) ==== @@ -37,6 +37,9 @@ #include <sys/sysmacros.h> #include <sys/elf.h> #include <sys/task.h> +#else +#include <sys/param.h> +#include <sys/linker.h> #endif #include <unistd.h> @@ -74,6 +77,7 @@ static uint_t dt_module_syminit32(dt_module_t *dmp) { +printf("%s:%s(%d): DOODAD\n",__FUNCTION__,__FILE__,__LINE__); #ifdef DOODAD const Elf32_Sym *sym = dmp->dm_symtab.cts_data; const char *base = dmp->dm_strtab.cts_data; @@ -107,6 +111,7 @@ static uint_t dt_module_syminit64(dt_module_t *dmp) { +printf("%s:%s(%d): DOODAD\n",__FUNCTION__,__FILE__,__LINE__); #ifdef DOODAD const Elf64_Sym *sym = dmp->dm_symtab.cts_data; const char *base = dmp->dm_strtab.cts_data; @@ -678,7 +683,6 @@ void dt_module_unload(dtrace_hdl_t *dtp, dt_module_t *dmp) { -#ifdef DOODAD ctf_close(dmp->dm_ctfp); dmp->dm_ctfp = NULL; @@ -707,11 +711,11 @@ dmp->dm_asrsv = 0; dmp->dm_aslen = 0; - dmp->dm_text_va = NULL; + dmp->dm_text_va = 0; dmp->dm_text_size = 0; - dmp->dm_data_va = NULL; + dmp->dm_data_va = 0; dmp->dm_data_size = 0; - dmp->dm_bss_va = NULL; + dmp->dm_bss_va = 0; dmp->dm_bss_size = 0; if (dmp->dm_extern != NULL) { @@ -723,7 +727,6 @@ dmp->dm_elf = NULL; dmp->dm_flags &= ~DT_DM_LOADED; -#endif } void @@ -803,6 +806,7 @@ static void dt_module_update(dtrace_hdl_t *dtp, const char *name) { +printf("%s:%s(%d): DOODAD\n",__FUNCTION__,__FILE__,__LINE__); #ifdef DOODAD char fname[MAXPATHLEN]; struct stat64 st; @@ -905,14 +909,17 @@ void dtrace_update(dtrace_hdl_t *dtp) { -#ifdef DOODAD dt_module_t *dmp; DIR *dirp; +#if defined(__FreeBSD__) + int fileid; +#endif for (dmp = dt_list_next(&dtp->dt_modlist); dmp != NULL; dmp = dt_list_next(dmp)) dt_module_unload(dtp, dmp); +#if defined(sun) /* * Open /system/object and attempt to create a libdtrace module for * each kernel module that is loaded on the current system. @@ -928,6 +935,20 @@ (void) closedir(dirp); } +#elif defined(__FreeBSD__) + /* + * Use FreeBSD's kernel loader interface to discover what kernel + * modules are loaded and create a libdtrace module for each one. + */ + for (fileid = kldnext(0); fileid > 0; fileid = kldnext(fileid)) { + struct kld_file_stat k_stat; + if (kldstat(fileid, &k_stat) == 0) +{ +printf("%s:%s(%d): Kernel module '%s'\n",__FUNCTION__,__FILE__,__LINE__,k_stat.name); + dt_module_update(dtp, k_stat.name); +} + } +#endif /* * Look up all the macro identifiers and set di_id to the latest value. @@ -940,9 +961,13 @@ dt_idhash_lookup(dtp->dt_macros, "pid")->di_id = getpid(); dt_idhash_lookup(dtp->dt_macros, "pgid")->di_id = getpgid(0); dt_idhash_lookup(dtp->dt_macros, "ppid")->di_id = getppid(); +#if defined(sun) dt_idhash_lookup(dtp->dt_macros, "projid")->di_id = getprojid(); +#endif dt_idhash_lookup(dtp->dt_macros, "sid")->di_id = getsid(0); +#if defined(sun) dt_idhash_lookup(dtp->dt_macros, "taskid")->di_id = gettaskid(); +#endif dt_idhash_lookup(dtp->dt_macros, "uid")->di_id = getuid(); /* @@ -965,7 +990,6 @@ dt_list_delete(&dtp->dt_modlist, dtp->dt_exec); dt_list_prepend(&dtp->dt_modlist, dtp->dt_exec); } -#endif } static dt_module_t *
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200604190043.k3J0hBAb009462>