Re: [PATCH RFC RESEND] Perf: lookup dwarf unwind stack info in debug file pointed by .gnu_debuglink

From: Jiri Olsa
Date: Mon Aug 22 2016 - 11:19:25 EST


On Mon, Aug 22, 2016 at 02:32:04PM +0200, Matija Glavinic Pecotic wrote:

SNIP

> Signed-off-by: Matija Glavinic Pecotic <matija.glavinic-pecotic.ext@xxxxxxxxx>
> ---
> tools/perf/util/unwind-libunwind-local.c | 36 ++++++++++++++++++++++++++++----
> 1 file changed, 32 insertions(+), 4 deletions(-)
>
> diff --git a/tools/perf/util/unwind-libunwind-local.c b/tools/perf/util/unwind-libunwind-local.c
> index 97c0f8f..5d40acd 100644
> --- a/tools/perf/util/unwind-libunwind-local.c
> +++ b/tools/perf/util/unwind-libunwind-local.c
> @@ -35,6 +35,7 @@
> #include "util.h"
> #include "debug.h"
> #include "asm/bug.h"
> +#include "dso.h"
>
> extern int
> UNW_OBJ(dwarf_search_unwind_table) (unw_addr_space_t as,
> @@ -292,10 +293,13 @@ static int read_unwind_spec_eh_frame(struct dso *dso, struct machine *machine,
>
> #ifndef NO_LIBUNWIND_DEBUG_FRAME
> static int read_unwind_spec_debug_frame(struct dso *dso,
> - struct machine *machine, u64 *offset)
> + struct machine *machine, u64 *offset,
> + char **symfile)
> {
> int fd;
> u64 ofs = dso->data.debug_frame_offset;
> + char *debuglink = malloc(PATH_MAX);
> + int ret = 0;
>
> if (ofs == 0) {
> fd = dso__data_get_fd(dso, machine);
> @@ -312,6 +316,26 @@ static int read_unwind_spec_debug_frame(struct dso *dso,
> if (*offset)
> return 0;
>
> + /* If not found, try to lookup in debuglink */
> + ret = dso__read_binary_type_filename(
> + dso, DSO_BINARY_TYPE__DEBUGLINK,
> + machine->root_dir, debuglink, PATH_MAX);
> + if (!ret) {
> + pr_debug("%s: dso: %s, ret: %d, debuglink: <%s>\n",
> + __func__, dso->short_name, ret, debuglink);
> +
> + fd = open(debuglink, O_RDONLY);
> + if (fd >= 0) {
> + ofs = elf_section_offset(fd, ".debug_frame");
> + close(fd);

should you also set following?

*offset = ofs
dso->debug_frame_offset = ofs;

I guess if we found the debuglink section with file having .debug_frame
section, we want to use it for this dso from now on..

I'd think let's have read_unwind_spec_debug_frame to find .debug_frame
and provide that info under dso object for subsequent reads

> +
> + if (ofs) {
> + *symfile = debuglink;
> + return 0;
> + }
> + }
> + }
> +
> return -EINVAL;
> }
> #endif
> @@ -343,6 +367,7 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
> unw_dyn_info_t di;
> u64 table_data, segbase, fde_count;
> int ret = -EINVAL;
> + char *symfile = NULL;
>
> map = find_map(ip, ui);
> if (!map || !map->dso)
> @@ -368,16 +393,19 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
> #ifndef NO_LIBUNWIND_DEBUG_FRAME
> /* Check the .debug_frame section for unwinding info */
> if (ret < 0 &&
> - !read_unwind_spec_debug_frame(map->dso, ui->machine, &segbase)) {
> + !read_unwind_spec_debug_frame(
> + map->dso, ui->machine, &segbase, &symfile)) {
> int fd = dso__data_get_fd(map->dso, ui->machine);
> int is_exec = elf_is_exec(fd, map->dso->name);
> unw_word_t base = is_exec ? 0 : map->start;
> - const char *symfile;
>
> if (fd >= 0)
> dso__data_put_fd(map->dso);
>
> - symfile = map->dso->symsrc_filename ?: map->dso->name;
> + if (!symfile)
> + symfile = map->dso->symsrc_filename ?: map->dso->name;

so in case we find debuglink-ed file, it has precedence over the file
we found symtab in? assuming thats what dso->symsrc_filename is..

thanks,
jirka