我怎样才能在程序中找到符号

时间:2021-01-10 15:03:13

When using perf report, I don't see any symbols for my program, instead I get output like this:

使用perf报表时,我没有看到我的程序的任何符号,而是得到如下输出:

$ perf record /path/to/racket ints.rkt 10000
$ perf report --stdio

# Overhead   Command      Shared Object  Symbol
# ........  ........  .................  ......
#
    70.06%  ints.rkt  [unknown]          [.] 0x5f99b8        
    26.28%  ints.rkt  [kernel.kallsyms]  [k] 0xffffffff8103d0ca
     3.66%  ints.rkt  perf-32046.map     [.] 0x7f1d9be46650  

Which is fairly uninformative.

这是相当不提供信息的。

The relevant program is built with debugging symbols, and the sysprof tool shows the appropriate symbols, as does Zoom, which I think is using perf under the hood.

相关程序是用调试符号构建的,sysprof工具显示适当的符号,如缩放,我认为是在引擎盖下使用perf。

Note that this is on x86-64, so the binary is compiled with -fomit-frame-pointer, but that's the case when running under the other tools as well.

注意,这是在x86-64上,所以二进制文件是用-fomit-frame-pointer编译的,但是在其他工具下运行时也是如此。

8 个解决方案

#1


12  

This post is already over a year old, but since it came out at the top of my Google search results when I had the same problem, I thought I'd answer it here. After some more searching around, I found the answer given in this related * question very helpful. On my Ubuntu Raring system, I then ended up doing the following:

这篇文章已经有一年多的历史了,但是由于它出现在谷歌搜索结果的顶部,当我遇到同样的问题时,我想我应该在这里回答它。经过更多的搜索,我发现这个相关的*问题的答案非常有用。在我的Ubuntu扩声系统上,我最后做了以下事情:

  1. Compile my C++ sources with -g (fairly obvious, you need debug symbols)
  2. 使用-g编译我的c++源代码(很明显,您需要调试符号)
  3. Run perf as

    运行性能

    record -g dwarf -F 97 /path/to/my/program
    

    This way perf is able to handle the DWARF 2 debug format, which is the standard format gcc uses on Linux. The -F 97 parameter reduces the sampling rate to 97 Hz. The default sampling rate was apparently too large for my system and resulted in messages like this:

    这样,perf就可以处理DWARF 2调试格式,这是gcc在Linux上使用的标准格式。f 97参数将采样率降低到97hz。对于我的系统来说,默认的采样率显然太大了,导致了这样的消息:

    Warning:
    Processed 172390 events and lost 126 chunks!
    
    Check IO/CPU overload!
    

    and the perf report call afterwards would fail with a segmentation fault. With the reduced sampling rate everything worked out fine.

    之后的perf报告调用将会由于分割错误而失败。随着采样率的降低,一切都很顺利。

  4. Once the perf.data file has been generated without any errors in the previous step, you can run perf report etc. I personally like the FlameGraph tools to generate SVG visualizations.
  5. 一旦穿孔。在之前的步骤中,没有任何错误生成数据文件,您可以运行perf报告等等。我个人喜欢FlameGraph工具来生成SVG可视化。
  6. Other people reported that running

    另一些人报告说跑步

    echo 0 > /proc/sys/kernel/kptr_restrict
    

    as root can help as well, if kernel symbols are required.

    如果需要内核符号,root也可以提供帮助。

#2


2  

In my case the solution was to delete the elf files which contained cached symbols from previous builds and were messing things up.

在我的例子中,解决方案是删除精灵文件,这些文件包含以前构建的缓存符号,并将其打乱。

They are in ~/.debug/ folder

它们在~/.debug/文件夹中

#3


1  

How about your dev host machine? Is it also running the x86_64 OS? If not, please make sure the perf is cross-compiled, because the perf depends on the objdump and other tools in toolchain.

那么您的开发主机呢?它也运行x86_64操作系统吗?如果没有,请确保perf是交叉编译的,因为perf依赖于objdump和工具链中的其他工具。

#4


1  

Make sure that you compile the program using -g option along with gcc(cc) so that debugging information is produced in the operating system's native format. Try to do the following and check if there are debug symbols present in the symbol table.

