无法为C++方法添加perf探针

17

我试图为我的库中的C++方法添加perf probe,但我不断收到以下错误消息:

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

我这样列出了可用的函数:

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

我尝试了一些也包含在内的 C 函数。这些可以很好地添加探针。因此,我尝试了被混淆的名称(例如 _ZN2my8Own16Method),但是 perf probe 显示它不存在。

有什么解决这个问题的方法吗?

2个回答

8

作为一种解决办法,您可以使用objdump获取方法地址,并且perf probe将接受它。

  $ 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

请注意,perf probe期望从文件中获取偏移量,而objdumpreadelf返回经过加载地址调整后的地址。对于使用 -pie 标记的可执行文件,其加载地址为0,地址将相同。
对于非 -pie 可执行文件,您可以通过查看 readelf -l /path/file 的输出并搜索偏移量 0x000000 并查看它指向的 VirtAddr,然后从 objdump --symsreadelf --syms 获取的符号地址中减去该数字。通常为 0x400000

3
对我来说 objdump ./<executable> --syms | grep -i <method> 起作用。输出中的第一列是要传递给 perf probe 的地址。但必须在地址前面加上 "0x",否则 perf 命令将失败。 - Marc Sherman

6
你可以运行以下命令,以查看所有函数名称的C++符号重载形式:
perf probe --exec=/path/to/file --funcs --no-demangle --filter='*'

找到你需要的函数(实际函数名将会在混淆后的标记中),然后使用--no-demangle选项添加它。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接