Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-29 Thread Ravi Bangoria


On Saturday 27 August 2016 01:24 AM, Arnaldo Carvalho de Melo wrote:
> Em Fri, Aug 26, 2016 at 04:30:27PM -0300, Arnaldo Carvalho de Melo escreveu:
>> Em Wed, Aug 03, 2016 at 02:28:45PM +0530, Ravi Bangoria escreveu:
>>> +++ b/tools/perf/util/probe-finder.c
>>> @@ -892,6 +892,169 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, 
>>> struct probe_finder *pf)
>>> return die_walk_lines(sp_die, probe_point_lazy_walker, pf);
>>>  }
>>   
>>> +static bool var_has_loclist(Dwarf_Die *die)
>> So, the variable 'die' cause the build to fail in multiple systems, I'm
>> renaming it to 'cu_die', there are some more problems when cross compiling it
>> to some arches, I'm trying to fix them all now:
> Fixed, please check:
>
> http://git.kernel.org/cgit/linux/kernel/git/acme/linux.git/commit/?h=perf/urgent=3866e3762da3291613dfb8b193885a8ed3836669

Thanks Arnaldo,

I've tested it. Looks fine to me.

-Ravi

> - Arnaldo
>



Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-29 Thread Ravi Bangoria


On Saturday 27 August 2016 01:24 AM, Arnaldo Carvalho de Melo wrote:
> Em Fri, Aug 26, 2016 at 04:30:27PM -0300, Arnaldo Carvalho de Melo escreveu:
>> Em Wed, Aug 03, 2016 at 02:28:45PM +0530, Ravi Bangoria escreveu:
>>> +++ b/tools/perf/util/probe-finder.c
>>> @@ -892,6 +892,169 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, 
>>> struct probe_finder *pf)
>>> return die_walk_lines(sp_die, probe_point_lazy_walker, pf);
>>>  }
>>   
>>> +static bool var_has_loclist(Dwarf_Die *die)
>> So, the variable 'die' cause the build to fail in multiple systems, I'm
>> renaming it to 'cu_die', there are some more problems when cross compiling it
>> to some arches, I'm trying to fix them all now:
> Fixed, please check:
>
> http://git.kernel.org/cgit/linux/kernel/git/acme/linux.git/commit/?h=perf/urgent=3866e3762da3291613dfb8b193885a8ed3836669

Thanks Arnaldo,

I've tested it. Looks fine to me.

-Ravi

> - Arnaldo
>



Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-29 Thread Ravi Bangoria


On Saturday 27 August 2016 01:00 AM, Arnaldo Carvalho de Melo wrote:
> Em Wed, Aug 03, 2016 at 02:28:45PM +0530, Ravi Bangoria escreveu:
>> +++ b/tools/perf/util/probe-finder.c
>> @@ -892,6 +892,169 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, 
>> struct probe_finder *pf)
>>  return die_walk_lines(sp_die, probe_point_lazy_walker, pf);
>>  }
>   
>> +static bool var_has_loclist(Dwarf_Die *die)
> So, the variable 'die' cause the build to fail in multiple systems, I'm
> renaming it to 'cu_die', there are some more problems when cross compiling it
> to some arches, I'm trying to fix them all now:

Sorry for this. I started using "make -C tools/perf build-test" but I don't have
infrastructure handy to test for cross arch.

If possible, can you please provide that to me. Otherwise I've to create it from
scratch.

-Ravi

> [root@jouet ~]# dm
>  1 65.668882867 alpine:3.4: Ok
>  2 24.327143744 android-ndk:r12b-arm: Ok
>  3 76.000455817 archlinux:latest: Ok
>  4 40.905282317 centos:5: Ok
>  5 28.799284950 centos:6: FAIL
> cc1: warnings being treated as errors
> util/probe-finder.c: In function 'var_has_loclist':
> util/probe-finder.c:904: error: declaration of 'die' shadows a global 
> declaration
> util/util.h:137: error: shadowed declaration is here
> util/probe-finder.c: In function 'optimized_target':
> util/probe-finder.c:921: error: declaration of 'die' shadows a global 
> declaration
> util/util.h:137: error: shadowed declaration is here
> -
>  6 68.157498673 centos:7: Ok
>  7 32.814597820 debian:7: FAIL
> util/probe-finder.c: In function 'var_has_loclist':
> util/probe-finder.c:904:40: error: declaration of 'die' shadows a global 
> declaration [-Werror=shadow]
> In file included from util/probe-finder.c:39:0:
> util/util.h:137:6: error: shadowed declaration is here [-Werror=shadow]
> util/probe-finder.c: In function 'optimized_target':
> util/probe-finder.c:921:41: error: declaration of 'die' shadows a global 
> declaration [-Werror=shadow]
> In file included from util/probe-finder.c:39:0:
> util/util.h:137:6: error: shadowed declaration is here [-Werror=shadow]
> -
>  8 69.535114125 debian:8: Ok
>  9 71.524733936 debian:experimental: Ok
> 10 66.956671932 fedora:20: Ok
> 11 72.127804972 fedora:21: Ok
> 12 75.767022465 fedora:22: Ok
> 13 72.244964710 fedora:23: Ok
> 14 75.556712624 fedora:24: Ok
> 15 30.825802615 fedora:24-x-ARC-uClibc: Ok
> 16 76.874903316 fedora:rawhide: Ok
> 17 76.756388879 mageia:5: Ok
> 18 71.700493646 opensuse:13.2: Ok
> 19 69.974649379 opensuse:42.1: Ok
> 20 75.265305896 opensuse:tumbleweed: Ok
> 21 28.800283739 ubuntu:12.04.5: FAIL
> util/probe-finder.c: In function 'var_has_loclist':
> util/probe-finder.c:904:40: error: declaration of 'die' shadows a global 
> declaration [-Werror=shadow]
> util/util.h:137:6: error: shadowed declaration is here [-Werror=shadow]
> util/probe-finder.c: In function 'optimized_target':
> util/probe-finder.c:921:41: error: declaration of 'die' shadows a global 
> declaration [-Werror=shadow]
> util/util.h:137:6: error: shadowed declaration is here [-Werror=shadow]
> -
> 22 66.514504455 ubuntu:14.04.4: Ok
> 23 69.100413367 ubuntu:15.10: Ok
> 24 64.414190947 ubuntu:16.04: Ok
> 25 29.481652689 ubuntu:16.04-x-arm: FAIL
> util/probe-finder.c: In function '__skip_prologue':
> util/probe-finder.c:1022:45: error: passing argument 3 of 'dwarf_getsrclines' 
> from incompatible pointer type [-Werror=incompatible-pointer-types]
>   if (dwarf_getsrclines(>cu_die, , _lines))
>  ^
> In file included from util/dwarf-aux.h:23:0,
>  from util/probe-finder.h:24,
>  from util/probe-finder.c:41:
> /usr/arm-linux-gnueabihf/include/elfutils/libdw.h:592:12: note: expected 
> 'size_t * {aka unsigned int *}' but argument is of type 'long unsigned int *'
>  extern int dwarf_getsrclines (Dwarf_Die *cudie, Dwarf_Lines **lines,
> ^
> In file included from util/probe-finder.c:37:0:
> util/probe-finder.c: In function 'skip_prologue':
> util/probe-finder.c:1060:10: error: format '%lx' expects argument of type 
> 'long unsigned int', but argument 4 has type 'Dwarf_Addr {aka long long 
> unsigned int}' [-Werror=format=]
>   pr_info("Target program is compiled without optimization. Skipping 
> prologue.\n"
>   ^
> util/debug.h:18:21: note: in definition of macro 'pr_fmt'
>  #define pr_fmt(fmt) fmt
>  ^
> util/probe-finder.c:1060:2: note: in expansion of macro 'pr_info'
>   pr_info("Target program is compiled without optimization. Skipping 
> prologue.\n"
>   ^
> -
> 26 51.979875334 ubuntu:16.04-x-arm64: Ok
> 27 28.808591224 ubuntu:16.04-x-powerpc64: FAIL
>   CC 

Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-29 Thread Ravi Bangoria


On Saturday 27 August 2016 01:00 AM, Arnaldo Carvalho de Melo wrote:
> Em Wed, Aug 03, 2016 at 02:28:45PM +0530, Ravi Bangoria escreveu:
>> +++ b/tools/perf/util/probe-finder.c
>> @@ -892,6 +892,169 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, 
>> struct probe_finder *pf)
>>  return die_walk_lines(sp_die, probe_point_lazy_walker, pf);
>>  }
>   
>> +static bool var_has_loclist(Dwarf_Die *die)
> So, the variable 'die' cause the build to fail in multiple systems, I'm
> renaming it to 'cu_die', there are some more problems when cross compiling it
> to some arches, I'm trying to fix them all now:

Sorry for this. I started using "make -C tools/perf build-test" but I don't have
infrastructure handy to test for cross arch.

If possible, can you please provide that to me. Otherwise I've to create it from
scratch.

-Ravi

