Received: by 2002:a17:90a:9103:0:0:0:0 with SMTP id k3csp11816368pjo; Thu, 2 Jan 2020 14:47:28 -0800 (PST) X-Google-Smtp-Source: APXvYqzHb3ahXCho0iVWuHXIHiFYbJaKlv98TMuuWFbkQKMI74jCzTkwp8aQlWWyAtkSG16aakyX X-Received: by 2002:a9d:53c4:: with SMTP id i4mr85078134oth.48.1578005248637; Thu, 02 Jan 2020 14:47:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578005248; cv=none; d=google.com; s=arc-20160816; b=A6MDrHRH65OdEWN0beHYixPNzNm8RI7w24q5T5UCpJY7PHtexzKabvsZxRvKcjpMrm ASNDApp0sQHDRTh1A8uP/4nGcsOGPbdZ0jQQ+LTU/xO/puy/rX1CA0hCTwcZJ8SOEdiq QSInwgIrjzEOmjHTGx2yY/UXFDyMdxJWXgSr5w5Z8o620pdUWVzNDnhOnhUR0tbnTYnP PreW2OiZCOthyvO0A0MI6mkWUoDvz2JXk4AMFwX82izb634BGGXeTjLocWfuORhIygWo VWJOTHYCm03QZlxE3N/xMClWFblnPsL3A7iWsuEEWAdtJSwZ36uvUFsJLcWttzUhy2c4 RKlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NhhW7ZZQ0PzpHOBwW4BM+hVsaZtXt7WOo3qyHDH1pbQ=; b=rnGpnXMLl1DhmoFW+UsdtyWQtflVCOBAhOxpbNHtT7XTl90NxB2JxkgzBPKtkFofGU 01HQYtbYO2QIzjfVbut1j/Lzp4lCE9mEN3oHvUU3IWRl+ggeMNTe8ug1KvHl6zAs4peM SfWd9Xvu0PiJHjqU3dTjMYhgMynwfD0ae73nfA1tTev5Km+mrmQRVCYqLCMzAmOTcITM has7yxvcVCaKZFBh0qDmHPIx5tzxph/wvqGxIvxbG0vc0K3VUUDmN4BJTG2l5GCl0Pkd adCwBo4jUn37/nqo3y7HRXXlaIqkp4lEt8yXEMFrRA9SdcpRZK3gqP0JeEy3cb5cm4lB EMIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=j1vjZYyc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r12si28465064otq.156.2020.01.02.14.47.17; Thu, 02 Jan 2020 14:47:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=j1vjZYyc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730266AbgABWbT (ORCPT + 99 others); Thu, 2 Jan 2020 17:31:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:36170 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730120AbgABWbO (ORCPT ); Thu, 2 Jan 2020 17:31:14 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2ACEE20866; Thu, 2 Jan 2020 22:31:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578004272; bh=DF/zNNSmy9moWJcGF6ffgJY4tdKF7S2cTuVnmuVeuDc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j1vjZYyca/6V7yIX9zRMnXtPQyzATLYCW2bwj0D02dthUE5q2uDQ46sOhiRzYewXF 1sFSGJw/odXx9yPg/jpAKeVKoyVz5DO3m5oyqDpv+KoG2aXYvGnduzKA1nb3zwdGNn QwcElm/IUwki2DpZFupAuo5n2uMuU5GsqLcim3Dk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Masami Hiramatsu , Jiri Olsa , Namhyung Kim , Arnaldo Carvalho de Melo , Thomas Backlund Subject: [PATCH 4.9 110/171] perf probe: Fix to show function entry line as probe-able Date: Thu, 2 Jan 2020 23:07:21 +0100 Message-Id: <20200102220602.398963748@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220546.960200039@linuxfoundation.org> References: <20200102220546.960200039@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Masami Hiramatsu commit 91e2f539eeda26ab00bd03fae8dc434c128c85ed upstream. Fix die_walk_lines() to list the function entry line correctly. Since the dwarf_entrypc() does not return the entry pc if the DIE has only range attribute, __die_walk_funclines() fails to list the declaration line (entry line) in that case. To solve this issue, this introduces die_entrypc() which correctly returns the entry PC (the first address range) even if the DIE has only range attribute. With this fix die_walk_lines() shows the function entry line is able to probe correctly. Fixes: 4cc9cec636e7 ("perf probe: Introduce lines walker interface") Signed-off-by: Masami Hiramatsu Cc: Jiri Olsa Cc: Namhyung Kim Link: http://lore.kernel.org/lkml/157190837419.1859.4619125803596816752.stgit@devnote2 Signed-off-by: Arnaldo Carvalho de Melo Cc: Thomas Backlund Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/dwarf-aux.c | 24 +++++++++++++++++++++++- tools/perf/util/dwarf-aux.h | 3 +++ 2 files changed, 26 insertions(+), 1 deletion(-) --- a/tools/perf/util/dwarf-aux.c +++ b/tools/perf/util/dwarf-aux.c @@ -318,6 +318,28 @@ bool die_is_func_def(Dwarf_Die *dw_die) } /** + * die_entrypc - Returns entry PC (the lowest address) of a DIE + * @dw_die: a DIE + * @addr: where to store entry PC + * + * Since dwarf_entrypc() does not return entry PC if the DIE has only address + * range, we have to use this to retrieve the lowest address from the address + * range attribute. + */ +int die_entrypc(Dwarf_Die *dw_die, Dwarf_Addr *addr) +{ + Dwarf_Addr base, end; + + if (!addr) + return -EINVAL; + + if (dwarf_entrypc(dw_die, addr) == 0) + return 0; + + return dwarf_ranges(dw_die, 0, &base, addr, &end) < 0 ? -ENOENT : 0; +} + +/** * die_is_func_instance - Ensure that this DIE is an instance of a subprogram * @dw_die: a DIE * @@ -730,7 +752,7 @@ static int __die_walk_funclines(Dwarf_Di /* Handle function declaration line */ fname = dwarf_decl_file(sp_die); if (fname && dwarf_decl_line(sp_die, &lineno) == 0 && - dwarf_entrypc(sp_die, &addr) == 0) { + die_entrypc(sp_die, &addr) == 0) { lw.retval = callback(fname, lineno, addr, data); if (lw.retval != 0) goto done; --- a/tools/perf/util/dwarf-aux.h +++ b/tools/perf/util/dwarf-aux.h @@ -41,6 +41,9 @@ int cu_walk_functions_at(Dwarf_Die *cu_d /* Get DW_AT_linkage_name (should be NULL for C binary) */ const char *die_get_linkage_name(Dwarf_Die *dw_die); +/* Get the lowest PC in DIE (including range list) */ +int die_entrypc(Dwarf_Die *dw_die, Dwarf_Addr *addr); + /* Ensure that this DIE is a subprogram and definition (not declaration) */ bool die_is_func_def(Dwarf_Die *dw_die);