From: Jason Wessel <[EMAIL PROTECTED]>

With more information in the kernel, gdb can be modified in such a way
as to automatically read the kernel module section information and
allow for easy kernel module debugging.

In gdb the solib-search-path must contain the location of any module
to be debugged.  When a module is loaded GDB acts like a shared
library has been loaded and will collect the information about the
memory location so the kernel module can be debugged or inspected.

Even when not using kgdb+gdb, it is quite useful for a
debugger+ICE/jtag to have the module section information.

Signed-off-by: Jason Wessel <[EMAIL PROTECTED]>
Signed-off-by: Ingo Molnar <[EMAIL PROTECTED]>
Signed-off-by: Thomas Gleixner <[EMAIL PROTECTED]>
---
 include/linux/module.h |    9 ++++++---
 kernel/module.c        |   34 ++++++++++++++++++++++------------
 2 files changed, 28 insertions(+), 15 deletions(-)

diff --git a/include/linux/module.h b/include/linux/module.h
index ac28e87..87b0301 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -342,13 +342,16 @@ struct module
        unsigned long num_symtab;
        char *strtab;
 
-       /* Section attributes */
-       struct module_sect_attrs *sect_attrs;
-
        /* Notes attributes */
        struct module_notes_attrs *notes_attrs;
 #endif
 
+#if defined(CONFIG_KALLSYMS) || defined(CONFIG_KGDB)
+       /* Section attributes */
+       struct module_sect_attrs *sect_attrs;
+#endif
+
+
        /* Per-cpu data. */
        void *percpu;
 
diff --git a/kernel/module.c b/kernel/module.c
index 4202da9..4a94d1a 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -602,6 +602,9 @@ static void module_unload_free(struct module *mod)
                        }
                }
        }
+       blocking_notifier_call_chain(&module_notify_list,
+                               MODULE_STATE_GOING,
+                               mod);
 }
 
 #ifdef CONFIG_MODULE_FORCE_UNLOAD
@@ -992,6 +995,7 @@ static unsigned long resolve_symbol(Elf_Shdr *sechdrs,
  * /sys/module/foo/sections stuff
  * J. Corbet <[EMAIL PROTECTED]>
  */
+#if defined(CONFIG_KALLSYMS) || defined(CONFIG_KGDB)
 #ifdef CONFIG_KALLSYMS
 static ssize_t module_sect_show(struct module_attribute *mattr,
                                struct module *mod, char *buf)
@@ -1000,6 +1004,7 @@ static ssize_t module_sect_show(struct module_attribute 
*mattr,
                container_of(mattr, struct module_sect_attr, mattr);
        return sprintf(buf, "0x%lx\n", sattr->address);
 }
+#endif /* CONFIG_KALLSYMS */
 
 static void free_sect_attrs(struct module_sect_attrs *sect_attrs)
 {
@@ -1046,7 +1051,9 @@ static void add_sect_attrs(struct module *mod, unsigned 
int nsect,
                if (sattr->name == NULL)
                        goto out;
                sect_attrs->nsections++;
+#ifdef CONFIG_KALLSYMS
                sattr->mattr.show = module_sect_show;
+#endif
                sattr->mattr.store = NULL;
                sattr->mattr.attr.name = sattr->name;
                sattr->mattr.attr.mode = S_IRUGO;
@@ -1074,7 +1081,20 @@ static void remove_sect_attrs(struct module *mod)
                mod->sect_attrs = NULL;
        }
 }
+#else /* ! (CONFIG_KALLSYMS || CONFIG_KGDB) */
 
+static inline void add_sect_attrs(struct module *mod, unsigned int nsect,
+               char *sectstrings, Elf_Shdr *sechdrs)
+{
+}
+
+static inline void remove_sect_attrs(struct module *mod)
+{
+}
+
+#endif /* CONFIG_KALLSYMS || CONFIG_KGDB */
+
+#ifdef CONFIG_KALLSYMS
 /*
  * /sys/module/foo/notes/.section.name gives contents of SHT_NOTE sections.
  */
@@ -1168,18 +1188,7 @@ static void remove_notes_attrs(struct module *mod)
        if (mod->notes_attrs)
                free_notes_attrs(mod->notes_attrs, mod->notes_attrs->notes);
 }
-
 #else
-
-static inline void add_sect_attrs(struct module *mod, unsigned int nsect,
-               char *sectstrings, Elf_Shdr *sechdrs)
-{
-}
-
-static inline void remove_sect_attrs(struct module *mod)
-{
-}
-
 static inline void add_notes_attrs(struct module *mod, unsigned int nsect,
                                   char *sectstrings, Elf_Shdr *sechdrs)
 {
@@ -1188,7 +1197,8 @@ static inline void add_notes_attrs(struct module *mod, 
unsigned int nsect,
 static inline void remove_notes_attrs(struct module *mod)
 {
 }
-#endif /* CONFIG_KALLSYMS */
+#endif
+
 
 #ifdef CONFIG_SYSFS
 int module_add_modinfo_attrs(struct module *mod)
-- 
1.5.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to