summaryrefslogtreecommitdiffstats
path: root/scripts/objdump-func
blob: 7b15b873d0e2a2227ed3df72c16feb543a3f91f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# Disassemble a single function.
#
# usage: objdump-func <file> <func> [<func> ...]

set -o errexit
set -o nounset

OBJDUMP="${CROSS_COMPILE:-}objdump"

command -v gawk >/dev/null 2>&1 || die "gawk isn't installed"

usage() {
	echo "usage: objdump-func <file> <func> [<func> ...]" >&2
	exit 1
}

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

OBJ=$1; shift
FUNCS=("$@")

${OBJDUMP} -wdr $OBJ | gawk -M -v _funcs="${FUNCS[*]}" '
	BEGIN { split(_funcs, funcs); }
	/^$/ { func_match=0; }
	/<.*>:/ {
		f = gensub(/.*<(.*)>:/, "\\1", 1);
		for (i in funcs) {
			# match compiler-added suffixes like ".cold", etc
			if (f ~ "^" funcs[i] "(\\..*)?") {
				func_match = 1;
				base = strtonum("0x" $1);
				break;
			}
		}
	}
	{
		if (func_match) {
			addr = strtonum("0x" $1);
			printf("%04x ", addr - base);
			print;
		}
	}'