diff options
author | Rabin Vincent <rabin@rab.in> | 2010-01-05 09:57:58 -0500 |
---|---|---|
committer | Michal Marek <mmarek@suse.cz> | 2010-02-02 08:33:54 -0500 |
commit | 5358db0b0e16470337c6ec08177deb3f68ed7673 (patch) | |
tree | 02eb5cb3a1d93b80b5db7ab2338822b272f84a84 /scripts/decodecode | |
parent | 84336466011c589b6af554f2f2f1fcfa1a5c1437 (diff) |
scripts: add ARM support to decodecode
This patch adds support for decoding ARM oopses to scripts/decodecode.
The following things are handled:
- ARCH and CROSS_COMPILE environment variables are respected.
- The Code: in x86 oopses is in bytes, while it is in either words (4
bytes) or halfwords for ARM.
- Some versions of ARM objdump refuse to disassemble instructions
generated by literal constants (".word 0x..."). The workaround is to
strip the object file first.
- The faulting instruction is marked (liked so) in ARM, but <like so>
in x86.
- ARM mnemonics may include characters such as [] which need to be
escaped before being passed to sed for the "<- trapping instruction"
substitution.
Signed-off-by: Rabin Vincent <rabin@rab.in>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Diffstat (limited to 'scripts/decodecode')
-rwxr-xr-x | scripts/decodecode | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/scripts/decodecode b/scripts/decodecode index 4b00647814b..8b30cc36744 100755 --- a/scripts/decodecode +++ b/scripts/decodecode | |||
@@ -7,7 +7,7 @@ | |||
7 | # AFLAGS=--32 decodecode < 386.oops | 7 | # AFLAGS=--32 decodecode < 386.oops |
8 | 8 | ||
9 | cleanup() { | 9 | cleanup() { |
10 | rm -f $T $T.s $T.o $T.oo $T.aa $T.aaa | 10 | rm -f $T $T.s $T.o $T.oo $T.aa $T.dis |
11 | exit 1 | 11 | exit 1 |
12 | } | 12 | } |
13 | 13 | ||
@@ -39,6 +39,29 @@ fi | |||
39 | echo $code | 39 | echo $code |
40 | code=`echo $code | sed -e 's/.*Code: //'` | 40 | code=`echo $code | sed -e 's/.*Code: //'` |
41 | 41 | ||
42 | width=`expr index "$code" ' '` | ||
43 | width=$[($width-1)/2] | ||
44 | case $width in | ||
45 | 1) type=byte ;; | ||
46 | 2) type=2byte ;; | ||
47 | 4) type=4byte ;; | ||
48 | esac | ||
49 | |||
50 | disas() { | ||
51 | ${CROSS_COMPILE}as $AFLAGS -o $1.o $1.s &> /dev/null | ||
52 | |||
53 | if [ "$ARCH" == "arm" ]; then | ||
54 | if [ $width == 2 ]; then | ||
55 | OBJDUMPFLAGS="-M force-thumb" | ||
56 | fi | ||
57 | |||
58 | ${CROSS_COMPILE}strip $1.o | ||
59 | fi | ||
60 | |||
61 | ${CROSS_COMPILE}objdump $OBJDUMPFLAGS -S $1.o | \ | ||
62 | grep -v "/tmp\|Disassembly\|\.text\|^$" &> $1.dis | ||
63 | } | ||
64 | |||
42 | marker=`expr index "$code" "\<"` | 65 | marker=`expr index "$code" "\<"` |
43 | if [ $marker -eq 0 ]; then | 66 | if [ $marker -eq 0 ]; then |
44 | marker=`expr index "$code" "\("` | 67 | marker=`expr index "$code" "\("` |
@@ -49,26 +72,25 @@ if [ $marker -ne 0 ]; then | |||
49 | echo All code >> $T.oo | 72 | echo All code >> $T.oo |
50 | echo ======== >> $T.oo | 73 | echo ======== >> $T.oo |
51 | beforemark=`echo "$code"` | 74 | beforemark=`echo "$code"` |
52 | echo -n " .byte 0x" > $T.s | 75 | echo -n " .$type 0x" > $T.s |
53 | echo $beforemark | sed -e 's/ /,0x/g' | sed -e 's/<//g' | sed -e 's/>//g' >> $T.s | 76 | echo $beforemark | sed -e 's/ /,0x/g; s/[<>()]//g' >> $T.s |
54 | as $AFLAGS -o $T.o $T.s &> /dev/null | 77 | disas $T |
55 | objdump -S $T.o | grep -v "/tmp" | grep -v "Disassembly" | grep -v "\.text" | grep -v "^$" &> $T.ooo | 78 | cat $T.dis >> $T.oo |
56 | cat $T.ooo >> $T.oo | 79 | rm -f $T.o $T.s $T.dis |
57 | rm -f $T.o $T.s $T.ooo | ||
58 | 80 | ||
59 | # and fix code at-and-after marker | 81 | # and fix code at-and-after marker |
60 | code=`echo "$code" | cut -c$((${marker} + 1))-` | 82 | code=`echo "$code" | cut -c$((${marker} + 1))-` |
61 | fi | 83 | fi |
62 | echo Code starting with the faulting instruction > $T.aa | 84 | echo Code starting with the faulting instruction > $T.aa |
63 | echo =========================================== >> $T.aa | 85 | echo =========================================== >> $T.aa |
64 | code=`echo $code | sed -e 's/ [<(]/ /;s/[>)] / /;s/ /,0x/g'` | 86 | code=`echo $code | sed -e 's/ [<(]/ /;s/[>)] / /;s/ /,0x/g; s/[>)]$//'` |
65 | echo -n " .byte 0x" > $T.s | 87 | echo -n " .$type 0x" > $T.s |
66 | echo $code >> $T.s | 88 | echo $code >> $T.s |
67 | as $AFLAGS -o $T.o $T.s &> /dev/null | 89 | disas $T |
68 | objdump -S $T.o | grep -v "Disassembly" | grep -v "/tmp" | grep -v "\.text" | grep -v "^$" &> $T.aaa | 90 | cat $T.dis >> $T.aa |
69 | cat $T.aaa >> $T.aa | ||
70 | 91 | ||
71 | faultline=`cat $T.aaa | head -1 | cut -d":" -f2` | 92 | faultline=`cat $T.dis | head -1 | cut -d":" -f2` |
93 | faultline=`echo "$faultline" | sed -e 's/\[/\\\[/g; s/\]/\\\]/g'` | ||
72 | 94 | ||
73 | cat $T.oo | sed -e "s/\($faultline\)/\*\1 <-- trapping instruction/g" | 95 | cat $T.oo | sed -e "s/\($faultline\)/\*\1 <-- trapping instruction/g" |
74 | echo | 96 | echo |