linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	Ingo Molnar <mingo@redhat.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	linux-kernel@vger.kernel.org,
	Tom Zanussi <tom.zanussi@linux.intel.com>,
	Ravi Bangoria <ravi.bangoria@linux.ibm.com>,
	Namhyung Kim <namhyung@kernel.org>
Subject: [PATCH v3 2/7] perf probe: Verify given line is a representive line
Date: Mon, 18 Nov 2019 17:12:00 +0900	[thread overview]
Message-ID: <157406472071.24476.14915451439785001021.stgit@devnote2> (raw)
In-Reply-To: <157406469983.24476.13195800716161845227.stgit@devnote2>

Verify user given probe line is a representive line (which doesn't
share the address with other lines or the line is the least line
among the lines which shares same address), and if not, it shows
what is the representive line.

Without this fix, user can put a probe on the lines which is not a
a representive line. But since this is not a representive line,
perf probe -l shows a representive line number instead of user given
line number. e.g. (put kernel_read:3, but listed as kernel_read:2)

  # perf probe -a kernel_read:3
  Added new event:
    probe:kernel_read    (on kernel_read:3)

  You can now use it in all perf tools, such as:

  	perf record -e probe:kernel_read -aR sleep 1

  # perf probe -l
    probe:kernel_read    (on kernel_read:2@linux-5.0.0/fs/read_write.c)

With this fix, perf probe doesn't allow user to put a probe on
a representive line, and tell what is the representive line.

  # perf probe -a kernel_read:3
  This line is sharing the addrees with other lines.
  Please try to probe at kernel_read:2 instead.
    Error: Failed to add events.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 tools/perf/util/probe-finder.c |   36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 9ecea45da4ca..ef1b320cedf8 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -776,6 +776,39 @@ static Dwarf_Die *find_best_scope(struct probe_finder *pf, Dwarf_Die *die_mem)
 	return fsp.found ? die_mem : NULL;
 }
 
+static int verify_representive_line(struct probe_finder *pf, const char *fname,
+				int lineno, Dwarf_Addr addr)
+{
+	const char *__fname, *__func = NULL;
+	Dwarf_Die die_mem;
+	int __lineno;
+
+	/* Verify line number and address by reverse search */
+	if (cu_find_lineinfo(&pf->cu_die, addr, &__fname, &__lineno) < 0)
+		return 0;
+
+	pr_debug2("Reversed line: %s:%d\n", __fname, __lineno);
+	if (strcmp(fname, __fname) || lineno == __lineno)
+		return 0;
+
+	pr_warning("This line is sharing the addrees with other lines.\n");
+
+	if (pf->pev->point.function) {
+		/* Find best match function name and lines */
+		pf->addr = addr;
+		if (find_best_scope(pf, &die_mem)
+		    && die_match_name(&die_mem, pf->pev->point.function)
+		    && dwarf_decl_line(&die_mem, &lineno) == 0) {
+			__func = dwarf_diename(&die_mem);
+			__lineno -= lineno;
+		}
+	}
+	pr_warning("Please try to probe at %s:%d instead.\n",
+		   __func ? : __fname, __lineno);
+
+	return -ENOENT;
+}
+
 static int probe_point_line_walker(const char *fname, int lineno,
 				   Dwarf_Addr addr, void *data)
 {
@@ -786,6 +819,9 @@ static int probe_point_line_walker(const char *fname, int lineno,
 	if (lineno != pf->lno || strtailcmp(fname, pf->fname) != 0)
 		return 0;
 
+	if (verify_representive_line(pf, fname, lineno, addr))
+		return -ENOENT;
+
 	pf->addr = addr;
 	sc_die = find_best_scope(pf, &die_mem);
 	if (!sc_die) {


  parent reply	other threads:[~2019-11-18  8:12 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-18  8:11 [PATCH v3 0/7] perf/probe: Support multiprobe and immediates with fixes Masami Hiramatsu
2019-11-18  8:11 ` [PATCH v3 1/7] perf probe: Show correct statement line number by perf probe -l Masami Hiramatsu
2019-11-18 21:57   ` Arnaldo Carvalho de Melo
2019-11-19 16:56   ` [tip: perf/core] " tip-bot2 for Masami Hiramatsu
2019-11-18  8:12 ` Masami Hiramatsu [this message]
2019-11-18 21:59   ` [PATCH v3 2/7] perf probe: Verify given line is a representive line Arnaldo Carvalho de Melo
2019-11-19 16:56   ` [tip: perf/core] " tip-bot2 for Masami Hiramatsu
2019-11-18  8:12 ` [PATCH v3 3/7] perf probe: Do not show non representive lines by perf-probe -L Masami Hiramatsu
2019-11-18 22:01   ` Arnaldo Carvalho de Melo
2019-11-19 16:56   ` [tip: perf/core] " tip-bot2 for Masami Hiramatsu
2019-11-18  8:12 ` [PATCH v3 4/7] perf probe: Generate event name with line number Masami Hiramatsu
2019-11-18 22:03   ` Arnaldo Carvalho de Melo
2019-11-19 16:56   ` [tip: perf/core] " tip-bot2 for Masami Hiramatsu
2019-11-18  8:12 ` [PATCH v3 5/7] perf probe: Support multiprobe event Masami Hiramatsu
2019-11-19 16:56   ` [tip: perf/core] " tip-bot2 for Masami Hiramatsu
2019-11-18  8:12 ` [PATCH v3 6/7] perf probe: Support DW_AT_const_value constant value Masami Hiramatsu
2019-11-19 16:56   ` [tip: perf/core] " tip-bot2 for Masami Hiramatsu
2019-11-18  8:12 ` [PATCH v3 7/7] perf probe: Trace a magic number if variable is not found Masami Hiramatsu
2019-11-19 16:56   ` [tip: perf/core] " tip-bot2 for Masami Hiramatsu
2019-11-18 22:11 ` [PATCH v3 0/7] perf/probe: Support multiprobe and immediates with fixes Arnaldo Carvalho de Melo
2019-11-19 13:46   ` Masami Hiramatsu
2019-11-19 14:33     ` Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=157406472071.24476.14915451439785001021.stgit@devnote2 \
    --to=mhiramat@kernel.org \
    --cc=acme@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=ravi.bangoria@linux.ibm.com \
    --cc=rostedt@goodmis.org \
    --cc=tom.zanussi@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).