> [root@jouet ~]# dm
>  1 65.668882867 alpine:3.4: Ok
>  2 24.327143744 android-ndk:r12b-arm: Ok
>  3 76.000455817 archlinux:latest: Ok
>  4 40.905282317 centos:5: Ok
>  5 28.799284950 centos:6: FAIL
> cc1: warnings being treated as errors
> util/probe-finder.c: In function 'var_has_loclist':
> util/probe-finder.c:904: error: declaration of 'die' shadows a global 
> declaration
> util/util.h:137: error: shadowed declaration is here
> util/probe-finder.c: In function 'optimized_target':
> util/probe-finder.c:921: error: declaration of 'die' shadows a global 
> declaration
> util/util.h:137: error: shadowed declaration is here
> -
>  6 68.157498673 centos:7: Ok
>  7 32.814597820 debian:7: FAIL
> util/probe-finder.c: In function 'var_has_loclist':
> util/probe-finder.c:904:40: error: declaration of 'die' shadows a global 
> declaration [-Werror=shadow]
> In file included from util/probe-finder.c:39:0:
> util/util.h:137:6: error: shadowed declaration is here [-Werror=shadow]
> util/probe-finder.c: In function 'optimized_target':
> util/probe-finder.c:921:41: error: declaration of 'die' shadows a global 
> declaration [-Werror=shadow]
> In file included from util/probe-finder.c:39:0:
> util/util.h:137:6: error: shadowed declaration is here [-Werror=shadow]
> -
>  8 69.535114125 debian:8: Ok
>  9 71.524733936 debian:experimental: Ok
> 10 66.956671932 fedora:20: Ok
> 11 72.127804972 fedora:21: Ok
> 12 75.767022465 fedora:22: Ok
> 13 72.244964710 fedora:23: Ok
> 14 75.556712624 fedora:24: Ok
> 15 30.825802615 fedora:24-x-ARC-uClibc: Ok
> 16 76.874903316 fedora:rawhide: Ok
> 17 76.756388879 mageia:5: Ok
> 18 71.700493646 opensuse:13.2: Ok
> 19 69.974649379 opensuse:42.1: Ok
> 20 75.265305896 opensuse:tumbleweed: Ok
> 21 28.800283739 ubuntu:12.04.5: FAIL
> util/probe-finder.c: In function 'var_has_loclist':
> util/probe-finder.c:904:40: error: declaration of 'die' shadows a global 
> declaration [-Werror=shadow]
> util/util.h:137:6: error: shadowed declaration is here [-Werror=shadow]
> util/probe-finder.c: In function 'optimized_target':
> util/probe-finder.c:921:41: error: declaration of 'die' shadows a global 
> declaration [-Werror=shadow]
> util/util.h:137:6: error: shadowed declaration is here [-Werror=shadow]
> -
> 22 66.514504455 ubuntu:14.04.4: Ok
> 23 69.100413367 ubuntu:15.10: Ok
> 24 64.414190947 ubuntu:16.04: Ok
> 25 29.481652689 ubuntu:16.04-x-arm: FAIL
> util/probe-finder.c: In function '__skip_prologue':
> util/probe-finder.c:1022:45: error: passing argument 3 of 'dwarf_getsrclines' 
> from incompatible pointer type [-Werror=incompatible-pointer-types]
>   if (dwarf_getsrclines(>cu_die, , _lines))
>  ^
> In file included from util/dwarf-aux.h:23:0,
>  from util/probe-finder.h:24,
>  from util/probe-finder.c:41:
> /usr/arm-linux-gnueabihf/include/elfutils/libdw.h:592:12: note: expected 
> 'size_t * {aka unsigned int *}' but argument is of type 'long unsigned int *'
>  extern int dwarf_getsrclines (Dwarf_Die *cudie, Dwarf_Lines **lines,
> ^
> In file included from util/probe-finder.c:37:0:
> util/probe-finder.c: In function 'skip_prologue':
> util/probe-finder.c:1060:10: error: format '%lx' expects argument of type 
> 'long unsigned int', but argument 4 has type 'Dwarf_Addr {aka long long 
> unsigned int}' [-Werror=format=]
>   pr_info("Target program is compiled without optimization. Skipping 
> prologue.\n"
>   ^
> util/debug.h:18:21: note: in definition of macro 'pr_fmt'
>  #define pr_fmt(fmt) fmt
>  ^
> util/probe-finder.c:1060:2: note: in expansion of macro 'pr_info'
>   pr_info("Target program is compiled without optimization. Skipping 
> prologue.\n"
>   ^
> -
> 26 51.979875334 ubuntu:16.04-x-arm64: Ok
> 27 28.808591224 ubuntu:16.04-x-powerpc64: FAIL
>   CC 

Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-26 Thread Masami Hiramatsu
On Fri, 26 Aug 2016 16:54:52 -0300
Arnaldo Carvalho de Melo  wrote:

> Em Fri, Aug 26, 2016 at 04:30:27PM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Wed, Aug 03, 2016 at 02:28:45PM +0530, Ravi Bangoria escreveu:
> > > +++ b/tools/perf/util/probe-finder.c
> > > @@ -892,6 +892,169 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, 
> > > struct probe_finder *pf)
> > >   return die_walk_lines(sp_die, probe_point_lazy_walker, pf);
> > >  }
> >   
> > > +static bool var_has_loclist(Dwarf_Die *die)
> > 
> > So, the variable 'die' cause the build to fail in multiple systems, I'm
> > renaming it to 'cu_die', there are some more problems when cross compiling 
> > it
> > to some arches, I'm trying to fix them all now:
> 
> Fixed, please check:
> 
> http://git.kernel.org/cgit/linux/kernel/git/acme/linux.git/commit/?h=perf/urgent=3866e3762da3291613dfb8b193885a8ed3836669

Hmm I think var_has_loclist(cu_die) should be vr_die(means Variable DIE) not
cu_die (Compile Unit DIE == object file itself) since user must pass the
DIE for local variable. And revisiting on the code, it seems this has several
generic dwarf related functions, which can be put into dwarf-aux.c/.h as
other APIs. 
But anyway it is a trivial & cleanup thing.

At first we should fix this bug for helping users ASAP. So I'm OK.

Thank you!

-- 
Masami Hiramatsu 


Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-26 Thread Masami Hiramatsu
On Fri, 26 Aug 2016 16:54:52 -0300
Arnaldo Carvalho de Melo  wrote:

> Em Fri, Aug 26, 2016 at 04:30:27PM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Wed, Aug 03, 2016 at 02:28:45PM +0530, Ravi Bangoria escreveu:
> > > +++ b/tools/perf/util/probe-finder.c
> > > @@ -892,6 +892,169 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, 
> > > struct probe_finder *pf)
> > >   return die_walk_lines(sp_die, probe_point_lazy_walker, pf);
> > >  }
> >   
> > > +static bool var_has_loclist(Dwarf_Die *die)
> > 
> > So, the variable 'die' cause the build to fail in multiple systems, I'm
> > renaming it to 'cu_die', there are some more problems when cross compiling 
> > it
> > to some arches, I'm trying to fix them all now:
> 
> Fixed, please check:
> 
> http://git.kernel.org/cgit/linux/kernel/git/acme/linux.git/commit/?h=perf/urgent=3866e3762da3291613dfb8b193885a8ed3836669

Hmm I think var_has_loclist(cu_die) should be vr_die(means Variable DIE) not
cu_die (Compile Unit DIE == object file itself) since user must pass the
DIE for local variable. And revisiting on the code, it seems this has several
generic dwarf related functions, which can be put into dwarf-aux.c/.h as
other APIs. 
But anyway it is a trivial & cleanup thing.

At first we should fix this bug for helping users ASAP. So I'm OK.

Thank you!

-- 
Masami Hiramatsu 


Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-26 Thread Arnaldo Carvalho de Melo
Em Fri, Aug 26, 2016 at 04:30:27PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Wed, Aug 03, 2016 at 02:28:45PM +0530, Ravi Bangoria escreveu:
> > +++ b/tools/perf/util/probe-finder.c
> > @@ -892,6 +892,169 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, 
> > struct probe_finder *pf)
> > return die_walk_lines(sp_die, probe_point_lazy_walker, pf);
> >  }
>   
> > +static bool var_has_loclist(Dwarf_Die *die)
> 
> So, the variable 'die' cause the build to fail in multiple systems, I'm
> renaming it to 'cu_die', there are some more problems when cross compiling it
> to some arches, I'm trying to fix them all now:

Fixed, please check:

http://git.kernel.org/cgit/linux/kernel/git/acme/linux.git/commit/?h=perf/urgent=3866e3762da3291613dfb8b193885a8ed3836669

- Arnaldo


Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-26 Thread Arnaldo Carvalho de Melo
Em Fri, Aug 26, 2016 at 04:30:27PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Wed, Aug 03, 2016 at 02:28:45PM +0530, Ravi Bangoria escreveu:
> > +++ b/tools/perf/util/probe-finder.c
> > @@ -892,6 +892,169 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, 
> > struct probe_finder *pf)
> > return die_walk_lines(sp_die, probe_point_lazy_walker, pf);
> >  }
>   
> > +static bool var_has_loclist(Dwarf_Die *die)
> 
> So, the variable 'die' cause the build to fail in multiple systems, I'm
> renaming it to 'cu_die', there are some more problems when cross compiling it
> to some arches, I'm trying to fix them all now:

Fixed, please check:

http://git.kernel.org/cgit/linux/kernel/git/acme/linux.git/commit/?h=perf/urgent=3866e3762da3291613dfb8b193885a8ed3836669

- Arnaldo


Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-26 Thread Arnaldo Carvalho de Melo
Em Wed, Aug 03, 2016 at 02:28:45PM +0530, Ravi Bangoria escreveu:
> +++ b/tools/perf/util/probe-finder.c
> @@ -892,6 +892,169 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, 
> struct probe_finder *pf)
>   return die_walk_lines(sp_die, probe_point_lazy_walker, pf);
>  }
  
> +static bool var_has_loclist(Dwarf_Die *die)

So, the variable 'die' cause the build to fail in multiple systems, I'm
renaming it to 'cu_die', there are some more problems when cross compiling it
to some arches, I'm trying to fix them all now:

[root@jouet ~]# dm
 1 65.668882867 alpine:3.4: Ok
 2 24.327143744 android-ndk:r12b-arm: Ok
 3 76.000455817 archlinux:latest: Ok
 4 40.905282317 centos:5: Ok
 5 28.799284950 centos:6: FAIL
cc1: warnings being treated as errors
util/probe-finder.c: In function 'var_has_loclist':
util/probe-finder.c:904: error: declaration of 'die' shadows a global 
declaration
util/util.h:137: error: shadowed declaration is here
util/probe-finder.c: In function 'optimized_target':
util/probe-finder.c:921: error: declaration of 'die' shadows a global 
declaration
util/util.h:137: error: shadowed declaration is here
-
 6 68.157498673 centos:7: Ok
 7 32.814597820 debian:7: FAIL
util/probe-finder.c: In function 'var_has_loclist':
util/probe-finder.c:904:40: error: declaration of 'die' shadows a global 
declaration [-Werror=shadow]
In file included from util/probe-finder.c:39:0:
util/util.h:137:6: error: shadowed declaration is here [-Werror=shadow]
util/probe-finder.c: In function 'optimized_target':
util/probe-finder.c:921:41: error: declaration of 'die' shadows a global 
declaration [-Werror=shadow]
In file included from util/probe-finder.c:39:0:
util/util.h:137:6: error: shadowed declaration is here [-Werror=shadow]
-
 8 69.535114125 debian:8: Ok
 9 71.524733936 debian:experimental: Ok
