~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/scripts/decodecode

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /scripts/decodecode (Version linux-6.12-rc7) and /scripts/decodecode (Version linux-5.9.16)


  1 #!/bin/bash                                    !!   1 #!/bin/sh
  2 # SPDX-License-Identifier: GPL-2.0                  2 # SPDX-License-Identifier: GPL-2.0
  3 # Disassemble the Code: line in Linux oopses        3 # Disassemble the Code: line in Linux oopses
  4 # usage: decodecode < oops.file                     4 # usage: decodecode < oops.file
  5 #                                                   5 #
  6 # options: set env. variable AFLAGS=options to      6 # options: set env. variable AFLAGS=options to pass options to "as";
  7 # e.g., to decode an i386 oops on an x86_64 sy      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 p << 
 10                                                << 
 11 faultlinenum=1                                 << 
 12                                                     9 
 13 cleanup() {                                        10 cleanup() {
 14         rm -f $T $T.s $T.o $T.oo $T.aa $T.dis      11         rm -f $T $T.s $T.o $T.oo $T.aa $T.dis
 15         exit 1                                     12         exit 1
 16 }                                                  13 }
 17                                                    14 
 18 die() {                                            15 die() {
 19         echo "$@"                                  16         echo "$@"
 20         exit 1                                     17         exit 1
 21 }                                                  18 }
 22                                                    19 
 23 trap cleanup EXIT                                  20 trap cleanup EXIT
 24                                                    21 
 25 T=`mktemp` || die "cannot create temp file"        22 T=`mktemp` || die "cannot create temp file"
 26 code=                                              23 code=
 27 cont=                                              24 cont=
 28                                                    25 
 29 while read i ; do                                  26 while read i ; do
 30                                                    27 
 31 case "$i" in                                       28 case "$i" in
 32 *Code:*)                                           29 *Code:*)
 33         code=$i                                    30         code=$i
 34         cont=yes                                   31         cont=yes
 35         ;;                                         32         ;;
 36 *)                                                 33 *)
 37         [ -n "$cont" ] && {                        34         [ -n "$cont" ] && {
 38                 xdump="$(echo $i | grep '^[[:x     35                 xdump="$(echo $i | grep '^[[:xdigit:]<>[:space:]]\+$')"
 39                 if [ -n "$xdump" ]; then           36                 if [ -n "$xdump" ]; then
 40                         code="$code $xdump"        37                         code="$code $xdump"
 41                 else                               38                 else
 42                         cont=                      39                         cont=
 43                 fi                                 40                 fi
 44         }                                          41         }
 45         ;;                                         42         ;;
 46 esac                                               43 esac
 47                                                    44 
 48 done                                               45 done
 49                                                    46 
 50 if [ -z "$code" ]; then                            47 if [ -z "$code" ]; then
 51         rm $T                                      48         rm $T
 52         exit                                       49         exit
 53 fi                                                 50 fi
 54                                                    51 
 55 echo $code                                         52 echo $code
 56 code=`echo $code | sed -e 's/.*Code: //'`          53 code=`echo $code | sed -e 's/.*Code: //'`
 57                                                    54 
 58 width=`expr index "$code" ' '`                     55 width=`expr index "$code" ' '`
 59 width=$((($width-1)/2))                            56 width=$((($width-1)/2))
 60 case $width in                                     57 case $width in
 61 1) type=byte ;;                                    58 1) type=byte ;;
 62 2) type=2byte ;;                                   59 2) type=2byte ;;
 63 4) type=4byte ;;                                   60 4) type=4byte ;;
 64 esac                                               61 esac
 65                                                    62 
 66 if [ -z "$ARCH" ]; then                            63 if [ -z "$ARCH" ]; then
 67     case `uname -m` in                             64     case `uname -m` in
 68         aarch64*) ARCH=arm64 ;;                    65         aarch64*) ARCH=arm64 ;;
 69         arm*) ARCH=arm ;;                          66         arm*) ARCH=arm ;;
 70         loongarch*) ARCH=loongarch ;;          << 
 71     esac                                           67     esac
 72 fi                                                 68 fi
 73                                                    69 
 74 # Params: (tmp_file, pc_sub)                   << 
 75 disas() {                                          70 disas() {
 76         t=$1                                   !!  71         ${CROSS_COMPILE}as $AFLAGS -o $1.o $1.s > /dev/null 2>&1
 77         pc_sub=$2                              << 
 78                                                << 
 79         ${CROSS_COMPILE}as $AFLAGS -o $t.o $t. << 
 80                                                    72 
 81         if [ "$ARCH" = "arm" ]; then               73         if [ "$ARCH" = "arm" ]; then
 82                 if [ $width -eq 2 ]; then          74                 if [ $width -eq 2 ]; then
 83                         OBJDUMPFLAGS="-M force     75                         OBJDUMPFLAGS="-M force-thumb"
 84                 fi                                 76                 fi
 85                                                    77 
 86                 ${CROSS_COMPILE}strip $t.o     !!  78                 ${CROSS_COMPILE}strip $1.o
 87         fi                                         79         fi
 88                                                    80 
 89         if [ "$ARCH" = "arm64" ]; then             81         if [ "$ARCH" = "arm64" ]; then
 90                 if [ $width -eq 4 ]; then          82                 if [ $width -eq 4 ]; then
 91                         type=inst                  83                         type=inst
 92                 fi                                 84                 fi
 93                                                    85 
 94                 ${CROSS_COMPILE}strip $t.o     !!  86                 ${CROSS_COMPILE}strip $1.o
 95         fi                                     << 
 96                                                << 
 97         if [ "$ARCH" = "riscv" ]; then         << 
 98                 OBJDUMPFLAGS="-M no-aliases -- << 
 99                 ${CROSS_COMPILE}strip $t.o     << 
100         fi                                     << 
101                                                << 
102         if [ "$ARCH" = "loongarch" ]; then     << 
103                 ${CROSS_COMPILE}strip $t.o     << 
104         fi                                         87         fi
105                                                    88 
106         if [ $pc_sub -ne 0 ]; then             !!  89         ${CROSS_COMPILE}objdump $OBJDUMPFLAGS -S $1.o | \
107                 if [ $PC ]; then               !!  90                 grep -v "/tmp\|Disassembly\|\.text\|^$" > $1.dis 2>&1
108                         adj_vma=$(( $PC - $pc_ << 
109                         OBJDUMPFLAGS="$OBJDUMP << 
110                 fi                             << 
111         fi                                     << 
112                                                << 
113         ${CROSS_COMPILE}objdump $OBJDUMPFLAGS  << 
114                 grep -v "/tmp\|Disassembly\|\. << 
115 }                                              << 
116                                                << 
117 # Match the maximum number of opcode bytes fro << 
118 # @opline                                      << 
119 #                                              << 
120 # Params:                                      << 
121 # @op_bytes: The string of bytes from the Code << 
122 # @opline: The disassembled line coming from o << 
123 #                                              << 
124 # Returns:                                     << 
125 # The max number of opcode bytes from the begi << 
126 # the opcode bytes in the objdump line.        << 
127 get_substr_opcode_bytes_num()                  << 
128 {                                              << 
129         local op_bytes=$1                      << 
130         local opline=$2                        << 
131                                                << 
132         local retval=0                         << 
133         substr=""                              << 
134                                                << 
135         for opc in $op_bytes;                  << 
136         do                                     << 
137                 substr+="$opc"                 << 
138                                                << 
139                 opcode="$substr"               << 
140                 if [ "$ARCH" = "riscv" ]; then << 
141                         opcode=$(echo $opcode  << 
142                 fi                             << 
143                                                << 
144                 # return if opcode bytes do no << 
145                 if ! echo $opline | grep -q "$ << 
146                 then                           << 
147                         break                  << 
148                 fi                             << 
149                                                << 
150                 # add trailing space           << 
151                 substr+=" "                    << 
152                 retval=$((retval+1))           << 
153         done                                   << 
154                                                << 
155         return $retval                         << 
156 }                                              << 
157                                                << 
158 # Return the line number in objdump output to  << 
159 # line points to                               << 
160 #                                              << 
161 # Params:                                      << 
162 # @all_code: code in bytes without the marker  << 
163 # @dis_file: disassembled file                 << 
164 # @ip_byte: The byte to which the IP points to << 
165 get_faultlinenum()                             << 
166 {                                              << 
167         local all_code="$1"                    << 
168         local dis_file="$2"                    << 
169                                                << 
170         # num bytes including IP byte          << 
171         local num_bytes_ip=$(( $3 + 1 * $width << 
172                                                << 
173         # Add the two header lines (we're coun << 
174         local retval=3                         << 
175                                                << 
176         # remove marker                        << 
177         all_code=$(echo $all_code | sed -e 's/ << 
178                                                << 
179         while read line                        << 
180         do                                     << 
181                 get_substr_opcode_bytes_num "$ << 
182                 ate_opcodes=$?                 << 
183                                                << 
184                 if ! (( $ate_opcodes )); then  << 
185                         continue               << 
186                 fi                             << 
187                                                << 
188                 num_bytes_ip=$((num_bytes_ip - << 
189                 if (( $num_bytes_ip <= 0 )); t << 
190                         break                  << 
191                 fi                             << 
192                                                << 
193                 # Delete matched opcode bytes  << 
194                 # how many chars those opcodes << 
195                 # trailing space.              << 
196                 #                              << 
197                 # a byte is 2 chars, ate_opcod << 
198                 # spaces                       << 
199                 del_chars=$(( ($ate_opcodes *  << 
200                                                << 
201                 all_code=$(echo $all_code | se << 
202                                                << 
203                 let "retval+=1"                << 
204                                                << 
205         done < $dis_file                       << 
206                                                << 
207         return $retval                         << 
208 }                                                  91 }
209                                                    92 
210 marker=`expr index "$code" "\<"`                   93 marker=`expr index "$code" "\<"`
211 if [ $marker -eq 0 ]; then                         94 if [ $marker -eq 0 ]; then
212         marker=`expr index "$code" "\("`           95         marker=`expr index "$code" "\("`
213 fi                                                 96 fi
214                                                    97 
215 touch $T.oo                                        98 touch $T.oo
216 if [ $marker -ne 0 ]; then                         99 if [ $marker -ne 0 ]; then
217         # How many bytes to subtract from the  << 
218         # in order to get to the beginning vir << 
219         # Code:                                << 
220         pc_sub=$(( (($marker - 1) / (2 * $widt << 
221         echo All code >> $T.oo                    100         echo All code >> $T.oo
222         echo ======== >> $T.oo                    101         echo ======== >> $T.oo
223         beforemark=`echo "$code"`                 102         beforemark=`echo "$code"`
224         echo -n "       .$type 0x" > $T.s         103         echo -n "       .$type 0x" > $T.s
225                                                << 
226         echo $beforemark | sed -e 's/ /,0x/g;     104         echo $beforemark | sed -e 's/ /,0x/g; s/[<>()]//g' >> $T.s
227                                                !! 105         disas $T
228         disas $T $pc_sub                       << 
229                                                << 
230         cat $T.dis >> $T.oo                       106         cat $T.dis >> $T.oo
                                                   >> 107         rm -f $T.o $T.s $T.dis
231                                                   108 
232         get_faultlinenum "$code" "$T.dis" $pc_ !! 109 # and fix code at-and-after marker
233         faultlinenum=$?                        << 
234                                                << 
235         # and fix code at-and-after marker     << 
236         code=`echo "$code" | cut -c$((${marker    110         code=`echo "$code" | cut -c$((${marker} + 1))-`
237                                                << 
238         rm -f $T.o $T.s $T.dis                 << 
239 fi                                                111 fi
240                                                << 
241 echo Code starting with the faulting instructi    112 echo Code starting with the faulting instruction  > $T.aa
242 echo =========================================    113 echo =========================================== >> $T.aa
243 code=`echo $code | sed -e 's/\r//;s/ [<(]/ /;s !! 114 code=`echo $code | sed -e 's/ [<(]/ /;s/[>)] / /;s/ /,0x/g; s/[>)]$//'`
244 echo -n "       .$type 0x" > $T.s                 115 echo -n "       .$type 0x" > $T.s
245 echo $code >> $T.s                                116 echo $code >> $T.s
246 disas $T 0                                     !! 117 disas $T
247 cat $T.dis >> $T.aa                               118 cat $T.dis >> $T.aa
                                                   >> 119 
                                                   >> 120 # (lines of whole $T.oo) - (lines of $T.aa, i.e. "Code starting") + 3,
                                                   >> 121 # i.e. the title + the "===..=" line (sed is counting from 1, 0 address is
                                                   >> 122 # special)
                                                   >> 123 faultlinenum=$(( $(wc -l $T.oo  | cut -d" " -f1) - \
                                                   >> 124                  $(wc -l $T.aa  | cut -d" " -f1) + 3))
                                                   >> 125 
                                                   >> 126 faultline=`cat $T.dis | head -1 | cut -d":" -f2-`
                                                   >> 127 faultline=`echo "$faultline" | sed -e 's/\[/\\\[/g; s/\]/\\\]/g'`
248                                                   128 
249 cat $T.oo | sed -e "${faultlinenum}s/^\([^:]*:    129 cat $T.oo | sed -e "${faultlinenum}s/^\([^:]*:\)\(.*\)/\1\*\2\t\t<-- trapping instruction/"
250 echo                                              130 echo
251 cat $T.aa                                         131 cat $T.aa
252 cleanup                                           132 cleanup
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php