首页 > 解决方案 > “符号”列显示地址而不是函数名

问题描述

这是我的系统信息。

$ uname -a
Linux pjchiou-X550JX 4.16.0-041600-generic #201804012230 SMP Sun Apr 1 22:31:39 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

我用一个很简单的 C 程序来测试perf

#include <stdio.h>
#include <stdlib.h>

void myloop()
{
    for (int i = 0; i < 100000; i++)
        printf("%d", i);
}

int main(void)
{
    myloop();
    return (0);
}

编译:

gcc -g -o test test.c

然后收集样本:

perf record ./test

最后,展示报告:

perf report

但是,我在报告中看到的是这样的:

# Overhead  Command  Shared Object      Symbol                      
# ........  .......  .................  ............................
#
 9.64%  test     libc-2.27.so       [.] 0x000000000005cb14
 6.17%  test     libc-2.27.so       [.] 0x000000000005bf8e
 5.75%  test     libc-2.27.so       [.] 0x000000000005885e
 5.61%  test     libc-2.27.so       [.] 0x000000000005886b
 5.33%  test     libc-2.27.so       [.] 0x00000000000587b0
 5.28%  test     libc-2.27.so       [.] 0x000000000005b6ff
 5.23%  test     [kernel.kallsyms]  [k] n_tty_write

为什么“符号”列显示的是地址而不是函数名?

标签: clinuxperf

解决方案


使用以下命令为 libc 安装调试符号以获取库函数的名称。

sudo apt-get install libc6-dbg
sudo apt-get source libc6-dev

推荐阅读