10 66.956671932 fedora:20: Ok
11 72.127804972 fedora:21: Ok
12 75.767022465 fedora:22: Ok
13 72.244964710 fedora:23: Ok
14 75.556712624 fedora:24: Ok
15 30.825802615 fedora:24-x-ARC-uClibc: Ok
16 76.874903316 fedora:rawhide: Ok
17 76.756388879 mageia:5: Ok
18 71.700493646 opensuse:13.2: Ok
19 69.974649379 opensuse:42.1: Ok
20 75.265305896 opensuse:tumbleweed: Ok
21 28.800283739 ubuntu:12.04.5: FAIL
util/probe-finder.c: In function 'var_has_loclist':
util/probe-finder.c:904:40: error: declaration of 'die' shadows a global 
declaration [-Werror=shadow]
util/util.h:137:6: error: shadowed declaration is here [-Werror=shadow]
util/probe-finder.c: In function 'optimized_target':
util/probe-finder.c:921:41: error: declaration of 'die' shadows a global 
declaration [-Werror=shadow]
util/util.h:137:6: error: shadowed declaration is here [-Werror=shadow]
-
22 66.514504455 ubuntu:14.04.4: Ok
23 69.100413367 ubuntu:15.10: Ok
24 64.414190947 ubuntu:16.04: Ok
25 29.481652689 ubuntu:16.04-x-arm: FAIL
util/probe-finder.c: In function '__skip_prologue':
util/probe-finder.c:1022:45: error: passing argument 3 of 'dwarf_getsrclines' 
from incompatible pointer type [-Werror=incompatible-pointer-types]
  if (dwarf_getsrclines(>cu_die, , _lines))
 ^
In file included from util/dwarf-aux.h:23:0,
 from util/probe-finder.h:24,
 from util/probe-finder.c:41:
/usr/arm-linux-gnueabihf/include/elfutils/libdw.h:592:12: note: expected 
'size_t * {aka unsigned int *}' but argument is of type 'long unsigned int *'
 extern int dwarf_getsrclines (Dwarf_Die *cudie, Dwarf_Lines **lines,
^
In file included from util/probe-finder.c:37:0:
util/probe-finder.c: In function 'skip_prologue':
util/probe-finder.c:1060:10: error: format '%lx' expects argument of type 'long 
unsigned int', but argument 4 has type 'Dwarf_Addr {aka long long unsigned 
int}' [-Werror=format=]
  pr_info("Target program is compiled without optimization. Skipping 
prologue.\n"
  ^
util/debug.h:18:21: note: in definition of macro 'pr_fmt'
 #define pr_fmt(fmt) fmt
 ^
util/probe-finder.c:1060:2: note: in expansion of macro 'pr_info'
  pr_info("Target program is compiled without optimization. Skipping 
prologue.\n"
  ^
-
26 51.979875334 ubuntu:16.04-x-arm64: Ok
27 28.808591224 ubuntu:16.04-x-powerpc64: FAIL
  CC   /tmp/build/perf/tests/bp_signal.o
util/probe-finder.c: In function '__skip_prologue':
util/probe-finder.c:1022:45: error: passing argument 3 of 'dwarf_getsrclines' 
from incompatible pointer type [-Werror=incompatible-pointer-types]
  if (dwarf_getsrclines(>cu_die, , _lines))
 ^
In file included from util/dwarf-aux.h:23:0,
 from util/probe-finder.h:24,
 from util/probe-finder.c:41:

Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-26 Thread Arnaldo Carvalho de Melo
Em Wed, Aug 03, 2016 at 02:28:45PM +0530, Ravi Bangoria escreveu:
> +++ b/tools/perf/util/probe-finder.c
> @@ -892,6 +892,169 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, 
> struct probe_finder *pf)
>   return die_walk_lines(sp_die, probe_point_lazy_walker, pf);
>  }
  
> +static bool var_has_loclist(Dwarf_Die *die)

So, the variable 'die' cause the build to fail in multiple systems, I'm
renaming it to 'cu_die', there are some more problems when cross compiling it
to some arches, I'm trying to fix them all now:

[root@jouet ~]# dm
 1 65.668882867 alpine:3.4: Ok
 2 24.327143744 android-ndk:r12b-arm: Ok
 3 76.000455817 archlinux:latest: Ok
 4 40.905282317 centos:5: Ok
 5 28.799284950 centos:6: FAIL
cc1: warnings being treated as errors
util/probe-finder.c: In function 'var_has_loclist':
util/probe-finder.c:904: error: declaration of 'die' shadows a global 
declaration
util/util.h:137: error: shadowed declaration is here
util/probe-finder.c: In function 'optimized_target':
util/probe-finder.c:921: error: declaration of 'die' shadows a global 
declaration
util/util.h:137: error: shadowed declaration is here
-
 6 68.157498673 centos:7: Ok
 7 32.814597820 debian:7: FAIL
util/probe-finder.c: In function 'var_has_loclist':
util/probe-finder.c:904:40: error: declaration of 'die' shadows a global 
declaration [-Werror=shadow]
In file included from util/probe-finder.c:39:0:
util/util.h:137:6: error: shadowed declaration is here [-Werror=shadow]
util/probe-finder.c: In function 'optimized_target':
util/probe-finder.c:921:41: error: declaration of 'die' shadows a global 
declaration [-Werror=shadow]
In file included from util/probe-finder.c:39:0:
util/util.h:137:6: error: shadowed declaration is here [-Werror=shadow]
-
 8 69.535114125 debian:8: Ok
 9 71.524733936 debian:experimental: Ok
10 66.956671932 fedora:20: Ok
11 72.127804972 fedora:21: Ok
12 75.767022465 fedora:22: Ok
13 72.244964710 fedora:23: Ok
14 75.556712624 fedora:24: Ok
15 30.825802615 fedora:24-x-ARC-uClibc: Ok
16 76.874903316 fedora:rawhide: Ok
17 76.756388879 mageia:5: Ok
18 71.700493646 opensuse:13.2: Ok
19 69.974649379 opensuse:42.1: Ok
20 75.265305896 opensuse:tumbleweed: Ok
21 28.800283739 ubuntu:12.04.5: FAIL
util/probe-finder.c: In function 'var_has_loclist':
util/probe-finder.c:904:40: error: declaration of 'die' shadows a global 
declaration [-Werror=shadow]
util/util.h:137:6: error: shadowed declaration is here [-Werror=shadow]
util/probe-finder.c: In function 'optimized_target':
util/probe-finder.c:921:41: error: declaration of 'die' shadows a global 
declaration [-Werror=shadow]
util/util.h:137:6: error: shadowed declaration is here [-Werror=shadow]
-
22 66.514504455 ubuntu:14.04.4: Ok
23 69.100413367 ubuntu:15.10: Ok
24 64.414190947 ubuntu:16.04: Ok
25 29.481652689 ubuntu:16.04-x-arm: FAIL
util/probe-finder.c: In function '__skip_prologue':
util/probe-finder.c:1022:45: error: passing argument 3 of 'dwarf_getsrclines' 
from incompatible pointer type [-Werror=incompatible-pointer-types]
  if (dwarf_getsrclines(>cu_die, , _lines))
 ^
In file included from util/dwarf-aux.h:23:0,
 from util/probe-finder.h:24,
 from util/probe-finder.c:41:
/usr/arm-linux-gnueabihf/include/elfutils/libdw.h:592:12: note: expected 
'size_t * {aka unsigned int *}' but argument is of type 'long unsigned int *'
 extern int dwarf_getsrclines (Dwarf_Die *cudie, Dwarf_Lines **lines,
^
In file included from util/probe-finder.c:37:0:
util/probe-finder.c: In function 'skip_prologue':
util/probe-finder.c:1060:10: error: format '%lx' expects argument of type 'long 
unsigned int', but argument 4 has type 'Dwarf_Addr {aka long long unsigned 
int}' [-Werror=format=]
  pr_info("Target program is compiled without optimization. Skipping 
prologue.\n"
  ^
util/debug.h:18:21: note: in definition of macro 'pr_fmt'
 #define pr_fmt(fmt) fmt
 ^
util/probe-finder.c:1060:2: note: in expansion of macro 'pr_info'
  pr_info("Target program is compiled without optimization. Skipping 
prologue.\n"
  ^
-
26 51.979875334 ubuntu:16.04-x-arm64: Ok
27 28.808591224 ubuntu:16.04-x-powerpc64: FAIL
  CC   /tmp/build/perf/tests/bp_signal.o
util/probe-finder.c: In function '__skip_prologue':
util/probe-finder.c:1022:45: error: passing argument 3 of 'dwarf_getsrclines' 
from incompatible pointer type [-Werror=incompatible-pointer-types]
  if (dwarf_getsrclines(>cu_die, , _lines))
 ^
In file included from util/dwarf-aux.h:23:0,
 from util/probe-finder.h:24,
 from util/probe-finder.c:41:

Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-25 Thread Jiri Olsa
On Thu, Aug 25, 2016 at 12:17:53PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Thu, Aug 25, 2016 at 03:59:43PM +0200, Jiri Olsa escreveu:
> > On Thu, Aug 25, 2016 at 09:50:04PM +0900, Masami Hiramatsu wrote:
> > 
> > SNIP
> > 
> > > > After applying patch:
> > > > 
> > > >   $ ./perf probe -x ./test 'foo i'
> > > >   $ cat /sys/kernel/debug/tracing/uprobe_events
> > > > p:probe_test/foo /home/ravi/test:0x0541 i=-4(%bp):s32
> > > > 
> > > >   $ ./perf record -e probe_test:foo ./test
> > > >   $ ./perf script
> > > > test  6300 [001]  5877.879327: probe_test:foo: (400541) i=42
> > > > 
> > > > No need to skip prologue for optimized case since debug info is correct
> > > > for each instructions for -O2 -g. For more details please visit:
> > > > https://bugzilla.redhat.com/show_bug.cgi?id=612253#c6
> > > > 
> > > > Signed-off-by: Ravi Bangoria 
> > > 
> > > Looks good for me:)
> > > 
> > > Acked-by: Masami Hiramatsu 
> > > 
> > > Jiri, Michael, please try this. Ravi's patch can fix your problem.
> > 
> > yes, that fixes the problem for me
> 
> Ok, so I'll add a Tested-by: Jiri, ok? And push it via perf/urgent.

yep, thanks

jirka


Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-25 Thread Jiri Olsa
On Thu, Aug 25, 2016 at 12:17:53PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Thu, Aug 25, 2016 at 03:59:43PM +0200, Jiri Olsa escreveu:
> > On Thu, Aug 25, 2016 at 09:50:04PM +0900, Masami Hiramatsu wrote:
> > 
> > SNIP
> > 
> > > > After applying patch:
> > > > 
> > > >   $ ./perf probe -x ./test 'foo i'
> > > >   $ cat /sys/kernel/debug/tracing/uprobe_events
> > > > p:probe_test/foo /home/ravi/test:0x0541 i=-4(%bp):s32
> > > > 
> > > >   $ ./perf record -e probe_test:foo ./test
> > > >   $ ./perf script
> > > > test  6300 [001]  5877.879327: probe_test:foo: (400541) i=42
> > > > 
> > > > No need to skip prologue for optimized case since debug info is correct
> > > > for each instructions for -O2 -g. For more details please visit:
> > > > https://bugzilla.redhat.com/show_bug.cgi?id=612253#c6
> > > > 
> > > > Signed-off-by: Ravi Bangoria 
> > > 
> > > Looks good for me:)
> > > 
> > > Acked-by: Masami Hiramatsu 
> > > 
> > > Jiri, Michael, please try this. Ravi's patch can fix your problem.
> > 
> > yes, that fixes the problem for me
> 
> Ok, so I'll add a Tested-by: Jiri, ok? And push it via perf/urgent.

yep, thanks

jirka


Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-25 Thread Arnaldo Carvalho de Melo
Em Thu, Aug 25, 2016 at 03:59:43PM +0200, Jiri Olsa escreveu:
> On Thu, Aug 25, 2016 at 09:50:04PM +0900, Masami Hiramatsu wrote:
> 
> SNIP
> 
> > > After applying patch:
> > > 
> > >   $ ./perf probe -x ./test 'foo i'
> > >   $ cat /sys/kernel/debug/tracing/uprobe_events
> > > p:probe_test/foo /home/ravi/test:0x0541 i=-4(%bp):s32
> > > 
> > >   $ ./perf record -e probe_test:foo ./test
> > >   $ ./perf script
> > > test  6300 [001]  5877.879327: probe_test:foo: (400541) i=42
> > > 
> > > No need to skip prologue for optimized case since debug info is correct
> > > for each instructions for -O2 -g. For more details please visit:
> > > https://bugzilla.redhat.com/show_bug.cgi?id=612253#c6
> > > 
> > > Signed-off-by: Ravi Bangoria 
> > 
> > Looks good for me:)
> > 
> > Acked-by: Masami Hiramatsu 
> > 
> > Jiri, Michael, please try this. Ravi's patch can fix your problem.
> 
> yes, that fixes the problem for me

Ok, so I'll add a Tested-by: Jiri, ok? And push it via perf/urgent.

- Arnaldo


Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-25 Thread Arnaldo Carvalho de Melo
Em Thu, Aug 25, 2016 at 03:59:43PM +0200, Jiri Olsa escreveu:
> On Thu, Aug 25, 2016 at 09:50:04PM +0900, Masami Hiramatsu wrote:
> 
> SNIP
> 
> > > After applying patch:
> > > 
> > >   $ ./perf probe -x ./test 'foo i'
> > >   $ cat /sys/kernel/debug/tracing/uprobe_events
> > > p:probe_test/foo /home/ravi/test:0x0541 i=-4(%bp):s32
> > > 
> > >   $ ./perf record -e probe_test:foo ./test
> > >   $ ./perf script
> > > test  6300 [001]  5877.879327: probe_test:foo: (400541) i=42
> > > 
> > > No need to skip prologue for optimized case since debug info is correct
> > > for each instructions for -O2 -g. For more details please visit:
> > > https://bugzilla.redhat.com/show_bug.cgi?id=612253#c6
> > > 
> > > Signed-off-by: Ravi Bangoria 
> > 
> > Looks good for me:)
> > 
> > Acked-by: Masami Hiramatsu 
> > 
> > Jiri, Michael, please try this. Ravi's patch can fix your problem.
> 
> yes, that fixes the problem for me

