简体   繁体   English

异常:执行 sudo opensnoop-bpfcc 时无法将 BPF 附加到 kprobe

[英]Exception: Failed to attach BPF to kprobe when executing sudo opensnoop-bpfcc

When I try to execute sudo opensnoop-bpfcc I get this message:当我尝试执行sudo opensnoop-bpfcc ,我收到以下消息:

In file included from /virtual/main.c:4:
In file included from include/linux/sched.h:14:
In file included from include/linux/pid.h:5:
In file included from include/linux/rculist.h:11:
In file included from include/linux/rcupdate.h:40:
In file included from include/linux/preempt.h:81:
In file included from ./arch/x86/include/asm/preempt.h:7:
In file included from include/linux/thread_info.h:38:
In file included from ./arch/x86/include/asm/thread_info.h:53:
./arch/x86/include/asm/cpufeature.h:150:2: warning: "Compiler lacks ASM_GOTO support. Add -D __BPF_TRACING__ to your compiler arguments"
      [-W#warnings]
#warning "Compiler lacks ASM_GOTO support. Add -D __BPF_TRACING__ to your compiler arguments"
 ^
1 warning generated.
Traceback (most recent call last):
  File "/usr/sbin/opensnoop-bpfcc", line 127, in <module>
    b.attach_kprobe(event="sys_open", fn_name="trace_entry")
  File "/usr/lib/python2.7/dist-packages/bcc/__init__.py", line 526, in attach_kprobe
    raise Exception("Failed to attach BPF to kprobe")
Exception: Failed to attach BPF to kprobe

I don't understand how to fix it.我不明白如何解决它。 I've just installed bcc tools using this command我刚刚使用此命令安装了密件抄送工具

sudo apt-get install bpfcc-tools linux-headers-$(uname -r)

as suggested on the github page https://github.com/iovisor/bcc/blob/master/INSTALL.md#ubuntu---binary正如 github 页面https://github.com/iovisor/bcc/blob/master/INSTALL.md#ubuntu---binary所建议的那样

The running OS is 18.04.2 LTS (Bionic Beaver).正在运行的操作系统是 18.04.2 LTS(仿生海狸)。

I had to compile bcc from source code instead of installing it using the package.我不得不从源代码编译 bcc 而不是使用包安装它。

1) Install linux kernel headers 1)安装linux内核头文件

sudo apt install linux-headers-$(uname -r)

2) Install required dependencies 2)安装所需的依赖项

sudo apt-get -y install bison build-essential cmake flex git libedit-dev \\ libllvm6.0 llvm-6.0-dev libclang-6.0-dev python zlib1g-dev libelf-dev

3) Compile bcc from source code 3) 从源代码编译 bcc

 git clone github.com/iovisor/bcc.git
 mkdir bcc/build; cd bcc/build 
 cmake .. -DCMAKE_INSTALL_PREFIX=/usr 
 make 
 sudo make install 

@Maicake is right. @Maicake 是对的。 Compiling and installing from source did work for me.从源代码编译和安装确实对我有用。 Here are the steps to install on Ubuntu 22.04:以下是在 Ubuntu 22.04 上安装的步骤:

  1. Follow the steps described here .按照此处描述的步骤进行操作。 Specifically for Ubuntu 22.04 you may need to make some changes after cloning the bcc repository.特别是对于 Ubuntu 22.04,您可能需要在克隆密件抄送存储库后进行一些更改

  2. Add the following line to your .bashrc file:将以下行添加到您的.bashrc文件中:

    export PATH=$PATH:/usr/share/bcc/tools

  3. Create a symlink to python3 as most of the tools use python (not python3 ) to run the scripts.创建指向 python3 的符号链接,因为大多数工具使用python (不是python3 )来运行脚本。

    sudo ln -s /usr/bin/python3 /usr/bin/python

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM