Hi Doug, I tried using the MODULE_DEBUG #define and I ran into some compile issues. This patch gets things to work and adds an official option / entry to NOTES for help with other folks debugging kern_module.c logic. I also added some additional data to assist with determining causes of failure, as well as remove an impossible == NULL case when using malloc(.., M_WAITOK). Thanks! -Garrett
Index: sys/kern/kern_module.c =================================================================== --- sys/kern/kern_module.c (revision 223138) +++ sys/kern/kern_module.c (working copy) @@ -25,6 +25,7 @@ */ #include "opt_compat.h" +#include "opt_global.h" #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); @@ -44,6 +45,15 @@ #include <sys/module.h> #include <sys/linker.h> +#ifdef MODULE_DEBUG +#include <sys/sysctl.h> + +int mod_debug = 1; + +SYSCTL_INT(_debug, OID_AUTO, module_debug, CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_TUN, + &mod_debug, 0, "kernel module events to intercept"); +#endif + static MALLOC_DEFINE(M_MODULE, "module", "module data structures"); struct module { @@ -164,10 +174,6 @@ } namelen = strlen(data->name) + 1; newmod = malloc(sizeof(struct module) + namelen, M_MODULE, M_WAITOK); - if (newmod == NULL) { - MOD_XUNLOCK; - return (ENOMEM); - } newmod->refs = 1; newmod->id = nextid++; newmod->name = (char *)(newmod + 1); @@ -190,7 +196,7 @@ MOD_XLOCK_ASSERT; - MOD_DPF(REFS, ("module_reference: before, refs=%d\n", mod->refs)); + MOD_DPF(REFS, "module_reference: before, refs=%d\n", mod->refs); mod->refs++; } @@ -201,12 +207,17 @@ MOD_XLOCK_ASSERT; if (mod->refs <= 0) - panic("module_release: bad reference count"); + panic("module_release: bad reference count, refs=%d\n", + mod->refs); - MOD_DPF(REFS, ("module_release: before, refs=%d\n", mod->refs)); - + MOD_DPF(REFS, "module_release: before, module=%s refs=%d\n", + mod->name, mod->refs); + mod->refs--; if (mod->refs == 0) { + MOD_DPF(REFS, + "module_release: freeing last reference to module: %s\n", + mod->name); TAILQ_REMOVE(&modules, mod, link); if (mod->file) TAILQ_REMOVE(&mod->file->modules, mod, flink); Index: sys/sys/module.h =================================================================== --- sys/sys/module.h (revision 223138) +++ sys/sys/module.h (working copy) @@ -177,18 +177,18 @@ void module_setspecific(module_t, modspecific_t *); struct linker_file *module_file(module_t); -#ifdef MOD_DEBUG +#ifdef MODULE_DEBUG extern int mod_debug; #define MOD_DEBUG_REFS 1 -#define MOD_DPF(cat, args) do { \ +#define MOD_DPF(cat, fmt, ...) do { \ if (mod_debug & MOD_DEBUG_##cat) \ - printf(args); \ + printf(fmt, ##__VA_ARGS__); \ } while (0) -#else /* !MOD_DEBUG */ +#else /* !MODULE_DEBUG */ -#define MOD_DPF(cat, args) +#define MOD_DPF(cat, fmt, ...) #endif #endif /* _KERNEL */
_______________________________________________ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"