From nobody Sun Nov 24 01:20:24 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D060F2E3EB; Thu, 7 Nov 2024 14:52:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730991137; cv=none; b=I178MSLXytqun36SG2pNzP8xnFyYsSEx0f6532XugHBYodO3uIAHWc9nh+LQkFYlJWbTpmEvpj+lhO/QiYRR7+ZdCVW1LvB0qT/EWZdyELgOpOotUZ4wV24g/Tz6mEGH1eN/yJv30lWfXa2kvbOIscatERCFBUu89AVgyRS416k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730991137; c=relaxed/simple; bh=niKnau8xp0QGeojUctFEmxGVTs9K3dLLDDtVIkokeG0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=k7VT/PAPJ4Lff10hUXqUhCgzXNt7MD6DK4238nH+EYXZoL9H7+18wE/8x1jlTxMHhYcesDUG4Cm9lFoPF4G1sKcH3XxD+vKnpskQTqYci+ITY1oZWOk2VUazQnp7ETFXkySHSgQ7ys9Pu6DRFezd3mq6jwxhFilCNzcfTxCS2qM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FegfRSTT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FegfRSTT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB155C4CECC; Thu, 7 Nov 2024 14:52:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730991137; bh=niKnau8xp0QGeojUctFEmxGVTs9K3dLLDDtVIkokeG0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FegfRSTTTsWZJdQoc2IapAbPhkFlRztoK8nCtV+qxD/sdisvxOGZNN5JFfmO5m9Tn Ky4Ts9lLxcRd2RIwXT1VghGkYkofEkRhZSt70/Owfy4RzXcxr+Hi9N+Qlpl1lqXl5O mBtlLUzoGkKhLwiN/SzvZksawWEwnO3BdtchPacJ0WbDVmuSWewEX+vIw1QTL2x5xm UvTuWFRldkYyclt7/7a12Tsagt87OcEyjTWJpJX99CEnwPY8ZUg5stcR7TONHuSvw7 2nhGLXRGRQyTKZFSYM0349XiDY1FZbcYKDcocGH95MhIKL0TdAYs9km9+f5jZ7zB5Z fxHNSP3ZIwdqg== From: "Masami Hiramatsu (Google)" To: Arnaldo Carvalho de Melo , Namhyung Kim Cc: Peter Zijlstra , Ingo Molnar , Masami Hiramatsu , Ian Rogers , Dima Kogan , Alexander Lobakin , Przemek Kitszel , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/6] perf-probe: Fix error message for failing to find line range Date: Thu, 7 Nov 2024 23:52:13 +0900 Message-ID: <173099113381.2431889.16263147678401426107.stgit@mhiramat.roam.corp.google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog In-Reply-To: <173099112488.2431889.1181692857521683304.stgit@mhiramat.roam.corp.google.com> References: <173099112488.2431889.1181692857521683304.stgit@mhiramat.roam.corp.google.com> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Masami Hiramatsu (Google) With --lines option, if perf-probe fails to find the specified line, it warns as "Debuginfo analysis failed." but this misleads user as the debuginfo is broken. Fix this message to "Specified source line(LINESPEC) is not found." so that user can understand the error correctly. Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - Added new patch. --- tools/perf/util/probe-event.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index a17c9b8a7a79..6bfe7ead3681 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -1036,6 +1036,17 @@ static int _show_one_line(FILE *fp, int l, bool skip= , bool show_num) return rv; } =20 +static int sprint_line_description(char *sbuf, size_t size, struct line_ra= nge *lr) +{ + if (!lr->function) + return snprintf(sbuf, size, "file: %s, line: %d", lr->file, lr->start); + + if (lr->file) + return snprintf(sbuf, size, "function: %s, file:%s, line: %d", lr->funct= ion, lr->file, lr->start); + + return snprintf(sbuf, size, "function: %s, line:%d", lr->function, lr->st= art); +} + #define show_one_line_with_num(f,l) _show_one_line(f,l,false,true) #define show_one_line(f,l) _show_one_line(f,l,false,false) #define skip_one_line(f,l) _show_one_line(f,l,true,false) @@ -1068,6 +1079,8 @@ static int __show_line_range(struct line_range *lr, c= onst char *module, ret =3D get_alternative_line_range(dinfo, lr, module, user); if (!ret) ret =3D debuginfo__find_line_range(dinfo, lr); + else /* Ignore error, we just failed to find it. */ + ret =3D -ENOENT; } if (dinfo->build_id) { build_id__init(&bid, dinfo->build_id, BUILD_ID_SIZE); @@ -1075,7 +1088,8 @@ static int __show_line_range(struct line_range *lr, c= onst char *module, } debuginfo__delete(dinfo); if (ret =3D=3D 0 || ret =3D=3D -ENOENT) { - pr_warning("Specified source line is not found.\n"); + sprint_line_description(sbuf, sizeof(sbuf), lr); + pr_warning("Specified source line(%s) is not found.\n", sbuf); return -ENOENT; } else if (ret < 0) { pr_warning("Debuginfo analysis failed.\n"); From nobody Sun Nov 24 01:20:24 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 967A9212EF7; Thu, 7 Nov 2024 14:52:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730991146; cv=none; b=WZ2449U54SCIOn7lc3tFmxTKYU74C1C/5CL10Pghxcgk1LUtok+EIYqKWuO7tw2li9fcRFWSSLIcM8I/pZsvNcxMgJJn/A6g0KdsGJckAhx2jTfYDogRds6ZDQeQi8MhiQoQw5J/nlOusBZKJf3+4JG67uYJyuZ0vgoBTtSxBRU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730991146; c=relaxed/simple; bh=R1SFzj/BMW6nwC7W6jz7Tajr09BNZ4XHK+JOMxdxMUM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=om1nSKD/ONav9dZPjfU95Z6Soo0q5Gji1I4/xWO/c2KQ6kS5Zhxgoam6akFZFgHNYzh6rhsodWh8UnCXk7vgk6sTtNhjwgmj0w2NREywckBtMIgUHFr8AnYH1XAkGKyQDMZJ9+QZYe5rD0IvAu3FGt9+y6SwmUKdeJ7K9SKcwJ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TSq0+A1z; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TSq0+A1z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89DC5C4CECC; Thu, 7 Nov 2024 14:52:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730991146; bh=R1SFzj/BMW6nwC7W6jz7Tajr09BNZ4XHK+JOMxdxMUM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TSq0+A1zFKKET+q9tjS3hyGD/TS7X67ZaeJJMZADclmN8Bpanh2fmlzTfAaa9ZGpd KITxN7wANokZwM8ATyQyUpUW/1fHEyq9ixzMPUY1/sccTCOCAZhBGT9qlf2zZQ7vlk QmU+RBsDZZifzTMJjgAxChLO6mZo/Bgsa6DrMHv7or77nvld2BSYiec4hVIuLYgm/t SlSmbGxI/Hgiu07KVDyhEbaNuXp6AAP6bt4j0chGqWG3XIcXN5eRYTumNS0NkjZTel fNSCX5bDbNFnSoBaNmAknCobYVHE/bgJMUl0ZRhFoYi/Ky//rIjceLnxB5XeSjakdU wY2hSuviHnW+Q== From: "Masami Hiramatsu (Google)" To: Arnaldo Carvalho de Melo , Namhyung Kim Cc: Peter Zijlstra , Ingo Molnar , Masami Hiramatsu , Ian Rogers , Dima Kogan , Alexander Lobakin , Przemek Kitszel , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/6] perf-probe: Fix to ignore escaped characters in --lines option Date: Thu, 7 Nov 2024 23:52:22 +0900 Message-ID: <173099114272.2431889.4820591557298941207.stgit@mhiramat.roam.corp.google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog In-Reply-To: <173099112488.2431889.1181692857521683304.stgit@mhiramat.roam.corp.google.com> References: <173099112488.2431889.1181692857521683304.stgit@mhiramat.roam.corp.google.com> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Masami Hiramatsu (Google) Use strbprk_esc() and strdup_esc() to ignore escaped characters in --lines option. This has been done for other options, but only --lines option doesn't. Signed-off-by: Masami Hiramatsu (Google) --- tools/perf/util/probe-event.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 6bfe7ead3681..edc205e4b0ee 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -1369,7 +1369,7 @@ int parse_line_range_desc(const char *arg, struct lin= e_range *lr) lr->start =3D 0; lr->end =3D INT_MAX; =20 - range =3D strchr(name, ':'); + range =3D strpbrk_esc(name, ":"); if (range) { *range++ =3D '\0'; =20 @@ -1410,7 +1410,7 @@ int parse_line_range_desc(const char *arg, struct lin= e_range *lr) } } =20 - file =3D strchr(name, '@'); + file =3D strpbrk_esc(name, "@"); if (file) { *file =3D '\0'; lr->file =3D strdup(++file); @@ -1419,7 +1419,7 @@ int parse_line_range_desc(const char *arg, struct lin= e_range *lr) goto err; } lr->function =3D name; - } else if (strchr(name, '/') || strchr(name, '.')) + } else if (strpbrk_esc(name, "/.")) lr->file =3D name; else if (is_c_func_name(name))/* We reuse it for checking funcname */ lr->function =3D name; From nobody Sun Nov 24 01:20:24 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46D53212D31; Thu, 7 Nov 2024 14:52:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730991155; cv=none; b=dxSjhfEfADrZ4YyFOnosOYui8v8FuyuwWSVSKU257KpNJjLG3N2R8PB3dRRF/BMgmxN08wzGfx3phVqQCZuz4JtCs+5E7TN6RqxOnGNf8lZRcumbostJbtGOb/F48tXlXRVy7tM32NKOA5NKdUiGiiujOIT6+8wuz41kYlnRR6Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730991155; c=relaxed/simple; bh=BvEaGbKvMA4VXey4QzVmBrEbnIqbTzoxmJ27zc63m2E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Afk/M7zH2mq97YbnAT842VpWuK42atRX1cYzazLxDgiBa+mE5moQZHQAoVrNk0pXXb94eLjrFKQ+6ukHxPeH9CZ4GX4Glq7zqlOvPinYBzAlnXEpm5WLhS0DN+kyKxAybmf/zsS5rXtclvPUJchnz8lZXgUJUvmxPXP6g/6K7aw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sHqXc8TV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sHqXc8TV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E334C4CECC; Thu, 7 Nov 2024 14:52:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730991155; bh=BvEaGbKvMA4VXey4QzVmBrEbnIqbTzoxmJ27zc63m2E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sHqXc8TVMXEgSTmI9AlU8fQfuotOEczC+pllvZXkaq6iM5z11L0g7Whb83b/gXknk ywB+1mp4tGVwvO1juDqebbXBmUHiuP6bmVWUWKwtL2g6PlT7PZj/fZKoqQp10GnqYo 6NdPdXQlz3gBeXPphremfHbxKHd3z/ZdX0pJesgi+CFqvv6T4Bx7XPferSH1Mz8U6z /VkPx44orrf42qcClvQ3DCSitB3wqtEzuRsIMOhMgLgjJw17srJcaSfPVSRsp7lIPG EjgXrSWTjW1szNtlFjiLKznhvV7FHZQiVjch3deczDBghsp8w+ccUU2F8YYkNdx3ZF ekya7H3HWTWDw== From: "Masami Hiramatsu (Google)" To: Arnaldo Carvalho de Melo , Namhyung Kim Cc: Peter Zijlstra , Ingo Molnar , Masami Hiramatsu , Ian Rogers , Dima Kogan , Alexander Lobakin , Przemek Kitszel , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/6] perf-probe: Accept FUNC@* to specify function name explicitly Date: Thu, 7 Nov 2024 23:52:31 +0900 Message-ID: <173099115149.2431889.13682110856853358354.stgit@mhiramat.roam.corp.google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog In-Reply-To: <173099112488.2431889.1181692857521683304.stgit@mhiramat.roam.corp.google.com> References: <173099112488.2431889.1181692857521683304.stgit@mhiramat.roam.corp.google.com> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Masami Hiramatsu (Google) In Golang, the function name will have the '.', and perf probe misinterpret it is a file name. To mitigate this situation, introduce `function@*` so that user can explicitly specify that is a function name. Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - Added new patch. --- tools/perf/util/probe-event.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index edc205e4b0ee..777ef00f0d3f 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -1357,6 +1357,8 @@ static bool is_c_func_name(const char *name) * * SRC[:SLN[+NUM|-ELN]] * FNC[@SRC][:SLN[+NUM|-ELN]] + * + * FNC@SRC accepts `FNC@*` which forcibly specify FNC as function name. */ int parse_line_range_desc(const char *arg, struct line_range *lr) { @@ -1412,13 +1414,21 @@ int parse_line_range_desc(const char *arg, struct l= ine_range *lr) =20 file =3D strpbrk_esc(name, "@"); if (file) { - *file =3D '\0'; - lr->file =3D strdup(++file); - if (lr->file =3D=3D NULL) { - err =3D -ENOMEM; + *file++ =3D '\0'; + if (strcmp(file, "*")) { + lr->file =3D strdup_esc(file); + if (lr->file =3D=3D NULL) { + err =3D -ENOMEM; + goto err; + } + } + if (*name !=3D '\0') + lr->function =3D name; + if (!lr->function && !lr->file) { + semantic_error("Only '@*' is not allowed.\n"); + err =3D -EINVAL; goto err; } - lr->function =3D name; } else if (strpbrk_esc(name, "/.")) lr->file =3D name; else if (is_c_func_name(name))/* We reuse it for checking funcname */ @@ -1619,6 +1629,8 @@ static int parse_perf_probe_point(char *arg, struct p= erf_probe_event *pev) semantic_error("SRC@SRC is not allowed.\n"); return -EINVAL; } + if (!strcmp(arg, "*")) + break; pp->file =3D strdup_esc(arg); if (pp->file =3D=3D NULL) return -ENOMEM; From nobody Sun Nov 24 01:20:24 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E1B0212EF0; Thu, 7 Nov 2024 14:52:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730991164; cv=none; b=ovwqj3Z/71Dg99ThZZbf8il0mYUgj5lecYbJ5vlG2uIrxFd8amDoXSmW8LFlr8Dxf//I8TeT7gnAu8ZJw+Em7uC1AxWEfT3Cjg+7bmqqQBhhdRk2JLIo2zi/hD1ajPW1H1wrgg9TEU+nbSnQvVGDAkhMexX+hisWdwU/JftQ7y0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730991164; c=relaxed/simple; bh=S3f5Wa2BEYIJpOYrj4xkQRdAC5fv4qqAL3qZ1pqT/cQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iwIiQkv8hPc0DsOcYtRZE9A3A58gL716ur+la7xncp2xQRD+MMixYb0F7lxasPXhAxxHd76XN3Mz+XBP4chMLeNC9/zMZrIGfGGWaCrk39DfwQf74tyhEv04r86/XQp9Jp7MuZaQ//1GUk/v0VtxeS7HbBL/zNnmDwld7QMhT6U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cL4qUNJ6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cL4qUNJ6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67FDEC4CECC; Thu, 7 Nov 2024 14:52:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730991164; bh=S3f5Wa2BEYIJpOYrj4xkQRdAC5fv4qqAL3qZ1pqT/cQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cL4qUNJ6ggDmh29MS7eR5CaG553gnBInVDfTlxp0GiqAbum/TMY7hDyImoMj5GS/r weI8+0zlknS4S5s5bHyrQhLNmAFKPhhgfQtAPhL73k+3n0YdITizx3IvLZo6sjGsx6 701HGpAcWIV1iDzh9Fkqh8gFx/f8N00qYuOs+ES76SDHFnJOfOk2evmGsY8LmkcZm0 bwZWiUFkih02llu558Z6SEoudUy/4sXBAoRPbBlTREW6+EsgbOjoB9jaPjSEu6qqp+ RK/5XR3dx1P8xPQEQLo1pniELyoN1nXK3aIrMLuu3xqgIP60p3bEcaZrG2ldpNgZ8I t4wdkeqD2+HEw== From: "Masami Hiramatsu (Google)" To: Arnaldo Carvalho de Melo , Namhyung Kim Cc: Peter Zijlstra , Ingo Molnar , Masami Hiramatsu , Ian Rogers , Dima Kogan , Alexander Lobakin , Przemek Kitszel , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/6] perf: Add strpbrk_esq() and strdup_esq() for escape and quote Date: Thu, 7 Nov 2024 23:52:40 +0900 Message-ID: <173099116045.2431889.15772916605719019533.stgit@mhiramat.roam.corp.google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog In-Reply-To: <173099112488.2431889.1181692857521683304.stgit@mhiramat.roam.corp.google.com> References: <173099112488.2431889.1181692857521683304.stgit@mhiramat.roam.corp.google.com> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Masami Hiramatsu (Google) strpbrk_esq() and strdup_esq() are new variants for strpbrk() and strdup() which handles escaped characters and quoted strings. - strpbrk_esq() searches specified set of characters but ignores the escaped characters and quoted strings. e.g. strpbrk_esq("'quote\d' \queue quiz", "qd") returns "quiz". - strdup_esq() duplicates string but removes backslash and quotes which is used for quotation. It also keeps the string (including backslash) in the quoted part. e.g. strdup_esq("'quote\d' \queue quiz") returns "quote\d queue quiz". The (single, double) quotes in the quoted part should be escaped by backslash. In this case, strdup_esq() removes that backslash. The same quotes must be paired. If you use double quotation, you need to use the double quotation to close the quoted part. Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - Added new patch. --- tools/perf/util/string.c | 100 +++++++++++++++++++++++++++++++++++++++++= ++++ tools/perf/util/string2.h | 2 + 2 files changed, 102 insertions(+) diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c index 116a642ad99d..308fc7ec88cc 100644 --- a/tools/perf/util/string.c +++ b/tools/perf/util/string.c @@ -263,6 +263,34 @@ char *strpbrk_esc(char *str, const char *stopset) return ptr; } =20 +/* Like strpbrk_esc(), but not break if it is quoted with single/double qu= otes */ +char *strpbrk_esq(char *str, const char *stopset) +{ + char *_stopset =3D NULL; + char *ptr; + const char *squote =3D "'"; + const char *dquote =3D "\""; + + if (asprintf(&_stopset, "%s%c%c", stopset, *squote, *dquote) < 0) + return NULL; + + do { + ptr =3D strpbrk_esc(str, _stopset); + if (!ptr) + break; + if (*ptr =3D=3D *squote) + ptr =3D strpbrk_esc(ptr + 1, squote); + else if (*ptr =3D=3D *dquote) + ptr =3D strpbrk_esc(ptr + 1, dquote); + else + break; + str =3D ptr + 1; + } while (ptr); + + free(_stopset); + return ptr; +} + /* Like strdup, but do not copy a single backslash */ char *strdup_esc(const char *str) { @@ -293,6 +321,78 @@ char *strdup_esc(const char *str) return ret; } =20 +/* Remove backslash right before quote and return next quote address. */ +static char *remove_consumed_esc(char *str, int len, int quote) +{ + char *ptr =3D str, *end =3D str + len; + + while (*ptr !=3D quote && ptr < end) { + if (*ptr =3D=3D '\\' && *(ptr + 1) =3D=3D quote) { + memmove(ptr, ptr + 1, end - (ptr + 1)); + /* now *ptr is `quote`. */ + end--; + } + ptr++; + } + + return *ptr =3D=3D quote ? ptr : NULL; +} + +/* + * Like strdup_esc, but keep quoted string as it is (and single backslash + * before quote is removed). If there is no closed quote, return NULL. + */ +char *strdup_esq(const char *str) +{ + char *d, *ret; + + /* If there is no quote, return normal strdup_esc() */ + d =3D strpbrk_esc((char *)str, "\"'"); + if (!d) + return strdup_esc(str); + + ret =3D strdup(str); + if (!ret) + return NULL; + + d =3D ret; + do { + d =3D strpbrk(d, "\\\"\'"); + if (!d) + break; + + if (*d =3D=3D '"' || *d =3D=3D '\'') { + /* This is non-escaped quote */ + int quote =3D *d; + int len =3D strlen(d + 1) + 1; + + /* + * Remove the start quote and remove consumed escape (backslash + * before quote) and remove the end quote. If there is no end + * quote, it is the input error. + */ + memmove(d, d + 1, len); + d =3D remove_consumed_esc(d, len, quote); + if (!d) + goto error; + memmove(d, d + 1, strlen(d + 1) + 1); + } + if (*d =3D=3D '\\') { + memmove(d, d + 1, strlen(d + 1) + 1); + if (*d =3D=3D '\\') { + /* double backslash -- keep the second one. */ + d++; + } + } + } while (*d !=3D '\0'); + + return ret; + +error: + free(ret); + return NULL; +} + unsigned int hex(char c) { if (c >=3D '0' && c <=3D '9') diff --git a/tools/perf/util/string2.h b/tools/perf/util/string2.h index 52cb8ba057c7..4c8bff47cfd3 100644 --- a/tools/perf/util/string2.h +++ b/tools/perf/util/string2.h @@ -37,6 +37,8 @@ char *asprintf__tp_filter_pids(size_t npids, pid_t *pids); =20 char *strpbrk_esc(char *str, const char *stopset); char *strdup_esc(const char *str); +char *strpbrk_esq(char *str, const char *stopset); +char *strdup_esq(const char *str); =20 unsigned int hex(char c); char *strreplace_chars(char needle, const char *haystack, const char *repl= ace); From nobody Sun Nov 24 01:20:24 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5EFC6212EF5; Thu, 7 Nov 2024 14:52:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730991173; cv=none; b=clM6jE+s+Jz7x6JtAozx8qBos3AA+kIoZbVkHsTu1fsG+7XU7LoMwdjfr16zNVPtm+m5hX/Qlo7XY88LsWHplyaZth0awwUocGVJfkGpEqyXLVAqbFZ9zIFyfsSXdH9z5MFFVwSO1iPPJhIOFKvaAIRvoMnJmKNpU5XD/+/TkA4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730991173; c=relaxed/simple; bh=KSH4WAzi4UEuFjxwQ20KJeJtd2CrJXRhr/o51tJNrLU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YpSGV1RqaEAapm3MoCHLhDogL4nYq7sOlU/mLZTfl60Po9gsEYrLcjdOmLedNLJPSoKFmLG/HwhDYsjD1Nxiq6WXFJWbuOc7Y6/H7ljjYs6ltgQbeGmctyw5JLxXuWBm8e3f7ON5CBDUGh7laRVhCrEym+QdTHqVGIgyhxlo6v4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SqT+4XAA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SqT+4XAA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C80BC4CECC; Thu, 7 Nov 2024 14:52:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730991172; bh=KSH4WAzi4UEuFjxwQ20KJeJtd2CrJXRhr/o51tJNrLU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SqT+4XAAeduKqeKXvHV6YMVSAVOthWXEoLRmGcuJSYN5E4IB2JOqtfH3HoXCiOeQU j//mKeNMPumQg1X2ko9lJroRUQinq8U/4Q47due2cpYEvPV5VXlD9wmKrIqlO8QrID ZKFrjDj+5jJhJfdm7+j3DctITpmnNX8QZ1dMboOlSE+eg/Gc9OXzPBdXMxiU44trJw yQIVtKt6imP5XFVQArPWeNqBUosn2crQw98zEieeembwtiCXSxxAbl28XVc1iDYBFo L1qIGuL7yqebeUXhemOHhWYryUljGsmd+L0Non8A5OQF6jOwpA1DDCTTtvqZO8fSit dMs+/KERYhuvw== From: "Masami Hiramatsu (Google)" To: Arnaldo Carvalho de Melo , Namhyung Kim Cc: Peter Zijlstra , Ingo Molnar , Masami Hiramatsu , Ian Rogers , Dima Kogan , Alexander Lobakin , Przemek Kitszel , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/6] perf-probe: Introduce quotation marks support Date: Thu, 7 Nov 2024 23:52:49 +0900 Message-ID: <173099116941.2431889.11609129616090100386.stgit@mhiramat.roam.corp.google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog In-Reply-To: <173099112488.2431889.1181692857521683304.stgit@mhiramat.roam.corp.google.com> References: <173099112488.2431889.1181692857521683304.stgit@mhiramat.roam.corp.google.com> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Masami Hiramatsu (Google) In non-C languages, it is possible to have ':' in the function names. It is possible to escape it with backslashes, but if there are too many backslashes, it is annoying. This introduce quotation marks (`"` or `'`) support. For example, without quotes, we have to pass it as below $ perf probe -x cro3 -L "cro3\:\:cmd\:\:servo\:\:run_show" 0 fn run_show(args: &ArgsShow) -> Result<()> { 1 let list =3D ServoList::discover()?; 2 let s =3D list.find_by_serial(&args.servo)?; 3 if args.json { 4 println!("{s}"); With quotes, we can more naturally write the function name as below; $ ./perf probe -x cro3 -L \"cro3::cmd::servo::run_show\" 0 fn run_show(args: &ArgsShow) -> Result<()> { 1 let list =3D ServoList::discover()?; 2 let s =3D list.find_by_serial(&args.servo)?; 3 if args.json { 4 println!("{s}"); Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - split str*_esq() functions from this patch. - update for the changes in previous patches. --- tools/perf/util/probe-event.c | 75 ++++++++++++++++++++++---------------= ---- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 777ef00f0d3f..31e257c84cd1 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -1076,6 +1076,7 @@ static int __show_line_range(struct line_range *lr, c= onst char *module, =20 ret =3D debuginfo__find_line_range(dinfo, lr); if (!ret) { /* Not found, retry with an alternative */ + pr_debug2("Failed to find line range in debuginfo. Fallback to alternati= ve\n"); ret =3D get_alternative_line_range(dinfo, lr, module, user); if (!ret) ret =3D debuginfo__find_line_range(dinfo, lr); @@ -1359,30 +1360,37 @@ static bool is_c_func_name(const char *name) * FNC[@SRC][:SLN[+NUM|-ELN]] * * FNC@SRC accepts `FNC@*` which forcibly specify FNC as function name. + * SRC and FUNC can be quoted by double/single quotes. */ int parse_line_range_desc(const char *arg, struct line_range *lr) { - char *range, *file, *name =3D strdup(arg); + char *buf =3D strdup(arg); + char *p; int err; =20 - if (!name) + if (!buf) return -ENOMEM; =20 lr->start =3D 0; lr->end =3D INT_MAX; =20 - range =3D strpbrk_esc(name, ":"); - if (range) { - *range++ =3D '\0'; + p =3D strpbrk_esq(buf, ":"); + if (p) { + if (p =3D=3D buf) { + semantic_error("No file/function name in '%s'.\n", p); + err =3D -EINVAL; + goto err; + } + *(p++) =3D '\0'; =20 - err =3D parse_line_num(&range, &lr->start, "start line"); + err =3D parse_line_num(&p, &lr->start, "start line"); if (err) goto err; =20 - if (*range =3D=3D '+' || *range =3D=3D '-') { - const char c =3D *range++; + if (*p =3D=3D '+' || *p =3D=3D '-') { + const char c =3D *(p++); =20 - err =3D parse_line_num(&range, &lr->end, "end line"); + err =3D parse_line_num(&p, &lr->end, "end line"); if (err) goto err; =20 @@ -1406,42 +1414,41 @@ int parse_line_range_desc(const char *arg, struct l= ine_range *lr) " than end line.\n"); goto err; } - if (*range !=3D '\0') { - semantic_error("Tailing with invalid str '%s'.\n", range); + if (*p !=3D '\0') { + semantic_error("Tailing with invalid str '%s'.\n", p); goto err; } } =20 - file =3D strpbrk_esc(name, "@"); - if (file) { - *file++ =3D '\0'; - if (strcmp(file, "*")) { - lr->file =3D strdup_esc(file); + p =3D strpbrk_esq(buf, "@"); + if (p) { + *p++ =3D '\0'; + if (strcmp(p, "*")) { + lr->file =3D strdup_esq(p); if (lr->file =3D=3D NULL) { err =3D -ENOMEM; goto err; } } - if (*name !=3D '\0') - lr->function =3D name; + if (*buf !=3D '\0') + lr->function =3D strdup_esq(buf); if (!lr->function && !lr->file) { semantic_error("Only '@*' is not allowed.\n"); err =3D -EINVAL; goto err; } - } else if (strpbrk_esc(name, "/.")) - lr->file =3D name; - else if (is_c_func_name(name))/* We reuse it for checking funcname */ - lr->function =3D name; + } else if (strpbrk_esq(buf, "/.")) + lr->file =3D strdup_esq(buf); + else if (is_c_func_name(buf))/* We reuse it for checking funcname */ + lr->function =3D strdup_esq(buf); else { /* Invalid name */ - semantic_error("'%s' is not a valid function name.\n", name); + semantic_error("'%s' is not a valid function name.\n", buf); err =3D -EINVAL; goto err; } =20 - return 0; err: - free(name); + free(buf); return err; } =20 @@ -1449,19 +1456,19 @@ static int parse_perf_probe_event_name(char **arg, = struct perf_probe_event *pev) { char *ptr; =20 - ptr =3D strpbrk_esc(*arg, ":"); + ptr =3D strpbrk_esq(*arg, ":"); if (ptr) { *ptr =3D '\0'; if (!pev->sdt && !is_c_func_name(*arg)) goto ng_name; - pev->group =3D strdup_esc(*arg); + pev->group =3D strdup_esq(*arg); if (!pev->group) return -ENOMEM; *arg =3D ptr + 1; } else pev->group =3D NULL; =20 - pev->event =3D strdup_esc(*arg); + pev->event =3D strdup_esq(*arg); if (pev->event =3D=3D NULL) return -ENOMEM; =20 @@ -1500,7 +1507,7 @@ static int parse_perf_probe_point(char *arg, struct p= erf_probe_event *pev) arg++; } =20 - ptr =3D strpbrk_esc(arg, ";=3D@+%"); + ptr =3D strpbrk_esq(arg, ";=3D@+%"); if (pev->sdt) { if (ptr) { if (*ptr !=3D '@') { @@ -1514,7 +1521,7 @@ static int parse_perf_probe_point(char *arg, struct p= erf_probe_event *pev) pev->target =3D build_id_cache__origname(tmp); free(tmp); } else - pev->target =3D strdup_esc(ptr + 1); + pev->target =3D strdup_esq(ptr + 1); if (!pev->target) return -ENOMEM; *ptr =3D '\0'; @@ -1555,7 +1562,7 @@ static int parse_perf_probe_point(char *arg, struct p= erf_probe_event *pev) file_spec =3D true; } =20 - ptr =3D strpbrk_esc(arg, ";:+@%"); + ptr =3D strpbrk_esq(arg, ";:+@%"); if (ptr) { nc =3D *ptr; *ptr++ =3D '\0'; @@ -1564,7 +1571,7 @@ static int parse_perf_probe_point(char *arg, struct p= erf_probe_event *pev) if (arg[0] =3D=3D '\0') tmp =3D NULL; else { - tmp =3D strdup_esc(arg); + tmp =3D strdup_esq(arg); if (tmp =3D=3D NULL) return -ENOMEM; } @@ -1602,7 +1609,7 @@ static int parse_perf_probe_point(char *arg, struct p= erf_probe_event *pev) return -ENOMEM; break; } - ptr =3D strpbrk_esc(arg, ";:+@%"); + ptr =3D strpbrk_esq(arg, ";:+@%"); if (ptr) { nc =3D *ptr; *ptr++ =3D '\0'; @@ -1631,7 +1638,7 @@ static int parse_perf_probe_point(char *arg, struct p= erf_probe_event *pev) } if (!strcmp(arg, "*")) break; - pp->file =3D strdup_esc(arg); + pp->file =3D strdup_esq(arg); if (pp->file =3D=3D NULL) return -ENOMEM; break; From nobody Sun Nov 24 01:20:24 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1245212F13; Thu, 7 Nov 2024 14:53:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730991181; cv=none; b=CIQ2eb2mSBRg8gL/DxrfMoT2DwlkeVlaStOYgYwspmtMbNw5E61mBVBAn6t+AsrdIJGmqDoNsUxbGZZnYRcgmlFT/XzqUbAjuFryOVd12ufmwWnqLwkn8226wtXCJnPR1UkLJ+iH6/0Ldy/Ux9cLB15jm40+CEm9Bvg9eiW7avU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730991181; c=relaxed/simple; bh=aF5UWRxmpeI2jfApNUrAdqNXT9wZqj6b1Dborwa4GoA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Yc3S5wBRj1pfmymLqqQK2Sjbf/dIcZJFKKMdq17HMcPDBd8yLQZs9RD/gI7swfwhnTeWuDVbcWuINF5sQhgMz9N1hWjfM1V8BPz0X3TgBg06QJRvebXVIua0Poi1rCikpaSLYPzP1CEiJviLOeDvqqmBRbJsq58DtXd8X8Dz4Pg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SNCa6TUE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SNCa6TUE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC241C4CECC; Thu, 7 Nov 2024 14:52:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730991181; bh=aF5UWRxmpeI2jfApNUrAdqNXT9wZqj6b1Dborwa4GoA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SNCa6TUEBx7JwU3aP10vL5rJXIEUBibgAdOd0nIz3Yyby1wvnt9d5BsRzT6WS1XBq AH8P4S6qazho8ykpqwWkxEXfg6di6xiQZQ+NSMB9OYb6S9ETxMFvof4jxgFS1xowop jAo47OqgtKNHXkIKubI6UxmcPLxRcseFD3u8d3Hi90+RxROoTxgDA8oSsusNqHj4L3 3i+0vDG52FRdJv1xCGu/5akmpDOAPFA7Gn0kZYBVnW26koH8qy82Q2wU9Y16XejSJZ h+I/ClGGEWo2aiMrOss26XJ+U2cukZp+VsM8VQMfNpnUN0+JglIDVU1thcj+KQVcTL e3HS5r/E57cvg== From: "Masami Hiramatsu (Google)" To: Arnaldo Carvalho de Melo , Namhyung Kim Cc: Peter Zijlstra , Ingo Molnar , Masami Hiramatsu , Ian Rogers , Dima Kogan , Alexander Lobakin , Przemek Kitszel , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 6/6] perf-probe: Replace unacceptable characters when generating event name Date: Thu, 7 Nov 2024 23:52:58 +0900 Message-ID: <173099117811.2431889.17590362733353379842.stgit@mhiramat.roam.corp.google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog In-Reply-To: <173099112488.2431889.1181692857521683304.stgit@mhiramat.roam.corp.google.com> References: <173099112488.2431889.1181692857521683304.stgit@mhiramat.roam.corp.google.com> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Masami Hiramatsu (Google) Replace unacceptable characters with '_' when generating event name from the probing function name. This is not for C program. For the C program, it will continue to remove suffixes. Note that this language checking depends on the debuginfo. So without the debuginfo, perf probe will always replaces unacceptable characters with '_'. For example. $ ./perf probe -x cro3 -D \"cro3::cmd::servo::run_show\" p:probe_cro3/cro3_cmd_servo_run_show /work/cro3/target/x86_64-unknown-linux= -gnu/debug/cro3:0x197530 $ ./perf probe -x /work/go/example/outyet/main -D 'main.(*Server).poll' p:probe_main/main_Server_poll /work/go/example/outyet/main:0x353040 Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - Check dwarf language instead of checking wildcards. --- tools/perf/util/probe-event.c | 32 +++++++++++++++++++++++++------- tools/perf/util/probe-event.h | 3 ++- tools/perf/util/probe-finder.c | 15 +++++++++++++++ tools/perf/util/probe-finder.h | 6 +++++- 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 31e257c84cd1..9eaf0fc7975a 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -2771,7 +2771,7 @@ int show_perf_probe_events(struct strfilter *filter) =20 static int get_new_event_name(char *buf, size_t len, const char *base, struct strlist *namelist, bool ret_event, - bool allow_suffix) + bool allow_suffix, bool not_C_symname) { int i, ret; char *p, *nbase; @@ -2782,10 +2782,24 @@ static int get_new_event_name(char *buf, size_t len= , const char *base, if (!nbase) return -ENOMEM; =20 - /* Cut off the dot suffixes (e.g. .const, .isra) and version suffixes */ - p =3D strpbrk(nbase, ".@"); - if (p && p !=3D nbase) - *p =3D '\0'; + if (not_C_symname) { + /* Replace non-alnum with '_' */ + char *s, *d; + + s =3D d =3D nbase; + do { + if (*s && !isalnum(*s)) { + if (d !=3D nbase && *(d - 1) !=3D '_') + *d++ =3D '_'; + } else + *d++ =3D *s; + } while (*s++); + } else { + /* Cut off the dot suffixes (e.g. .const, .isra) and version suffixes */ + p =3D strpbrk(nbase, ".@"); + if (p && p !=3D nbase) + *p =3D '\0'; + } =20 /* Try no suffix number */ ret =3D e_snprintf(buf, len, "%s%s", nbase, ret_event ? "__return" : ""); @@ -2874,6 +2888,7 @@ static int probe_trace_event__set_name(struct probe_t= race_event *tev, bool allow_suffix) { const char *event, *group; + bool not_C_symname =3D true; char buf[64]; int ret; =20 @@ -2888,8 +2903,10 @@ static int probe_trace_event__set_name(struct probe_= trace_event *tev, (strncmp(pev->point.function, "0x", 2) !=3D 0) && !strisglob(pev->point.function)) event =3D pev->point.function; - else + else { event =3D tev->point.realname; + not_C_symname =3D !is_known_C_lang(tev->lang); + } } if (pev->group && !pev->sdt) group =3D pev->group; @@ -2900,7 +2917,8 @@ static int probe_trace_event__set_name(struct probe_t= race_event *tev, =20 /* Get an unused new event name */ ret =3D get_new_event_name(buf, sizeof(buf), event, namelist, - tev->point.retprobe, allow_suffix); + tev->point.retprobe, allow_suffix, + not_C_symname); if (ret < 0) return ret; =20 diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h index 7e3b6c3d1f74..6516105f43e2 100644 --- a/tools/perf/util/probe-event.h +++ b/tools/perf/util/probe-event.h @@ -57,7 +57,8 @@ struct probe_trace_event { char *event; /* Event name */ char *group; /* Group name */ struct probe_trace_point point; /* Trace point */ - int nargs; /* Number of args */ + int nargs; /* Number of args */ + int lang; /* Dwarf language code */ bool uprobes; /* uprobes only */ struct probe_trace_arg *args; /* Arguments */ }; diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index 630e16c54ed5..13ff45d3d6a4 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c @@ -35,6 +35,19 @@ /* Kprobe tracer basic type is up to u64 */ #define MAX_BASIC_TYPE_BITS 64 =20 +bool is_known_C_lang(int lang) +{ + switch (lang) { + case DW_LANG_C89: + case DW_LANG_C: + case DW_LANG_C99: + case DW_LANG_C11: + return true; + default: + return false; + } +} + /* * Probe finder related functions */ @@ -1272,6 +1285,8 @@ static int add_probe_trace_event(Dwarf_Die *sc_die, s= truct probe_finder *pf) ret =3D -ENOMEM; goto end; } + tev->lang =3D dwarf_srclang(dwarf_diecu(sc_die, &pf->cu_die, + NULL, NULL)); =20 pr_debug("Probe point found: %s+%lu\n", tev->point.symbol, tev->point.offset); diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h index 3add5ff516e1..04a52d5fd568 100644 --- a/tools/perf/util/probe-finder.h +++ b/tools/perf/util/probe-finder.h @@ -26,6 +26,9 @@ static inline int is_c_varname(const char *name) #include "dwarf-aux.h" #include "debuginfo.h" =20 +/* Check the language code is known C */ +bool is_known_C_lang(int lang); + /* Find probe_trace_events specified by perf_probe_event from debuginfo */ int debuginfo__find_trace_events(struct debuginfo *dbg, struct perf_probe_event *pev, @@ -103,7 +106,8 @@ struct line_finder { Dwarf_Die sp_die; int found; }; - +#else +#define is_known_C_lang(lang) (false) #endif /* HAVE_DWARF_SUPPORT */ =20 #endif /*_PROBE_FINDER_H */