From: Masami Hiramatsu <mhiramat@redhat.com>
To: Ingo Molnar <mingo@elte.hu>, lkml<linux-kernel@vger.kernel.org>
Cc: systemtap<systemtap@sources.redhat.com>,
DLE<dle-develop@lists.sourceforge.net>,
Masami Hiramatsu <mhiramat@redhat.com>,
Ingo Molnar <mingo@elte.hu>,
Frederic Weisbecker <fweisbec@gmail.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Paul Mackerras <paulus@samba.org>,
Mike Galbraith <efault@gmx.de>,
"K.Prasad" <prasad@linux.vnet.ibm.com>,
Ulrich Drepper <drepper@redhat.com>,
Roland McGrath <roland@redhat.com>
Subject: [PATCH -tip v2 7/9] perf probe: Check function address range strictly in line finder
Date: Mon, 22 Feb 2010 22:50:00 -0000 [thread overview]
Message-ID: <20100222225410.20686.57365.stgit@localhost6.localdomain6> (raw)
In-Reply-To: <20100222225320.20686.17645.stgit@localhost6.localdomain6>
Check (inlined) function address range strictly for
improving output of probe-able lines of inline functions.
Without this change, perf probe --line <function> sometimes
showed other inline function bodies too, because it didn't
filter out inlined functions.
Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Ulrich Drepper <drepper@redhat.com>
Cc: Roland McGrath <roland@redhat.com>
---
tools/perf/util/probe-finder.c | 74 +++++++++++++++++++++++++++++-----------
tools/perf/util/probe-finder.h | 2 -
2 files changed, 53 insertions(+), 23 deletions(-)
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 7cc900f..c458711 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -161,6 +161,31 @@ static Dwarf_Die *die_get_real_subprogram(Dwarf_Die *cu_die, Dwarf_Addr addr,
return die_mem;
}
+/* Similar to dwarf_getfuncs, but returns inlined_subroutine if exists. */
+static Dwarf_Die *die_get_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr,
+ Dwarf_Die *die_mem)
+{
+ Dwarf_Die child_die;
+ int ret;
+
+ ret = dwarf_child(sp_die, die_mem);
+ if (ret != 0)
+ return NULL;
+
+ do {
+ if (dwarf_tag(die_mem) == DW_TAG_inlined_subroutine &&
+ dwarf_haspc(die_mem, addr))
+ return die_mem;
+
+ if (die_get_inlinefunc(die_mem, addr, &child_die)) {
+ memcpy(die_mem, &child_die, sizeof(Dwarf_Die));
+ return die_mem;
+ }
+ } while (dwarf_siblingof(die_mem, die_mem) == 0);
+
+ return NULL;
+}
+
/* Compare diename and tname */
static bool die_compare_name(Dwarf_Die *dw_die, const char *tname)
{
@@ -534,7 +559,7 @@ found:
}
/* Find line range from its line number */
-static void find_line_range_by_line(struct line_finder *lf)
+static void find_line_range_by_line(Dwarf_Die *sp_die, struct line_finder *lf)
{
Dwarf_Lines *lines;
Dwarf_Line *line;
@@ -543,6 +568,7 @@ static void find_line_range_by_line(struct line_finder *lf)
int lineno;
int ret;
const char *src;
+ Dwarf_Die die_mem;
INIT_LIST_HEAD(&lf->lr->line_list);
ret = dwarf_getsrclines(&lf->cu_die, &lines, &nlines);
@@ -550,22 +576,28 @@ static void find_line_range_by_line(struct line_finder *lf)
for (i = 0; i < nlines; i++) {
line = dwarf_onesrcline(lines, i);
- dwarf_lineno(line, &lineno);
+ ret = dwarf_lineno(line, &lineno);
+ DIE_IF(ret != 0);
if (lf->lno_s > lineno || lf->lno_e < lineno)
continue;
+ if (sp_die) {
+ /* Address filtering 1: does sp_die include addr? */
+ ret = dwarf_lineaddr(line, &addr);
+ DIE_IF(ret != 0);
+ if (!dwarf_haspc(sp_die, addr))
+ continue;
+
+ /* Address filtering 2: No child include addr? */
+ if (die_get_inlinefunc(sp_die, addr, &die_mem))
+ continue;
+ }
+
/* TODO: Get fileno from line, but how? */
src = dwarf_linesrc(line, NULL, NULL);
if (strtailcmp(src, lf->fname) != 0)
continue;
- /* Filter line in the function address range */
- if (lf->addr_s && lf->addr_e) {
- ret = dwarf_lineaddr(line, &addr);
- DIE_IF(ret != 0);
- if (lf->addr_s > addr || lf->addr_e <= addr)
- continue;
- }
/* Copy real path */
if (!lf->lr->path)
lf->lr->path = strdup(src);
@@ -580,24 +612,20 @@ static void find_line_range_by_line(struct line_finder *lf)
}
}
+static int line_range_inline_cb(Dwarf_Die *in_die, void *data)
+{
+ find_line_range_by_line(in_die, (struct line_finder *)data);
+ return DWARF_CB_ABORT; /* No need to find other instances */
+}
+
/* Search function from function name */
static int line_range_search_cb(Dwarf_Die *sp_die, void *data)
{
struct line_finder *lf = (struct line_finder *)data;
struct line_range *lr = lf->lr;
- int ret;
if (dwarf_tag(sp_die) == DW_TAG_subprogram &&
die_compare_name(sp_die, lr->function) == 0) {
- /* Get the address range of this function */
- ret = dwarf_highpc(sp_die, &lf->addr_e);
- if (ret == 0)
- ret = dwarf_lowpc(sp_die, &lf->addr_s);
- if (ret != 0) {
- lf->addr_s = 0;
- lf->addr_e = 0;
- }
-
lf->fname = dwarf_decl_file(sp_die);
dwarf_decl_line(sp_die, &lr->offset);
pr_debug("fname: %s, lineno:%d\n", lf->fname, lr->offset);
@@ -608,7 +636,11 @@ static int line_range_search_cb(Dwarf_Die *sp_die, void *data)
lf->lno_e = lr->offset + lr->end;
lr->start = lf->lno_s;
lr->end = lf->lno_e;
- find_line_range_by_line(lf);
+ if (dwarf_func_inline(sp_die))
+ dwarf_func_inline_instances(sp_die,
+ line_range_inline_cb, lf);
+ else
+ find_line_range_by_line(sp_die, lf);
return 1;
}
return 0;
@@ -660,7 +692,7 @@ int find_line_range(int fd, struct line_range *lr)
lf.lno_e = INT_MAX;
else
lf.lno_e = lr->end;
- find_line_range_by_line(&lf);
+ find_line_range_by_line(NULL, &lf);
}
}
off = noff;
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
index 74525ae..75a660d 100644
--- a/tools/perf/util/probe-finder.h
+++ b/tools/perf/util/probe-finder.h
@@ -82,8 +82,6 @@ struct line_finder {
const char *fname; /* File name */
int lno_s; /* Start line number */
int lno_e; /* End line number */
- Dwarf_Addr addr_s; /* Start address */
- Dwarf_Addr addr_e; /* End address */
Dwarf_Die cu_die; /* Current CU */
int found;
};
--
Masami Hiramatsu
Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division
e-mail: mhiramat@redhat.com
next prev parent reply other threads:[~2010-02-22 22:50 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-22 22:49 [PATCH -tip v2 0/9] perf-probe updates - use elfutils and introduce lazy matching Masami Hiramatsu
2010-02-22 22:49 ` [PATCH -tip v2 2/9] perf probe: Update perf probe document Masami Hiramatsu
2010-02-22 22:49 ` [PATCH -tip v2 4/9] perf probe: Rename probe finder functions Masami Hiramatsu
2010-02-22 22:49 ` [PATCH -tip v2 3/9] perf probe: Fix bugs in line range finder Masami Hiramatsu
2010-02-22 22:49 ` [PATCH -tip v2 1/9] perf probe: Do not show --line option without dwarf support Masami Hiramatsu
2010-02-22 22:50 ` [PATCH -tip v2 8/9] perf probe: show more lines after last line Masami Hiramatsu
2010-02-22 22:50 ` [PATCH -tip v2 5/9] perf probe: Use elfutils-libdw for analyzing debuginfo Masami Hiramatsu
2010-02-22 23:08 ` Ulrich Drepper
2010-02-22 23:13 ` Masami Hiramatsu
2010-02-22 23:18 ` Masami Hiramatsu
2010-02-22 23:20 ` Ulrich Drepper
2010-02-22 23:19 ` Ulrich Drepper
2010-02-22 22:50 ` [PATCH -tip v2 6/9] perf probe: Use libdw callback routines Masami Hiramatsu
2010-02-22 22:50 ` Masami Hiramatsu [this message]
2010-02-22 22:51 ` [PATCH -tip v2 9/9] perf probe: Add lazy line matching support Masami Hiramatsu
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=20100222225410.20686.57365.stgit@localhost6.localdomain6 \
--to=mhiramat@redhat.com \
--cc=acme@redhat.com \
--cc=dle-develop@lists.sourceforge.net \
--cc=drepper@redhat.com \
--cc=efault@gmx.de \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=paulus@samba.org \
--cc=peterz@infradead.org \
--cc=prasad@linux.vnet.ibm.com \
--cc=roland@redhat.com \
--cc=systemtap@sources.redhat.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 read-only IMAP folder(s) and NNTP newsgroup(s).