• Jonathan Corbet's avatar
    [PATCH] Module section offsets in /sys/module · 3f7b0672
    Jonathan Corbet authored
    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.
    Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
    3f7b0672
module.c 54.1 KB