Skip to content

Commit 27d000d

Browse files
jpoimboePeter Zijlstra
authored andcommitted
scripts/objdump-func: Support multiple functions
Allow specifying multiple functions on the cmdline. Note this removes the secret EXTRA_ARGS feature. While at it, spread out the awk to make it more readable. Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lkml.kernel.org/r/0bf5f4f5978660985037b24c6db49b114374eb4d.1681325924.git.jpoimboe@kernel.org
1 parent e8deb00 commit 27d000d

1 file changed

Lines changed: 25 additions & 9 deletions

File tree

scripts/objdump-func

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Disassemble a single function.
55
#
6-
# usage: objdump-func <file> <func>
6+
# usage: objdump-func <file> <func> [<func> ...]
77

88
set -o errexit
99
set -o nounset
@@ -13,17 +13,33 @@ OBJDUMP="${CROSS_COMPILE:-}objdump"
1313
command -v gawk >/dev/null 2>&1 || die "gawk isn't installed"
1414

1515
usage() {
16-
echo "usage: objdump-func <file> <func>" >&2
16+
echo "usage: objdump-func <file> <func> [<func> ...]" >&2
1717
exit 1
1818
}
1919

2020
[[ $# -lt 2 ]] && usage
2121

2222
OBJ=$1; shift
23-
FUNC=$1; shift
24-
25-
# Secret feature to allow adding extra objdump args at the end
26-
EXTRA_ARGS=$@
27-
28-
# Note this also matches compiler-added suffixes like ".cold", etc
29-
${OBJDUMP} -wdr $EXTRA_ARGS $OBJ | gawk -M -v f=$FUNC '/^$/ { P=0; } $0 ~ "<" f "(\\..*)?>:" { P=1; O=strtonum("0x" $1); } { if (P) { o=strtonum("0x" $1); printf("%04x ", o-O); print $0; } }'
23+
FUNCS=("$@")
24+
25+
${OBJDUMP} -wdr $OBJ | gawk -M -v _funcs="${FUNCS[*]}" '
26+
BEGIN { split(_funcs, funcs); }
27+
/^$/ { func_match=0; }
28+
/<.*>:/ {
29+
f = gensub(/.*<(.*)>:/, "\\1", 1);
30+
for (i in funcs) {
31+
# match compiler-added suffixes like ".cold", etc
32+
if (f ~ "^" funcs[i] "(\\..*)?") {
33+
func_match = 1;
34+
base = strtonum("0x" $1);
35+
break;
36+
}
37+
}
38+
}
39+
{
40+
if (func_match) {
41+
addr = strtonum("0x" $1);
42+
printf("%04x ", addr - base);
43+
print;
44+
}
45+
}'

0 commit comments

Comments
 (0)