PERFORCE change 95612 for review
John Birrell
jb at FreeBSD.org
Wed Apr 19 19:43:17 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=95612
Change 95612 by jb at jb_freebsd2 on 2006/04/19 19:42:41
Now that kldstat(2) reports the full module path name this code can be
used.
There are a few subtle differences between the Solaris implementation
and the FreeBSD one. Solaris uses the object file system to find out
what modules are loaded whereas FreeBSD uses the kernel linker status
(kldstat(2)) call. On FreeBSD, the kernel returns the full path to
the loaded module. This means that on FreeBSD the module name ends
up being the full path whereas on Solaris the module name is just the
name of the object in /system/object/[name]. On FreeBSD, there is
no .filename section in the linked file, so the dm_file field remains
empty.
Here is a section of the debug output from dtrace(1) -- this should
make sense to some people reading these submit messages. 8-)
libdtrace DEBUG: opened provider dtrace
libdtrace DEBUG: opened provider fasttrap
libdtrace DEBUG: opened 32-bit module /boot/kernel/kernel () [0]
libdtrace DEBUG: opened 32-bit module /boot/kernel/acpi.ko () [0]
libdtrace DEBUG: opened 32-bit module /boot/kernel/linprocfs.ko () [0]
libdtrace DEBUG: opened 32-bit module /boot/kernel/linux.ko () [0]
libdtrace DEBUG: opened 32-bit module /boot/kernel/dtrace.ko () [0]
libdtrace DEBUG: opened 32-bit module /boot/kernel/fasttrap.ko () [0]
libdtrace DEBUG: created CTF container for C (0x82e0160)
libdtrace DEBUG: created CTF container for D (0x82e02b0)
libdtrace DEBUG: loaded /boot/kernel/kernel [.symtab] (435696 bytes)
libdtrace DEBUG: loaded /boot/kernel/kernel [.strtab] (532503 bytes)
libdtrace DEBUG: hashed /boot/kernel/kernel [.symtab] (27203 symbols)
libdtrace DEBUG: sorted /boot/kernel/kernel [.symtab] (27115 symbols)
libdtrace DEBUG: loaded /boot/kernel/acpi.ko [.SUNW_ctf] (1204974 bytes)
libdtrace DEBUG: loaded /boot/kernel/acpi.ko [.symtab] (31776 bytes)
libdtrace DEBUG: loaded /boot/kernel/acpi.ko [.strtab] (43195 bytes)
libdtrace DEBUG: hashed /boot/kernel/acpi.ko [.symtab] (1968 symbols)
libdtrace DEBUG: sorted /boot/kernel/acpi.ko [.symtab] (1671 symbols)
libdtrace DEBUG: loaded CTF container for /boot/kernel/acpi.ko (0x82e0400)
libdtrace DEBUG: loaded /boot/kernel/linprocfs.ko [.SUNW_ctf] (44796 bytes)
libdtrace DEBUG: loaded /boot/kernel/linprocfs.ko [.symtab] (2320 bytes)
libdtrace DEBUG: loaded /boot/kernel/linprocfs.ko [.strtab] (2221 bytes)
libdtrace DEBUG: hashed /boot/kernel/linprocfs.ko [.symtab] (129 symbols)
libdtrace DEBUG: sorted /boot/kernel/linprocfs.ko [.symtab] (52 symbols)
libdtrace DEBUG: loaded CTF container for /boot/kernel/linprocfs.ko (0x82e0550)
libdtrace DEBUG: populating global idhash from 0x280da7e0
libdtrace DEBUG: loaded /boot/kernel/linux.ko [.SUNW_ctf] (67158 bytes)
libdtrace DEBUG: loaded /boot/kernel/linux.ko [.symtab] (11200 bytes)
libdtrace DEBUG: loaded /boot/kernel/linux.ko [.strtab] (10258 bytes)
libdtrace DEBUG: hashed /boot/kernel/linux.ko [.symtab] (681 symbols)
libdtrace DEBUG: sorted /boot/kernel/linux.ko [.symtab] (394 symbols)
libdtrace DEBUG: loaded CTF container for /boot/kernel/linux.ko (0x82e06a0)
libdtrace DEBUG: loaded /boot/kernel/dtrace.ko [.SUNW_ctf] (16472 bytes)
libdtrace DEBUG: loaded /boot/kernel/dtrace.ko [.symtab] (1008 bytes)
libdtrace DEBUG: loaded /boot/kernel/dtrace.ko [.strtab] (1055 bytes)
libdtrace DEBUG: hashed /boot/kernel/dtrace.ko [.symtab] (46 symbols)
libdtrace DEBUG: sorted /boot/kernel/dtrace.ko [.symtab] (37 symbols)
libdtrace DEBUG: loaded CTF container for /boot/kernel/dtrace.ko (0x82e07f0)
libdtrace DEBUG: loaded /boot/kernel/fasttrap.ko [.SUNW_ctf] (15655 bytes)
libdtrace DEBUG: loaded /boot/kernel/fasttrap.ko [.symtab] (672 bytes)
libdtrace DEBUG: loaded /boot/kernel/fasttrap.ko [.strtab] (558 bytes)
libdtrace DEBUG: hashed /boot/kernel/fasttrap.ko [.symtab] (26 symbols)
libdtrace DEBUG: sorted /boot/kernel/fasttrap.ko [.symtab] (23 symbols)
libdtrace DEBUG: loaded CTF container for /boot/kernel/fasttrap.ko (0x82e0940)
I'm a bit surprised to see the .SUNW_ctf section being reported on the
kernel modules. I would have sworn that I haven't built that in. Notice
that it is missing from the kernel module. That is definitely correct.
Affected files ...
.. //depot/projects/dtrace/src/contrib/opensolaris/lib/libdtrace/common/dt_module.c#5 edit
Differences ...
==== //depot/projects/dtrace/src/contrib/opensolaris/lib/libdtrace/common/dt_module.c#5 (text) ====
@@ -40,6 +40,8 @@
#else
#include <sys/param.h>
#include <sys/linker.h>
+#include <sys/stat.h>
+#include <opensolaris/compat/sys/stat.h>
#endif
#include <unistd.h>
@@ -77,8 +79,6 @@
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;
size_t ss_size = dmp->dm_strtab.cts_size;
@@ -103,16 +103,11 @@
}
return (asrsv);
-#else
-return 0;
-#endif
}
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;
size_t ss_size = dmp->dm_strtab.cts_size;
@@ -137,9 +132,6 @@
}
return (asrsv);
-#else
-return 0;
-#endif
}
/*
@@ -802,12 +794,13 @@
/*
* Update our module cache by adding an entry for the specified module 'name'.
* We create the dt_module_t and populate it using /system/object/<name>/.
+ *
+ * On FreeBSD, the module name is passed as the full module file name,
+ * including the path.
*/
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;
int fd, err, bits;
@@ -819,8 +812,12 @@
Elf_Data *dp;
Elf_Scn *sp;
+#if defined(sun)
(void) snprintf(fname, sizeof (fname),
"%s/%s/object", OBJFS_ROOT, name);
+#else
+ (void) strlcpy(fname, name, sizeof(fname));
+#endif
if ((fd = open(fname, O_RDONLY)) == -1 || fstat64(fd, &st) == -1 ||
(dmp = dt_module_create(dtp, name)) == NULL) {
@@ -892,14 +889,22 @@
}
dmp->dm_flags |= DT_DM_KERNEL;
+#if defined(sun)
dmp->dm_modid = (int)OBJFS_MODID(st.st_ino);
+#else
+ /*
+ * On FreeBSD we probably should map this to the 'fileid' that
+ * kldstat(2) reports. Unfortunately we discarded that info before
+ * this function was called.
+ */
+ dmp->dm_modid = 0;
+#endif
if (dmp->dm_info.objfs_info_primary)
dmp->dm_flags |= DT_DM_PRIMARY;
dt_dprintf("opened %d-bit module %s (%s) [%d]\n",
bits, dmp->dm_name, dmp->dm_file, dmp->dm_modid);
-#endif
}
/*
@@ -942,11 +947,9 @@
*/
for (fileid = kldnext(0); fileid > 0; fileid = kldnext(fileid)) {
struct kld_file_stat k_stat;
+ k_stat.version = sizeof(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);
-}
+ dt_module_update(dtp, k_stat.pathname);
}
#endif
More information about the p4-projects
mailing list