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>,
Paul Mackerras <paulus@samba.org>,
Mike Galbraith <efault@gmx.de>,
Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: [PATCH -tip 06/10] perf probe: Introduce die_find_child() function
Date: Tue, 16 Mar 2010 21:57:00 -0000 [thread overview]
Message-ID: <20100316220558.32050.7905.stgit@localhost6.localdomain6> (raw)
In-Reply-To: <20100316220515.32050.82185.stgit@localhost6.localdomain6>
Introduce die_find_child() function to integrate DIE-tree searching
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: Paul Mackerras <paulus@samba.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
tools/perf/util/probe-finder.c | 136 ++++++++++++++++++++++++----------------
1 files changed, 80 insertions(+), 56 deletions(-)
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index c91a960..3942e14 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -186,6 +186,62 @@ static const char *cu_find_realpath(Dwarf_Die *cu_die, const char *fname)
return src;
}
+/* Compare diename and tname */
+static bool die_compare_name(Dwarf_Die *dw_die, const char *tname)
+{
+ const char *name;
+ name = dwarf_diename(dw_die);
+ DIE_IF(name == NULL);
+ return strcmp(tname, name);
+}
+
+/* Get entry pc(or low pc, 1st entry of ranges) of the die */
+static Dwarf_Addr die_get_entrypc(Dwarf_Die *dw_die)
+{
+ Dwarf_Addr epc;
+ int ret;
+
+ ret = dwarf_entrypc(dw_die, &epc);
+ DIE_IF(ret == -1);
+ return epc;
+}
+
+/* Return values for die_find callbacks */
+enum {
+ DIE_FIND_CB_FOUND = 0, /* End of Search */
+ DIE_FIND_CB_CHILD = 1, /* Search only children */
+ DIE_FIND_CB_SIBLING = 2, /* Search only siblings */
+ DIE_FIND_CB_CONTINUE = 3, /* Search children and siblings */
+};
+
+/* Search a child die */
+static Dwarf_Die *die_find_child(Dwarf_Die *rt_die,
+ int (*callback)(Dwarf_Die *, void *),
+ void *data, Dwarf_Die *die_mem)
+{
+ Dwarf_Die child_die;
+ int ret;
+
+ ret = dwarf_child(rt_die, die_mem);
+ if (ret != 0)
+ return NULL;
+
+ do {
+ ret = callback(die_mem, data);
+ if (ret == DIE_FIND_CB_FOUND)
+ return die_mem;
+
+ if ((ret & DIE_FIND_CB_CHILD) &&
+ die_find_child(die_mem, callback, data, &child_die)) {
+ memcpy(die_mem, &child_die, sizeof(Dwarf_Die));
+ return die_mem;
+ }
+ } while ((ret & DIE_FIND_CB_SIBLING) &&
+ dwarf_siblingof(die_mem, die_mem) == 0);
+
+ return NULL;
+}
+
struct __addr_die_search_param {
Dwarf_Addr addr;
Dwarf_Die *die_mem;
@@ -217,77 +273,45 @@ static Dwarf_Die *die_find_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_find_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr,
- Dwarf_Die *die_mem)
+/* die_find callback for inline function search */
+static int __die_find_inline_cb(Dwarf_Die *die_mem, void *data)
{
- Dwarf_Die child_die;
- int ret;
+ Dwarf_Addr *addr = data;
- 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 (dwarf_tag(die_mem) == DW_TAG_inlined_subroutine &&
+ dwarf_haspc(die_mem, *addr))
+ return DIE_FIND_CB_FOUND;
- if (die_find_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;
+ return DIE_FIND_CB_CONTINUE;
}
-/* Compare diename and tname */
-static bool die_compare_name(Dwarf_Die *dw_die, const char *tname)
+/* Similar to dwarf_getfuncs, but returns inlined_subroutine if exists. */
+static Dwarf_Die *die_find_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr,
+ Dwarf_Die *die_mem)
{
- const char *name;
- name = dwarf_diename(dw_die);
- DIE_IF(name == NULL);
- return strcmp(tname, name);
+ return die_find_child(sp_die, __die_find_inline_cb, &addr, die_mem);
}
-/* Get entry pc(or low pc, 1st entry of ranges) of the die */
-static Dwarf_Addr die_get_entrypc(Dwarf_Die *dw_die)
+static int __die_find_variable_cb(Dwarf_Die *die_mem, void *data)
{
- Dwarf_Addr epc;
- int ret;
+ const char *name = data;
+ int tag;
- ret = dwarf_entrypc(dw_die, &epc);
- DIE_IF(ret == -1);
- return epc;
+ tag = dwarf_tag(die_mem);
+ if ((tag == DW_TAG_formal_parameter ||
+ tag == DW_TAG_variable) &&
+ (die_compare_name(die_mem, name) == 0))
+ return DIE_FIND_CB_FOUND;
+
+ return DIE_FIND_CB_CONTINUE;
}
-/* Get a variable die */
+/* Find a variable called 'name' */
static Dwarf_Die *die_find_variable(Dwarf_Die *sp_die, const char *name,
Dwarf_Die *die_mem)
{
- Dwarf_Die child_die;
- int tag;
- int ret;
-
- ret = dwarf_child(sp_die, die_mem);
- if (ret != 0)
- return NULL;
-
- do {
- tag = dwarf_tag(die_mem);
- if ((tag == DW_TAG_formal_parameter ||
- tag == DW_TAG_variable) &&
- (die_compare_name(die_mem, name) == 0))
- return die_mem;
-
- if (die_find_variable(die_mem, name, &child_die)) {
- memcpy(die_mem, &child_die, sizeof(Dwarf_Die));
- return die_mem;
- }
- } while (dwarf_siblingof(die_mem, die_mem) == 0);
-
- return NULL;
+ return die_find_child(sp_die, __die_find_variable_cb, (void *)name,
+ die_mem);
}
/*
--
Masami Hiramatsu
e-mail: mhiramat@redhat.com
next prev parent reply other threads:[~2010-03-16 21:57 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-16 21:56 [PATCH -tip 00/10] perf-probe updates - data-structure support, etc Masami Hiramatsu
2010-03-16 21:57 ` [PATCH -tip 05/10] perf probe: Rename some die_get_* functions Masami Hiramatsu
2010-03-17 11:29 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-03-16 21:57 ` [PATCH -tip 01/10] perf tools: Introduce xzalloc() for detecting out of memory Masami Hiramatsu
2010-03-17 11:28 ` [tip:perf/core] perf tools: Introduce xzalloc() for detecting out of memory conditions tip-bot for Masami Hiramatsu
2010-03-16 21:57 ` Masami Hiramatsu [this message]
2010-03-17 11:29 ` [tip:perf/core] perf probe: Introduce die_find_child() function tip-bot for Masami Hiramatsu
2010-03-16 21:57 ` [PATCH -tip 07/10] perf probe: Add --dry-run option Masami Hiramatsu
2010-03-17 11:30 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-03-16 21:57 ` [PATCH -tip 03/10] perf probe: Move add-probe routine under util/ Masami Hiramatsu
2010-03-17 11:29 ` [tip:perf/core] perf probe: Move add-probe routine to util/ tip-bot for Masami Hiramatsu
2010-03-16 21:57 ` [PATCH -tip 04/10] perf probe: Rename session to param Masami Hiramatsu
2010-03-17 11:29 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-03-16 21:57 ` [PATCH -tip 02/10] perf probe: Use wrapper functions Masami Hiramatsu
2010-03-17 11:29 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-03-16 21:58 ` [PATCH -tip 10/10] perf probe: Accessing members in data structures Masami Hiramatsu
2010-03-17 10:25 ` Mark Wielaard
2010-03-17 19:14 ` Masami Hiramatsu
2010-03-18 3:28 ` Frederic Weisbecker
2010-03-20 4:20 ` Masami Hiramatsu
2010-03-23 15:55 ` Peter Zijlstra
2010-03-23 16:27 ` Arnaldo Carvalho de Melo
2010-03-17 11:31 ` [tip:perf/core] perf probe: Add data structure member access support tip-bot for Masami Hiramatsu
2010-03-16 21:58 ` [PATCH -tip 09/10] perf probe: List probes with line number and file name Masami Hiramatsu
2010-03-17 11:31 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-03-16 21:58 ` [PATCH -tip 08/10] perf probe: Introduce kprobe_trace_event and perf_probe_event Masami Hiramatsu
2010-03-17 11:31 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-03-17 10:35 ` [PATCH -tip 00/10] perf-probe updates - data-structure support, etc Ingo Molnar
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=20100316220558.32050.7905.stgit@localhost6.localdomain6 \
--to=mhiramat@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@redhat.com \
--cc=dle-develop@lists.sourceforge.net \
--cc=efault@gmx.de \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=paulus@samba.org \
--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).