Commit 52e13e219d5930fb8fb774050e6ecffa244a60a9

Authored by Hui Zhu
Committed by Michal Marek
1 parent d224a94ab9

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>

Showing 1 changed file with 36 additions and 13 deletions Side-by-side Diff

scripts/markup_oops.pl
... ... @@ -2,6 +2,7 @@
2 2  
3 3 use File::Basename;
4 4 use Math::BigInt;
  5 +use Getopt::Long;
5 6  
6 7 # Copyright 2008, Intel Corporation
7 8 #
... ... @@ -15,7 +16,17 @@
15 16 # Arjan van de Ven <arjan@linux.intel.com>
16 17  
17 18  
18   -my $vmlinux_name = $ARGV[0];
  19 +my $cross_compile = "";
  20 +my $vmlinux_name = "";
  21 +my $modulefile = "";
  22 +
  23 +# Get options
  24 +Getopt::Long::GetOptions(
  25 + 'cross-compile|c=s' => \$cross_compile,
  26 + 'module|m=s' => \$modulefile,
  27 + 'help|h' => \&usage,
  28 +);
  29 +my $vmlinux_name = $ARGV[$#ARGV];
19 30 if (!defined($vmlinux_name)) {
20 31 my $kerver = `uname -r`;
21 32 chomp($kerver);
22 33  
... ... @@ -23,10 +34,9 @@
23 34 print "No vmlinux specified, assuming $vmlinux_name\n";
24 35 }
25 36 my $filename = $vmlinux_name;
26   -#
27   -# Step 1: Parse the oops to find the EIP value
28   -#
29 37  
  38 +# Parse the oops to find the EIP value
  39 +
30 40 my $target = "0";
31 41 my $function;
32 42 my $module = "";
33 43  
34 44  
35 45  
... ... @@ -177,26 +187,26 @@
177 187 my $decodestop = Math::BigInt->from_hex("0x$target") + 8192;
178 188 if ($target eq "0") {
179 189 print "No oops found!\n";
180   - print "Usage: \n";
181   - print " dmesg | perl scripts/markup_oops.pl vmlinux\n";
182   - exit;
  190 + usage();
183 191 }
184 192  
185 193 # if it's a module, we need to find the .ko file and calculate a load offset
186 194 if ($module ne "") {
187   - my $modulefile = `modinfo $module | grep '^filename:' | awk '{ print \$2 }'`;
188   - chomp($modulefile);
  195 + if ($modulefile eq "") {
  196 + my $modulefile = `modinfo $module | grep '^filename:' | awk '{ print \$2 }'`;
  197 + chomp($modulefile);
  198 + }
189 199 $filename = $modulefile;
190 200 if ($filename eq "") {
191 201 print "Module .ko file for $module not found. Aborting\n";
192 202 exit;
193 203 }
194 204 # ok so we found the module, now we need to calculate the vma offset
195   - open(FILE, "objdump -dS $filename |") || die "Cannot start objdump";
  205 + open(FILE, $cross_compile."objdump -dS $filename |") || die "Cannot start objdump";
196 206 while (<FILE>) {
197 207 if ($_ =~ /^([0-9a-f]+) \<$function\>\:/) {
198 208 my $fu = $1;
199   - $vmaoffset = hex($target) - hex($fu) - hex($func_offset);
  209 + $vmaoffset = Math::BigInt->from_hex("0x$target") - Math::BigInt->from_hex("0x$fu") - Math::BigInt->from_hex("0x$func_offset");
200 210 }
201 211 }
202 212 close(FILE);
... ... @@ -212,7 +222,7 @@
212 222 my ($address, $target) = @_;
213 223 my $ad = "0x".$address;
214 224 my $ta = "0x".$target;
215   - my $delta = hex($ad) - hex($ta);
  225 + my $delta = Math::BigInt->from_hex($ad) - Math::BigInt->from_hex($ta);
216 226  
217 227 if (($delta > -4096) && ($delta < 4096)) {
218 228 return 1;
... ... @@ -225,7 +235,7 @@
225 235 # first, parse the input into the lines array, but to keep size down,
226 236 # we only do this for 4Kb around the sweet spot
227 237  
228   -open(FILE, "objdump -dS --adjust-vma=$vmaoffset --start-address=$decodestart --stop-address=$decodestop $filename |") || die "Cannot start objdump";
  238 +open(FILE, $cross_compile."objdump -dS --adjust-vma=$vmaoffset --start-address=$decodestart --stop-address=$decodestop $filename |") || die "Cannot start objdump";
229 239  
230 240 while (<FILE>) {
231 241 my $line = $_;
... ... @@ -343,5 +353,18 @@
343 353 }
344 354 print "\n";
345 355 $i = $i +1;
  356 +}
  357 +
  358 +sub usage {
  359 + print <<EOT;
  360 +Usage:
  361 + dmesg | perl $0 [OPTION] [VMLINUX]
  362 +
  363 +OPTION:
  364 + -c, --cross-compile CROSS_COMPILE Specify the prefix used for toolchain.
  365 + -m, --module MODULE_DIRNAME Specify the module directory name.
  366 + -h, --help Help.
  367 +EOT
  368 + exit;
346 369 }