1*dcecc6c7SRandy Dunlap#!/bin/sh 2*dcecc6c7SRandy Dunlap# Disassemble the Code: line in Linux oopses 3*dcecc6c7SRandy Dunlap# usage: decodecode < oops.file 4*dcecc6c7SRandy Dunlap# 5*dcecc6c7SRandy Dunlap# options: set env. variable AFLAGS=options to pass options to "as"; 6*dcecc6c7SRandy Dunlap# e.g., to decode an i386 oops on an x86_64 system, use: 7*dcecc6c7SRandy Dunlap# AFLAGS=--32 decodecode < 386.oops 8*dcecc6c7SRandy Dunlap 9*dcecc6c7SRandy DunlapT=`mktemp` 10*dcecc6c7SRandy Dunlapcode= 11*dcecc6c7SRandy Dunlap 12*dcecc6c7SRandy Dunlapwhile read i ; do 13*dcecc6c7SRandy Dunlap 14*dcecc6c7SRandy Dunlapcase "$i" in 15*dcecc6c7SRandy Dunlap*Code:*) 16*dcecc6c7SRandy Dunlap code=$i 17*dcecc6c7SRandy Dunlap ;; 18*dcecc6c7SRandy Dunlapesac 19*dcecc6c7SRandy Dunlap 20*dcecc6c7SRandy Dunlapdone 21*dcecc6c7SRandy Dunlap 22*dcecc6c7SRandy Dunlapif [ -z "$code" ]; then 23*dcecc6c7SRandy Dunlap exit 24*dcecc6c7SRandy Dunlapfi 25*dcecc6c7SRandy Dunlap 26*dcecc6c7SRandy Dunlapecho $code 27*dcecc6c7SRandy Dunlapcode=`echo $code | sed -e 's/.*Code: //'` 28*dcecc6c7SRandy Dunlap 29*dcecc6c7SRandy Dunlapmarker=`expr index "$code" "\<"` 30*dcecc6c7SRandy Dunlapif [ $marker -eq 0 ]; then 31*dcecc6c7SRandy Dunlap marker=`expr index "$code" "\("` 32*dcecc6c7SRandy Dunlapfi 33*dcecc6c7SRandy Dunlap 34*dcecc6c7SRandy Dunlapif [ $marker -ne 0 ]; then 35*dcecc6c7SRandy Dunlap beforemark=`echo "$code" | cut -c-$((${marker} - 1))` 36*dcecc6c7SRandy Dunlap echo -n " .byte 0x" > $T.s 37*dcecc6c7SRandy Dunlap echo $beforemark | sed -e 's/ /,0x/g' >> $T.s 38*dcecc6c7SRandy Dunlap as $AFLAGS -o $T.o $T.s 39*dcecc6c7SRandy Dunlap objdump -S $T.o 40*dcecc6c7SRandy Dunlap rm $T.o $T.s 41*dcecc6c7SRandy Dunlap 42*dcecc6c7SRandy Dunlap# and fix code at-and-after marker 43*dcecc6c7SRandy Dunlap code=`echo "$code" | cut -c$((${marker} + 1))-` 44*dcecc6c7SRandy Dunlapfi 45*dcecc6c7SRandy Dunlap 46*dcecc6c7SRandy Dunlapcode=`echo $code | sed -e 's/ [<(]/ /;s/[>)] / /;s/ /,0x/g'` 47*dcecc6c7SRandy Dunlapecho -n " .byte 0x" > $T.s 48*dcecc6c7SRandy Dunlapecho $code >> $T.s 49*dcecc6c7SRandy Dunlapas $AFLAGS -o $T.o $T.s 50*dcecc6c7SRandy Dunlapobjdump -S $T.o 51*dcecc6c7SRandy Dunlaprm $T.o $T.s 52