linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
	David Ahern <dsahern@gmail.com>, Jiri Olsa <jolsa@redhat.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 05/15] perf probe: Fix to track down unnamed union/structure members
Date: Thu,  2 Apr 2015 19:28:56 -0300	[thread overview]
Message-ID: <1428013746-2037-6-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1428013746-2037-1-git-send-email-acme@kernel.org>

From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>

Fix 'perf probe' to track down unnamed union/structure members.

perf probe did not track down the tree of unnamed union/structure
members, since it just failed to find given "name" in a parent
structure/union.  To solve this issue, I've introduced 2 changes.

- Fix die_find_member() to track down the type-DIE if it is
  unnamed, and if it contains the specified member, returns the
  unnamed member.
  (note that we don't return found member, since unnamed member
   has the offset in the parent structure)
- Fix convert_variable_fields() to track down the unnamed union/
  structure (one-by-one).

With this patch, perf probe can access unnamed fields:
  -----
  #./perf probe -nfx ./perf lock__delete ops 'locked_ops=ops->locked.ops'
  Added new event:
    probe_perf:lock__delete (on lock__delete in /home/mhiramat/ksrc/linux-3/tools/perf/perf with ops locked_ops=ops->locked.ops)

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

          perf record -e probe_perf:lock__delete -aR sleep 1
  -----

Reported-by: Arnaldo Carvalho de Melo <acme@kernel.org>
Report-Link: https://lkml.org/lkml/2015/3/5/431
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20150402073312.14482.37942.stgit@localhost.localdomain
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/dwarf-aux.c    | 14 ++++++++++----
 tools/perf/util/probe-finder.c |  8 +++++++-
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c
index 780b2bc11128..c34e024020c7 100644
--- a/tools/perf/util/dwarf-aux.c
+++ b/tools/perf/util/dwarf-aux.c
@@ -801,10 +801,16 @@ static int __die_find_member_cb(Dwarf_Die *die_mem, void *data)
 {
 	const char *name = data;
 
-	if ((dwarf_tag(die_mem) == DW_TAG_member) &&
-	    die_compare_name(die_mem, name))
-		return DIE_FIND_CB_END;
-
+	if (dwarf_tag(die_mem) == DW_TAG_member) {
+		if (die_compare_name(die_mem, name))
+			return DIE_FIND_CB_END;
+		else if (!dwarf_diename(die_mem)) {	/* Unnamed structure */
+			Dwarf_Die type_die, tmp_die;
+			if (die_get_type(die_mem, &type_die) &&
+			    die_find_member(&type_die, name, &tmp_die))
+				return DIE_FIND_CB_END;
+		}
+	}
 	return DIE_FIND_CB_SIBLING;
 }
 
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 46f009aa486c..7831e2d93949 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -460,7 +460,8 @@ static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname,
 			       " nor array.\n", varname);
 			return -EINVAL;
 		}
-		if (field->ref) {
+		/* While prcessing unnamed field, we don't care about this */
+		if (field->ref && dwarf_diename(vr_die)) {
 			pr_err("Semantic error: %s must be referred by '.'\n",
 			       field->name);
 			return -EINVAL;
@@ -491,6 +492,11 @@ static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname,
 	}
 	ref->offset += (long)offs;
 
+	/* If this member is unnamed, we need to reuse this field */
+	if (!dwarf_diename(die_mem))
+		return convert_variable_fields(die_mem, varname, field,
+						&ref, die_mem);
+
 next:
 	/* Converting next field */
 	if (field->next)
-- 
1.9.3


  parent reply	other threads:[~2015-04-02 22:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-02 22:28 [GIT PULL 00/15] perf/core improvements and fixes Arnaldo Carvalho de Melo
2015-04-02 22:28 ` [PATCH 01/15] perf script: No need to lookup thread twice Arnaldo Carvalho de Melo
2015-04-02 22:28 ` [PATCH 02/15] perf scripting: No need to pass thread twice to the scripting callbacks Arnaldo Carvalho de Melo
2015-04-02 22:28 ` [PATCH 03/15] perf db-export: No need to pass thread twice to db_export__sample Arnaldo Carvalho de Melo
2015-04-02 22:28 ` [PATCH 04/15] perf db-export: No need to have ->thread twice in struct export_sample Arnaldo Carvalho de Melo
2015-04-02 22:28 ` Arnaldo Carvalho de Melo [this message]
2015-04-02 22:28 ` [PATCH 06/15] perf evlist: Support using -f to override perf.data file ownership Arnaldo Carvalho de Melo
2015-04-02 22:28 ` [PATCH 07/15] perf inject: " Arnaldo Carvalho de Melo
2015-04-02 22:28 ` [PATCH 08/15] perf kmem: " Arnaldo Carvalho de Melo
2015-04-02 22:29 ` [PATCH 09/15] perf kvm: Support using -f to override perf.data.guest " Arnaldo Carvalho de Melo
2015-04-02 22:29 ` [PATCH 10/15] perf lock: Support using -f to override perf.data " Arnaldo Carvalho de Melo
2015-04-02 22:29 ` [PATCH 11/15] perf mem: " Arnaldo Carvalho de Melo
2015-04-02 22:29 ` [PATCH 12/15] perf script: " Arnaldo Carvalho de Melo
2015-04-02 22:29 ` [PATCH 13/15] perf timechart: " Arnaldo Carvalho de Melo
2015-04-02 22:29 ` [PATCH 14/15] perf trace: " Arnaldo Carvalho de Melo
2015-04-02 22:29 ` [PATCH 15/15] perf data: Support using -f to override perf.data file ownership for 'convert' Arnaldo Carvalho de Melo
2015-04-03  5:02 ` [GIT PULL 00/15] perf/core improvements and fixes 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=1428013746-2037-6-git-send-email-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=dsahern@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /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).