2022-04-22 19:04:02

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v3] scripts: Create objdump-func helper script

Add a simple script which disassembles a single function from an object
file. Comes in handy for objtool warnings and kernel stack traces.

Originally-by: Peter Zijlstra <[email protected]>
Signed-off-by: Josh Poimboeuf <[email protected]>
---
v3:
- Add usage
- Fix vmlinux

scripts/objdump-func | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
create mode 100755 scripts/objdump-func

diff --git a/scripts/objdump-func b/scripts/objdump-func
new file mode 100755
index 000000000000..0908f9f616c3
--- /dev/null
+++ b/scripts/objdump-func
@@ -0,0 +1,25 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Disassemble a single function.
+#
+# usage: objdump-func <file> <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>" >&2
+ exit 1
+}
+
+[[ $# -ne 2 ]] && usage
+
+OBJ=$1; shift
+FUNC=$1; shift
+
+${OBJDUMP} -wdr $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; } }'
--
2.34.1


2022-04-22 20:27:39

by Borislav Petkov

[permalink] [raw]
Subject: Re: [PATCH v3] scripts: Create objdump-func helper script

On Wed, Apr 20, 2022 at 10:16:36AM -0700, Josh Poimboeuf wrote:
> Add a simple script which disassembles a single function from an object
> file. Comes in handy for objtool warnings and kernel stack traces.
>
> Originally-by: Peter Zijlstra <[email protected]>
> Signed-off-by: Josh Poimboeuf <[email protected]>
> ---
> v3:
> - Add usage

Thanks!

Acked-by: Borislav Petkov <[email protected]>

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette

2022-04-22 21:03:32

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [PATCH v3] scripts: Create objdump-func helper script

On Wed, Apr 20, 2022 at 10:16:36AM -0700, Josh Poimboeuf wrote:

> +${OBJDUMP} -wdr $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; } }'

Two noteworthy changes:

- $@ went missing, I've occasionally abused that to add extra argument
to objdump.

- you removed the glob after FUNC, I had that so that .cold and
.constprop etc.. variants of the function also show up.

I don't suppose either one are super important, but esp. that latter one
has been convenient.

2022-04-22 21:38:07

by Josh Poimboeuf

[permalink] [raw]
Subject: Re: [PATCH v3] scripts: Create objdump-func helper script

On Thu, Apr 21, 2022 at 10:52:44AM +0200, Peter Zijlstra wrote:
> On Wed, Apr 20, 2022 at 10:16:36AM -0700, Josh Poimboeuf wrote:
>
> > +${OBJDUMP} -wdr $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; } }'
>
> Two noteworthy changes:
>
> - $@ went missing, I've occasionally abused that to add extra argument
> to objdump.

Just to clarify, you'd add the extra arg at the end like this, right?

objdump-func <file> <func> -Mintel

> - you removed the glob after FUNC, I had that so that .cold and
> .constprop etc.. variants of the function also show up.

Sure, I'll match ".whatever" if there's a period, but not other
substring matches, e.g. "put_page" shouldn't match "put_pages_list".

{OBJDUMP} -wdr $@ $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; } }'


--
Josh