Linux 2.6.26-rc1
[cris-mirror.git] / scripts / decodecode
blob235d3938529db23f34c53996ec65bca70172d34a
1 #!/bin/sh
2 # Disassemble the Code: line in Linux oopses
3 # usage: decodecode < oops.file
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
9 cleanup() {
10 rm -f $T $T.s $T.o
11 exit 1
14 die() {
15 echo "$@"
16 exit 1
19 trap cleanup EXIT
21 T=`mktemp` || die "cannot create temp file"
22 code=
24 while read i ; do
26 case "$i" in
27 *Code:*)
28 code=$i
30 esac
32 done
34 if [ -z "$code" ]; then
35 rm $T
36 exit
39 echo $code
40 code=`echo $code | sed -e 's/.*Code: //'`
42 marker=`expr index "$code" "\<"`
43 if [ $marker -eq 0 ]; then
44 marker=`expr index "$code" "\("`
47 if [ $marker -ne 0 ]; then
48 beforemark=`echo "$code" | cut -c-$((${marker} - 1))`
49 echo -n " .byte 0x" > $T.s
50 echo $beforemark | sed -e 's/ /,0x/g' >> $T.s
51 as $AFLAGS -o $T.o $T.s
52 objdump -S $T.o
53 rm $T.o $T.s
55 # and fix code at-and-after marker
56 code=`echo "$code" | cut -c$((${marker} + 1))-`
59 code=`echo $code | sed -e 's/ [<(]/ /;s/[>)] / /;s/ /,0x/g'`
60 echo -n " .byte 0x" > $T.s
61 echo $code >> $T.s
62 as $AFLAGS -o $T.o $T.s
63 objdump -S $T.o
64 rm $T $T.s $T.o