From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753790AbcHRJRm (ORCPT ); Thu, 18 Aug 2016 05:17:42 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:49929 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752864AbcHRJRk (ORCPT ); Thu, 18 Aug 2016 05:17:40 -0400 X-IBM-Helo: d03dlp01.boulder.ibm.com X-IBM-MailFrom: naveen.n.rao@linux.vnet.ibm.com Date: Thu, 18 Aug 2016 14:47:23 +0530 From: "Naveen N. Rao" To: Ravi Bangoria , Arnaldo Carvalho de Melo Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, mhiramat@kernel.org, wangnan0@huawei.com, hemant@linux.vnet.ibm.com, Michael Petlan Subject: Re: [PATCH v2 2/2] perf uprobe: Skip prologue if program compiled without optimization References: <1470214725-5023-1-git-send-email-ravi.bangoria@linux.vnet.ibm.com> <1470214725-5023-2-git-send-email-ravi.bangoria@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1470214725-5023-2-git-send-email-ravi.bangoria@linux.vnet.ibm.com> User-Agent: Mutt/1.6.2 (2016-07-01) X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16081809-0004-0000-0000-0000102A8FC8 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00005611; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000181; SDB=6.00746320; UDB=6.00351847; IPR=6.00518858; BA=6.00004666; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00012376; XFM=3.00000011; UTC=2016-08-18 09:17:38 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16081809-0005-0000-0000-00007814FC57 Message-Id: <20160818091723.GA4887@naverao1-tp.localdomain> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-08-18_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1608180107 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 e5 mov %rsp,%rbp > 40053a: 48 83 ec 10 sub -bashx10,%rsp > 40053e: 89 7d fc mov %edi,-0x4(%rbp) > /home/ravi/test.c:5 > 400541: 8b 45 fc mov -0x4(%rbp),%eax > ... > ... > main(): > /home/ravi/test.c:9 > 400558: 55 push %rbp > 400559: 48 89 e5 mov %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:0x0000000000000536 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:0x0000000000000541 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