Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp725369pxj; Thu, 27 May 2021 10:13:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwd8gfGy8jDUGz/Ry0hFSZw9pR5dlV9KkwJrvDri3R0LTbm91Yq/ksfzwDNhQxg43KdO53L X-Received: by 2002:a05:6602:2437:: with SMTP id g23mr3573744iob.142.1622135612838; Thu, 27 May 2021 10:13:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622135612; cv=none; d=google.com; s=arc-20160816; b=ltLr3qpBzoGjNJWBdxDzU6G37PGoI2Bp6YBrUnacwpx9UsXvOqXSog0D3pVJrSxjd/ EK3gcyKODVJTCltX9+cNT3BD81cuG/yX0ia2+DB1rCqeEpd2xd38W4+rvYrqKPYXmgXi vORBDB9MQc1cEdK5bZ+MmQhwjX0xPCxv246lfjjS1CFcbJWUTl7P3n3oUKdzrpVwkYb0 DSxniGHXQA9pi8lEx7vrHyiXeAMU9V5za0CeYu7uSVDbh4ajPSaLl6Uk6uRzWF4zAvhb tLuJCP7NjN0g2++jDHRO4zsWN5V8oPW63ZH11Gs6CTliE3t7voPxuTdwoHsLtu9qOqUx vmtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dBwycrFN/+s+M1BqvZQRBYlv8yoa3GMwFluRD/9GhgQ=; b=axxa9zHPNdrEAsmsR3yhjvghYqCU9e2VRJZ2M8Y7xsGBY3qXHH1l2a3oiUCBQfi0GX pD4UcZ5fvv46i9c0kh6KVzu4aM4/YSDN8zuUxIvFkhe6LQAj/5MjmBBeo5a/EO+0Qsza u1I28gkVKDpsWtfyzr4A/hDZHDBqpCQSSIbXMzN6RtlkOCNNDuHacpPeMUZ7mNN0LjFw qke+cW6xrRPGyXrHy9DKQ6198ZLRsDw/Z42UP2oKSU+ekxXS1GNP3lUFa8Nwv41Pk5lS rdclInbslq0i3/7UisTgL5jmDgO5MXN/QUcyGGctYy4HOopSyNMhfGg9gT2nNjH6R/T2 st6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QkVmHVQq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l1si2836794ilg.123.2021.05.27.10.13.18; Thu, 27 May 2021 10:13:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QkVmHVQq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236994AbhE0PO7 (ORCPT + 99 others); Thu, 27 May 2021 11:14:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:43196 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236902AbhE0POk (ORCPT ); Thu, 27 May 2021 11:14:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0FC9C60724; Thu, 27 May 2021 15:13:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622128387; bh=P4cHp4mjoWKDoBbgpH4pQLwRbAbw8CpoL9g8GbHVnSs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QkVmHVQq1/Y+blIlzD72nkS/I0OO7I0JNy5ASp3vqkIb5cb3AU2Xcge/t0SGWGUZt SrFsfwLMFf4Kusppv5RoU49KuEIc2b7qsGP90+bggowwcspw1/2zVVCLrdIGXPXuET TboSydx+l65sX8vrC7tW9uDEjIvlIGxfbsXiTC+g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Kratochvil , Jiri Olsa , Adrian Hunter , David Ahern , Ian Rogers , Namhyung Kim , Arnaldo Carvalho de Melo , "Tommi Rantala" Subject: [PATCH 5.4 5/7] perf unwind: Fix separate debug info files when using elfutils libdws unwinder Date: Thu, 27 May 2021 17:12:47 +0200 Message-Id: <20210527151139.394008531@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210527151139.224619013@linuxfoundation.org> References: <20210527151139.224619013@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jan Kratochvil commit bf53fc6b5f415cddc7118091cb8fd6a211b2320d upstream. elfutils needs to be provided main binary and separate debug info file respectively. Providing separate debug info file instead of the main binary is not sufficient. One needs to try both supplied filename and its possible cache by its build-id depending on the use case. Signed-off-by: Jan Kratochvil Tested-by: Jiri Olsa Cc: Adrian Hunter Cc: David Ahern Cc: Ian Rogers Cc: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo Cc: "Tommi Rantala" Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/unwind-libdw.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) --- a/tools/perf/util/unwind-libdw.c +++ b/tools/perf/util/unwind-libdw.c @@ -20,10 +20,24 @@ static char *debuginfo_path; +static int __find_debuginfo(Dwfl_Module *mod __maybe_unused, void **userdata, + const char *modname __maybe_unused, Dwarf_Addr base __maybe_unused, + const char *file_name, const char *debuglink_file __maybe_unused, + GElf_Word debuglink_crc __maybe_unused, char **debuginfo_file_name) +{ + const struct dso *dso = *userdata; + + assert(dso); + if (dso->symsrc_filename && strcmp (file_name, dso->symsrc_filename)) + *debuginfo_file_name = strdup(dso->symsrc_filename); + return -1; +} + static const Dwfl_Callbacks offline_callbacks = { - .find_debuginfo = dwfl_standard_find_debuginfo, + .find_debuginfo = __find_debuginfo, .debuginfo_path = &debuginfo_path, .section_address = dwfl_offline_section_address, + // .find_elf is not set as we use dwfl_report_elf() instead. }; static int __report_module(struct addr_location *al, u64 ip, @@ -46,16 +60,24 @@ static int __report_module(struct addr_l mod = dwfl_addrmodule(ui->dwfl, ip); if (mod) { Dwarf_Addr s; + void **userdatap; - dwfl_module_info(mod, NULL, &s, NULL, NULL, NULL, NULL, NULL); + dwfl_module_info(mod, &userdatap, &s, NULL, NULL, NULL, NULL, NULL); + *userdatap = dso; if (s != al->map->start - al->map->pgoff) mod = 0; } if (!mod) - mod = dwfl_report_elf(ui->dwfl, dso->short_name, - (dso->symsrc_filename ? dso->symsrc_filename : dso->long_name), -1, al->map->start - al->map->pgoff, - false); + mod = dwfl_report_elf(ui->dwfl, dso->short_name, dso->long_name, -1, + al->map->start - al->map->pgoff, false); + if (!mod) { + char filename[PATH_MAX]; + + if (dso__build_id_filename(dso, filename, sizeof(filename), false)) + mod = dwfl_report_elf(ui->dwfl, dso->short_name, filename, -1, + al->map->start - al->map->pgoff, false); + } return mod && dwfl_addrmodule(ui->dwfl, ip) == mod ? 0 : -1; }