Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1485072

[PATCH] scripts: add script for translating stack dump function offsets

From Josh Poimboeuf <jpoimboe@redhat.com>
Newsgroups linux.kernel
Subject [PATCH] scripts: add script for translating stack dump function offsets
Date 2016-09-16 16:50 +0200
Message-ID <si2CK-608-23@gated-at.bofh.it> (permalink)
References <shuUq-12G-5@gated-at.bofh.it> <shxyV-2Tv-5@gated-at.bofh.it> <shzhn-3Zo-3@gated-at.bofh.it> <shDO2-6VP-31@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Thu, Sep 15, 2016 at 07:10:14AM -0500, Josh Poimboeuf wrote:
> On Thu, Sep 15, 2016 at 09:24:25AM +0200, Peter Zijlstra wrote:
> > On Wed, Sep 14, 2016 at 10:35:49PM -0700, Stephane Eranian wrote:
> > > On Wed, Sep 14, 2016 at 7:43 PM, Vince Weaver <vincent.weaver@maine.edu> wrote:
> > > >
> > > > so the skylake that was fuzzing finally is mostly locked up.
> > > >
> > > > Really hard to tell what's going, especially as KASLR made looking up the
> > > > addresses a big pain.
> > > >
> > > I would think there is a way to disable KASLR for this kind of testing!
> > 
> > I always kill CONFIG_RANDOMIZE_BASE, but there's also talk of killing
> > the address print entirely..  :-(
> > 
> >   https://lkml.kernel.org/r/20160831165303.tvcudt7wkpechuqt@treble
> 
> So you should be able to do something like:
> 
>   echo "list *driver_probe_device+0x223" |gdb vmlinux |grep "is in"
> 
> Though that's admittedly quite a bit slower than addr2line.

Here's something a lot faster than gdb, which also handles duplicate
symbols properly.

---

From: Josh Poimboeuf <jpoimboe@redhat.com>
Subject: [PATCH] scripts: add script for translating stack dump function
 offsets

addr2line doesn't work with KASLR addresses.  Add a basic addr2line
wrapper script which takes the 'func+0x123' format as input.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 scripts/faddr2line | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100755 scripts/faddr2line

diff --git a/scripts/faddr2line b/scripts/faddr2line
new file mode 100755
index 0000000..17f300f
--- /dev/null
+++ b/scripts/faddr2line
@@ -0,0 +1,54 @@
+#!/bin/bash
+#
+# Translate stack dump function offsets.
+#
+# addr2line doesn't work with KASLR addresses.  This works similarly to
+# addr2line, but instead takes the 'func+0x123' format as input:
+#
+#   $ scripts/faddr2line vmlinux meminfo_proc_show+0x5/0x1b0
+#   fs/proc/meminfo.c:27
+#
+# It also supports duplicate symbols:
+#
+#   $ scripts/faddr2line vmlinux raw_ioctl+0x5
+#   drivers/char/raw.c:122
+#   net/ipv4/raw.c:876
+
+set -o errexit
+set -o nounset
+
+usage() {
+	echo "usage: faddr2line <object file> <func+offset>" >&2
+	exit 1
+}
+
+die() {
+	echo "ERROR: $1" >&2
+	exit 1
+}
+
+[[ $# != 2 ]] && usage
+
+objfile=$1
+[[ ! -f $objfile ]] && die "can't find objfile $objfile"
+
+func_offset=$2
+func=${func_offset%+*}
+offset=${func_offset#*+}
+offset=${offset%/*}
+[[ -z $func ]] || [[ -z $offset ]] || [[ $func = $func_offset ]] ||
+	[[ $offset = $func_offset ]] && die "bad func+offset $func_offset"
+
+command -v objdump >/dev/null 2>&1 || die "objdump isn't installed"
+command -v addr2line >/dev/null 2>&1 || die "addr2line isn't installed"
+
+addrs=$(objdump -t $objfile | awk -v f=$func '$6 == f {print $1}')
+[[ -z $addrs ]] && die "can't find $func in $objfile"
+
+for base in $addrs; do
+	addr=$((0x$base + $offset))
+	[[ -z $addr ]] || [[ $addr = 0 ]] && die "bad address: 0x$base + $offset"
+
+	hexaddr=$(printf %x $addr)
+	addr2line -ie $objfile $hexaddr
+done
-- 
2.7.4

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

perf: perf_fuzzer lockup in perf_cgroup_attach Vince Weaver <vincent.weaver@maine.edu> - 2016-09-15 04:50 +0200
  Re: perf: perf_fuzzer lockup in perf_cgroup_attach Stephane Eranian <eranian@google.com> - 2016-09-15 07:40 +0200
    Re: perf: perf_fuzzer lockup in perf_cgroup_attach Peter Zijlstra <peterz@infradead.org> - 2016-09-15 09:30 +0200
      Re: perf: perf_fuzzer lockup in perf_cgroup_attach Josh Poimboeuf <jpoimboe@redhat.com> - 2016-09-15 14:20 +0200
        [PATCH] scripts: add script for translating stack dump function  offsets Josh Poimboeuf <jpoimboe@redhat.com> - 2016-09-16 16:50 +0200
          Re: [PATCH] scripts: add script for translating stack dump function offsets Linus Torvalds <torvalds@linux-foundation.org> - 2016-09-16 20:20 +0200
            Re: [PATCH] scripts: add script for translating stack dump function  offsets Josh Poimboeuf <jpoimboe@redhat.com> - 2016-09-16 21:20 +0200
              Re: [PATCH] scripts: add script for translating stack dump function offsets Linus Torvalds <torvalds@linux-foundation.org> - 2016-09-16 21:30 +0200
                [PATCH v2] scripts: add script for translating stack dump function  offsets Josh Poimboeuf <jpoimboe@redhat.com> - 2016-09-16 23:30 +0200
                Re: [PATCH v2] scripts: add script for translating stack dump  function offsets Linus Torvalds <torvalds@linux-foundation.org> - 2016-09-17 02:10 +0200
                Re: [PATCH v2] scripts: add script for translating stack dump  function offsets Josh Poimboeuf <jpoimboe@redhat.com> - 2016-09-17 02:50 +0200
                Re: [PATCH v2] scripts: add script for translating stack dump  function offsets Linus Torvalds <torvalds@linux-foundation.org> - 2016-09-17 04:00 +0200
                Re: [PATCH v2] scripts: add script for translating stack dump  function offsets Linus Torvalds <torvalds@linux-foundation.org> - 2016-09-17 04:40 +0200
                Re: [PATCH v2] scripts: add script for translating stack dump  function offsets Josh Poimboeuf <jpoimboe@redhat.com> - 2016-09-17 20:50 +0200
                [PATCH v3] scripts: add script for translating stack dump function Josh Poimboeuf <jpoimboe@redhat.com> - 2016-09-19 18:00 +0200
                Re: [PATCH v3] scripts: add script for translating stack dump function Linus Torvalds <torvalds@linux-foundation.org> - 2016-09-19 21:00 +0200
                Re: [PATCH v3] scripts: add script for translating stack dump function Linus Torvalds <torvalds@linux-foundation.org> - 2016-09-19 21:20 +0200
                Re: [PATCH v3] scripts: add script for translating stack dump  function Josh Poimboeuf <jpoimboe@redhat.com> - 2016-09-19 21:30 +0200
                Re: [PATCH v3] scripts: add script for translating stack dump  function Rabin Vincent <rabin@rab.in> - 2016-09-19 22:10 +0200
                Re: [PATCH v3] scripts: add script for translating stack dump function Linus Torvalds <torvalds@linux-foundation.org> - 2016-09-19 22:30 +0200
                Re: [PATCH v3] scripts: add script for translating stack dump  function Josh Poimboeuf <jpoimboe@redhat.com> - 2016-09-19 23:00 +0200
                Re: [PATCH v3] scripts: add script for translating stack dump  function Josh Poimboeuf <jpoimboe@redhat.com> - 2016-09-19 23:10 +0200
                Re: [PATCH v3] scripts: add script for translating stack dump function Linus Torvalds <torvalds@linux-foundation.org> - 2016-09-19 23:10 +0200
                Re: [PATCH v2] scripts: add script for translating stack dump  function offsets Peter Zijlstra <peterz@infradead.org> - 2016-09-17 03:30 +0200
                Re: [PATCH v2] scripts: add script for translating stack dump  function offsets Rabin Vincent <rabin@rab.in> - 2016-09-17 10:20 +0200
                Re: [PATCH v2] scripts: add script for translating stack dump  function offsets Josh Poimboeuf <jpoimboe@redhat.com> - 2016-09-17 20:50 +0200
              Re: [PATCH] scripts: add script for translating stack dump function offsets Vegard Nossum <vegard.nossum@gmail.com> - 2016-09-17 11:20 +0200
                Re: [PATCH] scripts: add script for translating stack dump function  offsets Josh Poimboeuf <jpoimboe@redhat.com> - 2016-09-17 21:00 +0200
    Re: perf: perf_fuzzer lockup in perf_cgroup_attach Vince Weaver <vincent.weaver@maine.edu> - 2016-09-15 14:50 +0200
  Re: perf: perf_fuzzer lockup in perf_cgroup_attach Peter Zijlstra <peterz@infradead.org> - 2016-09-15 09:20 +0200
    Re: perf: perf_fuzzer lockup in perf_cgroup_attach Vince Weaver <vincent.weaver@maine.edu> - 2016-09-15 14:50 +0200

csiph-web