blob: 235d3938529db23f34c53996ec65bca70172d34a [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() {
10 rm -f $T $T.s $T.o
11 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
47if [ $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
54
55# and fix code at-and-after marker
56 code=`echo "$code" | cut -c$((${marker} + 1))-`
57fi
58
59code=`echo $code | sed -e 's/ [<(]/ /;s/[>)] / /;s/ /,0x/g'`
60echo -n " .byte 0x" > $T.s
61echo $code >> $T.s
62as $AFLAGS -o $T.o $T.s
63objdump -S $T.o
Randy Dunlapfa220d82008-01-14 15:18:31 -080064rm $T $T.s $T.o