Ok, so I'll add a Tested-by: Jiri, ok? And push it via perf/urgent.

- Arnaldo


Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-25 Thread Jiri Olsa
On Thu, Aug 25, 2016 at 09:50:04PM +0900, Masami Hiramatsu wrote:

SNIP

> > After applying patch:
> > 
> >   $ ./perf probe -x ./test 'foo i'
> >   $ cat /sys/kernel/debug/tracing/uprobe_events
> > p:probe_test/foo /home/ravi/test:0x0541 i=-4(%bp):s32
> > 
> >   $ ./perf record -e probe_test:foo ./test
> >   $ ./perf script
> > test  6300 [001]  5877.879327: probe_test:foo: (400541) i=42
> > 
> > No need to skip prologue for optimized case since debug info is correct
> > for each instructions for -O2 -g. For more details please visit:
> > https://bugzilla.redhat.com/show_bug.cgi?id=612253#c6
> > 
> > Signed-off-by: Ravi Bangoria 
> 
> Looks good for me:)
> 
> Acked-by: Masami Hiramatsu 
> 
> Jiri, Michael, please try this. Ravi's patch can fix your problem.

yes, that fixes the problem for me

thanks a lot,
jirka


Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-25 Thread Jiri Olsa
On Thu, Aug 25, 2016 at 09:50:04PM +0900, Masami Hiramatsu wrote:

SNIP

> > After applying patch:
> > 
> >   $ ./perf probe -x ./test 'foo i'
> >   $ cat /sys/kernel/debug/tracing/uprobe_events
> > p:probe_test/foo /home/ravi/test:0x0541 i=-4(%bp):s32
> > 
> >   $ ./perf record -e probe_test:foo ./test
> >   $ ./perf script
> > test  6300 [001]  5877.879327: probe_test:foo: (400541) i=42
> > 
> > No need to skip prologue for optimized case since debug info is correct
> > for each instructions for -O2 -g. For more details please visit:
> > https://bugzilla.redhat.com/show_bug.cgi?id=612253#c6
> > 
> > Signed-off-by: Ravi Bangoria 
> 
> Looks good for me:)
> 
> Acked-by: Masami Hiramatsu 
> 
> Jiri, Michael, please try this. Ravi's patch can fix your problem.

yes, that fixes the problem for me

thanks a lot,
jirka


Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-25 Thread Masami Hiramatsu
On Wed,  3 Aug 2016 14:28:45 +0530
Ravi Bangoria  wrote:

> Function prologue prepares stack and registers before executing function
> logic. When target program is compiled without optimization, function
> parameter information is only valid after prologue. When we probe entrypc
> of the function, and try to record function parameter, it contains
> garbage value.
> 
> For example,
>   $ vim test.c
> #include 
> 
> void foo(int i)
> {
>printf("i: %d\n", i);
> }
> 
> int main()
> {
>   foo(42);
>   return 0;
> }
> 
>   $ gcc -g test.c -o test
>   $ objdump -dl test | less
> foo():
> /home/ravi/test.c:4
>   400536:   55  push   %rbp
>   400537:   48 89 e5mov%rsp,%rbp
>   40053a:   48 83 ec 10 sub-bashx10,%rsp
>   40053e:   89 7d fcmov%edi,-0x4(%rbp)
> /home/ravi/test.c:5
>   400541:   8b 45 fcmov-0x4(%rbp),%eax
> ...
> ...
> main():
> /home/ravi/test.c:9
>   400558:   55  push   %rbp
>   400559:   48 89 e5mov%rsp,%rbp
> /home/ravi/test.c:10
>   40055c:   bf 2a 00 00 00  mov-bashx2a,%edi
>   400561:   e8 d0 ff ff ff  callq  400536 
> /home/ravi/test.c:11
> 
>   $ ./perf probe -x ./test 'foo i'
>   $ cat /sys/kernel/debug/tracing/uprobe_events
>  p:probe_test/foo /home/ravi/test:0x0536 i=-12(%sp):s32
> 
>   $ ./perf record -e probe_test:foo ./test
>   $ ./perf script
>  test  5778 [001]  4918.562027: probe_test:foo: (400536) i=0
> 
> Here variable 'i' is passed via stack which is pushed on stack at
> 0x40053e. But we are probing at 0x400536.
> 
> To resolve this issues, we need to probe on next instruction after
> prologue. gdb and systemtap also does same thing. I've implemented
> this patch based on approach systemtap has used.
> 
> After applying patch:
> 
>   $ ./perf probe -x ./test 'foo i'
>   $ cat /sys/kernel/debug/tracing/uprobe_events
> p:probe_test/foo /home/ravi/test:0x0541 i=-4(%bp):s32
> 
>   $ ./perf record -e probe_test:foo ./test
>   $ ./perf script
> test  6300 [001]  5877.879327: probe_test:foo: (400541) i=42
> 
> No need to skip prologue for optimized case since debug info is correct
> for each instructions for -O2 -g. For more details please visit:
> https://bugzilla.redhat.com/show_bug.cgi?id=612253#c6
> 
> Signed-off-by: Ravi Bangoria 

Looks good for me:)

Acked-by: Masami Hiramatsu 

Jiri, Michael, please try this. Ravi's patch can fix your problem.

Thank you!