确保使用-g选项和gcc(cc)编译程序,以便以操作系统的本机格式生成调试信息。尝试执行以下操作,并检查符号表中是否存在调试符号。

$objdump -t your-elf 
$readelf -a your-elf
$nm -a your-elf

#5


0  

You can always use the '$ nm ' command.

您总是可以使用“$ nm”命令。

here is some sample output:

以下是一些输出示例:

Ethans-MacBook-Pro:~ phyrrus9$ nm a.out
0000000100000000 T __mh_execute_header
0000000100000f30 T _main
                 U _printf
0000000100000f00 T _sigint
                 U _signal
                 U dyld_stub_binder

#6


0  

I got the same problem with perf after overriding the name of my program via prctl(PR_SET_NAME)

在通过prctl(PR_SET_NAME)覆盖程序的名称之后,perf遇到了同样的问题

As I can see your case is pretty similar:

正如我所看到的,你的情况非常相似:

70.06% ints.rkt [unknown]

70.06%的整数。rkt(未知)

Command you have executed (racket) is different from the one perf have seen.

您执行的命令(球拍)与您所看到的不同。

#7


0  

you can check the value of kptr_restrict by cat /proc/kallsyms. If the addresses of the symbols in the result are all 0x000000, you can fix it by command echo 0 > sys/kernel/kptr_restrict . After this , you may get a wanted result of the perf report

您可以通过cat /proc/kallsyms检查kptr_limit的值如果结果中的符号的地址都是0x000000,您可以通过命令echo 0 > sys/kernel/ kptr_limit来修复它。在此之后,您可能会从perf报告中得到想要的结果

#8


0  

I had this problem too, I couldn't see any userspace symbol, but I saw some kernel symbols. I thought this was a symbol loading issue. After tried all the possible solutions I could find, I still couldn't get it work.

我也有这个问题,我看不到任何用户空间符号,但我看到了一些内核符号。我认为这是一个符号加载问题。在尝试了所有可能的解决方案之后,我仍然无法让它发挥作用。

Then I faintly remember that

然后我隐约记得

ulimit -u unlimited

ulimit - u无限

is needed. I tried and it magically worked.

是必要的。我试了试,结果奇迹般地成功了。

I found from this wiki that this command is needed when you use too many file descriptors.

我从这个wiki中发现,当您使用太多的文件描述符时,需要使用这个命令。

https://perf.wiki.kernel.org/index.php/Tutorial#Troubleshooting_and_Tips

https://perf.wiki.kernel.org/index.php/Tutorial Troubleshooting_and_Tips

my final command was

我最后的命令

perf record -F 999 -g ./my_program

记录- f999 -g ./my_program

didn't need --call-graph

不需要调用图

#1


12  

This post is already over a year old, but since it came out at the top of my Google search results when I had the same problem, I thought I'd answer it here. After some more searching around, I found the answer given in this related * question very helpful. On my Ubuntu Raring system, I then ended up doing the following:

这篇文章已经有一年多的历史了,但是由于它出现在谷歌搜索结果的顶部,当我遇到同样的问题时,我想我应该在这里回答它。经过更多的搜索,我发现这个相关的*问题的答案非常有用。在我的Ubuntu扩声系统上,我最后做了以下事情:

  1. Compile my C++ sources with -g (fairly obvious, you need debug symbols)
  2. 使用-g编译我的c++源代码(很明显,您需要调试符号)
  3. Run perf as

    运行性能

    record -g dwarf -F 97 /path/to/my/program
    

    This way perf is able to handle the DWARF 2 debug format, which is the standard format gcc uses on Linux. The -F 97 parameter reduces the sampling rate to 97 Hz. The default sampling rate was apparently too large for my system and resulted in messages like this:

    这样,perf就可以处理DWARF 2调试格式,这是gcc在Linux上使用的标准格式。f 97参数将采样率降低到97hz。对于我的系统来说,默认的采样率显然太大了,导致了这样的消息:

    Warning:
    Processed 172390 events and lost 126 chunks!
    
    Check IO/CPU overload!
    

    and the perf report call afterwards would fail with a segmentation fault. With the reduced sampling rate everything worked out fine.

    之后的perf报告调用将会由于分割错误而失败。随着采样率的降低,一切都很顺利。

  4. Once the perf.data file has been generated without any errors in the previous step, you can run perf report etc. I personally like the FlameGraph tools to generate SVG visualizations.
  5. 一旦穿孔。在之前的步骤中,没有任何错误生成数据文件,您可以运行perf报告等等。我个人喜欢FlameGraph工具来生成SVG可视化。
  6. Other people reported that running

    另一些人报告说跑步

    echo 0 > /proc/sys/kernel/kptr_restrict
    

    as root can help as well, if kernel symbols are required.

    如果需要内核符号,root也可以提供帮助。

