markup_oops.pl: add options to improve cross-sompilation environments
The markup_oops.pl have 3 troubles to support cross-compiler environment: 1. It use objdump directly. 2. It use modinfo to get the message of module. 3. It use hex function that cannot support 64-bit number in 32-bit arch. This patch add 3 options to markup_oops.pl: 1. -c CROSS_COMPILE Specify the prefix used for toolchain. 2. -m MODULE_DIRNAME Specify the module directory name. 3. Change hex function to Math::BigInt->from_hex. After this patch, parse the x8664 oops in x86, we can: cat amd64m | perl ~/kernel/tmp/m.pl -c /home/teawater/kernel/bin/x8664- -m ./e.ko vmlinux Thanks, Hui Signed-off-by: Hui Zhu <teawater@gmail.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Arjan van de Ven <arjan@linux.intel.com> Cc: Sam Ravnborg <sam@ravnborg.org> Cc: ozan@pardus.org.tr Cc: Matthew Wilcox <willy@linux.intel.com> Acked-by: WANG Cong <xiyou.wangcong@gmail.com> Signed-off-by: Michal Marek <mmarek@suse.cz>
This commit is contained in:
parent
d224a94ab9
commit
52e13e219d
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use File::Basename;
|
use File::Basename;
|
||||||
use Math::BigInt;
|
use Math::BigInt;
|
||||||
|
use Getopt::Long;
|
||||||
|
|
||||||
# Copyright 2008, Intel Corporation
|
# Copyright 2008, Intel Corporation
|
||||||
#
|
#
|
||||||
|
@ -15,7 +16,17 @@ use Math::BigInt;
|
||||||
# Arjan van de Ven <arjan@linux.intel.com>
|
# Arjan van de Ven <arjan@linux.intel.com>
|
||||||
|
|
||||||
|
|
||||||
my $vmlinux_name = $ARGV[0];
|
my $cross_compile = "";
|
||||||
|
my $vmlinux_name = "";
|
||||||
|
my $modulefile = "";
|
||||||
|
|
||||||
|
# Get options
|
||||||
|
Getopt::Long::GetOptions(
|
||||||
|
'cross-compile|c=s' => \$cross_compile,
|
||||||
|
'module|m=s' => \$modulefile,
|
||||||
|
'help|h' => \&usage,
|
||||||
|
);
|
||||||
|
my $vmlinux_name = $ARGV[$#ARGV];
|
||||||
if (!defined($vmlinux_name)) {
|
if (!defined($vmlinux_name)) {
|
||||||
my $kerver = `uname -r`;
|
my $kerver = `uname -r`;
|
||||||
chomp($kerver);
|
chomp($kerver);
|
||||||
|
@ -23,9 +34,8 @@ if (!defined($vmlinux_name)) {
|
||||||
print "No vmlinux specified, assuming $vmlinux_name\n";
|
print "No vmlinux specified, assuming $vmlinux_name\n";
|
||||||
}
|
}
|
||||||
my $filename = $vmlinux_name;
|
my $filename = $vmlinux_name;
|
||||||
#
|
|
||||||
# Step 1: Parse the oops to find the EIP value
|
# Parse the oops to find the EIP value
|
||||||
#
|
|
||||||
|
|
||||||
my $target = "0";
|
my $target = "0";
|
||||||
my $function;
|
my $function;
|
||||||
|
@ -177,26 +187,26 @@ my $decodestart = Math::BigInt->from_hex("0x$target") - Math::BigInt->from_hex("
|
||||||
my $decodestop = Math::BigInt->from_hex("0x$target") + 8192;
|
my $decodestop = Math::BigInt->from_hex("0x$target") + 8192;
|
||||||
if ($target eq "0") {
|
if ($target eq "0") {
|
||||||
print "No oops found!\n";
|
print "No oops found!\n";
|
||||||
print "Usage: \n";
|
usage();
|
||||||
print " dmesg | perl scripts/markup_oops.pl vmlinux\n";
|
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# if it's a module, we need to find the .ko file and calculate a load offset
|
# if it's a module, we need to find the .ko file and calculate a load offset
|
||||||
if ($module ne "") {
|
if ($module ne "") {
|
||||||
my $modulefile = `modinfo $module | grep '^filename:' | awk '{ print \$2 }'`;
|
if ($modulefile eq "") {
|
||||||
chomp($modulefile);
|
my $modulefile = `modinfo $module | grep '^filename:' | awk '{ print \$2 }'`;
|
||||||
|
chomp($modulefile);
|
||||||
|
}
|
||||||
$filename = $modulefile;
|
$filename = $modulefile;
|
||||||
if ($filename eq "") {
|
if ($filename eq "") {
|
||||||
print "Module .ko file for $module not found. Aborting\n";
|
print "Module .ko file for $module not found. Aborting\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
# ok so we found the module, now we need to calculate the vma offset
|
# ok so we found the module, now we need to calculate the vma offset
|
||||||
open(FILE, "objdump -dS $filename |") || die "Cannot start objdump";
|
open(FILE, $cross_compile."objdump -dS $filename |") || die "Cannot start objdump";
|
||||||
while (<FILE>) {
|
while (<FILE>) {
|
||||||
if ($_ =~ /^([0-9a-f]+) \<$function\>\:/) {
|
if ($_ =~ /^([0-9a-f]+) \<$function\>\:/) {
|
||||||
my $fu = $1;
|
my $fu = $1;
|
||||||
$vmaoffset = hex($target) - hex($fu) - hex($func_offset);
|
$vmaoffset = Math::BigInt->from_hex("0x$target") - Math::BigInt->from_hex("0x$fu") - Math::BigInt->from_hex("0x$func_offset");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close(FILE);
|
close(FILE);
|
||||||
|
@ -212,7 +222,7 @@ sub InRange {
|
||||||
my ($address, $target) = @_;
|
my ($address, $target) = @_;
|
||||||
my $ad = "0x".$address;
|
my $ad = "0x".$address;
|
||||||
my $ta = "0x".$target;
|
my $ta = "0x".$target;
|
||||||
my $delta = hex($ad) - hex($ta);
|
my $delta = Math::BigInt->from_hex($ad) - Math::BigInt->from_hex($ta);
|
||||||
|
|
||||||
if (($delta > -4096) && ($delta < 4096)) {
|
if (($delta > -4096) && ($delta < 4096)) {
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -225,7 +235,7 @@ sub InRange {
|
||||||
# first, parse the input into the lines array, but to keep size down,
|
# first, parse the input into the lines array, but to keep size down,
|
||||||
# we only do this for 4Kb around the sweet spot
|
# we only do this for 4Kb around the sweet spot
|
||||||
|
|
||||||
open(FILE, "objdump -dS --adjust-vma=$vmaoffset --start-address=$decodestart --stop-address=$decodestop $filename |") || die "Cannot start objdump";
|
open(FILE, $cross_compile."objdump -dS --adjust-vma=$vmaoffset --start-address=$decodestart --stop-address=$decodestop $filename |") || die "Cannot start objdump";
|
||||||
|
|
||||||
while (<FILE>) {
|
while (<FILE>) {
|
||||||
my $line = $_;
|
my $line = $_;
|
||||||
|
@ -345,3 +355,16 @@ while ($i < $finish) {
|
||||||
$i = $i +1;
|
$i = $i +1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub usage {
|
||||||
|
print <<EOT;
|
||||||
|
Usage:
|
||||||
|
dmesg | perl $0 [OPTION] [VMLINUX]
|
||||||
|
|
||||||
|
OPTION:
|
||||||
|
-c, --cross-compile CROSS_COMPILE Specify the prefix used for toolchain.
|
||||||
|
-m, --module MODULE_DIRNAME Specify the module directory name.
|
||||||
|
-h, --help Help.
|
||||||
|
EOT
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue