gpt4 book ai didi

Linux 跟踪/trace_pipe 文件不可读 (debugfs)

转载 作者:行者123 更新时间:2023-12-04 19:24:29 26 4
gpt4 key购买 nike

我有写入 trace_pipe 文件的 BPF 程序,即使程序正确执行,我也无法从该文件中读取数据。
每当我尝试 cat /sys/kernel/debug/tracing/trace_pipe ,进程卡住,没有任何输出显示。
enter image description here
我已经通过运行手动安装了 debugfs:mount -t debugfs none /sys/kernel/debug当我尝试 cat、tail、vi 或以某种方式读取此文件的内容时,结果是相同的。
即使在我挂载 debugfs 之后,“trace_pipe”文件也无法读取,所以我认为这与我的 BPF 代码执行无关。
这个文件根本不可读,我想了解我应该怎么做才能读取它。
我可以确认 debugfs 已正确安装,并且该文件确实存在:
enter image description here
enter image description here
我很感激有关如何阅读此文件的任何提示。

最佳答案

所以这只是你的 eBPF 程序中的一个错误。从您的链接:

int my_pid = 0;

SEC("tp/syscalls/sys_enter_write")
int handle_tp(void *ctx)
{
int pid = bpf_get_current_pid_tgid() >> 32;

if (pid != my_pid)
return 0;

bpf_printk("BPF triggered from PID %d.\n", pid);

return 0;
}
if (pid != my_pid) return 0; , 与 my_pid = 0 , 意味着您每次收集的 PID 为非 0 时退出 - 这几乎一直都是。所以你的程序提前退出,你没有机会执行对 bpf_printk() 的调用。并将数据发送到跟踪管道。

关于Linux 跟踪/trace_pipe 文件不可读 (debugfs),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72447692/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com