Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save spiculator/5081789 to your computer and use it in GitHub Desktop.
Save spiculator/5081789 to your computer and use it in GitHub Desktop.
resolve kernel trace with system map
#!/usr/bin/perl -w
use strict;
use FindBin;
1 == @ARGV or die "Usage: cat kernel-call-trace.txt |$FindBin::Script <system-map-file>\n";
my $map = shift @ARGV;
my (@address, @type, @name);
open MAP, "<", $map or die $!;
while(<MAP>) {
/^([\da-f]{16}) (\w) ([\w\.]+)$/ or die "Bad line from $map: $_\n";
{
no warnings "portable";
push @address, hex $1;
}
push @type, $2;
push @name, $3;
}
close MAP or die $!;
sub mapfind($) {
my $in;
{
no warnings "portable";
$in = hex shift;
}
my $i = 0;
for( $i = 1; $i <= @address; ++$i ) {
last if $i == @address or $address[$i] > $in;
}
--$i;
return sprintf "%s %s (+%s)", $type[$i], $name[$i], $in - $address[$i];
}
while(<>) {
s/\<([\da-f]{16})\>/mapfind($1)/ge;
print;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment