#!/bin/sh # # Print gdb command to load a module's symbols # # Copyright (C) 2006 Panasas, Inc. All rights reserved. # Copyright (C) 2006 Benny Halevy # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # Usage: add-symbol-file module # module can be either the module name or path to the module object. # # Note: When used in UML, this script must run in UML's context in order # to access /sys/module/$mod/sections/.* to get the dynamic relocation # addresses but the module path must be valid in gdb's context so that # gdb can load the object. # progname=`basename $0` mod=$1 if [ "$mod" = "" ]; then echo Usage: `$progname` module 1>&2 exit 1 fi if [[ -e "$mod" || "$mod" == */* ]]; then obj="$mod" else rel=`uname -r` modpath="/lib/modules/$rel/kernel" obj=`find $modpath -name "$mod" -o -name "$mod.ko" -o -name "$mod.o" | head -1` if [ ! -e "$obj" ]; then echo "$progname: $mod was not found in $modpath" 1>&2 exit 1 fi fi mod=`basename $mod | sed 's/\..*o$//'` dir=/sys/module/$mod/sections if [ ! -d $dir ]; then echo "$progname: $dir not found" 1>&2 exit 1 fi s="`cat $dir/.text`" for i in .rodata .data .bss; do s="$s -s $i `cat $dir/$i`" done echo "add-symbol-file $obj $s"