From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754678AbbCFR7V (ORCPT ); Fri, 6 Mar 2015 12:59:21 -0500 Received: from mail.kernel.org ([198.145.29.136]:42028 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751844AbbCFR7U (ORCPT ); Fri, 6 Mar 2015 12:59:20 -0500 Date: Fri, 6 Mar 2015 14:59:19 -0300 From: Arnaldo Carvalho de Melo To: Masami Hiramatsu Cc: Naohiro Aota , Peter Zijlstra , Linux Kernel Mailing List , David Ahern , namhyung@kernel.org, Jiri Olsa , Ingo Molnar Subject: Re: [PATCH perf/core v2 1/5] perf-probe: Fix to handle aliased symbols in glibc Message-ID: <20150306175919.GA5187@kernel.org> References: <20150306073118.6904.72740.stgit@localhost.localdomain> <20150306073120.6904.13779.stgit@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150306073120.6904.13779.stgit@localhost.localdomain> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Fri, Mar 06, 2015 at 04:31:20PM +0900, Masami Hiramatsu escreveu: > Fix perf probe to handle aliased symbols correctly in glibc. > In the glibc, several symbols are defined as an alias of > __libc_XXX, e.g. malloc is an alias of __libc_malloc. > In such cases, dwarf has no subroutine instances of the > alias functions (e.g. no "malloc" instance), but the map > has that symbol and its address. > Thus, if we search the alieased symbol in debuginfo, we > always fail to find it, but it is in the map. > > To solve this problem, this fails back to address-based > alternative search, which searches the symbol in the map, > translates its address to alternative (correct) function > name by using debuginfo, and retry to find the alternative > function point from debuginfo. > > This adds fail-back process to --vars, --lines and --add > options. So, now you can use those on malloc@libc :) --vars and --add works, but not --lines: [root@ssdandy ~]# perf probe -x /usr/lib64/libc-2.17.so -V malloc Available variables at malloc @<__libc_malloc+96> size_t bytes [root@ssdandy ~]# perf probe -x /usr/lib64/libc-2.17.so -L malloc Specified source line is not found. Error: Failed to show lines. [root@ssdandy ~]# [root@ssdandy ~]# perf probe -x /usr/lib64/libc-2.17.so -a "malloc bytes" Added new event: probe_libc:malloc (on malloc in /usr/lib64/libc-2.17.so with bytes) You can now use it in all perf tools, such as: perf record -e probe_libc:malloc -aR sleep 1 [root@ssdandy ~]# [root@ssdandy ~]# cat /t/events/probe_libc/malloc/format name: malloc ID: 1921 format: field:unsigned short common_type; offset:0; size:2; signed:0; field:unsigned char common_flags; offset:2; size:1; signed:0; field:unsigned char common_preempt_count; offset:3; size:1; signed:0; field:int common_pid; offset:4; size:4; signed:1; field:unsigned long __probe_ip; offset:8; size:8; signed:0; field:u64 bytes; offset:16; size:8; signed:0; print fmt: "(%lx) bytes=0x%Lx", REC->__probe_ip, REC->bytes [root@ssdandy ~]# Works for the aliased symbol, anyway, applying as it makes progress. [root@ssdandy ~]# perf probe -x /usr/lib64/libc-2.17.so -L __libc_malloc <__libc_malloc@/usr/src/debug/glibc-2.17-c758a686/malloc/malloc.c:0> 0 __libc_malloc(size_t bytes) 1 { mstate ar_ptr; void *victim; __malloc_ptr_t (*hook) (size_t, const __malloc_ptr_t) 6 = force_reg (__malloc_hook); 7 if (__builtin_expect (hook != NULL, 0)) 8 return (*hook)(bytes, RETURN_ADDRESS (0)); 10 arena_lookup(ar_ptr); 12 arena_lock(ar_ptr, bytes); 13 if(!ar_ptr) 14 return 0; 15 victim = _int_malloc(ar_ptr, bytes); 16 if(!victim) { 17 LIBC_PROBE (memory_malloc_retry, 1, bytes); 18 ar_ptr = arena_get_retry(ar_ptr, bytes); 19 if (__builtin_expect(ar_ptr != NULL, 1)) { 20 victim = _int_malloc(ar_ptr, bytes); 21 (void)mutex_unlock(&ar_ptr->mutex); } } else 24 (void)mutex_unlock(&ar_ptr->mutex); assert(!victim || chunk_is_mmapped(mem2chunk(victim)) || ar_ptr == arena_for_chunk(mem2chunk(victim))); return victim; 28 } libc_hidden_def(__libc_malloc) void [root@ssdandy ~]#