From: jean.pihet@linaro.org (Jean Pihet)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 3/3] perf: parse the .debug_frame section in case .eh_frame is not present
Date: Mon, 9 Sep 2013 12:00:15 +0200 [thread overview]
Message-ID: <1378720815-23964-4-git-send-email-jean.pihet@linaro.org> (raw)
In-Reply-To: <1378720815-23964-1-git-send-email-jean.pihet@linaro.org>
On ARM the debug info is not present in the .eh_frame sections but
in .debug_frame instead, in the dwarf format.
Use libunwind to load and parse the debug info.
Dependencies:
. if present, libunwind >= 1.1 is needed to prevent a segfault when
parsing the dwarf info,
. libunwind needs to be configured with --enable-debug-frame
to prevent a linkage error. Note: --enable-debug-frame is automatically
selected on ARM).
Signed-off-by: Jean Pihet <jean.pihet@linaro.org>
---
tools/perf/config/Makefile | 2 +-
tools/perf/util/unwind.c | 71 +++++++++++++++++++++++++++++++++++-----------
2 files changed, 56 insertions(+), 17 deletions(-)
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index 7014373..54532b8 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -222,7 +222,7 @@ endif
FLAGS_UNWIND=$(LIBUNWIND_CFLAGS) $(CFLAGS) $(LIBUNWIND_LDFLAGS) $(LDFLAGS) $(EXTLIBS) $(LIBUNWIND_LIBS)
ifneq ($(call try-cc,$(SOURCE_LIBUNWIND),$(FLAGS_UNWIND),libunwind),y)
- msg := $(warning No libunwind found, disabling post unwind support. Please install libunwind-dev[el] >= 0.99);
+ msg := $(warning No libunwind found, disabling post unwind support. Please install libunwind-dev[el] >= 1.1);
NO_LIBUNWIND := 1
endif # Libunwind support
endif # NO_LIBUNWIND
diff --git a/tools/perf/util/unwind.c b/tools/perf/util/unwind.c
index 958723b..028c18a 100644
--- a/tools/perf/util/unwind.c
+++ b/tools/perf/util/unwind.c
@@ -39,6 +39,15 @@ UNW_OBJ(dwarf_search_unwind_table) (unw_addr_space_t as,
#define dwarf_search_unwind_table UNW_OBJ(dwarf_search_unwind_table)
+extern int
+UNW_OBJ(dwarf_find_debug_frame) (int found, unw_dyn_info_t *di_debug,
+ unw_word_t ip,
+ unw_word_t segbase,
+ const char *obj_name, unw_word_t start,
+ unw_word_t end);
+
+#define dwarf_find_debug_frame UNW_OBJ(dwarf_find_debug_frame)
+
#define DW_EH_PE_FORMAT_MASK 0x0f /* format of the encoded value */
#define DW_EH_PE_APPL_MASK 0x70 /* how the value is to be applied */
@@ -245,8 +254,9 @@ static int unwind_spec_ehframe(struct dso *dso, struct machine *machine,
return 0;
}
-static int read_unwind_spec(struct dso *dso, struct machine *machine,
- u64 *table_data, u64 *segbase, u64 *fde_count)
+static int read_unwind_spec_eh_frame(struct dso *dso, struct machine *machine,
+ u64 *table_data, u64 *segbase,
+ u64 *fde_count)
{
int ret = -EINVAL, fd;
u64 offset;
@@ -255,6 +265,7 @@ static int read_unwind_spec(struct dso *dso, struct machine *machine,
if (fd < 0)
return -EINVAL;
+ /* Check the .eh_frame section for unwinding info */
offset = elf_section_offset(fd, ".eh_frame_hdr");
close(fd);
@@ -263,10 +274,27 @@ static int read_unwind_spec(struct dso *dso, struct machine *machine,
table_data, segbase,
fde_count);
- /* TODO .debug_frame check if eh_frame_hdr fails */
return ret;
}
+static int read_unwind_spec_debug_frame(struct dso *dso,
+ struct machine *machine, u64 *offset)
+{
+ int fd = dso__data_fd(dso, machine);
+
+ if (fd < 0)
+ return -EINVAL;
+
+ /* Check the .debug_frame section for unwinding info */
+ *offset = elf_section_offset(fd, ".debug_frame");
+ close(fd);
+
+ if (*offset)
+ return 0;
+
+ return -EINVAL;
+}
+
static struct map *find_map(unw_word_t ip, struct unwind_info *ui)
{
struct addr_location al;
@@ -291,20 +319,31 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
pr_debug("unwind: find_proc_info dso %s\n", map->dso->name);
- if (read_unwind_spec(map->dso, ui->machine,
- &table_data, &segbase, &fde_count))
- return -EINVAL;
+ /* Check the .eh_frame section for unwinding info */
+ if (!read_unwind_spec_eh_frame(map->dso, ui->machine,
+ &table_data, &segbase, &fde_count)) {
+ memset(&di, 0, sizeof(di));
+ di.format = UNW_INFO_FORMAT_REMOTE_TABLE;
+ di.start_ip = map->start;
+ di.end_ip = map->end;
+ di.u.rti.segbase = map->start + segbase;
+ di.u.rti.table_data = map->start + table_data;
+ di.u.rti.table_len = fde_count * sizeof(struct table_entry)
+ / sizeof(unw_word_t);
+ return dwarf_search_unwind_table(as, ip, &di, pi,
+ need_unwind_info, arg);
+ }
+
+ /* Check the .debug_frame section for unwinding info */
+ if (!read_unwind_spec_debug_frame(map->dso, ui->machine, &segbase)) {
+ memset(&di, 0, sizeof(di));
+ dwarf_find_debug_frame(0, &di, ip, 0, map->dso->name,
+ map->start, map->end);
+ return dwarf_search_unwind_table(as, ip, &di, pi,
+ need_unwind_info, arg);
+ }
- memset(&di, 0, sizeof(di));
- di.format = UNW_INFO_FORMAT_REMOTE_TABLE;
- di.start_ip = map->start;
- di.end_ip = map->end;
- di.u.rti.segbase = map->start + segbase;
- di.u.rti.table_data = map->start + table_data;
- di.u.rti.table_len = fde_count * sizeof(struct table_entry)
- / sizeof(unw_word_t);
- return dwarf_search_unwind_table(as, ip, &di, pi,
- need_unwind_info, arg);
+ return -EINVAL;
}
static int access_fpreg(unw_addr_space_t __maybe_unused as,
--
1.7.11.7
next prev parent reply other threads:[~2013-09-09 10:00 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-09 10:00 [PATCH 0/3] perf: parse the dwarf backtrace info from .debug_frame section Jean Pihet
2013-09-09 10:00 ` [PATCH 1/3] ARM: perf: add support for perf registers API Jean Pihet
2013-09-09 10:00 ` [PATCH 2/3] ARM: perf: wire up perf_regs and unwind support for ARM Jean Pihet
2013-09-09 10:00 ` Jean Pihet [this message]
2013-09-10 19:14 ` [PATCH 3/3] perf: parse the .debug_frame section in case .eh_frame is not present David Ahern
2013-09-10 19:38 ` Jean Pihet
2013-09-12 12:38 ` Jiri Olsa
2013-09-10 7:29 ` [PATCH 0/3] perf: parse the dwarf backtrace info from .debug_frame section Jean Pihet
2013-09-12 12:07 ` Jean Pihet
2013-09-12 12:19 ` Peter Zijlstra
2013-09-12 12:28 ` Will Deacon
-- strict thread matches above, loose matches on Subject: below --
2013-09-04 18:04 Jean Pihet
2013-09-04 18:04 ` [PATCH 3/3] perf: parse the .debug_frame section in case .eh_frame is not present Jean Pihet
2013-09-05 12:45 ` Will Deacon
2013-09-05 13:05 ` Jean Pihet
2013-09-05 13:17 ` Ard Biesheuvel
2013-09-05 13:19 ` Will Deacon
2013-09-05 13:33 ` Jean Pihet
2013-09-05 15:29 ` Jean Pihet
2013-09-05 15:45 ` Ard Biesheuvel
2013-09-05 13:10 ` Ard Biesheuvel
2013-09-05 16:30 ` Jiri Olsa
2013-09-05 16:49 ` Jean Pihet
2013-09-06 10:17 ` Jiri Olsa
2013-09-06 9:31 ` Jean Pihet
2013-09-06 10:17 ` Jiri Olsa
2013-09-06 14:10 ` Jean Pihet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1378720815-23964-4-git-send-email-jean.pihet@linaro.org \
--to=jean.pihet@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).