> ---
> Changes in v2:
>   - Skipping prologue only when any ARG is either C variable, $params
> or $vars.
>   - Probe on line(:1) may not be always possible. Recommend only address
> to force probe on function entry.
> 
>  tools/perf/util/probe-finder.c | 164 
> +
>  1 file changed, 164 insertions(+)
> 
> diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
> index f2d9ff0..b2bc77c 100644
> --- a/tools/perf/util/probe-finder.c
> +++ b/tools/perf/util/probe-finder.c
> @@ -892,6 +892,169 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, 
> struct probe_finder *pf)
>   return die_walk_lines(sp_die, probe_point_lazy_walker, pf);
>  }
>  
> +static bool var_has_loclist(Dwarf_Die *die)
> +{
> + Dwarf_Attribute loc;
> + int tag = dwarf_tag(die);
> +
> + if (tag != DW_TAG_formal_parameter &&
> + tag != DW_TAG_variable)
> + return false;
> +
> + return (dwarf_attr_integrate(die, DW_AT_location, ) &&
> + dwarf_whatform() == DW_FORM_sec_offset);
> +}
> +
> +/*
> + * For any object in given CU whose DW_AT_location is a location list,
> + * target program is compiled with optimization.
> + */
> +static bool optimized_target(Dwarf_Die *die)
> +{
> + Dwarf_Die tmp_die;
> +
> + if (var_has_loclist(die))
> + return true;
> +
> + if (!dwarf_child(die, _die) && optimized_target(_die))
> + return true;
> +
> + if (!dwarf_siblingof(die, _die) && optimized_target(_die))
> + return true;
> +
> + return false;
> +}
> +
> +static bool get_entrypc_idx(Dwarf_Lines *lines, unsigned long nr_lines,
> + Dwarf_Addr pf_addr, unsigned long *entrypc_idx)
> +{
> + unsigned long i;
> + Dwarf_Addr addr;
> +
> + for (i = 0; i < nr_lines; i++) {
> + if (dwarf_lineaddr(dwarf_onesrcline(lines, i), ))
> + return false;
> +
> + if (addr == pf_addr) {
> + *entrypc_idx = i;
> + return true;
> + }
> + }
> + return false;
> +}
> +
> +static bool get_postprologue_addr(unsigned long entrypc_idx,
> + 

Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-25 Thread Masami Hiramatsu
On Wed,  3 Aug 2016 14:28:45 +0530
Ravi Bangoria  wrote:

> Function prologue prepares stack and registers before executing function
> logic. When target program is compiled without optimization, function
> parameter information is only valid after prologue. When we probe entrypc
> of the function, and try to record function parameter, it contains
> garbage value.
> 
> For example,
>   $ vim test.c
> #include 
> 
> void foo(int i)
> {
>printf("i: %d\n", i);
> }
> 
> int main()
> {
>   foo(42);
>   return 0;
> }
> 
>   $ gcc -g test.c -o test
>   $ objdump -dl test | less
> foo():
> /home/ravi/test.c:4
>   400536:   55  push   %rbp
>   400537:   48 89 e5mov%rsp,%rbp
>   40053a:   48 83 ec 10 sub-bashx10,%rsp
>   40053e:   89 7d fcmov%edi,-0x4(%rbp)
> /home/ravi/test.c:5
>   400541:   8b 45 fcmov-0x4(%rbp),%eax
> ...
> ...
> main():
> /home/ravi/test.c:9
>   400558:   55  push   %rbp
>   400559:   48 89 e5mov%rsp,%rbp
> /home/ravi/test.c:10
>   40055c:   bf 2a 00 00 00  mov-bashx2a,%edi
>   400561:   e8 d0 ff ff ff  callq  400536 
> /home/ravi/test.c:11
> 
>   $ ./perf probe -x ./test 'foo i'
>   $ cat /sys/kernel/debug/tracing/uprobe_events
>  p:probe_test/foo /home/ravi/test:0x0536 i=-12(%sp):s32
> 
>   $ ./perf record -e probe_test:foo ./test
>   $ ./perf script
>  test  5778 [001]  4918.562027: probe_test:foo: (400536) i=0
> 
> Here variable 'i' is passed via stack which is pushed on stack at
> 0x40053e. But we are probing at 0x400536.
> 
> To resolve this issues, we need to probe on next instruction after
> prologue. gdb and systemtap also does same thing. I've implemented
> this patch based on approach systemtap has used.
> 
> After applying patch:
> 
>   $ ./perf probe -x ./test 'foo i'
>   $ cat /sys/kernel/debug/tracing/uprobe_events
> p:probe_test/foo /home/ravi/test:0x0541 i=-4(%bp):s32
> 
>   $ ./perf record -e probe_test:foo ./test
>   $ ./perf script
> test  6300 [001]  5877.879327: probe_test:foo: (400541) i=42
> 
> No need to skip prologue for optimized case since debug info is correct
> for each instructions for -O2 -g. For more details please visit:
> https://bugzilla.redhat.com/show_bug.cgi?id=612253#c6
> 
> Signed-off-by: Ravi Bangoria 

Looks good for me:)

Acked-by: Masami Hiramatsu 

Jiri, Michael, please try this. Ravi's patch can fix your problem.

Thank you!


