Subject: Re: [PATCH perf/core ] perf-probe: Fix to track down unnamed union/structure members

Ping?

(2015/03/09 11:15), Masami Hiramatsu wrote:
> 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
> -----
>
> The original report of this issue is: https://lkml.org/lkml/2015/3/5/431
>
> Reported-by: Arnaldo Carvalho de Melo <[email protected]>
> Signed-off-by: Masami Hiramatsu <[email protected]>
> ---
> 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 780b2bc..c34e024 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 46f009a..3898eba 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)
>
>


--
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: [email protected]


2015-04-01 14:41:06

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH perf/core ] perf-probe: Fix to track down unnamed union/structure members

Em Wed, Apr 01, 2015 at 06:08:17PM +0900, Masami Hiramatsu escreveu:
> Ping?

<SNIP>

> > 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
> > -----

> > The original report of this issue is: https://lkml.org/lkml/2015/3/5/431

what am I doing wrong?

[root@ssdandy ~]# perf probe ~acme/bin/perf lock__delete 'locked_ops=ops'
Added new event:
probe_perf:lock__delete (on lock__delete in /home/acme/bin/perf with locked_ops=ops)

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

perf record -e probe_perf:lock__delete -aR sleep 1

[root@ssdandy ~]# perf probe -d probe_perf:*
Removed event: probe_perf:lock__delete
[root@ssdandy ~]# perf probe ~acme/bin/perf lock__delete 'locked_ops=ops->locked'
Semantic error: locked must be referred by '.'
Error: Failed to add events.
[root@ssdandy ~]# perf probe ~acme/bin/perf lock__delete 'locked_ops=ops.locked'
Semantic error: locked must be referred by '->'
Error: Failed to add events.
[root@ssdandy ~]# perf probe ~acme/bin/perf lock__delete 'locked_ops=ops->locked'
Semantic error: locked must be referred by '.'
Error: Failed to add events.
[root@ssdandy ~]# perf probe ~acme/bin/perf lock__delete 'locked_ops=ops->locked.ops'
Semantic error: locked must be referred by '.'
Error: Failed to add events.
[root@ssdandy ~]#

Subject: Re: Re: [PATCH perf/core ] perf-probe: Fix to track down unnamed union/structure members

(2015/04/01 23:41), Arnaldo Carvalho de Melo wrote:
> Em Wed, Apr 01, 2015 at 06:08:17PM +0900, Masami Hiramatsu escreveu:
>> Ping?
>
> <SNIP>
>
>>> 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
>>> -----
>
>>> The original report of this issue is: https://lkml.org/lkml/2015/3/5/431
>
> what am I doing wrong?
>
> [root@ssdandy ~]# perf probe ~acme/bin/perf lock__delete 'locked_ops=ops'
> Added new event:
> probe_perf:lock__delete (on lock__delete in /home/acme/bin/perf with locked_ops=ops)
>
> You can now use it in all perf tools, such as:
>
> perf record -e probe_perf:lock__delete -aR sleep 1
>
> [root@ssdandy ~]# perf probe -d probe_perf:*
> Removed event: probe_perf:lock__delete
> [root@ssdandy ~]# perf probe ~acme/bin/perf lock__delete 'locked_ops=ops->locked'
> Semantic error: locked must be referred by '.'
> Error: Failed to add events.
> [root@ssdandy ~]# perf probe ~acme/bin/perf lock__delete 'locked_ops=ops.locked'
> Semantic error: locked must be referred by '->'
> Error: Failed to add events.
> [root@ssdandy ~]# perf probe ~acme/bin/perf lock__delete 'locked_ops=ops->locked'
> Semantic error: locked must be referred by '.'
> Error: Failed to add events.
> [root@ssdandy ~]# perf probe ~acme/bin/perf lock__delete 'locked_ops=ops->locked.ops'
> Semantic error: locked must be referred by '.'
> Error: Failed to add events.
> [root@ssdandy ~]#

Oops, thank you for reporting!
I must miss something...

Thank you,

> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>


--
Masami HIRAMATSU
Linux Technology Research Center, System Productivity Research Dept.
Center for Technology Innovation - Systems Engineering
Hitachi, Ltd., Research & Development Group
E-mail: [email protected]

Subject: [PATCH perf/core v2] perf-probe: Fix to track down unnamed union/structure members

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
-----

The original report of this issue is: https://lkml.org/lkml/2015/3/5/431

Reported-by: Arnaldo Carvalho de Melo <[email protected]>
Signed-off-by: Masami Hiramatsu <[email protected]>
---
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 780b2bc..c34e024 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 46f009a..7831e2d 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)

2015-04-02 14:57:38

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH perf/core v2] perf-probe: Fix to track down unnamed union/structure members

Em Thu, Apr 02, 2015 at 04:33:12PM +0900, Masami Hiramatsu escreveu:
> 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
> -----
>
> The original report of this issue is: https://lkml.org/lkml/2015/3/5/431

Thanks a lot! Applied, built and tested, all works as expected,

Merged,

- Arnaldo

Subject: [tip:perf/core] perf probe: Fix to track down unnamed union/ structure members

Commit-ID: c72738355b2ac79506fbfa10ffee8fe3a27e69da
Gitweb: http://git.kernel.org/tip/c72738355b2ac79506fbfa10ffee8fe3a27e69da
Author: Masami Hiramatsu <[email protected]>
AuthorDate: Thu, 2 Apr 2015 16:33:12 +0900
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 2 Apr 2015 13:18:44 -0300

perf probe: Fix to track down unnamed union/structure members

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 <[email protected]>
Report-Link: https://lkml.org/lkml/2015/3/5/431
Signed-off-by: Masami Hiramatsu <[email protected]>
Tested-by: Arnaldo Carvalho de Melo <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
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 780b2bc..c34e024 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 46f009a..7831e2d 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)