1 #!/bin/bash 1 #!/bin/bash 2 # SPDX-License-Identifier: GPL-2.0 2 # SPDX-License-Identifier: GPL-2.0 3 # 3 # 4 # Disassemble a single function. 4 # Disassemble a single function. 5 # 5 # 6 # usage: objdump-func <file> <func> [<func> .. !! 6 # usage: objdump-func <file> <func> 7 7 8 set -o errexit 8 set -o errexit 9 set -o nounset 9 set -o nounset 10 10 11 OBJDUMP="${CROSS_COMPILE:-}objdump" 11 OBJDUMP="${CROSS_COMPILE:-}objdump" 12 12 13 command -v gawk >/dev/null 2>&1 || die "gawk i 13 command -v gawk >/dev/null 2>&1 || die "gawk isn't installed" 14 14 15 usage() { 15 usage() { 16 echo "usage: objdump-func <file> <func !! 16 echo "usage: objdump-func <file> <func>" >&2 17 exit 1 17 exit 1 18 } 18 } 19 19 20 [[ $# -lt 2 ]] && usage 20 [[ $# -lt 2 ]] && usage 21 21 22 OBJ=$1; shift 22 OBJ=$1; shift 23 FUNCS=("$@") !! 23 FUNC=$1; shift 24 24 25 ${OBJDUMP} -wdr $OBJ | gawk -M -v _funcs="${FU !! 25 # Secret feature to allow adding extra objdump args at the end 26 BEGIN { split(_funcs, funcs); } !! 26 EXTRA_ARGS=$@ 27 /^$/ { func_match=0; } !! 27 28 /<.*>:/ { !! 28 # Note this also matches compiler-added suffixes like ".cold", etc 29 f = gensub(/.*<(.*)>:/, "\\1", !! 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; } }' 30 for (i in funcs) { << 31 # match compiler-added << 32 if (f ~ "^" funcs[i] " << 33 func_match = 1 << 34 base = strtonu << 35 break; << 36 } << 37 } << 38 } << 39 { << 40 if (func_match) { << 41 addr = strtonum("0x" $ << 42 printf("%04x ", addr - << 43 print; << 44 } << 45 }' <<
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.