#! /usr/bin/perl # This program is distributed under the GNU GPL. # Randy Dunlap (rddunlap AT osdl.org) # 2001.June.21 # 2002.March.8: email address updated # Reads some kernel System.map file ($1 else ./System.map) & # searches for the given address in the map file. # Usually just finds addresses less than & greater than the one # requested & shows them. # On an exact match, # prints line before + exact match + line after for context. # # Usage: ksysmap c02f8000 # or: ksysmap linux-work/System.map-test1 c02f8000 $PROGNAME = "ksysmap"; $VERSION = "v0.1"; if (scalar @ARGV > 1) { $TARGET = $ARGV[1]; $MAPFILENAME = $ARGV[0]; } else { $TARGET = $ARGV[0]; $MAPFILENAME = "./System.map"; } if (length ($TARGET) == 0) { print "usage: $PROGNAME [mapfile] address {$VERSION}\n"; print " where mapfile is optional [def = ./System.map]\n\n"; exit 1; } $targ = hex $TARGET; if (length ($MAPFILENAME) == 0) { $MAPFILENAME = "./System.map"; } $prevline = ""; $line = ""; if (! open (MAPNUM, "<$MAPFILENAME")) { print "$PROGNAME: cannot open '$MAPFILENAME'\n\n"; exit 1; } print "$PROGNAME: searching '$MAPFILENAME' for '$TARGET'\n\n"; readmap: while ($line = ) # read a text line from MAPNUM { if ($line =~ /^$TARGET/i) # this line contains the TARGET address { print "$prevline"; chomp $line; print "$line <<<<<\n"; if ($line = ) # & print the next line (if any) { print "$line"; } last readmap; # exit the while loop } $adrstr = $line; $adrstr =~ /^\w/; # search/match word at beginning of line # $adrstr = substr $line, 0, 8; $adr = hex $adrstr; # print "adrstr = '$adrstr', adr = $adr\n"; if ($adr > $targ) # print prevline & this line, then fini. { print "$prevline"; print "$TARGET ..... <<<<<\n"; print "$line"; last readmap; } $prevline = $line; } # end while MAPNUM close (MAPNUM); print "\n"; # END.