From nobody Wed Dec 17 20:41:16 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACAA9C77B75 for ; Tue, 18 Apr 2023 03:17:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230064AbjDRDRG (ORCPT ); Mon, 17 Apr 2023 23:17:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229685AbjDRDQ4 (ORCPT ); Mon, 17 Apr 2023 23:16:56 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 635244685; Mon, 17 Apr 2023 20:16:55 -0700 (PDT) Received: from kwepemi500013.china.huawei.com (unknown [7.221.188.120]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Q0pwM4LgdzKs8m; Tue, 18 Apr 2023 11:16:03 +0800 (CST) Received: from M910t.huawei.com (10.110.54.157) by kwepemi500013.china.huawei.com (7.221.188.120) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Tue, 18 Apr 2023 11:15:35 +0800 From: Changbin Du To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar CC: Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , , , Hui Wang , Changbin Du Subject: [PATCH v5 1/2] perf: add helper map__fprintf_dsoname_dsoff Date: Tue, 18 Apr 2023 11:15:18 +0800 Message-ID: <20230418031519.1261310-2-changbin.du@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230418031519.1261310-1-changbin.du@huawei.com> References: <20230418031519.1261310-1-changbin.du@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.110.54.157] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemi500013.china.huawei.com (7.221.188.120) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This adds a helper function map__fprintf_dsoname_dsoff() to print dsoname with optional dso offset. Suggested-by: Adrian Hunter Signed-off-by: Changbin Du --- tools/perf/util/map.c | 13 +++++++++++++ tools/perf/util/map.h | 1 + 2 files changed, 14 insertions(+) diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index d81b6ca18ee9..7da96b41100f 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -445,6 +445,19 @@ size_t map__fprintf_dsoname(struct map *map, FILE *fp) return fprintf(fp, "%s", dsoname); } =20 +size_t map__fprintf_dsoname_dsoff(struct map *map, bool print_off, u64 add= r, FILE *fp) +{ + int printed =3D 0; + + printed +=3D fprintf(fp, " ("); + printed +=3D map__fprintf_dsoname(map, fp); + if (print_off && map && map__dso(map) && !map__dso(map)->kernel) + printed +=3D fprintf(fp, "+0x%" PRIx64, addr); + printed +=3D fprintf(fp, ")"); + + return printed; +} + char *map__srcline(struct map *map, u64 addr, struct symbol *sym) { if (map =3D=3D NULL) diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index f89ab7c2d327..4cca211b6e66 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h @@ -175,6 +175,7 @@ static inline void __map__zput(struct map **map) =20 size_t map__fprintf(struct map *map, FILE *fp); size_t map__fprintf_dsoname(struct map *map, FILE *fp); +size_t map__fprintf_dsoname_dsoff(struct map *map, bool print_off, u64 add= r, FILE *fp); char *map__srcline(struct map *map, u64 addr, struct symbol *sym); int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix, FILE *fp); --=20 2.25.1