Re: NAK (bashizm in the /bin/sh script): [PATCH v3]doc/oops-tracing: add Code: decode info

From: Randy Dunlap
Date: Tue Jun 26 2007 - 13:54:23 EST


On Tue, 26 Jun 2007 19:25:00 +0200 Julio M. Merino Vidal wrote:

> On 26/06/2007, at 19:19, Randy Dunlap wrote:
> >
> > Are these 2 line changes all that is needed?
> >
> > I sort of expected expressions like $((a + 2)) to need change also...
> > maybe not for dash, but for sh?
>
> The correct expression could be $((${a} + 2)). Tested under NetBSD's
> sh, which is very POSIX-compliant.

Thanks. Does anyone see other changes that are needed?


The diff currently looks like:

--- decodecode.~3~ 2007-06-22 13:25:39.000000000 -0700
+++ decodecode 2007-06-26 10:40:28.000000000 -0700
@@ -28,7 +28,7 @@
fi

if [ $marker -ne 0 ]; then
- beforemark=${code:0:$((marker - 1))}
+ beforemark=`echo "$code" | cut -c-$((${marker} - 1))`
echo -n " .byte 0x" > $T.s
echo $beforemark | sed -e 's/ /,0x/g' >> $T.s
as -o $T.o $T.s
@@ -36,7 +36,7 @@
rm $T.o $T.s

# and fix code at-and-after marker
- code=${code:$marker}
+ code=`echo "$code" | cut -c$((${marker} + 1))-`
fi

code=`echo $code | sed -e 's/ [<(]/ /;s/[>)] / /;s/ /,0x/g'`




and the complete script is:

#!/bin/sh
# Disassemble the Code: line in Linux oopses
# usage: decodecode < oops.file

T=`mktemp`
code=

while read i ; do

case "$i" in
*Code:*)
code=$i
;;
esac

done

if [ -z "$code" ]; then
exit
fi

echo $code
code=`echo $code | sed -e 's/.*Code: //'`

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

if [ $marker -ne 0 ]; then
beforemark=`echo "$code" | cut -c-$((${marker} - 1))`
echo -n " .byte 0x" > $T.s
echo $beforemark | sed -e 's/ /,0x/g' >> $T.s
as -o $T.o $T.s
objdump -S $T.o
rm $T.o $T.s

# and fix code at-and-after marker
code=`echo "$code" | cut -c$((${marker} + 1))-`
fi

code=`echo $code | sed -e 's/ [<(]/ /;s/[>)] / /;s/ /,0x/g'`
echo -n " .byte 0x" > $T.s
echo $code >> $T.s
as -o $T.o $T.s
objdump -S $T.o
rm $T.o $T.s
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/