Back to home page

LXR

 
 

    


0001 #!/bin/sh
0002 # Disassemble the Code: line in Linux oopses
0003 # usage: decodecode < oops.file
0004 #
0005 # options: set env. variable AFLAGS=options to pass options to "as";
0006 # e.g., to decode an i386 oops on an x86_64 system, use:
0007 # AFLAGS=--32 decodecode < 386.oops
0008 
0009 cleanup() {
0010         rm -f $T $T.s $T.o $T.oo $T.aa $T.dis
0011         exit 1
0012 }
0013 
0014 die() {
0015         echo "$@"
0016         exit 1
0017 }
0018 
0019 trap cleanup EXIT
0020 
0021 T=`mktemp` || die "cannot create temp file"
0022 code=
0023 
0024 while read i ; do
0025 
0026 case "$i" in
0027 *Code:*)
0028         code=$i
0029         ;;
0030 esac
0031 
0032 done
0033 
0034 if [ -z "$code" ]; then
0035         rm $T
0036         exit
0037 fi
0038 
0039 echo $code
0040 code=`echo $code | sed -e 's/.*Code: //'`
0041 
0042 width=`expr index "$code" ' '`
0043 width=$((($width-1)/2))
0044 case $width in
0045 1) type=byte ;;
0046 2) type=2byte ;;
0047 4) type=4byte ;;
0048 esac
0049 
0050 disas() {
0051         ${CROSS_COMPILE}as $AFLAGS -o $1.o $1.s > /dev/null 2>&1
0052 
0053         if [ "$ARCH" = "arm" ]; then
0054                 if [ $width -eq 2 ]; then
0055                         OBJDUMPFLAGS="-M force-thumb"
0056                 fi
0057 
0058                 ${CROSS_COMPILE}strip $1.o
0059         fi
0060 
0061         ${CROSS_COMPILE}objdump $OBJDUMPFLAGS -S $1.o | \
0062                 grep -v "/tmp\|Disassembly\|\.text\|^$" > $1.dis 2>&1
0063 }
0064 
0065 marker=`expr index "$code" "\<"`
0066 if [ $marker -eq 0 ]; then
0067         marker=`expr index "$code" "\("`
0068 fi
0069 
0070 touch $T.oo
0071 if [ $marker -ne 0 ]; then
0072         echo All code >> $T.oo
0073         echo ======== >> $T.oo
0074         beforemark=`echo "$code"`
0075         echo -n "       .$type 0x" > $T.s
0076         echo $beforemark | sed -e 's/ /,0x/g; s/[<>()]//g' >> $T.s
0077         disas $T
0078         cat $T.dis >> $T.oo
0079         rm -f $T.o $T.s $T.dis
0080 
0081 # and fix code at-and-after marker
0082         code=`echo "$code" | cut -c$((${marker} + 1))-`
0083 fi
0084 echo Code starting with the faulting instruction  > $T.aa
0085 echo =========================================== >> $T.aa
0086 code=`echo $code | sed -e 's/ [<(]/ /;s/[>)] / /;s/ /,0x/g; s/[>)]$//'`
0087 echo -n "       .$type 0x" > $T.s
0088 echo $code >> $T.s
0089 disas $T
0090 cat $T.dis >> $T.aa
0091 
0092 # (lines of whole $T.oo) - (lines of $T.aa, i.e. "Code starting") + 3,
0093 # i.e. the title + the "===..=" line (sed is counting from 1, 0 address is
0094 # special)
0095 faultlinenum=$(( $(wc -l $T.oo  | cut -d" " -f1) - \
0096                  $(wc -l $T.aa  | cut -d" " -f1) + 3))
0097 
0098 faultline=`cat $T.dis | head -1 | cut -d":" -f2-`
0099 faultline=`echo "$faultline" | sed -e 's/\[/\\\[/g; s/\]/\\\]/g'`
0100 
0101 cat $T.oo | sed -e "${faultlinenum}s/^\(.*:\)\(.*\)/\1\*\2\t\t<-- trapping instruction/"
0102 echo
0103 cat $T.aa
0104 cleanup