xref: /linux/scripts/objdump-func (revision 21e350233b07619dbfc3ce606ff1fc468fce2d82)
1*21e35023SJosh Poimboeuf#!/bin/bash
2*21e35023SJosh Poimboeuf# SPDX-License-Identifier: GPL-2.0
3*21e35023SJosh Poimboeuf#
4*21e35023SJosh Poimboeuf# Disassemble a single function.
5*21e35023SJosh Poimboeuf#
6*21e35023SJosh Poimboeuf# usage: objdump-func <file> <func>
7*21e35023SJosh Poimboeuf
8*21e35023SJosh Poimboeufset -o errexit
9*21e35023SJosh Poimboeufset -o nounset
10*21e35023SJosh Poimboeuf
11*21e35023SJosh PoimboeufOBJDUMP="${CROSS_COMPILE:-}objdump"
12*21e35023SJosh Poimboeuf
13*21e35023SJosh Poimboeufcommand -v gawk >/dev/null 2>&1 || die "gawk isn't installed"
14*21e35023SJosh Poimboeuf
15*21e35023SJosh Poimboeufusage() {
16*21e35023SJosh Poimboeuf	echo "usage: objdump-func <file> <func>" >&2
17*21e35023SJosh Poimboeuf	exit 1
18*21e35023SJosh Poimboeuf}
19*21e35023SJosh Poimboeuf
20*21e35023SJosh Poimboeuf[[ $# -lt 2 ]] && usage
21*21e35023SJosh Poimboeuf
22*21e35023SJosh PoimboeufOBJ=$1; shift
23*21e35023SJosh PoimboeufFUNC=$1; shift
24*21e35023SJosh Poimboeuf
25*21e35023SJosh Poimboeuf# Secret feature to allow adding extra objdump args at the end
26*21e35023SJosh PoimboeufEXTRA_ARGS=$@
27*21e35023SJosh Poimboeuf
28*21e35023SJosh Poimboeuf# Note this also matches compiler-added suffixes like ".cold", etc
29*21e35023SJosh Poimboeuf${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