Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't add perf probe for C++ methods

Tags:

c++

linux

perf

I'm trying to add a perf probe for a C++ method in my library, but I keep getting the following:

$ perf probe --exec=/path/to/file --add='my::Own::Method'
Semantic error :There is non-digit char in line number.

I've listed the available functions like so:

$ perf probe --funcs --exec=/path/to/file

And tried some C functions that are also included. A probe can be added for these just fine. So I tried the mangled name (e.g. _ZN2my8Own16Method) and perf probe says it doesn't exist.

Is there a way around this issue?

like image 928
Trevor Norris Avatar asked Nov 24 '13 08:11

Trevor Norris


1 Answers

As a workaround you can get the method address with objdump and perf probe will accept it.

  $ perf probe -x /path/file '0x643f30'
Added new event:
  probe_libfile:abs_643f30 (on 0x643f30 in /path/file)

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

    perf record -e probe_libfile:abs_643f30 -aR sleep 1

Do note that perf probe expects an offset from the file, and objdump and readelf return the address after adjusting for the loading address. For -pie executable, where the loading address is 0, the addresses will be the same.
For non -pie executables you can get the loading address by looking at the output of readelf -l /path/file and searching for the offset 0x000000 and looking at what VirtAddr it points to, then subtract that number from the symbol address that you get from objdump --syms or readelf --syms. It will usually be 0x400000

like image 141
ceeaspb Avatar answered Sep 17 '22 12:09

ceeaspb