Commit | Line | Data |
---|---|---|
dcecc6c7 RD |
1 | #!/bin/sh |
2 | # Disassemble the Code: line in Linux oopses | |
3 | # usage: decodecode < oops.file | |
4 | # | |
5 | # options: set env. variable AFLAGS=options to pass options to "as"; | |
6 | # e.g., to decode an i386 oops on an x86_64 system, use: | |
7 | # AFLAGS=--32 decodecode < 386.oops | |
8 | ||
fa220d89 | 9 | cleanup() { |
846442c8 | 10 | rm -f $T $T.s $T.o $T.oo $T.aa $T.aaa |
fa220d89 RD |
11 | exit 1 |
12 | } | |
13 | ||
14 | die() { | |
15 | echo "$@" | |
16 | exit 1 | |
17 | } | |
18 | ||
19 | trap cleanup EXIT | |
20 | ||
21 | T=`mktemp` || die "cannot create temp file" | |
dcecc6c7 RD |
22 | code= |
23 | ||
24 | while read i ; do | |
25 | ||
26 | case "$i" in | |
27 | *Code:*) | |
28 | code=$i | |
29 | ;; | |
30 | esac | |
31 | ||
32 | done | |
33 | ||
34 | if [ -z "$code" ]; then | |
fa220d89 | 35 | rm $T |
dcecc6c7 RD |
36 | exit |
37 | fi | |
38 | ||
39 | echo $code | |
40 | code=`echo $code | sed -e 's/.*Code: //'` | |
41 | ||
42 | marker=`expr index "$code" "\<"` | |
43 | if [ $marker -eq 0 ]; then | |
44 | marker=`expr index "$code" "\("` | |
45 | fi | |
46 | ||
846442c8 | 47 | touch $T.oo |
dcecc6c7 | 48 | if [ $marker -ne 0 ]; then |
846442c8 AV |
49 | echo All code >> $T.oo |
50 | echo ======== >> $T.oo | |
51 | beforemark=`echo "$code"` | |
dcecc6c7 | 52 | echo -n " .byte 0x" > $T.s |
846442c8 AV |
53 | echo $beforemark | sed -e 's/ /,0x/g' | sed -e 's/<//g' | sed -e 's/>//g' >> $T.s |
54 | as $AFLAGS -o $T.o $T.s &> /dev/null | |
55 | objdump -S $T.o | grep -v "/tmp" | grep -v "Disassembly" | grep -v "\.text" | grep -v "^$" &> $T.ooo | |
56 | cat $T.ooo >> $T.oo | |
57 | rm -f $T.o $T.s $T.ooo | |
dcecc6c7 RD |
58 | |
59 | # and fix code at-and-after marker | |
60 | code=`echo "$code" | cut -c$((${marker} + 1))-` | |
61 | fi | |
846442c8 AV |
62 | echo Code starting with the faulting instruction > $T.aa |
63 | echo =========================================== >> $T.aa | |
dcecc6c7 RD |
64 | code=`echo $code | sed -e 's/ [<(]/ /;s/[>)] / /;s/ /,0x/g'` |
65 | echo -n " .byte 0x" > $T.s | |
66 | echo $code >> $T.s | |
846442c8 AV |
67 | as $AFLAGS -o $T.o $T.s &> /dev/null |
68 | objdump -S $T.o | grep -v "Disassembly" | grep -v "/tmp" | grep -v "\.text" | grep -v "^$" &> $T.aaa | |
69 | cat $T.aaa >> $T.aa | |
70 | ||
71 | faultline=`cat $T.aaa | head -1 | cut -d":" -f2` | |
72 | ||
73 | cat $T.oo | sed -e "s/\($faultline\)/\*\1 <-- trapping instruction/g" | |
74 | echo | |
75 | cat $T.aa | |
76 | cleanup |