> ---
> Changes in v2:
>   - Skipping prologue only when any ARG is either C variable, $params
> or $vars.
>   - Probe on line(:1) may not be always possible. Recommend only address
> to force probe on function entry.
> 
>  tools/perf/util/probe-finder.c | 164 
> +
>  1 file changed, 164 insertions(+)
> 
> diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
> index f2d9ff0..b2bc77c 100644
> --- a/tools/perf/util/probe-finder.c
> +++ b/tools/perf/util/probe-finder.c
> @@ -892,6 +892,169 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, 
> struct probe_finder *pf)
>   return die_walk_lines(sp_die, probe_point_lazy_walker, pf);
>  }
>  
> +static bool var_has_loclist(Dwarf_Die *die)
> +{
> + Dwarf_Attribute loc;
> + int tag = dwarf_tag(die);
> +
> + if (tag != DW_TAG_formal_parameter &&
> + tag != DW_TAG_variable)
> + return false;
> +
> + return (dwarf_attr_integrate(die, DW_AT_location, ) &&
> + dwarf_whatform() == DW_FORM_sec_offset);
> +}
> +
> +/*
> + * For any object in given CU whose DW_AT_location is a location list,
> + * target program is compiled with optimization.
> + */
> +static bool optimized_target(Dwarf_Die *die)
> +{
> + Dwarf_Die tmp_die;
> +
> + if (var_has_loclist(die))
> + return true;
> +
> + if (!dwarf_child(die, _die) && optimized_target(_die))
> + return true;
> +
> + if (!dwarf_siblingof(die, _die) && optimized_target(_die))
> + return true;
> +
> + return false;
> +}
> +
> +static bool get_entrypc_idx(Dwarf_Lines *lines, unsigned long nr_lines,
> + Dwarf_Addr pf_addr, unsigned long *entrypc_idx)
> +{
> + unsigned long i;
> + Dwarf_Addr addr;
> +
> + for (i = 0; i < nr_lines; i++) {
> + if (dwarf_lineaddr(dwarf_onesrcline(lines, i), ))
> + return false;
> +
> + if (addr == pf_addr) {
> + *entrypc_idx = i;
> + return true;
> + }
> + }
> + return false;
> +}
> +
> +static bool get_postprologue_addr(unsigned long entrypc_idx,
> +   Dwarf_Lines *lines,
> +   unsigned long nr_lines,

Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-25 Thread Masami Hiramatsu
Hi Ravi,

On Sat, 13 Aug 2016 19:15:53 +0530
Ravi Bangoria  wrote:

> Hi Masami, Arnaldo,
> 
> Any updates on this?

Oops, sorry I missed this mail, I was on vacation...


> 
> Thanks,
> Ravi
> 
> On Wednesday 03 August 2016 02:28 PM, Ravi Bangoria wrote:
> > Function prologue prepares stack and registers before executing function
> > logic. When target program is compiled without optimization, function
> > parameter information is only valid after prologue. When we probe entrypc
> > of the function, and try to record function parameter, it contains
> > garbage value.
> >
> > For example,
> >   $ vim test.c
> > #include 
> >
> > void foo(int i)
> > {
> >printf("i: %d\n", i);
> > }
> >
> > int main()
> > {
> >   foo(42);
> >   return 0;
> > }
> >
> >   $ gcc -g test.c -o test
> >   $ objdump -dl test | less
> > foo():
> > /home/ravi/test.c:4
> >   400536:   55  push   %rbp
> >   400537:   48 89 e5mov%rsp,%rbp
> >   40053a:   48 83 ec 10 sub-bashx10,%rsp
> >   40053e:   89 7d fcmov%edi,-0x4(%rbp)
> > /home/ravi/test.c:5
> >   400541:   8b 45 fcmov-0x4(%rbp),%eax
> > ...
> > ...
> > main():
> > /home/ravi/test.c:9
> >   400558:   55  push   %rbp
> >   400559:   48 89 e5mov%rsp,%rbp
> > /home/ravi/test.c:10
> >   40055c:   bf 2a 00 00 00  mov-bashx2a,%edi
> >   400561:   e8 d0 ff ff ff  callq  400536 
> > /home/ravi/test.c:11
> >
> >   $ ./perf probe -x ./test 'foo i'
> >   $ cat /sys/kernel/debug/tracing/uprobe_events
> >  p:probe_test/foo /home/ravi/test:0x0536 i=-12(%sp):s32
> >
> >   $ ./perf record -e probe_test:foo ./test
> >   $ ./perf script
> >  test  5778 [001]  4918.562027: probe_test:foo: (400536) i=0
> >
> > Here variable 'i' is passed via stack which is pushed on stack at
> > 0x40053e. But we are probing at 0x400536.
> >
> > To resolve this issues, we need to probe on next instruction after
> > prologue. gdb and systemtap also does same thing. I've implemented
> > this patch based on approach systemtap has used.
> >
> > After applying patch:
> >
> >   $ ./perf probe -x ./test 'foo i'
> >   $ cat /sys/kernel/debug/tracing/uprobe_events
> > p:probe_test/foo /home/ravi/test:0x0541 i=-4(%bp):s32
> >
> >   $ ./perf record -e probe_test:foo ./test
> >   $ ./perf script
> > test  6300 [001]  5877.879327: probe_test:foo: (400541) i=42
> >
> > No need to skip prologue for optimized case since debug info is correct
> > for each instructions for -O2 -g. For more details please visit:
> > https://bugzilla.redhat.com/show_bug.cgi?id=612253#c6
> >
> > Signed-off-by: Ravi Bangoria 
> > ---
> > Changes in v2:
> >   - Skipping prologue only when any ARG is either C variable, $params
> > or $vars.
> >   - Probe on line(:1) may not be always possible. Recommend only address
> > to force probe on function entry.
> >
> >  tools/perf/util/probe-finder.c | 164 
> > +
> >  1 file changed, 164 insertions(+)
> >
> > diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
> > index f2d9ff0..b2bc77c 100644
> > --- a/tools/perf/util/probe-finder.c
> > +++ b/tools/perf/util/probe-finder.c
> > @@ -892,6 +892,169 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, 
> > struct probe_finder *pf)
> > return die_walk_lines(sp_die, probe_point_lazy_walker, pf);
> >  }
> >
> > +static bool var_has_loclist(Dwarf_Die *die)
> > +{
> > +   Dwarf_Attribute loc;
> > +   int tag = dwarf_tag(die);
> > +
> > +   if (tag != DW_TAG_formal_parameter &&
> > +   tag != DW_TAG_variable)
> > +   return false;
> > +
> > +   return (dwarf_attr_integrate(die, DW_AT_location, ) &&
> > +   dwarf_whatform() == DW_FORM_sec_offset);
> > +}
> > +
> > +/*
> > + * For any object in given CU whose DW_AT_location is a location list,
> > + * target program is compiled with optimization.
> > + */
> > +static bool optimized_target(Dwarf_Die *die)
> > +{
> > +   Dwarf_Die tmp_die;
> > +
> > +   if (var_has_loclist(die))
> > +   return true;
> > +
> > +   if (!dwarf_child(die, _die) && optimized_target(_die))
> > +   return true;
> > +
> > +   if (!dwarf_siblingof(die, _die) && optimized_target(_die))
> > +   return true;
> > +
> > +   return false;
> > +}
> > +
> > +static bool get_entrypc_idx(Dwarf_Lines *lines, unsigned long nr_lines,
> > +   Dwarf_Addr pf_addr, unsigned long *entrypc_idx)
> > +{
> > +   unsigned long i;
> > +   Dwarf_Addr addr;
> > +
> > +   for (i = 0; i < nr_lines; i++) {
> > +   if (dwarf_lineaddr(dwarf_onesrcline(lines, i), ))
> > +   return false;
> > +
> > +  

Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-25 Thread Masami Hiramatsu
Hi Ravi,

On Sat, 13 Aug 2016 19:15:53 +0530
Ravi Bangoria  wrote:

> Hi Masami, Arnaldo,
> 
> Any updates on this?

Oops, sorry I missed this mail, I was on vacation...


> 
> Thanks,
> Ravi
> 
> On Wednesday 03 August 2016 02:28 PM, Ravi Bangoria wrote:
> > Function prologue prepares stack and registers before executing function
> > logic. When target program is compiled without optimization, function
> > parameter information is only valid after prologue. When we probe entrypc
> > of the function, and try to record function parameter, it contains
> > garbage value.
> >
> > For example,
> >   $ vim test.c
> > #include 
> >
> > void foo(int i)
> > {
> >printf("i: %d\n", i);
> > }
> >
> > int main()
> > {
> >   foo(42);
> >   return 0;
> > }
> >
> >   $ gcc -g test.c -o test
> >   $ objdump -dl test | less
> > foo():
> > /home/ravi/test.c:4
> >   400536:   55  push   %rbp
> >   400537:   48 89 e5mov%rsp,%rbp
> >   40053a:   48 83 ec 10 sub-bashx10,%rsp
> >   40053e:   89 7d fcmov%edi,-0x4(%rbp)
> > /home/ravi/test.c:5
> >   400541:   8b 45 fcmov-0x4(%rbp),%eax
> > ...
> > ...
> > main():
> > /home/ravi/test.c:9
> >   400558:   55  push   %rbp
> >   400559:   48 89 e5mov%rsp,%rbp
> > /home/ravi/test.c:10
> >   40055c:   bf 2a 00 00 00  mov-bashx2a,%edi
> >   400561:   e8 d0 ff ff ff  callq  400536 
> > /home/ravi/test.c:11
> >
> >   $ ./perf probe -x ./test 'foo i'
> >   $ cat /sys/kernel/debug/tracing/uprobe_events
> >  p:probe_test/foo /home/ravi/test:0x0536 i=-12(%sp):s32
> >
> >   $ ./perf record -e probe_test:foo ./test
> >   $ ./perf script
> >  test  5778 [001]  4918.562027: probe_test:foo: (400536) i=0
> >
> > Here variable 'i' is passed via stack which is pushed on stack at
> > 0x40053e. But we are probing at 0x400536.
> >
> > To resolve this issues, we need to probe on next instruction after
> > prologue. gdb and systemtap also does same thing. I've implemented
> > this patch based on approach systemtap has used.
> >
> > After applying patch:
> >
> >   $ ./perf probe -x ./test 'foo i'
> >   $ cat /sys/kernel/debug/tracing/uprobe_events
> > p:probe_test/foo /home/ravi/test:0x0541 i=-4(%bp):s32
> >
> >   $ ./perf record -e probe_test:foo ./test
> >   $ ./perf script
> > test  6300 [001]  5877.879327: probe_test:foo: (400541) i=42
> >
> > No need to skip prologue for optimized case since debug info is correct
> > for each instructions for -O2 -g. For more details please visit:
> > https://bugzilla.redhat.com/show_bug.cgi?id=612253#c6
> >
> > Signed-off-by: Ravi Bangoria 
> > ---
> > Changes in v2:
> >   - Skipping prologue only when any ARG is either C variable, $params
> > or $vars.
> >   - Probe on line(:1) may not be always possible. Recommend only address
> > to force probe on function entry.
> >
> >  tools/perf/util/probe-finder.c | 164 
> > +
> >  1 file changed, 164 insertions(+)
> >
> > diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
> > index f2d9ff0..b2bc77c 100644
> > --- a/tools/perf/util/probe-finder.c
> > +++ b/tools/perf/util/probe-finder.c
> > @@ -892,6 +892,169 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, 
> > struct probe_finder *pf)
> > return die_walk_lines(sp_die, probe_point_lazy_walker, pf);
> >  }
> >
> > +static bool var_has_loclist(Dwarf_Die *die)
> > +{
> > +   Dwarf_Attribute loc;
> > +   int tag = dwarf_tag(die);
> > +
> > +   if (tag != DW_TAG_formal_parameter &&
> > +   tag != DW_TAG_variable)
> > +   return false;
> > +
> > +   return (dwarf_attr_integrate(die, DW_AT_location, ) &&
> > +   dwarf_whatform() == DW_FORM_sec_offset);
> > +}
> > +
> > +/*
> > + * For any object in given CU whose DW_AT_location is a location list,
> > + * target program is compiled with optimization.
> > + */
> > +static bool optimized_target(Dwarf_Die *die)
> > +{
> > +   Dwarf_Die tmp_die;
> > +
> > +   if (var_has_loclist(die))
> > +   return true;
> > +
> > +   if (!dwarf_child(die, _die) && optimized_target(_die))
> > +   return true;
> > +
> > +   if (!dwarf_siblingof(die, _die) && optimized_target(_die))
> > +   return true;
> > +
> > +   return false;
> > +}
> > +
> > +static bool get_entrypc_idx(Dwarf_Lines *lines, unsigned long nr_lines,
> > +   Dwarf_Addr pf_addr, unsigned long *entrypc_idx)
> > +{
> > +   unsigned long i;
> > +   Dwarf_Addr addr;
> > +
> > +   for (i = 0; i < nr_lines; i++) {
> > +   if (dwarf_lineaddr(dwarf_onesrcline(lines, i), ))
> > +   return false;
> > +
> > +   if (addr == pf_addr) {
> > +   *entrypc_idx = 

Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-18 Thread Naveen N. Rao
On 2016/08/03 02:28PM, Ravi Bangoria wrote:
> Function prologue prepares stack and registers before executing function
> logic. When target program is compiled without optimization, function
> parameter information is only valid after prologue. When we probe entrypc
> of the function, and try to record function parameter, it contains
> garbage value.
> 
> For example,
>   $ vim test.c
> #include 
> 
> void foo(int i)
> {
>printf("i: %d\n", i);
> }
> 
> int main()
> {
>   foo(42);
>   return 0;
> }
> 
>   $ gcc -g test.c -o test
>   $ objdump -dl test | less
> foo():
> /home/ravi/test.c:4
>   400536:   55  push   %rbp
>   400537:   48 89 e5mov%rsp,%rbp
>   40053a:   48 83 ec 10 sub-bashx10,%rsp
>   40053e:   89 7d fcmov%edi,-0x4(%rbp)
> /home/ravi/test.c:5
>   400541:   8b 45 fcmov-0x4(%rbp),%eax
> ...
> ...
> main():
> /home/ravi/test.c:9
>   400558:   55  push   %rbp
>   400559:   48 89 e5mov%rsp,%rbp
> /home/ravi/test.c:10
>   40055c:   bf 2a 00 00 00  mov-bashx2a,%edi
>   400561:   e8 d0 ff ff ff  callq  400536 
> /home/ravi/test.c:11
> 
>   $ ./perf probe -x ./test 'foo i'
>   $ cat /sys/kernel/debug/tracing/uprobe_events
>  p:probe_test/foo /home/ravi/test:0x0536 i=-12(%sp):s32
> 
>   $ ./perf record -e probe_test:foo ./test
>   $ ./perf script
>  test  5778 [001]  4918.562027: probe_test:foo: (400536) i=0
> 
> Here variable 'i' is passed via stack which is pushed on stack at
> 0x40053e. But we are probing at 0x400536.
> 
> To resolve this issues, we need to probe on next instruction after
> prologue. gdb and systemtap also does same thing. I've implemented
> this patch based on approach systemtap has used.
> 
> After applying patch:
> 
>   $ ./perf probe -x ./test 'foo i'
>   $ cat /sys/kernel/debug/tracing/uprobe_events
> p:probe_test/foo /home/ravi/test:0x0541 i=-4(%bp):s32
> 
>   $ ./perf record -e probe_test:foo ./test
>   $ ./perf script
> test  6300 [001]  5877.879327: probe_test:foo: (400541) i=42
> 
> No need to skip prologue for optimized case since debug info is correct
> for each instructions for -O2 -g. For more details please visit:
> https://bugzilla.redhat.com/show_bug.cgi?id=612253#c6
> 
> Signed-off-by: Ravi Bangoria 
> ---
> Changes in v2:
>   - Skipping prologue only when any ARG is either C variable, $params
> or $vars.
>   - Probe on line(:1) may not be always possible. Recommend only address
> to force probe on function entry.
> 
>  tools/perf/util/probe-finder.c | 164 
> +
>  1 file changed, 164 insertions(+)

This fixes the uprobe issue reported by Michael Petlan:
https://www.mail-archive.com/linux-perf-users@vger.kernel.org/msg02348.html

Acked-by: Naveen N. Rao 



Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-18 Thread Naveen N. Rao
On 2016/08/03 02:28PM, Ravi Bangoria wrote:
> Function prologue prepares stack and registers before executing function
> logic. When target program is compiled without optimization, function
> parameter information is only valid after prologue. When we probe entrypc
> of the function, and try to record function parameter, it contains
> garbage value.
> 
> For example,
>   $ vim test.c
> #include 
> 
> void foo(int i)
> {
>printf("i: %d\n", i);
> }
> 
> int main()
> {
>   foo(42);
>   return 0;
> }
> 
>   $ gcc -g test.c -o test
>   $ objdump -dl test | less
> foo():
> /home/ravi/test.c:4
>   400536:   55  push   %rbp
>   400537:   48 89 e5mov%rsp,%rbp
>   40053a:   48 83 ec 10 sub-bashx10,%rsp
>   40053e:   89 7d fcmov%edi,-0x4(%rbp)
> /home/ravi/test.c:5
>   400541:   8b 45 fcmov-0x4(%rbp),%eax
> ...
> ...
> main():
> /home/ravi/test.c:9
>   400558:   55  push   %rbp
>   400559:   48 89 e5mov%rsp,%rbp
> /home/ravi/test.c:10
>   40055c:   bf 2a 00 00 00  mov-bashx2a,%edi
>   400561:   e8 d0 ff ff ff  callq  400536 
> /home/ravi/test.c:11
> 
>   $ ./perf probe -x ./test 'foo i'
>   $ cat /sys/kernel/debug/tracing/uprobe_events
>  p:probe_test/foo /home/ravi/test:0x0536 i=-12(%sp):s32
> 
>   $ ./perf record -e probe_test:foo ./test
>   $ ./perf script
>  test  5778 [001]  4918.562027: probe_test:foo: (400536) i=0
> 
> Here variable 'i' is passed via stack which is pushed on stack at
> 0x40053e. But we are probing at 0x400536.
> 
> To resolve this issues, we need to probe on next instruction after
> prologue. gdb and systemtap also does same thing. I've implemented
> this patch based on approach systemtap has used.
> 
> After applying patch:
> 
>   $ ./perf probe -x ./test 'foo i'
>   $ cat /sys/kernel/debug/tracing/uprobe_events
> p:probe_test/foo /home/ravi/test:0x0541 i=-4(%bp):s32
> 
>   $ ./perf record -e probe_test:foo ./test
>   $ ./perf script
> test  6300 [001]  5877.879327: probe_test:foo: (400541) i=42
> 
> No need to skip prologue for optimized case since debug info is correct
> for each instructions for -O2 -g. For more details please visit:
> https://bugzilla.redhat.com/show_bug.cgi?id=612253#c6
> 
> Signed-off-by: Ravi Bangoria 
> ---
> Changes in v2:
>   - Skipping prologue only when any ARG is either C variable, $params
> or $vars.
>   - Probe on line(:1) may not be always possible. Recommend only address
> to force probe on function entry.
> 
>  tools/perf/util/probe-finder.c | 164 
> +
>  1 file changed, 164 insertions(+)

This fixes the uprobe issue reported by Michael Petlan:
https://www.mail-archive.com/linux-perf-users@vger.kernel.org/msg02348.html

Acked-by: Naveen N. Rao 



Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-13 Thread Ravi Bangoria
Hi Masami, Arnaldo,

Any updates on this?

Thanks,
Ravi

On Wednesday 03 August 2016 02:28 PM, Ravi Bangoria wrote:
> Function prologue prepares stack and registers before executing function
> logic. When target program is compiled without optimization, function
> parameter information is only valid after prologue. When we probe entrypc
> of the function, and try to record function parameter, it contains
> garbage value.
>
> For example,
>   $ vim test.c
> #include 
>
> void foo(int i)
> {
>printf("i: %d\n", i);
> }
>
> int main()
> {
>   foo(42);
>   return 0;
> }
>
>   $ gcc -g test.c -o test
>   $ objdump -dl test | less
> foo():
> /home/ravi/test.c:4
>   400536:   55  push   %rbp
>   400537:   48 89 e5mov%rsp,%rbp
>   40053a:   48 83 ec 10 sub-bashx10,%rsp
>   40053e:   89 7d fcmov%edi,-0x4(%rbp)
> /home/ravi/test.c:5
>   400541:   8b 45 fcmov-0x4(%rbp),%eax
> ...
> ...
> main():
> /home/ravi/test.c:9
>   400558:   55  push   %rbp
>   400559:   48 89 e5mov%rsp,%rbp
> /home/ravi/test.c:10
>   40055c:   bf 2a 00 00 00  mov-bashx2a,%edi
>   400561:   e8 d0 ff ff ff  callq  400536 
> /home/ravi/test.c:11
>
>   $ ./perf probe -x ./test 'foo i'
>   $ cat /sys/kernel/debug/tracing/uprobe_events
>  p:probe_test/foo /home/ravi/test:0x0536 i=-12(%sp):s32
>
>   $ ./perf record -e probe_test:foo ./test
>   $ ./perf script
>  test  5778 [001]  4918.562027: probe_test:foo: (400536) i=0
>
> Here variable 'i' is passed via stack which is pushed on stack at
> 0x40053e. But we are probing at 0x400536.
>
> To resolve this issues, we need to probe on next instruction after
> prologue. gdb and systemtap also does same thing. I've implemented
> this patch based on approach systemtap has used.
>
> After applying patch:
>
>   $ ./perf probe -x ./test 'foo i'
>   $ cat /sys/kernel/debug/tracing/uprobe_events
> p:probe_test/foo /home/ravi/test:0x0541 i=-4(%bp):s32
>
>   $ ./perf record -e probe_test:foo ./test
>   $ ./perf script
> test  6300 [001]  5877.879327: probe_test:foo: (400541) i=42
>
> No need to skip prologue for optimized case since debug info is correct
> for each instructions for -O2 -g. For more details please visit:
> https://bugzilla.redhat.com/show_bug.cgi?id=612253#c6
>
> Signed-off-by: Ravi Bangoria 
> ---
> Changes in v2:
>   - Skipping prologue only when any ARG is either C variable, $params
> or $vars.
>   - Probe on line(:1) may not be always possible. Recommend only address
> to force probe on function entry.
>
>  tools/perf/util/probe-finder.c | 164 
> +
>  1 file changed, 164 insertions(+)
>
> diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
> index f2d9ff0..b2bc77c 100644
> --- a/tools/perf/util/probe-finder.c
> +++ b/tools/perf/util/probe-finder.c
> @@ -892,6 +892,169 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, 
> struct probe_finder *pf)
>   return die_walk_lines(sp_die, probe_point_lazy_walker, pf);
>  }
>
> +static bool var_has_loclist(Dwarf_Die *die)
> +{
> + Dwarf_Attribute loc;
> + int tag = dwarf_tag(die);
> +
> + if (tag != DW_TAG_formal_parameter &&
> + tag != DW_TAG_variable)
> + return false;
> +
> + return (dwarf_attr_integrate(die, DW_AT_location, ) &&
> + dwarf_whatform() == DW_FORM_sec_offset);
> +}
> +
> +/*
> + * For any object in given CU whose DW_AT_location is a location list,
> + * target program is compiled with optimization.
> + */
> +static bool optimized_target(Dwarf_Die *die)
> +{
> + Dwarf_Die tmp_die;
> +
> + if (var_has_loclist(die))
> + return true;
> +
> + if (!dwarf_child(die, _die) && optimized_target(_die))
> + return true;
> +
> + if (!dwarf_siblingof(die, _die) && optimized_target(_die))
> + return true;
> +
> + return false;
> +}
> +
> +static bool get_entrypc_idx(Dwarf_Lines *lines, unsigned long nr_lines,
> + Dwarf_Addr pf_addr, unsigned long *entrypc_idx)
> +{
> + unsigned long i;
> + Dwarf_Addr addr;
> +
> + for (i = 0; i < nr_lines; i++) {
> + if (dwarf_lineaddr(dwarf_onesrcline(lines, i), ))
> + return false;
> +
> + if (addr == pf_addr) {
> + *entrypc_idx = i;
> + return true;
> + }
> + }
> + return false;
> +}
> +
> +static bool get_postprologue_addr(unsigned long entrypc_idx,
> +   Dwarf_Lines *lines,
> +   unsigned long nr_lines,
> +   Dwarf_Addr highpc,
> +  

Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-13 Thread Ravi Bangoria
Hi Masami, Arnaldo,

Any updates on this?

Thanks,
Ravi

On Wednesday 03 August 2016 02:28 PM, Ravi Bangoria wrote:
> Function prologue prepares stack and registers before executing function
> logic. When target program is compiled without optimization, function
> parameter information is only valid after prologue. When we probe entrypc
> of the function, and try to record function parameter, it contains
> garbage value.
>
> For example,
>   $ vim test.c
> #include 
>
> void foo(int i)
> {
>printf("i: %d\n", i);
> }
>
> int main()
> {
>   foo(42);
>   return 0;
> }
>
>   $ gcc -g test.c -o test
>   $ objdump -dl test | less
> foo():
> /home/ravi/test.c:4
>   400536:   55  push   %rbp
>   400537:   48 89 e5mov%rsp,%rbp
>   40053a:   48 83 ec 10 sub-bashx10,%rsp
>   40053e:   89 7d fcmov%edi,-0x4(%rbp)
> /home/ravi/test.c:5
>   400541:   8b 45 fcmov-0x4(%rbp),%eax
> ...
> ...
> main():
> /home/ravi/test.c:9
>   400558:   55  push   %rbp
>   400559:   48 89 e5mov%rsp,%rbp
> /home/ravi/test.c:10
>   40055c:   bf 2a 00 00 00  mov-bashx2a,%edi
>   400561:   e8 d0 ff ff ff  callq  400536 
> /home/ravi/test.c:11
>
>   $ ./perf probe -x ./test 'foo i'
>   $ cat /sys/kernel/debug/tracing/uprobe_events
>  p:probe_test/foo /home/ravi/test:0x0536 i=-12(%sp):s32
>
>   $ ./perf record -e probe_test:foo ./test
>   $ ./perf script
>  test  5778 [001]  4918.562027: probe_test:foo: (400536) i=0
>
> Here variable 'i' is passed via stack which is pushed on stack at
> 0x40053e. But we are probing at 0x400536.
>
> To resolve this issues, we need to probe on next instruction after
> prologue. gdb and systemtap also does same thing. I've implemented
> this patch based on approach systemtap has used.
>
> After applying patch:
>
>   $ ./perf probe -x ./test 'foo i'
>   $ cat /sys/kernel/debug/tracing/uprobe_events
> p:probe_test/foo /home/ravi/test:0x0541 i=-4(%bp):s32
>
>   $ ./perf record -e probe_test:foo ./test
>   $ ./perf script
> test  6300 [001]  5877.879327: probe_test:foo: (400541) i=42
>
> No need to skip prologue for optimized case since debug info is correct
> for each instructions for -O2 -g. For more details please visit:
> https://bugzilla.redhat.com/show_bug.cgi?id=612253#c6
>
> Signed-off-by: Ravi Bangoria 
> ---
> Changes in v2:
>   - Skipping prologue only when any ARG is either C variable, $params
> or $vars.
>   - Probe on line(:1) may not be always possible. Recommend only address
> to force probe on function entry.
>
>  tools/perf/util/probe-finder.c | 164 
> +
>  1 file changed, 164 insertions(+)
>
> diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
> index f2d9ff0..b2bc77c 100644
> --- a/tools/perf/util/probe-finder.c
> +++ b/tools/perf/util/probe-finder.c
> @@ -892,6 +892,169 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, 
> struct probe_finder *pf)
>   return die_walk_lines(sp_die, probe_point_lazy_walker, pf);
>  }
>
> +static bool var_has_loclist(Dwarf_Die *die)
> +{
> + Dwarf_Attribute loc;
> + int tag = dwarf_tag(die);
> +
> + if (tag != DW_TAG_formal_parameter &&
> + tag != DW_TAG_variable)
> + return false;
> +
> + return (dwarf_attr_integrate(die, DW_AT_location, ) &&
> + dwarf_whatform() == DW_FORM_sec_offset);
> +}
> +
> +/*
> + * For any object in given CU whose DW_AT_location is a location list,
> + * target program is compiled with optimization.
> + */
> +static bool optimized_target(Dwarf_Die *die)
> +{
> + Dwarf_Die tmp_die;
> +
> + if (var_has_loclist(die))
> + return true;
> +
> + if (!dwarf_child(die, _die) && optimized_target(_die))
> + return true;
> +
> + if (!dwarf_siblingof(die, _die) && optimized_target(_die))
> + return true;
> +
> + return false;
> +}
> +
> +static bool get_entrypc_idx(Dwarf_Lines *lines, unsigned long nr_lines,
> + Dwarf_Addr pf_addr, unsigned long *entrypc_idx)
> +{
> + unsigned long i;
> + Dwarf_Addr addr;
> +
> + for (i = 0; i < nr_lines; i++) {
> + if (dwarf_lineaddr(dwarf_onesrcline(lines, i), ))
> + return false;
> +
> + if (addr == pf_addr) {
> + *entrypc_idx = i;
> + return true;
> + }
> + }
> + return false;
> +}
> +
> +static bool get_postprologue_addr(unsigned long entrypc_idx,
> +   Dwarf_Lines *lines,
> +   unsigned long nr_lines,
> +   Dwarf_Addr highpc,
> +   

[PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-03 Thread Ravi Bangoria
Function prologue prepares stack and registers before executing function
logic. When target program is compiled without optimization, function
parameter information is only valid after prologue. When we probe entrypc
of the function, and try to record function parameter, it contains
garbage value.

For example,
  $ vim test.c
#include 

void foo(int i)
{
   printf("i: %d\n", i);
}

int main()
{
  foo(42);
  return 0;
}

  $ gcc -g test.c -o test
  $ objdump -dl test | less
foo():
/home/ravi/test.c:4
  400536:   55  push   %rbp
  400537:   48 89 e5mov%rsp,%rbp
  40053a:   48 83 ec 10 sub-bashx10,%rsp
  40053e:   89 7d fcmov%edi,-0x4(%rbp)
/home/ravi/test.c:5
  400541:   8b 45 fcmov-0x4(%rbp),%eax
...
...
main():
/home/ravi/test.c:9
  400558:   55  push   %rbp
  400559:   48 89 e5mov%rsp,%rbp
/home/ravi/test.c:10
  40055c:   bf 2a 00 00 00  mov-bashx2a,%edi
  400561:   e8 d0 ff ff ff  callq  400536 
/home/ravi/test.c:11

  $ ./perf probe -x ./test 'foo i'
  $ cat /sys/kernel/debug/tracing/uprobe_events
 p:probe_test/foo /home/ravi/test:0x0536 i=-12(%sp):s32

  $ ./perf record -e probe_test:foo ./test
  $ ./perf script
 test  5778 [001]  4918.562027: probe_test:foo: (400536) i=0

Here variable 'i' is passed via stack which is pushed on stack at
0x40053e. But we are probing at 0x400536.

To resolve this issues, we need to probe on next instruction after
prologue. gdb and systemtap also does same thing. I've implemented
this patch based on approach systemtap has used.

After applying patch:

  $ ./perf probe -x ./test 'foo i'
  $ cat /sys/kernel/debug/tracing/uprobe_events
p:probe_test/foo /home/ravi/test:0x0541 i=-4(%bp):s32

  $ ./perf record -e probe_test:foo ./test
  $ ./perf script
test  6300 [001]  5877.879327: probe_test:foo: (400541) i=42

No need to skip prologue for optimized case since debug info is correct
for each instructions for -O2 -g. For more details please visit:
https://bugzilla.redhat.com/show_bug.cgi?id=612253#c6

Signed-off-by: Ravi Bangoria 
---
Changes in v2:
  - Skipping prologue only when any ARG is either C variable, $params
or $vars.
  - Probe on line(:1) may not be always possible. Recommend only address
to force probe on function entry.

 tools/perf/util/probe-finder.c | 164 +
 1 file changed, 164 insertions(+)

diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index f2d9ff0..b2bc77c 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -892,6 +892,169 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, 
struct probe_finder *pf)
return die_walk_lines(sp_die, probe_point_lazy_walker, pf);
 }
 
