blob: 7b15b873d0e2a2227ed3df72c16feb543a3f91f2 [file] [log] [blame]
Josh Poimboeuf21e35022022-04-21 14:56:55 -07001#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# Disassemble a single function.
5#
Josh Poimboeuf27d000d2023-04-12 12:03:16 -07006# usage: objdump-func <file> <func> [<func> ...]
Josh Poimboeuf21e35022022-04-21 14:56:55 -07007
8set -o errexit
9set -o nounset
10
11OBJDUMP="${CROSS_COMPILE:-}objdump"
12
13command -v gawk >/dev/null 2>&1 || die "gawk isn't installed"
14
15usage() {
Josh Poimboeuf27d000d2023-04-12 12:03:16 -070016 echo "usage: objdump-func <file> <func> [<func> ...]" >&2
Josh Poimboeuf21e35022022-04-21 14:56:55 -070017 exit 1
18}
19
20[[ $# -lt 2 ]] && usage
21
22OBJ=$1; shift
Josh Poimboeuf27d000d2023-04-12 12:03:16 -070023FUNCS=("$@")
Josh Poimboeuf21e35022022-04-21 14:56:55 -070024
Josh Poimboeuf27d000d2023-04-12 12:03:16 -070025${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 }'