So that comparing with objdump output from vmlinux can ease pinpointing where the trapping instruction actually is. An example is better than a thousand words: $ PC=0xffffffff8329a927 ./scripts/decodecode < ~/tmp/syz/gfs2.splat [ 477.379104][T23917] Code: 48 83 ec 28 48 89 3c 24 48 89 54 24 08 e8 c1 b4 4a fe 48 8d bb 00 01 00 00 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f 85 97 05 00 00 48 8b 9b 00 01 00 00 48 85 db 0f 84 All code ======== ffffffff8329a8fd: 48 83 ec 28 sub $0x28,%rsp ffffffff8329a901: 48 89 3c 24 mov %rdi,(%rsp) ffffffff8329a905: 48 89 54 24 08 mov %rdx,0x8(%rsp) ffffffff8329a90a: e8 c1 b4 4a fe callq 0xffffffff81745dd0 ffffffff8329a90f: 48 8d bb 00 01 00 00 lea 0x100(%rbx),%rdi ffffffff8329a916: 48 b8 00 00 00 00 00 movabs $0xdffffc0000000000,%rax ffffffff8329a91d: fc ff df ffffffff8329a920: 48 89 fa mov %rdi,%rdx ffffffff8329a923: 48 c1 ea 03 shr $0x3,%rdx ffffffff8329a927:* 80 3c 02 00 cmpb $0x0,(%rdx,%rax,1) <-- trapping instruction ffffffff8329a92b: 0f 85 97 05 00 00 jne 0xffffffff8329aec8 ffffffff8329a931: 48 8b 9b 00 01 00 00 mov 0x100(%rbx),%rbx ffffffff8329a938: 48 85 db test %rbx,%rbx ffffffff8329a93b: 0f .byte 0xf ffffffff8329a93c: 84 .byte 0x84
Showing the changes to scripts (1 of 1 file). Show all
Unified · Split
| @@ -6,6 +6,7 @@ · 5 unmodified lines | |||
| 6 | # options: set env. variable AFLAGS=options to pass options to "as"; | 6 | # options: set env. variable AFLAGS=options to pass options to "as"; |
| 7 | # e.g., to decode an i386 oops on an x86_64 system, use: | 7 | # e.g., to decode an i386 oops on an x86_64 system, use: |
| 8 | # AFLAGS=--32 decodecode < 386.oops | 8 | # AFLAGS=--32 decodecode < 386.oops |
| 9 | # PC=hex - the PC (program counter) the oops points to | ||
| 9 | 10 | ||
| 10 | cleanup() { | 11 | cleanup() { |
| 11 | rm -f $T $T.s $T.o $T.oo $T.aa $T.dis | 12 | rm -f $T $T.s $T.o $T.oo $T.aa $T.dis |
| @@ -67,15 +68,19 @@ if [ -z "$ARCH" ]; then · 55 unmodified lines | |||
| 67 | esac | 68 | esac |
| 68 | fi | 69 | fi |
| 69 | 70 | ||
| 71 | # Params: (tmp_file, pc_sub) | ||
| 70 | disas() { | 72 | disas() { |
| 71 | ${CROSS_COMPILE}as $AFLAGS -o $1.o $1.s > /dev/null 2>&1 | 73 | t=$1 |
| 74 | pc_sub=$2 | ||
| 75 | |||
| 76 | ${CROSS_COMPILE}as $AFLAGS -o $t.o $t.s > /dev/null 2>&1 | ||
| 72 | 77 | ||
| 73 | if [ "$ARCH" = "arm" ]; then | 78 | if [ "$ARCH" = "arm" ]; then |
| 74 | if [ $width -eq 2 ]; then | 79 | if [ $width -eq 2 ]; then |
| 75 | OBJDUMPFLAGS="-M force-thumb" | 80 | OBJDUMPFLAGS="-M force-thumb" |
| 76 | fi | 81 | fi |
| 77 | 82 | ||
| 78 | ${CROSS_COMPILE}strip $1.o | 83 | ${CROSS_COMPILE}strip $t.o |
| 79 | fi | 84 | fi |
| 80 | 85 | ||
| 81 | if [ "$ARCH" = "arm64" ]; then | 86 | if [ "$ARCH" = "arm64" ]; then |
| @@ -83,11 +88,18 @@ disas() { · 1 unmodified line | |||
| 83 | type=inst | 88 | type=inst |
| 84 | fi | 89 | fi |
| 85 | 90 | ||
| 86 | ${CROSS_COMPILE}strip $1.o | 91 | ${CROSS_COMPILE}strip $t.o |
| 87 | fi | 92 | fi |
| 88 | 93 | ||
| 89 | ${CROSS_COMPILE}objdump $OBJDUMPFLAGS -S $1.o | \ | 94 | if [ $pc_sub -ne 0 ]; then |
| 90 | grep -v "/tmp\|Disassembly\|\.text\|^$" > $1.dis 2>&1 | 95 | if [ $PC ]; then |
| 96 | adj_vma=$(( $PC - $pc_sub )) | ||
| 97 | OBJDUMPFLAGS="$OBJDUMPFLAGS --adjust-vma=$adj_vma" | ||
| 98 | fi | ||
| 99 | fi | ||
| 100 | |||
| 101 | ${CROSS_COMPILE}objdump $OBJDUMPFLAGS -S $t.o | \ | ||
| 102 | grep -v "/tmp\|Disassembly\|\.text\|^$" > $t.dis 2>&1 | ||
| 91 | } | 103 | } |
| 92 | 104 | ||
| 93 | marker=`expr index "$code" "\<"` | 105 | marker=`expr index "$code" "\<"` |
| @@ -95,14 +107,17 @@ if [ $marker -eq 0 ]; then · 1 unmodified line | |||
| 95 | marker=`expr index "$code" "\("` | 107 | marker=`expr index "$code" "\("` |
| 96 | fi | 108 | fi |
| 97 | 109 | ||
| 110 | |||
| 98 | touch $T.oo | 111 | touch $T.oo |
| 99 | if [ $marker -ne 0 ]; then | 112 | if [ $marker -ne 0 ]; then |
| 113 | # 2 opcode bytes and a single space | ||
| 114 | pc_sub=$(( $marker / 3 )) | ||
| 100 | echo All code >> $T.oo | 115 | echo All code >> $T.oo |
| 101 | echo ======== >> $T.oo | 116 | echo ======== >> $T.oo |
| 102 | beforemark=`echo "$code"` | 117 | beforemark=`echo "$code"` |
| 103 | echo -n " .$type 0x" > $T.s | 118 | echo -n " .$type 0x" > $T.s |
| 104 | echo $beforemark | sed -e 's/ /,0x/g; s/[<>()]//g' >> $T.s | 119 | echo $beforemark | sed -e 's/ /,0x/g; s/[<>()]//g' >> $T.s |
| 105 | disas $T | 120 | disas $T $pc_sub |
| 106 | cat $T.dis >> $T.oo | 121 | cat $T.dis >> $T.oo |
| 107 | rm -f $T.o $T.s $T.dis | 122 | rm -f $T.o $T.s $T.dis |
| 108 | 123 | ||
| @@ -114,7 +129,7 @@ echo =========================================== >> $T.aa · 5 unmodified lines | |||
| 114 | code=`echo $code | sed -e 's/ [<(]/ /;s/[>)] / /;s/ /,0x/g; s/[>)]$//'` | 129 | code=`echo $code | sed -e 's/ [<(]/ /;s/[>)] / /;s/ /,0x/g; s/[>)]$//'` |
| 115 | echo -n " .$type 0x" > $T.s | 130 | echo -n " .$type 0x" > $T.s |
| 116 | echo $code >> $T.s | 131 | echo $code >> $T.s |
| 117 | disas $T | 132 | disas $T 0 |
| 118 | cat $T.dis >> $T.aa | 133 | cat $T.dis >> $T.aa |
| 119 | 134 | ||
| 120 | # (lines of whole $T.oo) - (lines of $T.aa, i.e. "Code starting") + 3, | 135 | # (lines of whole $T.oo) - (lines of $T.aa, i.e. "Code starting") + 3, |