+static bool var_has_loclist(Dwarf_Die *die)
+{
+   Dwarf_Attribute loc;
+   int tag = dwarf_tag(die);
+
+   if (tag != DW_TAG_formal_parameter &&
+   tag != DW_TAG_variable)
+   return false;
+
+   return (dwarf_attr_integrate(die, DW_AT_location, ) &&
+   dwarf_whatform() == DW_FORM_sec_offset);
+}
+
+/*
+ * For any object in given CU whose DW_AT_location is a location list,
+ * target program is compiled with optimization.
+ */
+static bool optimized_target(Dwarf_Die *die)
+{
+   Dwarf_Die tmp_die;
+
+   if (var_has_loclist(die))
+   return true;
+
+   if (!dwarf_child(die, _die) && optimized_target(_die))
+   return true;
+
+   if (!dwarf_siblingof(die, _die) && optimized_target(_die))
+   return true;
+
+   return false;
+}
+
+static bool get_entrypc_idx(Dwarf_Lines *lines, unsigned long nr_lines,
+   Dwarf_Addr pf_addr, unsigned long *entrypc_idx)
+{
+   unsigned long i;
+   Dwarf_Addr addr;
+
+   for (i = 0; i < nr_lines; i++) {
+   if (dwarf_lineaddr(dwarf_onesrcline(lines, i), ))
+   return false;
+
+   if (addr == pf_addr) {
+   *entrypc_idx = i;
+   return true;
+   }
+   }
+   return false;
+}
+
+static bool get_postprologue_addr(unsigned long entrypc_idx,
+ Dwarf_Lines *lines,
+ unsigned long nr_lines,
+ Dwarf_Addr highpc,
+ Dwarf_Addr *postprologue_addr)
+{
+   unsigned long i;
+   int entrypc_lno, lno;
+   Dwarf_Line *line;
+   Dwarf_Addr addr;
+   bool p_end;
+
+   /* entrypc_lno is actual source line number */
+   line = dwarf_onesrcline(lines, entrypc_idx);
+   if (dwarf_lineno(line, 

[PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization

2016-08-03 Thread Ravi Bangoria
Function prologue prepares stack and registers before executing function
logic. When target program is compiled without optimization, function
parameter information is only valid after prologue. When we probe entrypc
of the function, and try to record function parameter, it contains
garbage value.

For example,
  $ vim test.c
#include 

void foo(int i)
{
   printf("i: %d\n", i);
}

int main()
{
  foo(42);
  return 0;
}

  $ gcc -g test.c -o test
  $ objdump -dl test | less
foo():
/home/ravi/test.c:4
  400536:   55  push   %rbp
  400537:   48 89 e5mov%rsp,%rbp
  40053a:   48 83 ec 10 sub-bashx10,%rsp
  40053e:   89 7d fcmov%edi,-0x4(%rbp)
/home/ravi/test.c:5
  400541:   8b 45 fcmov-0x4(%rbp),%eax
...
...
main():
/home/ravi/test.c:9
  400558:   55  push   %rbp
  400559:   48 89 e5mov%rsp,%rbp
/home/ravi/test.c:10
  40055c:   bf 2a 00 00 00  mov-bashx2a,%edi
  400561:   e8 d0 ff ff ff  callq  400536 
/home/ravi/test.c:11

  $ ./perf probe -x ./test 'foo i'
  $ cat /sys/kernel/debug/tracing/uprobe_events
 p:probe_test/foo /home/ravi/test:0x0536 i=-12(%sp):s32

  $ ./perf record -e probe_test:foo ./test
  $ ./perf script
 test  5778 [001]  4918.562027: probe_test:foo: (400536) i=0

Here variable 'i' is passed via stack which is pushed on stack at
0x40053e. But we are probing at 0x400536.

To resolve this issues, we need to probe on next instruction after
prologue. gdb and systemtap also does same thing. I've implemented
this patch based on approach systemtap has used.

After applying patch:

  $ ./perf probe -x ./test 'foo i'
  $ cat /sys/kernel/debug/tracing/uprobe_events
p:probe_test/foo /home/ravi/test:0x0541 i=-4(%bp):s32

  $ ./perf record -e probe_test:foo ./test
  $ ./perf script
test  6300 [001]  5877.879327: probe_test:foo: (400541) i=42

No need to skip prologue for optimized case since debug info is correct
for each instructions for -O2 -g. For more details please visit:
https://bugzilla.redhat.com/show_bug.cgi?id=612253#c6

Signed-off-by: Ravi Bangoria 
---
Changes in v2:
  - Skipping prologue only when any ARG is either C variable, $params
or $vars.
  - Probe on line(:1) may not be always possible. Recommend only address
to force probe on function entry.

 tools/perf/util/probe-finder.c | 164 +
 1 file changed, 164 insertions(+)

diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index f2d9ff0..b2bc77c 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -892,6 +892,169 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, 
struct probe_finder *pf)
return die_walk_lines(sp_die, probe_point_lazy_walker, pf);
 }
 
+static bool var_has_loclist(Dwarf_Die *die)
+{
+   Dwarf_Attribute loc;
+   int tag = dwarf_tag(die);
+
+   if (tag != DW_TAG_formal_parameter &&
+   tag != DW_TAG_variable)
+   return false;
+
+   return (dwarf_attr_integrate(die, DW_AT_location, ) &&
+   dwarf_whatform() == DW_FORM_sec_offset);
+}
+
+/*
+ * For any object in given CU whose DW_AT_location is a location list,
+ * target program is compiled with optimization.
+ */
+static bool optimized_target(Dwarf_Die *die)
+{
+   Dwarf_Die tmp_die;
+
+   if (var_has_loclist(die))
+   return true;
+
+   if (!dwarf_child(die, _die) && optimized_target(_die))
+   return true;
+
+   if (!dwarf_siblingof(die, _die) && optimized_target(_die))
+   return true;
+
+   return false;
+}
+
+static bool get_entrypc_idx(Dwarf_Lines *lines, unsigned long nr_lines,
+   Dwarf_Addr pf_addr, unsigned long *entrypc_idx)
+{
+   unsigned long i;
+   Dwarf_Addr addr;
+
+   for (i = 0; i < nr_lines; i++) {
+   if (dwarf_lineaddr(dwarf_onesrcline(lines, i), ))
+   return false;
+
+   if (addr == pf_addr) {
+   *entrypc_idx = i;
+   return true;
+   }
+   }
+   return false;
+}
+
+static bool get_postprologue_addr(unsigned long entrypc_idx,
+ Dwarf_Lines *lines,
+ unsigned long nr_lines,
+ Dwarf_Addr highpc,
+ Dwarf_Addr *postprologue_addr)
+{
+   unsigned long i;
+   int entrypc_lno, lno;
+   Dwarf_Line *line;
+   Dwarf_Addr addr;
+   bool p_end;
+
+   /* entrypc_lno is actual source line number */
+   line = dwarf_onesrcline(lines, entrypc_idx);
+   if (dwarf_lineno(line, _lno))
+   return