5 # Copyright 2008, Intel Corporation
7 # This file is part of the Linux kernel
9 # This program file is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by the
11 # Free Software Foundation; version 2 of the License.
14 # Arjan van de Ven <arjan@linux.intel.com>
17 my $vmlinux_name = $ARGV[0];
18 if (!defined($vmlinux_name)) {
19 my $kerver = `uname -r`;
21 $vmlinux_name = "/lib/modules/$kerver/build/vmlinux";
22 print "No vmlinux specified, assuming $vmlinux_name\n";
24 my $filename = $vmlinux_name;
26 # Step 1: Parse the oops to find the EIP value
41 if ($line =~ /EAX: ([0-9a-f]+) EBX: ([0-9a-f]+) ECX: ([0-9a-f]+) EDX: ([0-9a-f]+)/) {
47 if ($line =~ /ESI: ([0-9a-f]+) EDI: ([0-9a-f]+) EBP: ([0-9a-f]+) ESP: ([0-9a-f]+)/) {
56 my ($line, $cntr) = @_;
58 if (length($line) < 40) {
59 return ""; # not an asm istruction
62 # find the arguments to the instruction
63 if ($line =~ /([0-9a-zA-Z\,\%\(\)\-\+]+)$/) {
69 # we need to find the registers that get clobbered,
70 # since their value is no longer relevant for previous
71 # instructions in the stream.
74 # first, remove all memory operands, they're read only
75 $clobber =~ s/\([a-z0-9\%\,]+\)//g;
76 # then, remove everything before the comma, thats the read part
77 $clobber =~ s/.*\,//g;
79 # if this is the instruction that faulted, we haven't actually done
80 # the write yet... nothing is clobbered.
85 foreach $reg (keys(%regs)) {
86 my $val = $regs{$reg};
87 # first check if we're clobbering this register; if we do
88 # we print it with a =>, and then delete its value
89 if ($clobber =~ /$reg/) {
90 if (length($val) > 0) {
91 $str = $str . " $reg => $val ";
96 # now check if we're reading this register
97 if ($lastword =~ /$reg/) {
98 if (length($val) > 0) {
99 $str = $str . " $reg = $val ";
109 if ($line =~ /EIP: 0060:\[\<([a-z0-9]+)\>\]/) {
112 if ($line =~ /EIP is at ([a-zA-Z0-9\_]+)\+(0x[0-9a-f]+)\/0x[a-f0-9]/) {
117 # check if it's a module
118 if ($line =~ /EIP is at ([a-zA-Z0-9\_]+)\+(0x[0-9a-f]+)\/0x[a-f0-9]+\W\[([a-zA-Z0-9\_\-]+)\]/) {
121 parse_x86_regs($line);
124 my $decodestart = hex($target) - hex($func_offset);
125 my $decodestop = hex($target) + 8192;
126 if ($target eq "0") {
127 print "No oops found!\n";
129 print " dmesg | perl scripts/markup_oops.pl vmlinux\n";
133 # if it's a module, we need to find the .ko file and calculate a load offset
135 my $dir = dirname($filename);
137 my $mod = $module . ".ko";
138 my $modulefile = `find $dir -name $mod | head -1`;
140 $filename = $modulefile;
141 if ($filename eq "") {
142 print "Module .ko file for $module not found. Aborting\n";
145 # ok so we found the module, now we need to calculate the vma offset
146 open(FILE, "objdump -dS $filename |") || die "Cannot start objdump";
148 if ($_ =~ /^([0-9a-f]+) \<$function\>\:/) {
150 $vmaoffset = hex($target) - hex($fu) - hex($func_offset);
163 my ($address, $target) = @_;
164 my $ad = "0x".$address;
165 my $ta = "0x".$target;
166 my $delta = hex($ad) - hex($ta);
168 if (($delta > -4096) && ($delta < 4096)) {
176 # first, parse the input into the lines array, but to keep size down,
177 # we only do this for 4Kb around the sweet spot
179 open(FILE, "objdump -dS --adjust-vma=$vmaoffset --start-address=$decodestart --stop-address=$decodestop $filename |") || die "Cannot start objdump";
185 if ($line =~ /^([a-f0-9]+)\:/) {
186 if (InRange($1, $target)) {
191 if ($line =~ /^([a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]+)\:/) {
193 if (!InRange($val, $target)) {
196 if ($val eq $target) {
200 $lines[$counter] = $line;
202 $counter = $counter + 1;
209 print "No matching code found \n";
214 print "No matching code found \n";
222 # now we go up and down in the array to find how much we want to print
228 my $line = $lines[$start];
229 if ($line =~ /^([a-f0-9]+)\:/) {
230 $binarylines = $binarylines + 1;
232 $codelines = $codelines + 1;
234 if ($codelines > 10) {
237 if ($binarylines > 20) {
246 while ($finish < $counter) {
247 $finish = $finish + 1;
248 my $line = $lines[$finish];
249 if ($line =~ /^([a-f0-9]+)\:/) {
250 $binarylines = $binarylines + 1;
252 $codelines = $codelines + 1;
254 if ($codelines > 10) {
257 if ($binarylines > 20) {
266 # start annotating the registers in the asm.
267 # this goes from the oopsing point back, so that the annotator
268 # can track (opportunistically) which registers got written and
269 # whos value no longer is relevant.
272 while ($i >= $start) {
273 $reglines[$i] = process_x86_regs($lines[$i], $center - $i);
278 while ($i < $finish) {
281 $line = "*$lines[$i] ";
283 $line = " $lines[$i] ";
286 if (defined($reglines[$i]) && length($reglines[$i]) > 0) {
287 my $c = 60 - length($line);
288 while ($c > 0) { print " "; $c = $c - 1; };
289 print "| $reglines[$i]";
292 print "<--- faulting instruction";