15

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?

Trevor Norris
  • 17,761
  • 3
  • 24
  • 26

2 Answers2

5

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

Daniel Shaulov
  • 2,084
  • 2
  • 15
  • 25
ceeaspb
  • 376
  • 3
  • 4
  • 1
    `objdump ./ --syms | grep -i ` worked for me. The first column in the output is the address to pass to `perf probe`. But "0x" must be prepended to the address or the perf command will fail. – Marc Sherman Dec 13 '18 at 03:36
1

You can run this to see all the function names in their C++ mangled form:

perf probe --exec=/path/to/file --funcs --no-demangle --filter='*'

Find the one you want (the actual function name will be amongst the mangled tokens), and add it with the --no-demangle option.

John Zwinck
  • 207,363
  • 31
  • 261
  • 371