Merge branch 'for-linus' of git://oss.sgi.com/xfs/xfs into for-2.6.34-incoming
[safe/jmp/linux-2.6] / scripts / markup_oops.pl
index bb20468..e950f9c 100644 (file)
@@ -1,6 +1,7 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl
 
 use File::Basename;
+use Math::BigInt;
 
 # Copyright 2008, Intel Corporation
 #
@@ -29,7 +30,7 @@ my $filename = $vmlinux_name;
 my $target = "0";
 my $function;
 my $module = "";
-my $func_offset;
+my $func_offset = 0;
 my $vmaoffset = 0;
 
 my %regs;
@@ -49,6 +50,39 @@ sub parse_x86_regs
                $regs{"%edi"} = $2;
                $regs{"%esp"} = $4;
        }
+       if ($line =~ /RAX: ([0-9a-f]+) RBX: ([0-9a-f]+) RCX: ([0-9a-f]+)/) {
+               $regs{"%eax"} = $1;
+               $regs{"%ebx"} = $2;
+               $regs{"%ecx"} = $3;
+       }
+       if ($line =~ /RDX: ([0-9a-f]+) RSI: ([0-9a-f]+) RDI: ([0-9a-f]+)/) {
+               $regs{"%edx"} = $1;
+               $regs{"%esi"} = $2;
+               $regs{"%edi"} = $3;
+       }
+       if ($line =~ /RBP: ([0-9a-f]+) R08: ([0-9a-f]+) R09: ([0-9a-f]+)/) {
+               $regs{"%r08"} = $2;
+               $regs{"%r09"} = $3;
+       }
+       if ($line =~ /R10: ([0-9a-f]+) R11: ([0-9a-f]+) R12: ([0-9a-f]+)/) {
+               $regs{"%r10"} = $1;
+               $regs{"%r11"} = $2;
+               $regs{"%r12"} = $3;
+       }
+       if ($line =~ /R13: ([0-9a-f]+) R14: ([0-9a-f]+) R15: ([0-9a-f]+)/) {
+               $regs{"%r13"} = $1;
+               $regs{"%r14"} = $2;
+               $regs{"%r15"} = $3;
+       }
+}
+
+sub reg_name
+{
+       my ($reg) = @_;
+       $reg =~ s/r(.)x/e\1x/;
+       $reg =~ s/r(.)i/e\1i/;
+       $reg =~ s/r(.)p/e\1p/;
+       return $reg;
 }
 
 sub process_x86_regs
@@ -83,10 +117,18 @@ sub process_x86_regs
        }
 
        foreach $reg (keys(%regs)) {
+               my $clobberprime = reg_name($clobber);
+               my $lastwordprime = reg_name($lastword);
                my $val = $regs{$reg};
+               if ($val =~ /^[0]+$/) {
+                       $val = "0";
+               } else {
+                       $val =~ s/^0*//;
+               }
+
                # first check if we're clobbering this register; if we do
                # we print it with a =>, and then delete its value
-               if ($clobber =~ /$reg/) {
+               if ($clobber =~ /$reg/ || $clobberprime =~ /$reg/) {
                        if (length($val) > 0) {
                                $str = $str . " $reg => $val ";
                        }
@@ -94,7 +136,7 @@ sub process_x86_regs
                        $val = "";
                }
                # now check if we're reading this register
-               if ($lastword =~ /$reg/) {
+               if ($lastword =~ /$reg/ || $lastwordprime =~ /$reg/) {
                        if (length($val) > 0) {
                                $str = $str . " $reg = $val ";
                        }
@@ -109,7 +151,14 @@ while (<STDIN>) {
        if ($line =~ /EIP: 0060:\[\<([a-z0-9]+)\>\]/) {
                $target = $1;
        }
-       if ($line =~ /EIP is at ([a-zA-Z0-9\_]+)\+(0x[0-9a-f]+)\/0x[a-f0-9]/) {
+       if ($line =~ /RIP: 0010:\[\<([a-z0-9]+)\>\]/) {
+               $target = $1;
+       }
+       if ($line =~ /EIP is at ([a-zA-Z0-9\_]+)\+0x([0-9a-f]+)\/0x[a-f0-9]/) {
+               $function = $1;
+               $func_offset = $2;
+       }
+       if ($line =~ /RIP: 0010:\[\<[0-9a-f]+\>\]  \[\<[0-9a-f]+\>\] ([a-zA-Z0-9\_]+)\+0x([0-9a-f]+)\/0x[a-f0-9]/) {
                $function = $1;
                $func_offset = $2;
        }
@@ -118,11 +167,14 @@ while (<STDIN>) {
        if ($line =~ /EIP is at ([a-zA-Z0-9\_]+)\+(0x[0-9a-f]+)\/0x[a-f0-9]+\W\[([a-zA-Z0-9\_\-]+)\]/) {
                $module = $3;
        }
+       if ($line =~ /RIP: 0010:\[\<[0-9a-f]+\>\]  \[\<[0-9a-f]+\>\] ([a-zA-Z0-9\_]+)\+(0x[0-9a-f]+)\/0x[a-f0-9]+\W\[([a-zA-Z0-9\_\-]+)\]/) {
+               $module = $3;
+       }
        parse_x86_regs($line);
 }
 
-my $decodestart = hex($target) - hex($func_offset);
-my $decodestop = hex($target) + 8192;
+my $decodestart = Math::BigInt->from_hex("0x$target") - Math::BigInt->from_hex("0x$func_offset");
+my $decodestop = Math::BigInt->from_hex("0x$target") + 8192;
 if ($target eq "0") {
        print "No oops found!\n";
        print "Usage: \n";
@@ -132,10 +184,7 @@ if ($target eq "0") {
 
 # if it's a module, we need to find the .ko file and calculate a load offset
 if ($module ne "") {
-       my $dir = dirname($filename);
-       $dir = $dir . "/";
-       my $mod = $module . ".ko";
-       my $modulefile = `find $dir -name $mod | head -1`;
+       my $modulefile = `modinfo $module | grep '^filename:' | awk '{ print \$2 }'`;
        chomp($modulefile);
        $filename = $modulefile;
        if ($filename eq "") {