aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/markup_oops.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/markup_oops.pl')
-rw-r--r--scripts/markup_oops.pl216
1 files changed, 201 insertions, 15 deletions
diff --git a/scripts/markup_oops.pl b/scripts/markup_oops.pl
index 700a7a654a3f..528492bcba5b 100644
--- a/scripts/markup_oops.pl
+++ b/scripts/markup_oops.pl
@@ -1,4 +1,6 @@
1#!/usr/bin/perl -w 1#!/usr/bin/perl
2
3use File::Basename;
2 4
3# Copyright 2008, Intel Corporation 5# Copyright 2008, Intel Corporation
4# 6#
@@ -13,23 +15,165 @@
13 15
14 16
15my $vmlinux_name = $ARGV[0]; 17my $vmlinux_name = $ARGV[0];
16 18if (!defined($vmlinux_name)) {
19 my $kerver = `uname -r`;
20 chomp($kerver);
21 $vmlinux_name = "/lib/modules/$kerver/build/vmlinux";
22 print "No vmlinux specified, assuming $vmlinux_name\n";
23}
24my $filename = $vmlinux_name;
17# 25#
18# Step 1: Parse the oops to find the EIP value 26# Step 1: Parse the oops to find the EIP value
19# 27#
20 28
21my $target = "0"; 29my $target = "0";
30my $function;
31my $module = "";
32my $func_offset = 0;
33my $vmaoffset = 0;
34
35my %regs;
36
37
38sub parse_x86_regs
39{
40 my ($line) = @_;
41 if ($line =~ /EAX: ([0-9a-f]+) EBX: ([0-9a-f]+) ECX: ([0-9a-f]+) EDX: ([0-9a-f]+)/) {
42 $regs{"%eax"} = $1;
43 $regs{"%ebx"} = $2;
44 $regs{"%ecx"} = $3;
45 $regs{"%edx"} = $4;
46 }
47 if ($line =~ /ESI: ([0-9a-f]+) EDI: ([0-9a-f]+) EBP: ([0-9a-f]+) ESP: ([0-9a-f]+)/) {
48 $regs{"%esi"} = $1;
49 $regs{"%edi"} = $2;
50 $regs{"%esp"} = $4;
51 }
52 if ($line =~ /RAX: ([0-9a-f]+) RBX: ([0-9a-f]+) RCX: ([0-9a-f]+)/) {
53 $regs{"%eax"} = $1;
54 $regs{"%ebx"} = $2;
55 $regs{"%ecx"} = $3;
56 }
57 if ($line =~ /RDX: ([0-9a-f]+) RSI: ([0-9a-f]+) RDI: ([0-9a-f]+)/) {
58 $regs{"%edx"} = $1;
59 $regs{"%esi"} = $2;
60 $regs{"%edi"} = $3;
61 }
62 if ($line =~ /RBP: ([0-9a-f]+) R08: ([0-9a-f]+) R09: ([0-9a-f]+)/) {
63 $regs{"%r08"} = $2;
64 $regs{"%r09"} = $3;
65 }
66 if ($line =~ /R10: ([0-9a-f]+) R11: ([0-9a-f]+) R12: ([0-9a-f]+)/) {
67 $regs{"%r10"} = $1;
68 $regs{"%r11"} = $2;
69 $regs{"%r12"} = $3;
70 }
71 if ($line =~ /R13: ([0-9a-f]+) R14: ([0-9a-f]+) R15: ([0-9a-f]+)/) {
72 $regs{"%r13"} = $1;
73 $regs{"%r14"} = $2;
74 $regs{"%r15"} = $3;
75 }
76}
77
78sub reg_name
79{
80 my ($reg) = @_;
81 $reg =~ s/r(.)x/e\1x/;
82 $reg =~ s/r(.)i/e\1i/;
83 $reg =~ s/r(.)p/e\1p/;
84 return $reg;
85}
86
87sub process_x86_regs
88{
89 my ($line, $cntr) = @_;
90 my $str = "";
91 if (length($line) < 40) {
92 return ""; # not an asm istruction
93 }
94
95 # find the arguments to the instruction
96 if ($line =~ /([0-9a-zA-Z\,\%\(\)\-\+]+)$/) {
97 $lastword = $1;
98 } else {
99 return "";
100 }
101
102 # we need to find the registers that get clobbered,
103 # since their value is no longer relevant for previous
104 # instructions in the stream.
105
106 $clobber = $lastword;
107 # first, remove all memory operands, they're read only
108 $clobber =~ s/\([a-z0-9\%\,]+\)//g;
109 # then, remove everything before the comma, thats the read part
110 $clobber =~ s/.*\,//g;
111
112 # if this is the instruction that faulted, we haven't actually done
113 # the write yet... nothing is clobbered.
114 if ($cntr == 0) {
115 $clobber = "";
116 }
117
118 foreach $reg (keys(%regs)) {
119 my $clobberprime = reg_name($clobber);
120 my $lastwordprime = reg_name($lastword);
121 my $val = $regs{$reg};
122 if ($val =~ /^[0]+$/) {
123 $val = "0";
124 } else {
125 $val =~ s/^0*//;
126 }
127
128 # first check if we're clobbering this register; if we do
129 # we print it with a =>, and then delete its value
130 if ($clobber =~ /$reg/ || $clobberprime =~ /$reg/) {
131 if (length($val) > 0) {
132 $str = $str . " $reg => $val ";
133 }
134 $regs{$reg} = "";
135 $val = "";
136 }
137 # now check if we're reading this register
138 if ($lastword =~ /$reg/ || $lastwordprime =~ /$reg/) {
139 if (length($val) > 0) {
140 $str = $str . " $reg = $val ";
141 }
142 }
143 }
144 return $str;
145}
146
147# parse the oops
22while (<STDIN>) { 148while (<STDIN>) {
23 if ($_ =~ /EIP: 0060:\[\<([a-z0-9]+)\>\]/) { 149 my $line = $_;
150 if ($line =~ /EIP: 0060:\[\<([a-z0-9]+)\>\]/) {
24 $target = $1; 151 $target = $1;
25 } 152 }
26} 153 if ($line =~ /RIP: 0010:\[\<([a-z0-9]+)\>\]/) {
154 $target = $1;
155 }
156 if ($line =~ /EIP is at ([a-zA-Z0-9\_]+)\+(0x[0-9a-f]+)\/0x[a-f0-9]/) {
157 $function = $1;
158 $func_offset = $2;
159 }
160 if ($line =~ /RIP: 0010:\[\<[0-9a-f]+\>\] \[\<[0-9a-f]+\>\] ([a-zA-Z0-9\_]+)\+(0x[0-9a-f]+)\/0x[a-f0-9]/) {
161 $function = $1;
162 $func_offset = $2;
163 }
27 164
28if ($target =~ /^f8/) { 165 # check if it's a module
29 print "This script does not work on modules ... \n"; 166 if ($line =~ /EIP is at ([a-zA-Z0-9\_]+)\+(0x[0-9a-f]+)\/0x[a-f0-9]+\W\[([a-zA-Z0-9\_\-]+)\]/) {
30 exit; 167 $module = $3;
168 }
169 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\_\-]+)\]/) {
170 $module = $3;
171 }
172 parse_x86_regs($line);
31} 173}
32 174
175my $decodestart = hex($target) - hex($func_offset);
176my $decodestop = hex($target) + 8192;
33if ($target eq "0") { 177if ($target eq "0") {
34 print "No oops found!\n"; 178 print "No oops found!\n";
35 print "Usage: \n"; 179 print "Usage: \n";
@@ -37,10 +181,34 @@ if ($target eq "0") {
37 exit; 181 exit;
38} 182}
39 183
184# if it's a module, we need to find the .ko file and calculate a load offset
185if ($module ne "") {
186 my $dir = dirname($filename);
187 $dir = $dir . "/";
188 my $mod = $module . ".ko";
189 my $modulefile = `find $dir -name $mod | head -1`;
190 chomp($modulefile);
191 $filename = $modulefile;
192 if ($filename eq "") {
193 print "Module .ko file for $module not found. Aborting\n";
194 exit;
195 }
196 # ok so we found the module, now we need to calculate the vma offset
197 open(FILE, "objdump -dS $filename |") || die "Cannot start objdump";
198 while (<FILE>) {
199 if ($_ =~ /^([0-9a-f]+) \<$function\>\:/) {
200 my $fu = $1;
201 $vmaoffset = hex($target) - hex($fu) - hex($func_offset);
202 }
203 }
204 close(FILE);
205}
206
40my $counter = 0; 207my $counter = 0;
41my $state = 0; 208my $state = 0;
42my $center = 0; 209my $center = 0;
43my @lines; 210my @lines;
211my @reglines;
44 212
45sub InRange { 213sub InRange {
46 my ($address, $target) = @_; 214 my ($address, $target) = @_;
@@ -59,9 +227,7 @@ sub InRange {
59# first, parse the input into the lines array, but to keep size down, 227# first, parse the input into the lines array, but to keep size down,
60# we only do this for 4Kb around the sweet spot 228# we only do this for 4Kb around the sweet spot
61 229
62my $filename; 230open(FILE, "objdump -dS --adjust-vma=$vmaoffset --start-address=$decodestart --stop-address=$decodestop $filename |") || die "Cannot start objdump";
63
64open(FILE, "objdump -dS $vmlinux_name |") || die "Cannot start objdump";
65 231
66while (<FILE>) { 232while (<FILE>) {
67 my $line = $_; 233 my $line = $_;
@@ -147,16 +313,36 @@ while ($finish < $counter) {
147 313
148my $i; 314my $i;
149 315
150my $fulltext = ""; 316
317# start annotating the registers in the asm.
318# this goes from the oopsing point back, so that the annotator
319# can track (opportunistically) which registers got written and
320# whos value no longer is relevant.
321
322$i = $center;
323while ($i >= $start) {
324 $reglines[$i] = process_x86_regs($lines[$i], $center - $i);
325 $i = $i - 1;
326}
327
151$i = $start; 328$i = $start;
152while ($i < $finish) { 329while ($i < $finish) {
330 my $line;
153 if ($i == $center) { 331 if ($i == $center) {
154 $fulltext = $fulltext . "*$lines[$i] <----- faulting instruction\n"; 332 $line = "*$lines[$i] ";
155 } else { 333 } else {
156 $fulltext = $fulltext . " $lines[$i]\n"; 334 $line = " $lines[$i] ";
335 }
336 print $line;
337 if (defined($reglines[$i]) && length($reglines[$i]) > 0) {
338 my $c = 60 - length($line);
339 while ($c > 0) { print " "; $c = $c - 1; };
340 print "| $reglines[$i]";
157 } 341 }
342 if ($i == $center) {
343 print "<--- faulting instruction";
344 }
345 print "\n";
158 $i = $i +1; 346 $i = $i +1;
159} 347}
160 348
161print $fulltext;
162