decodecode 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/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. cleanup() {
  9. rm -f $T $T.s $T.o $T.oo $T.aa $T.aaa
  10. exit 1
  11. }
  12. die() {
  13. echo "$@"
  14. exit 1
  15. }
  16. trap cleanup EXIT
  17. T=`mktemp` || die "cannot create temp file"
  18. code=
  19. while read i ; do
  20. case "$i" in
  21. *Code:*)
  22. code=$i
  23. ;;
  24. esac
  25. done
  26. if [ -z "$code" ]; then
  27. rm $T
  28. exit
  29. fi
  30. echo $code
  31. code=`echo $code | sed -e 's/.*Code: //'`
  32. marker=`expr index "$code" "\<"`
  33. if [ $marker -eq 0 ]; then
  34. marker=`expr index "$code" "\("`
  35. fi
  36. touch $T.oo
  37. if [ $marker -ne 0 ]; then
  38. echo All code >> $T.oo
  39. echo ======== >> $T.oo
  40. beforemark=`echo "$code"`
  41. echo -n " .byte 0x" > $T.s
  42. echo $beforemark | sed -e 's/ /,0x/g' | sed -e 's/<//g' | sed -e 's/>//g' >> $T.s
  43. as $AFLAGS -o $T.o $T.s &> /dev/null
  44. objdump -S $T.o | grep -v "/tmp" | grep -v "Disassembly" | grep -v "\.text" | grep -v "^$" &> $T.ooo
  45. cat $T.ooo >> $T.oo
  46. rm -f $T.o $T.s $T.ooo
  47. # and fix code at-and-after marker
  48. code=`echo "$code" | cut -c$((${marker} + 1))-`
  49. fi
  50. echo Code starting with the faulting instruction > $T.aa
  51. echo =========================================== >> $T.aa
  52. code=`echo $code | sed -e 's/ [<(]/ /;s/[>)] / /;s/ /,0x/g'`
  53. echo -n " .byte 0x" > $T.s
  54. echo $code >> $T.s
  55. as $AFLAGS -o $T.o $T.s &> /dev/null
  56. objdump -S $T.o | grep -v "Disassembly" | grep -v "/tmp" | grep -v "\.text" | grep -v "^$" &> $T.aaa
  57. cat $T.aaa >> $T.aa
  58. faultline=`cat $T.aaa | head -1 | cut -d":" -f2`
  59. cat $T.oo | sed -e "s/\($faultline\)/\*\1 <-- trapping instruction/g"
  60. echo
  61. cat $T.aa
  62. cleanup