annotate scripts/showasm @ 1613:96aa7ec74936 draft

Fix yet another sed bug. The s/// command would copy the \ of substitutions before deciding what to do with them (generally overwriting the \ with the new data). When the substitution was A) at the very end of the new string, B) resolved to nothing, it could leave a trailing \ that didn't belong there and didn't get overwritten because the "copy trailing data" part that copies the original string's null terminator already happened before the \ overwrote it. The ghostwheel() function restarts regexes after embedded NUL bytes, but if the string it's passed is _longer_ than the length it's told then it gets confused (and it means we're off the end of our allocation so segfaults are likely). Fix: test for \ first and move the "copy byte" logic into an else case.
author Rob Landley <rob@landley.net>
date Mon, 15 Dec 2014 03:34:55 -0600
parents a43bdc6f53af
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
41
a43bdc6f53af Add bloat-o-meter, make bloatcheck, and scripts/showasm.
Rob Landley <rob@landley.net>
parents:
diff changeset
1 #!/bin/sh
a43bdc6f53af Add bloat-o-meter, make bloatcheck, and scripts/showasm.
Rob Landley <rob@landley.net>
parents:
diff changeset
2
a43bdc6f53af Add bloat-o-meter, make bloatcheck, and scripts/showasm.
Rob Landley <rob@landley.net>
parents:
diff changeset
3 # Copyright 2006 Rob Landley <rob@landley.net>
a43bdc6f53af Add bloat-o-meter, make bloatcheck, and scripts/showasm.
Rob Landley <rob@landley.net>
parents:
diff changeset
4
a43bdc6f53af Add bloat-o-meter, make bloatcheck, and scripts/showasm.
Rob Landley <rob@landley.net>
parents:
diff changeset
5 # Dumb little utility function to print out the assembly dump of a single
a43bdc6f53af Add bloat-o-meter, make bloatcheck, and scripts/showasm.
Rob Landley <rob@landley.net>
parents:
diff changeset
6 # function, or list the functions so dumpable in an executable. You'd think
a43bdc6f53af Add bloat-o-meter, make bloatcheck, and scripts/showasm.
Rob Landley <rob@landley.net>
parents:
diff changeset
7 # there would be a way to get objdump to do this, but I can't find it.
a43bdc6f53af Add bloat-o-meter, make bloatcheck, and scripts/showasm.
Rob Landley <rob@landley.net>
parents:
diff changeset
8
a43bdc6f53af Add bloat-o-meter, make bloatcheck, and scripts/showasm.
Rob Landley <rob@landley.net>
parents:
diff changeset
9 [ $# -lt 1 ] || [ $# -gt 2 ] && { echo "usage: showasm file function"; exit 1; }
a43bdc6f53af Add bloat-o-meter, make bloatcheck, and scripts/showasm.
Rob Landley <rob@landley.net>
parents:
diff changeset
10
a43bdc6f53af Add bloat-o-meter, make bloatcheck, and scripts/showasm.
Rob Landley <rob@landley.net>
parents:
diff changeset
11 [ ! -f $1 ] && { echo "File $1 not found"; exit 1; }
a43bdc6f53af Add bloat-o-meter, make bloatcheck, and scripts/showasm.
Rob Landley <rob@landley.net>
parents:
diff changeset
12
a43bdc6f53af Add bloat-o-meter, make bloatcheck, and scripts/showasm.
Rob Landley <rob@landley.net>
parents:
diff changeset
13 if [ $# -eq 1 ]
a43bdc6f53af Add bloat-o-meter, make bloatcheck, and scripts/showasm.
Rob Landley <rob@landley.net>
parents:
diff changeset
14 then
a43bdc6f53af Add bloat-o-meter, make bloatcheck, and scripts/showasm.
Rob Landley <rob@landley.net>
parents:
diff changeset
15 objdump -d $1 | sed -n -e 's/^[0-9a-fA-F]* <\(.*\)>:$/\1/p'
a43bdc6f53af Add bloat-o-meter, make bloatcheck, and scripts/showasm.
Rob Landley <rob@landley.net>
parents:
diff changeset
16 exit 0
a43bdc6f53af Add bloat-o-meter, make bloatcheck, and scripts/showasm.
Rob Landley <rob@landley.net>
parents:
diff changeset
17 fi
a43bdc6f53af Add bloat-o-meter, make bloatcheck, and scripts/showasm.
Rob Landley <rob@landley.net>
parents:
diff changeset
18
a43bdc6f53af Add bloat-o-meter, make bloatcheck, and scripts/showasm.
Rob Landley <rob@landley.net>
parents:
diff changeset
19 objdump -d $1 | sed -n -e '/./{H;$!d}' -e "x;/^.[0-9a-fA-F]* <$2>:/p"
a43bdc6f53af Add bloat-o-meter, make bloatcheck, and scripts/showasm.
Rob Landley <rob@landley.net>
parents:
diff changeset
20