blob: 4b00647814bc46c9525dfc6e806d28af7641f9d6 [file] [log] [blame]
Randy Dunlapdcecc6c2007-07-15 23:41:15 -07001#!/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
Randy Dunlapfa220d82008-01-14 15:18:31 -08009cleanup() {
Arjan van de Ven846442c2008-12-01 14:21:06 -080010 rm -f $T $T.s $T.o $T.oo $T.aa $T.aaa
Randy Dunlapfa220d82008-01-14 15:18:31 -080011 exit 1
12}
13
14die() {
15 echo "$@"
16 exit 1
17}
18
19trap cleanup EXIT
20
21T=`mktemp` || die "cannot create temp file"
Randy Dunlapdcecc6c2007-07-15 23:41:15 -070022code=
23
24while read i ; do
25
26case "$i" in
27*Code:*)
28 code=$i
29 ;;
30esac
31
32done
33
34if [ -z "$code" ]; then
Randy Dunlapfa220d82008-01-14 15:18:31 -080035 rm $T
Randy Dunlapdcecc6c2007-07-15 23:41:15 -070036 exit
37fi
38
39echo $code
40code=`echo $code | sed -e 's/.*Code: //'`
41
42marker=`expr index "$code" "\<"`
43if [ $marker -eq 0 ]; then
44 marker=`expr index "$code" "\("`
45fi
46
Arjan van de Ven846442c2008-12-01 14:21:06 -080047touch $T.oo
Randy Dunlapdcecc6c2007-07-15 23:41:15 -070048if [ $marker -ne 0 ]; then
Arjan van de Ven846442c2008-12-01 14:21:06 -080049 echo All code >> $T.oo
50 echo ======== >> $T.oo
51 beforemark=`echo "$code"`
Randy Dunlapdcecc6c2007-07-15 23:41:15 -070052 echo -n " .byte 0x" > $T.s
Arjan van de Ven846442c2008-12-01 14:21:06 -080053 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
Randy Dunlapdcecc6c2007-07-15 23:41:15 -070058
59# and fix code at-and-after marker
60 code=`echo "$code" | cut -c$((${marker} + 1))-`
61fi
Arjan van de Ven846442c2008-12-01 14:21:06 -080062echo Code starting with the faulting instruction > $T.aa
63echo =========================================== >> $T.aa
Randy Dunlapdcecc6c2007-07-15 23:41:15 -070064code=`echo $code | sed -e 's/ [<(]/ /;s/[>)] / /;s/ /,0x/g'`
65echo -n " .byte 0x" > $T.s
66echo $code >> $T.s
Arjan van de Ven846442c2008-12-01 14:21:06 -080067as $AFLAGS -o $T.o $T.s &> /dev/null
68objdump -S $T.o | grep -v "Disassembly" | grep -v "/tmp" | grep -v "\.text" | grep -v "^$" &> $T.aaa
69cat $T.aaa >> $T.aa
70
71faultline=`cat $T.aaa | head -1 | cut -d":" -f2`
72
73cat $T.oo | sed -e "s/\($faultline\)/\*\1 <-- trapping instruction/g"
74echo
75cat $T.aa
76cleanup