update readme and add gitignore
[client-tools.git] / tools / mapFileLookUpWin32.pl
blob830cb2d133e5d3188426b3ecde8d2034af483ea9
1 die "usage: mapFileLookUpWin32.pl file.map [[address | \@responseFile]...]\n" if (@ARGV < 2);
3 $mapFile = shift(@ARGV);
4 open(MAP, $mapFile);
6 while (@ARGV)
8 $find = shift(@ARGV);
10 # handle response files that are call stacks
11 if ($find =~ /^\@/)
13 $find =~ s/^.//;
15 # search the file for IP addresses to look up
16 undef @find;
17 open(FIND, $find);
18 while (<FIND>)
20 chomp;
21 s/^.*unknown\(// && s/\).*//;
22 push(@find, $_) if ($_ ne "");
24 close(FIND);
26 # insert all the found entries at the beginning of @ARGV
27 splice(@ARGV, 0, 0, @find);
28 $find = shift(@ARGV);
31 $find = hex($find);
33 # go to the beginning and skip past some cruft
34 seek(MAP, 0, 0);
35 while (<MAP>)
37 last if (/^\s+Address/)
40 # search for the symbol containg this address
41 $found = 0;
42 $lastAddress = 0;
43 $lastSymbol = "";
44 while (<MAP>)
46 chomp;
47 ($seg, $symbol, $address, $junk) = split;
48 $address = hex($address);
50 if ($lastAddress <= $find && $address > $find)
52 printf "%08x: %08x %08x %s\n", $find, $lastAddress, $address, $lastSymbol;
53 $found = 1;
54 last;
57 $lastAddress = $address;
58 $lastSymbol = $symbol;
60 printf "%08x: not found\n", $find if ($found == 0);
64 close(MAP);