aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMasami Hiramatsu <mhiramat@redhat.com>2010-02-25 08:35:57 -0500
committerIngo Molnar <mingo@elte.hu>2010-02-25 11:49:29 -0500
commit161a26b0c231b5d2e60e9c132fa360cd9dac4720 (patch)
tree65890fa84d614d04ded92b4214f0e76a46b90461 /tools
parente92b85e1ffaa0bd8e5d92e7c378a3909e7f23122 (diff)
perf probe: Check function address range strictly in line finder
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: systemtap <systemtap@sources.redhat.com> Cc: DLE <dle-develop@lists.sourceforge.net> 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> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com> LKML-Reference: <20100225133557.6725.20697.stgit@localhost6.localdomain6> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/probe-finder.c74
-rw-r--r--tools/perf/util/probe-finder.h2
2 files changed, 53 insertions, 23 deletions
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 6305f344f382..a41035634dd8 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,
161 return die_mem; 161 return die_mem;
162} 162}
163 163
164/* Similar to dwarf_getfuncs, but returns inlined_subroutine if exists. */
165static Dwarf_Die *die_get_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr,
166 Dwarf_Die *die_mem)
167{
168 Dwarf_Die child_die;
169 int ret;
170
171 ret = dwarf_child(sp_die, die_mem);
172 if (ret != 0)
173 return NULL;
174
175 do {
176 if (dwarf_tag(die_mem) == DW_TAG_inlined_subroutine &&
177 dwarf_haspc(die_mem, addr))
178 return die_mem;
179
180 if (die_get_inlinefunc(die_mem, addr, &child_die)) {
181 memcpy(die_mem, &child_die, sizeof(Dwarf_Die));
182 return die_mem;
183 }
184 } while (dwarf_siblingof(die_mem, die_mem) == 0);
185
186 return NULL;
187}
188
164/* Compare diename and tname */ 189/* Compare diename and tname */
165static bool die_compare_name(Dwarf_Die *dw_die, const char *tname) 190static bool die_compare_name(Dwarf_Die *dw_die, const char *tname)
166{ 191{
@@ -534,7 +559,7 @@ found:
534} 559}
535 560
536/* Find line range from its line number */ 561/* Find line range from its line number */
537static void find_line_range_by_line(struct line_finder *lf) 562static void find_line_range_by_line(Dwarf_Die *sp_die, struct line_finder *lf)
538{ 563{
539 Dwarf_Lines *lines; 564 Dwarf_Lines *lines;
540 Dwarf_Line *line; 565 Dwarf_Line *line;
@@ -543,6 +568,7 @@ static void find_line_range_by_line(struct line_finder *lf)
543 int lineno; 568 int lineno;
544 int ret; 569 int ret;
545 const char *src; 570 const char *src;
571 Dwarf_Die die_mem;
546 572
547 INIT_LIST_HEAD(&lf->lr->line_list); 573 INIT_LIST_HEAD(&lf->lr->line_list);
548 ret = dwarf_getsrclines(&lf->cu_die, &lines, &nlines); 574 ret = dwarf_getsrclines(&lf->cu_die, &lines, &nlines);
@@ -550,22 +576,28 @@ static void find_line_range_by_line(struct line_finder *lf)
550 576
551 for (i = 0; i < nlines; i++) { 577 for (i = 0; i < nlines; i++) {
552 line = dwarf_onesrcline(lines, i); 578 line = dwarf_onesrcline(lines, i);
553 dwarf_lineno(line, &lineno); 579 ret = dwarf_lineno(line, &lineno);
580 DIE_IF(ret != 0);
554 if (lf->lno_s > lineno || lf->lno_e < lineno) 581 if (lf->lno_s > lineno || lf->lno_e < lineno)
555 continue; 582 continue;
556 583
584 if (sp_die) {
585 /* Address filtering 1: does sp_die include addr? */
586 ret = dwarf_lineaddr(line, &addr);
587 DIE_IF(ret != 0);
588 if (!dwarf_haspc(sp_die, addr))
589 continue;
590
591 /* Address filtering 2: No child include addr? */
592 if (die_get_inlinefunc(sp_die, addr, &die_mem))
593 continue;
594 }
595
557 /* TODO: Get fileno from line, but how? */ 596 /* TODO: Get fileno from line, but how? */
558 src = dwarf_linesrc(line, NULL, NULL); 597 src = dwarf_linesrc(line, NULL, NULL);
559 if (strtailcmp(src, lf->fname) != 0) 598 if (strtailcmp(src, lf->fname) != 0)
560 continue; 599 continue;
561 600
562 /* Filter line in the function address range */
563 if (lf->addr_s && lf->addr_e) {
564 ret = dwarf_lineaddr(line, &addr);
565 DIE_IF(ret != 0);
566 if (lf->addr_s > addr || lf->addr_e <= addr)
567 continue;
568 }
569 /* Copy real path */ 601 /* Copy real path */
570 if (!lf->lr->path) 602 if (!lf->lr->path)
571 lf->lr->path = strdup(src); 603 lf->lr->path = strdup(src);
@@ -580,24 +612,20 @@ static void find_line_range_by_line(struct line_finder *lf)
580 } 612 }
581} 613}
582 614
615static int line_range_inline_cb(Dwarf_Die *in_die, void *data)
616{
617 find_line_range_by_line(in_die, (struct line_finder *)data);
618 return DWARF_CB_ABORT; /* No need to find other instances */
619}
620
583/* Search function from function name */ 621/* Search function from function name */
584static int line_range_search_cb(Dwarf_Die *sp_die, void *data) 622static int line_range_search_cb(Dwarf_Die *sp_die, void *data)
585{ 623{
586 struct line_finder *lf = (struct line_finder *)data; 624 struct line_finder *lf = (struct line_finder *)data;
587 struct line_range *lr = lf->lr; 625 struct line_range *lr = lf->lr;
588 int ret;
589 626
590 if (dwarf_tag(sp_die) == DW_TAG_subprogram && 627 if (dwarf_tag(sp_die) == DW_TAG_subprogram &&
591 die_compare_name(sp_die, lr->function) == 0) { 628 die_compare_name(sp_die, lr->function) == 0) {
592 /* Get the address range of this function */
593 ret = dwarf_highpc(sp_die, &lf->addr_e);
594 if (ret == 0)
595 ret = dwarf_lowpc(sp_die, &lf->addr_s);
596 if (ret != 0) {
597 lf->addr_s = 0;
598 lf->addr_e = 0;
599 }
600
601 lf->fname = dwarf_decl_file(sp_die); 629 lf->fname = dwarf_decl_file(sp_die);
602 dwarf_decl_line(sp_die, &lr->offset); 630 dwarf_decl_line(sp_die, &lr->offset);
603 pr_debug("fname: %s, lineno:%d\n", lf->fname, lr->offset); 631 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)
608 lf->lno_e = lr->offset + lr->end; 636 lf->lno_e = lr->offset + lr->end;
609 lr->start = lf->lno_s; 637 lr->start = lf->lno_s;
610 lr->end = lf->lno_e; 638 lr->end = lf->lno_e;
611 find_line_range_by_line(lf); 639 if (dwarf_func_inline(sp_die))
640 dwarf_func_inline_instances(sp_die,
641 line_range_inline_cb, lf);
642 else
643 find_line_range_by_line(sp_die, lf);
612 return 1; 644 return 1;
613 } 645 }
614 return 0; 646 return 0;
@@ -660,7 +692,7 @@ int find_line_range(int fd, struct line_range *lr)
660 lf.lno_e = INT_MAX; 692 lf.lno_e = INT_MAX;
661 else 693 else
662 lf.lno_e = lr->end; 694 lf.lno_e = lr->end;
663 find_line_range_by_line(&lf); 695 find_line_range_by_line(NULL, &lf);
664 } 696 }
665 } 697 }
666 off = noff; 698 off = noff;
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
index 74525aeb30fe..75a660d4bdb2 100644
--- a/tools/perf/util/probe-finder.h
+++ b/tools/perf/util/probe-finder.h
@@ -82,8 +82,6 @@ struct line_finder {
82 const char *fname; /* File name */ 82 const char *fname; /* File name */
83 int lno_s; /* Start line number */ 83 int lno_s; /* Start line number */
84 int lno_e; /* End line number */ 84 int lno_e; /* End line number */
85 Dwarf_Addr addr_s; /* Start address */
86 Dwarf_Addr addr_e; /* End address */
87 Dwarf_Die cu_die; /* Current CU */ 85 Dwarf_Die cu_die; /* Current CU */
88 int found; 86 int found;
89}; 87};