Commit 52e13e219d5930fb8fb774050e6ecffa244a60a9
Committed by
Michal Marek
1 parent
d224a94ab9
Exists in
master
and in
20 other branches
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 Inline Diff
scripts/markup_oops.pl
1 | #!/usr/bin/perl | 1 | #!/usr/bin/perl |
2 | 2 | ||
3 | use File::Basename; | 3 | use File::Basename; |
4 | use Math::BigInt; | 4 | use Math::BigInt; |
5 | use Getopt::Long; | ||
5 | 6 | ||
6 | # Copyright 2008, Intel Corporation | 7 | # Copyright 2008, Intel Corporation |
7 | # | 8 | # |
8 | # This file is part of the Linux kernel | 9 | # This file is part of the Linux kernel |
9 | # | 10 | # |
10 | # This program file is free software; you can redistribute it and/or modify it | 11 | # This program file is free software; you can redistribute it and/or modify it |
11 | # under the terms of the GNU General Public License as published by the | 12 | # under the terms of the GNU General Public License as published by the |
12 | # Free Software Foundation; version 2 of the License. | 13 | # Free Software Foundation; version 2 of the License. |
13 | # | 14 | # |
14 | # Authors: | 15 | # Authors: |
15 | # Arjan van de Ven <arjan@linux.intel.com> | 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 | if (!defined($vmlinux_name)) { | 30 | if (!defined($vmlinux_name)) { |
20 | my $kerver = `uname -r`; | 31 | my $kerver = `uname -r`; |
21 | chomp($kerver); | 32 | chomp($kerver); |
22 | $vmlinux_name = "/lib/modules/$kerver/build/vmlinux"; | 33 | $vmlinux_name = "/lib/modules/$kerver/build/vmlinux"; |
23 | print "No vmlinux specified, assuming $vmlinux_name\n"; | 34 | print "No vmlinux specified, assuming $vmlinux_name\n"; |
24 | } | 35 | } |
25 | my $filename = $vmlinux_name; | 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 | my $target = "0"; | 40 | my $target = "0"; |
31 | my $function; | 41 | my $function; |
32 | my $module = ""; | 42 | my $module = ""; |
33 | my $func_offset = 0; | 43 | my $func_offset = 0; |
34 | my $vmaoffset = 0; | 44 | my $vmaoffset = 0; |
35 | 45 | ||
36 | my %regs; | 46 | my %regs; |
37 | 47 | ||
38 | 48 | ||
39 | sub parse_x86_regs | 49 | sub parse_x86_regs |
40 | { | 50 | { |
41 | my ($line) = @_; | 51 | my ($line) = @_; |
42 | if ($line =~ /EAX: ([0-9a-f]+) EBX: ([0-9a-f]+) ECX: ([0-9a-f]+) EDX: ([0-9a-f]+)/) { | 52 | if ($line =~ /EAX: ([0-9a-f]+) EBX: ([0-9a-f]+) ECX: ([0-9a-f]+) EDX: ([0-9a-f]+)/) { |
43 | $regs{"%eax"} = $1; | 53 | $regs{"%eax"} = $1; |
44 | $regs{"%ebx"} = $2; | 54 | $regs{"%ebx"} = $2; |
45 | $regs{"%ecx"} = $3; | 55 | $regs{"%ecx"} = $3; |
46 | $regs{"%edx"} = $4; | 56 | $regs{"%edx"} = $4; |
47 | } | 57 | } |
48 | if ($line =~ /ESI: ([0-9a-f]+) EDI: ([0-9a-f]+) EBP: ([0-9a-f]+) ESP: ([0-9a-f]+)/) { | 58 | if ($line =~ /ESI: ([0-9a-f]+) EDI: ([0-9a-f]+) EBP: ([0-9a-f]+) ESP: ([0-9a-f]+)/) { |
49 | $regs{"%esi"} = $1; | 59 | $regs{"%esi"} = $1; |
50 | $regs{"%edi"} = $2; | 60 | $regs{"%edi"} = $2; |
51 | $regs{"%esp"} = $4; | 61 | $regs{"%esp"} = $4; |
52 | } | 62 | } |
53 | if ($line =~ /RAX: ([0-9a-f]+) RBX: ([0-9a-f]+) RCX: ([0-9a-f]+)/) { | 63 | if ($line =~ /RAX: ([0-9a-f]+) RBX: ([0-9a-f]+) RCX: ([0-9a-f]+)/) { |
54 | $regs{"%eax"} = $1; | 64 | $regs{"%eax"} = $1; |
55 | $regs{"%ebx"} = $2; | 65 | $regs{"%ebx"} = $2; |
56 | $regs{"%ecx"} = $3; | 66 | $regs{"%ecx"} = $3; |
57 | } | 67 | } |
58 | if ($line =~ /RDX: ([0-9a-f]+) RSI: ([0-9a-f]+) RDI: ([0-9a-f]+)/) { | 68 | if ($line =~ /RDX: ([0-9a-f]+) RSI: ([0-9a-f]+) RDI: ([0-9a-f]+)/) { |
59 | $regs{"%edx"} = $1; | 69 | $regs{"%edx"} = $1; |
60 | $regs{"%esi"} = $2; | 70 | $regs{"%esi"} = $2; |
61 | $regs{"%edi"} = $3; | 71 | $regs{"%edi"} = $3; |
62 | } | 72 | } |
63 | if ($line =~ /RBP: ([0-9a-f]+) R08: ([0-9a-f]+) R09: ([0-9a-f]+)/) { | 73 | if ($line =~ /RBP: ([0-9a-f]+) R08: ([0-9a-f]+) R09: ([0-9a-f]+)/) { |
64 | $regs{"%r08"} = $2; | 74 | $regs{"%r08"} = $2; |
65 | $regs{"%r09"} = $3; | 75 | $regs{"%r09"} = $3; |
66 | } | 76 | } |
67 | if ($line =~ /R10: ([0-9a-f]+) R11: ([0-9a-f]+) R12: ([0-9a-f]+)/) { | 77 | if ($line =~ /R10: ([0-9a-f]+) R11: ([0-9a-f]+) R12: ([0-9a-f]+)/) { |
68 | $regs{"%r10"} = $1; | 78 | $regs{"%r10"} = $1; |
69 | $regs{"%r11"} = $2; | 79 | $regs{"%r11"} = $2; |
70 | $regs{"%r12"} = $3; | 80 | $regs{"%r12"} = $3; |
71 | } | 81 | } |
72 | if ($line =~ /R13: ([0-9a-f]+) R14: ([0-9a-f]+) R15: ([0-9a-f]+)/) { | 82 | if ($line =~ /R13: ([0-9a-f]+) R14: ([0-9a-f]+) R15: ([0-9a-f]+)/) { |
73 | $regs{"%r13"} = $1; | 83 | $regs{"%r13"} = $1; |
74 | $regs{"%r14"} = $2; | 84 | $regs{"%r14"} = $2; |
75 | $regs{"%r15"} = $3; | 85 | $regs{"%r15"} = $3; |
76 | } | 86 | } |
77 | } | 87 | } |
78 | 88 | ||
79 | sub reg_name | 89 | sub reg_name |
80 | { | 90 | { |
81 | my ($reg) = @_; | 91 | my ($reg) = @_; |
82 | $reg =~ s/r(.)x/e\1x/; | 92 | $reg =~ s/r(.)x/e\1x/; |
83 | $reg =~ s/r(.)i/e\1i/; | 93 | $reg =~ s/r(.)i/e\1i/; |
84 | $reg =~ s/r(.)p/e\1p/; | 94 | $reg =~ s/r(.)p/e\1p/; |
85 | return $reg; | 95 | return $reg; |
86 | } | 96 | } |
87 | 97 | ||
88 | sub process_x86_regs | 98 | sub process_x86_regs |
89 | { | 99 | { |
90 | my ($line, $cntr) = @_; | 100 | my ($line, $cntr) = @_; |
91 | my $str = ""; | 101 | my $str = ""; |
92 | if (length($line) < 40) { | 102 | if (length($line) < 40) { |
93 | return ""; # not an asm istruction | 103 | return ""; # not an asm istruction |
94 | } | 104 | } |
95 | 105 | ||
96 | # find the arguments to the instruction | 106 | # find the arguments to the instruction |
97 | if ($line =~ /([0-9a-zA-Z\,\%\(\)\-\+]+)$/) { | 107 | if ($line =~ /([0-9a-zA-Z\,\%\(\)\-\+]+)$/) { |
98 | $lastword = $1; | 108 | $lastword = $1; |
99 | } else { | 109 | } else { |
100 | return ""; | 110 | return ""; |
101 | } | 111 | } |
102 | 112 | ||
103 | # we need to find the registers that get clobbered, | 113 | # we need to find the registers that get clobbered, |
104 | # since their value is no longer relevant for previous | 114 | # since their value is no longer relevant for previous |
105 | # instructions in the stream. | 115 | # instructions in the stream. |
106 | 116 | ||
107 | $clobber = $lastword; | 117 | $clobber = $lastword; |
108 | # first, remove all memory operands, they're read only | 118 | # first, remove all memory operands, they're read only |
109 | $clobber =~ s/\([a-z0-9\%\,]+\)//g; | 119 | $clobber =~ s/\([a-z0-9\%\,]+\)//g; |
110 | # then, remove everything before the comma, thats the read part | 120 | # then, remove everything before the comma, thats the read part |
111 | $clobber =~ s/.*\,//g; | 121 | $clobber =~ s/.*\,//g; |
112 | 122 | ||
113 | # if this is the instruction that faulted, we haven't actually done | 123 | # if this is the instruction that faulted, we haven't actually done |
114 | # the write yet... nothing is clobbered. | 124 | # the write yet... nothing is clobbered. |
115 | if ($cntr == 0) { | 125 | if ($cntr == 0) { |
116 | $clobber = ""; | 126 | $clobber = ""; |
117 | } | 127 | } |
118 | 128 | ||
119 | foreach $reg (keys(%regs)) { | 129 | foreach $reg (keys(%regs)) { |
120 | my $clobberprime = reg_name($clobber); | 130 | my $clobberprime = reg_name($clobber); |
121 | my $lastwordprime = reg_name($lastword); | 131 | my $lastwordprime = reg_name($lastword); |
122 | my $val = $regs{$reg}; | 132 | my $val = $regs{$reg}; |
123 | if ($val =~ /^[0]+$/) { | 133 | if ($val =~ /^[0]+$/) { |
124 | $val = "0"; | 134 | $val = "0"; |
125 | } else { | 135 | } else { |
126 | $val =~ s/^0*//; | 136 | $val =~ s/^0*//; |
127 | } | 137 | } |
128 | 138 | ||
129 | # first check if we're clobbering this register; if we do | 139 | # first check if we're clobbering this register; if we do |
130 | # we print it with a =>, and then delete its value | 140 | # we print it with a =>, and then delete its value |
131 | if ($clobber =~ /$reg/ || $clobberprime =~ /$reg/) { | 141 | if ($clobber =~ /$reg/ || $clobberprime =~ /$reg/) { |
132 | if (length($val) > 0) { | 142 | if (length($val) > 0) { |
133 | $str = $str . " $reg => $val "; | 143 | $str = $str . " $reg => $val "; |
134 | } | 144 | } |
135 | $regs{$reg} = ""; | 145 | $regs{$reg} = ""; |
136 | $val = ""; | 146 | $val = ""; |
137 | } | 147 | } |
138 | # now check if we're reading this register | 148 | # now check if we're reading this register |
139 | if ($lastword =~ /$reg/ || $lastwordprime =~ /$reg/) { | 149 | if ($lastword =~ /$reg/ || $lastwordprime =~ /$reg/) { |
140 | if (length($val) > 0) { | 150 | if (length($val) > 0) { |
141 | $str = $str . " $reg = $val "; | 151 | $str = $str . " $reg = $val "; |
142 | } | 152 | } |
143 | } | 153 | } |
144 | } | 154 | } |
145 | return $str; | 155 | return $str; |
146 | } | 156 | } |
147 | 157 | ||
148 | # parse the oops | 158 | # parse the oops |
149 | while (<STDIN>) { | 159 | while (<STDIN>) { |
150 | my $line = $_; | 160 | my $line = $_; |
151 | if ($line =~ /EIP: 0060:\[\<([a-z0-9]+)\>\]/) { | 161 | if ($line =~ /EIP: 0060:\[\<([a-z0-9]+)\>\]/) { |
152 | $target = $1; | 162 | $target = $1; |
153 | } | 163 | } |
154 | if ($line =~ /RIP: 0010:\[\<([a-z0-9]+)\>\]/) { | 164 | if ($line =~ /RIP: 0010:\[\<([a-z0-9]+)\>\]/) { |
155 | $target = $1; | 165 | $target = $1; |
156 | } | 166 | } |
157 | if ($line =~ /EIP is at ([a-zA-Z0-9\_]+)\+0x([0-9a-f]+)\/0x[a-f0-9]/) { | 167 | if ($line =~ /EIP is at ([a-zA-Z0-9\_]+)\+0x([0-9a-f]+)\/0x[a-f0-9]/) { |
158 | $function = $1; | 168 | $function = $1; |
159 | $func_offset = $2; | 169 | $func_offset = $2; |
160 | } | 170 | } |
161 | if ($line =~ /RIP: 0010:\[\<[0-9a-f]+\>\] \[\<[0-9a-f]+\>\] ([a-zA-Z0-9\_]+)\+(0x[0-9a-f]+)\/0x[a-f0-9]/) { | 171 | if ($line =~ /RIP: 0010:\[\<[0-9a-f]+\>\] \[\<[0-9a-f]+\>\] ([a-zA-Z0-9\_]+)\+(0x[0-9a-f]+)\/0x[a-f0-9]/) { |
162 | $function = $1; | 172 | $function = $1; |
163 | $func_offset = $2; | 173 | $func_offset = $2; |
164 | } | 174 | } |
165 | 175 | ||
166 | # check if it's a module | 176 | # check if it's a module |
167 | if ($line =~ /EIP is at ([a-zA-Z0-9\_]+)\+(0x[0-9a-f]+)\/0x[a-f0-9]+\W\[([a-zA-Z0-9\_\-]+)\]/) { | 177 | if ($line =~ /EIP is at ([a-zA-Z0-9\_]+)\+(0x[0-9a-f]+)\/0x[a-f0-9]+\W\[([a-zA-Z0-9\_\-]+)\]/) { |
168 | $module = $3; | 178 | $module = $3; |
169 | } | 179 | } |
170 | 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\_\-]+)\]/) { | 180 | 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\_\-]+)\]/) { |
171 | $module = $3; | 181 | $module = $3; |
172 | } | 182 | } |
173 | parse_x86_regs($line); | 183 | parse_x86_regs($line); |
174 | } | 184 | } |
175 | 185 | ||
176 | my $decodestart = Math::BigInt->from_hex("0x$target") - Math::BigInt->from_hex("0x$func_offset"); | 186 | my $decodestart = Math::BigInt->from_hex("0x$target") - Math::BigInt->from_hex("0x$func_offset"); |
177 | my $decodestop = Math::BigInt->from_hex("0x$target") + 8192; | 187 | my $decodestop = Math::BigInt->from_hex("0x$target") + 8192; |
178 | if ($target eq "0") { | 188 | if ($target eq "0") { |
179 | print "No oops found!\n"; | 189 | print "No oops found!\n"; |
180 | print "Usage: \n"; | 190 | usage(); |
181 | print " dmesg | perl scripts/markup_oops.pl vmlinux\n"; | ||
182 | exit; | ||
183 | } | 191 | } |
184 | 192 | ||
185 | # if it's a module, we need to find the .ko file and calculate a load offset | 193 | # if it's a module, we need to find the .ko file and calculate a load offset |
186 | if ($module ne "") { | 194 | if ($module ne "") { |
187 | my $modulefile = `modinfo $module | grep '^filename:' | awk '{ print \$2 }'`; | 195 | if ($modulefile eq "") { |
188 | chomp($modulefile); | 196 | my $modulefile = `modinfo $module | grep '^filename:' | awk '{ print \$2 }'`; |
197 | chomp($modulefile); | ||
198 | } | ||
189 | $filename = $modulefile; | 199 | $filename = $modulefile; |
190 | if ($filename eq "") { | 200 | if ($filename eq "") { |
191 | print "Module .ko file for $module not found. Aborting\n"; | 201 | print "Module .ko file for $module not found. Aborting\n"; |
192 | exit; | 202 | exit; |
193 | } | 203 | } |
194 | # ok so we found the module, now we need to calculate the vma offset | 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 | while (<FILE>) { | 206 | while (<FILE>) { |
197 | if ($_ =~ /^([0-9a-f]+) \<$function\>\:/) { | 207 | if ($_ =~ /^([0-9a-f]+) \<$function\>\:/) { |
198 | my $fu = $1; | 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 | close(FILE); | 212 | close(FILE); |
203 | } | 213 | } |
204 | 214 | ||
205 | my $counter = 0; | 215 | my $counter = 0; |
206 | my $state = 0; | 216 | my $state = 0; |
207 | my $center = -1; | 217 | my $center = -1; |
208 | my @lines; | 218 | my @lines; |
209 | my @reglines; | 219 | my @reglines; |
210 | 220 | ||
211 | sub InRange { | 221 | sub InRange { |
212 | my ($address, $target) = @_; | 222 | my ($address, $target) = @_; |
213 | my $ad = "0x".$address; | 223 | my $ad = "0x".$address; |
214 | my $ta = "0x".$target; | 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 | if (($delta > -4096) && ($delta < 4096)) { | 227 | if (($delta > -4096) && ($delta < 4096)) { |
218 | return 1; | 228 | return 1; |
219 | } | 229 | } |
220 | return 0; | 230 | return 0; |
221 | } | 231 | } |
222 | 232 | ||
223 | 233 | ||
224 | 234 | ||
225 | # first, parse the input into the lines array, but to keep size down, | 235 | # first, parse the input into the lines array, but to keep size down, |
226 | # we only do this for 4Kb around the sweet spot | 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 | while (<FILE>) { | 240 | while (<FILE>) { |
231 | my $line = $_; | 241 | my $line = $_; |
232 | chomp($line); | 242 | chomp($line); |
233 | if ($state == 0) { | 243 | if ($state == 0) { |
234 | if ($line =~ /^([a-f0-9]+)\:/) { | 244 | if ($line =~ /^([a-f0-9]+)\:/) { |
235 | if (InRange($1, $target)) { | 245 | if (InRange($1, $target)) { |
236 | $state = 1; | 246 | $state = 1; |
237 | } | 247 | } |
238 | } | 248 | } |
239 | } | 249 | } |
240 | if ($state == 1) { | 250 | if ($state == 1) { |
241 | if ($line =~ /^([a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]+)\:/) { | 251 | if ($line =~ /^([a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]+)\:/) { |
242 | my $val = $1; | 252 | my $val = $1; |
243 | if (!InRange($val, $target)) { | 253 | if (!InRange($val, $target)) { |
244 | last; | 254 | last; |
245 | } | 255 | } |
246 | if ($val eq $target) { | 256 | if ($val eq $target) { |
247 | $center = $counter; | 257 | $center = $counter; |
248 | } | 258 | } |
249 | } | 259 | } |
250 | $lines[$counter] = $line; | 260 | $lines[$counter] = $line; |
251 | 261 | ||
252 | $counter = $counter + 1; | 262 | $counter = $counter + 1; |
253 | } | 263 | } |
254 | } | 264 | } |
255 | 265 | ||
256 | close(FILE); | 266 | close(FILE); |
257 | 267 | ||
258 | if ($counter == 0) { | 268 | if ($counter == 0) { |
259 | print "No matching code found \n"; | 269 | print "No matching code found \n"; |
260 | exit; | 270 | exit; |
261 | } | 271 | } |
262 | 272 | ||
263 | if ($center == -1) { | 273 | if ($center == -1) { |
264 | print "No matching code found \n"; | 274 | print "No matching code found \n"; |
265 | exit; | 275 | exit; |
266 | } | 276 | } |
267 | 277 | ||
268 | my $start; | 278 | my $start; |
269 | my $finish; | 279 | my $finish; |
270 | my $codelines = 0; | 280 | my $codelines = 0; |
271 | my $binarylines = 0; | 281 | my $binarylines = 0; |
272 | # now we go up and down in the array to find how much we want to print | 282 | # now we go up and down in the array to find how much we want to print |
273 | 283 | ||
274 | $start = $center; | 284 | $start = $center; |
275 | 285 | ||
276 | while ($start > 1) { | 286 | while ($start > 1) { |
277 | $start = $start - 1; | 287 | $start = $start - 1; |
278 | my $line = $lines[$start]; | 288 | my $line = $lines[$start]; |
279 | if ($line =~ /^([a-f0-9]+)\:/) { | 289 | if ($line =~ /^([a-f0-9]+)\:/) { |
280 | $binarylines = $binarylines + 1; | 290 | $binarylines = $binarylines + 1; |
281 | } else { | 291 | } else { |
282 | $codelines = $codelines + 1; | 292 | $codelines = $codelines + 1; |
283 | } | 293 | } |
284 | if ($codelines > 10) { | 294 | if ($codelines > 10) { |
285 | last; | 295 | last; |
286 | } | 296 | } |
287 | if ($binarylines > 20) { | 297 | if ($binarylines > 20) { |
288 | last; | 298 | last; |
289 | } | 299 | } |
290 | } | 300 | } |
291 | 301 | ||
292 | 302 | ||
293 | $finish = $center; | 303 | $finish = $center; |
294 | $codelines = 0; | 304 | $codelines = 0; |
295 | $binarylines = 0; | 305 | $binarylines = 0; |
296 | while ($finish < $counter) { | 306 | while ($finish < $counter) { |
297 | $finish = $finish + 1; | 307 | $finish = $finish + 1; |
298 | my $line = $lines[$finish]; | 308 | my $line = $lines[$finish]; |
299 | if ($line =~ /^([a-f0-9]+)\:/) { | 309 | if ($line =~ /^([a-f0-9]+)\:/) { |
300 | $binarylines = $binarylines + 1; | 310 | $binarylines = $binarylines + 1; |
301 | } else { | 311 | } else { |
302 | $codelines = $codelines + 1; | 312 | $codelines = $codelines + 1; |
303 | } | 313 | } |
304 | if ($codelines > 10) { | 314 | if ($codelines > 10) { |
305 | last; | 315 | last; |
306 | } | 316 | } |
307 | if ($binarylines > 20) { | 317 | if ($binarylines > 20) { |
308 | last; | 318 | last; |
309 | } | 319 | } |
310 | } | 320 | } |
311 | 321 | ||
312 | 322 | ||
313 | my $i; | 323 | my $i; |
314 | 324 | ||
315 | 325 | ||
316 | # start annotating the registers in the asm. | 326 | # start annotating the registers in the asm. |
317 | # this goes from the oopsing point back, so that the annotator | 327 | # this goes from the oopsing point back, so that the annotator |
318 | # can track (opportunistically) which registers got written and | 328 | # can track (opportunistically) which registers got written and |
319 | # whos value no longer is relevant. | 329 | # whos value no longer is relevant. |
320 | 330 | ||
321 | $i = $center; | 331 | $i = $center; |
322 | while ($i >= $start) { | 332 | while ($i >= $start) { |
323 | $reglines[$i] = process_x86_regs($lines[$i], $center - $i); | 333 | $reglines[$i] = process_x86_regs($lines[$i], $center - $i); |
324 | $i = $i - 1; | 334 | $i = $i - 1; |
325 | } | 335 | } |
326 | 336 | ||
327 | $i = $start; | 337 | $i = $start; |
328 | while ($i < $finish) { | 338 | while ($i < $finish) { |
329 | my $line; | 339 | my $line; |
330 | if ($i == $center) { | 340 | if ($i == $center) { |
331 | $line = "*$lines[$i] "; | 341 | $line = "*$lines[$i] "; |
332 | } else { | 342 | } else { |
333 | $line = " $lines[$i] "; | 343 | $line = " $lines[$i] "; |
334 | } | 344 | } |
335 | print $line; | 345 | print $line; |
336 | if (defined($reglines[$i]) && length($reglines[$i]) > 0) { | 346 | if (defined($reglines[$i]) && length($reglines[$i]) > 0) { |
337 | my $c = 60 - length($line); | 347 | my $c = 60 - length($line); |
338 | while ($c > 0) { print " "; $c = $c - 1; }; | 348 | while ($c > 0) { print " "; $c = $c - 1; }; |
339 | print "| $reglines[$i]"; | 349 | print "| $reglines[$i]"; |
340 | } | 350 | } |
341 | if ($i == $center) { | 351 | if ($i == $center) { |
342 | print "<--- faulting instruction"; | 352 | print "<--- faulting instruction"; |
343 | } | 353 | } |
344 | print "\n"; | 354 | print "\n"; |
345 | $i = $i +1; | 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. |