Re: [PATCH perf/core v2 1/5] perf-probe: Fix to handle aliased symbols in glibc

From: Arnaldo Carvalho de Melo
Date: Fri Mar 06 2015 - 12:59:24 EST


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 ~]#
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/