我正在使用基于“ubuntu”标签的Docker容器,并且无法获得linux perf工具来显示调试符号.
这是我正在做的来证明这个问题.
首先,我启动一个容器,这里有一个交互式shell.
docker run -t -i ubuntu:14.04 /bin/bash
然后从容器提示我安装linux perf工具.
apt-get update
apt-get install -y linux-tools-common linux-tools-generic linux-tools-`uname -r`
我现在可以使用perf工具了.我的内核是3.16.0-77-generic.
现在我将安装gcc,编译测试程序,并尝试在perf记录下运行它.
apt-get install -y gcc
我将测试程序粘贴到test.c中:
#include dio.h>
int function(int i) {
int j;
for(j = 2; j <= i / 2; j++) {
if (i % j == 0) {
return 0;
}
}
return 1;
}
int main() {
int i;
for(i = 2; i < 100000; i++) {
if(function(i)) {
printf("%d\n",i);
}
}
}
然后编译,运行和报告:
gcc -g -O0 test.c&& perf记录./a.out&& perf报告
输出看起来像这样:
72.38%a.out a.out [.] 0x0000000000000544
8.37%a.out a.out [.] 0x000000000000055a
8.30%a.out a.out [.] 0x000000000000053d
7.81%a.out a.out [.] 0x0000000000000551
0.40%a.out a.out [.] 0x0000000000000540
即使可执行文件具有符号信息,也没有符号.
在容器外执行相同的一般步骤可以正常工作,并显示如下内容:
a.out [.]函数的96.96%
0.35%a.out libc-2.19.so [.] _IO_file_xsputn @@ GLIBC_2.2.5
0.14%a.out [kernel.kallsyms] [k] update_curr
0.12%a.out [kernel.kallsyms] [k] update_cfs_shares
0.11%a.out [kernel.kallsyms] [k] _raw_spin_lock_irqsave
在主机系统中,我已经通过成为root并执行以下内容来打开内核符号:
echo 0>的/ proc / SYS /内核/ kptr_restrict
如何使容器化版本正常工作并显示调试符号?