#2


2  

In my case the solution was to delete the elf files which contained cached symbols from previous builds and were messing things up.

在我的例子中,解决方案是删除精灵文件,这些文件包含以前构建的缓存符号,并将其打乱。

They are in ~/.debug/ folder

它们在~/.debug/文件夹中

#3


1  

How about your dev host machine? Is it also running the x86_64 OS? If not, please make sure the perf is cross-compiled, because the perf depends on the objdump and other tools in toolchain.

那么您的开发主机呢?它也运行x86_64操作系统吗?如果没有,请确保perf是交叉编译的,因为perf依赖于objdump和工具链中的其他工具。

#4


1  

Make sure that you compile the program using -g option along with gcc(cc) so that debugging information is produced in the operating system's native format. Try to do the following and check if there are debug symbols present in the symbol table.

确保使用-g选项和gcc(cc)编译程序,以便以操作系统的本机格式生成调试信息。尝试执行以下操作,并检查符号表中是否存在调试符号。

$objdump -t your-elf 
$readelf -a your-elf
$nm -a your-elf

#5


0  

You can always use the '$ nm ' command.

您总是可以使用“$ nm”命令。

here is some sample output:

以下是一些输出示例:

Ethans-MacBook-Pro:~ phyrrus9$ nm a.out
0000000100000000 T __mh_execute_header
0000000100000f30 T _main
                 U _printf
0000000100000f00 T _sigint
                 U _signal
                 U dyld_stub_binder

#6


0  

I got the same problem with perf after overriding the name of my program via prctl(PR_SET_NAME)

在通过prctl(PR_SET_NAME)覆盖程序的名称之后,perf遇到了同样的问题

As I can see your case is pretty similar:

正如我所看到的,你的情况非常相似:

70.06% ints.rkt [unknown]

70.06%的整数。rkt(未知)

Command you have executed (racket) is different from the one perf have seen.

您执行的命令(球拍)与您所看到的不同。

#7


0  

you can check the value of kptr_restrict by cat /proc/kallsyms. If the addresses of the symbols in the result are all 0x000000, you can fix it by command echo 0 > sys/kernel/kptr_restrict . After this , you may get a wanted result of the perf report

您可以通过cat /proc/kallsyms检查kptr_limit的值如果结果中的符号的地址都是0x000000,您可以通过命令echo 0 > sys/kernel/ kptr_limit来修复它。在此之后,您可能会从perf报告中得到想要的结果

#8


0  

I had this problem too, I couldn't see any userspace symbol, but I saw some kernel symbols. I thought this was a symbol loading issue. After tried all the possible solutions I could find, I still couldn't get it work.

我也有这个问题,我看不到任何用户空间符号,但我看到了一些内核符号。我认为这是一个符号加载问题。在尝试了所有可能的解决方案之后,我仍然无法让它发挥作用。

Then I faintly remember that

然后我隐约记得

ulimit -u unlimited

ulimit - u无限

is needed. I tried and it magically worked.

是必要的。我试了试,结果奇迹般地成功了。

I found from this wiki that this command is needed when you use too many file descriptors.

我从这个wiki中发现,当您使用太多的文件描述符时,需要使用这个命令。

https://perf.wiki.kernel.org/index.php/Tutorial#Troubleshooting_and_Tips

https://perf.wiki.kernel.org/index.php/Tutorial Troubleshooting_and_Tips

my final command was

我最后的命令

perf record -F 999 -g ./my_program

记录- f999 -g ./my_program

didn't need --call-graph

不需要调用图