Skip to contentSkip to conversation

Module section offsets in /sys/module

PATCH In review Jonathan Corbet 2 participants 2 messages Jun 3, 2004 – Jun 4, 2004 Module support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Module section offsets in /sys/module

So here I am trying to write about how one can apply gdb to a running kernel, and I'd like to tell people how to debug loadable modules. Only with the 2.6 module loader, there's no way to find out where the various sections in the module image ended up, so you can't do much. This patch attempts to fix that by adding a "sections" subdirectory to every module's entry in /sys/module; each attribute in that directory associates a beginning address with the section name. Those attributes can be used by a a simple script to generate an add-symbol-file command for gdb, something like:

#!/bin/bash
#

# gdbline module image
#
# Outputs an add-symbol-file line suitable for pasting into gdb to examine
# a loaded module.
#
cd /sys/module/$1/sections
echo -n add-symbol-file $2 `/bin/cat .text`

for section in .[a-z]* *; do

    if [ $section != ".text" ]; then
	echo  " \\"
	echo -n "	-s" $section `/bin/cat $section`
    fi

done
echo

Currently, this feature is absent if CONFIG_KALLSYMS is not set. I do wonder if CONFIG_DEBUG_INFO might not be a better choice, now that I think about it. Section names are unmunged, so "ls -a" is needed to see most of them.

Applies to 2.6.7-rc2. Comments?

jon

include/linux/module.h +19 -0
diff -urNp -X ../dontdiff 2.6.7-rc2-vanilla/include/linux/module.h 2.6.7-rc2/include/linux/module.h
@@ -225,6 +225,22 @@ struct module_kobject
 	struct module_attribute attr[0];
 };
 
+/* Similar stuff for section attributes. */
+#define MODULE_SECT_NAME_LEN 32
+struct module_sect_attr
+{
+	struct attribute attr;
+	char name[MODULE_SECT_NAME_LEN];
+	unsigned long address;
+};
+
+struct module_sections
+{
+	struct kobject kobj;
+	struct module_sect_attr attrs[0];
+};
+
+
 struct module
 {
 	enum module_state state;
@@ -298,6 +314,9 @@ struct module
 	Elf_Sym *symtab;
 	unsigned long num_symtab;
 	char *strtab;
+
+	/* Section attributes */
+	struct module_sections *sect_attrs;
 #endif
 
 	/* Per-cpu data. */
kernel/module.c +100 -0

118 lines not on this page · raw message

#1 lore raw
Quoted 7 lines · Jonathan Corbet

Currently, this feature is absent if CONFIG_KALLSYMS is not set. I do wonder if CONFIG_DEBUG_INFO might not be a better choice, now that I think about it. Section names are unmunged, so "ls -a" is needed to see most of them.

Applies to 2.6.7-rc2. Comments?

Nice, I like this. I've added it to my driver-2.6 tree to have it show up in the next -mm release.

If you want to change the config option, feel free to send a patch on top of this one.

thanks,

greg k-h