Skip to content

Commit d72e720

Browse files
suryasaimadhutorvalds
authored andcommitted
scripts/decodecode: add the capability to supply the program counter
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 Signed-off-by: Borislav Petkov <bp@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Cc: Marc Zyngier <maz@misterjones.org> Cc: Will Deacon <will@kernel.org> Cc: Rabin Vincent <rabin@rab.in> Link: https://lkml.kernel.org/r/20200930111416.GF6810@zn.tnic Link: https://lkml.kernel.org/r/20200929113238.GC21110@zn.tnic Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 33c5bb3 commit d72e720

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

‎scripts/decodecode‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# options: set env. variable AFLAGS=options to pass options to "as";
77
# e.g., to decode an i386 oops on an x86_64 system, use:
88
# AFLAGS=--32 decodecode < 386.oops
9+
# PC=hex - the PC (program counter) the oops points to
910

1011
cleanup() {
1112
rm -f $T $T.s $T.o $T.oo $T.aa $T.dis
@@ -67,42 +68,56 @@ if [ -z "$ARCH" ]; then
6768
esac
6869
fi
6970

71+
# Params: (tmp_file, pc_sub)
7072
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
7277

7378
if [ "$ARCH" = "arm" ]; then
7479
if [ $width -eq 2 ]; then
7580
OBJDUMPFLAGS="-M force-thumb"
7681
fi
7782

78-
${CROSS_COMPILE}strip $1.o
83+
${CROSS_COMPILE}strip $t.o
7984
fi
8085

8186
if [ "$ARCH" = "arm64" ]; then
8287
if [ $width -eq 4 ]; then
8388
type=inst
8489
fi
8590

86-
${CROSS_COMPILE}strip $1.o
91+
${CROSS_COMPILE}strip $t.o
8792
fi
8893

89-
${CROSS_COMPILE}objdump $OBJDUMPFLAGS -S $1.o | \
90-
grep -v "/tmp\|Disassembly\|\.text\|^$" > $1.dis 2>&1
94+
if [ $pc_sub -ne 0 ]; then
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
91103
}
92104

93105
marker=`expr index "$code" "\<"`
94106
if [ $marker -eq 0 ]; then
95107
marker=`expr index "$code" "\("`
96108
fi
97109

110+
98111
touch $T.oo
99112
if [ $marker -ne 0 ]; then
113+
# 2 opcode bytes and a single space
114+
pc_sub=$(( $marker / 3 ))
100115
echo All code >> $T.oo
101116
echo ======== >> $T.oo
102117
beforemark=`echo "$code"`
103118
echo -n " .$type 0x" > $T.s
104119
echo $beforemark | sed -e 's/ /,0x/g; s/[<>()]//g' >> $T.s
105-
disas $T
120+
disas $T $pc_sub
106121
cat $T.dis >> $T.oo
107122
rm -f $T.o $T.s $T.dis
108123

@@ -114,7 +129,7 @@ echo =========================================== >> $T.aa
114129
code=`echo $code | sed -e 's/ [<(]/ /;s/[>)] / /;s/ /,0x/g; s/[>)]$//'`
115130
echo -n " .$type 0x" > $T.s
116131
echo $code >> $T.s
117-
disas $T
132+
disas $T 0
118133
cat $T.dis >> $T.aa
119134

120135
# (lines of whole $T.oo) - (lines of $T.aa, i.e. "Code starting") + 3,

0 commit comments

Comments
 (0)