我已经编写了一个func.bt文件来使用我的kprobe例程中的结构。
/* func.bt */
struct FUNC_PARAMS
{
unsigned int client;
void * params;
unsigned int paramsSize;
unsigned int status;
};
/* This script provides a reasonable estimate of the time spent
* in processessing ioctls.
*/
BEGIN
但是,当我运行bpftrace func.bt
时,我得到以下错误:
func.bt:34:19-41: ERROR: Unknown struct/union: 'FUNC_PARAMS'
完整的脚本:
struct FUNC_PARAMS
{
unsigned int client;
unsigned int paramsSize;
void *data;
unsigned int status;
};
kprobe:is_ioctl
{
@start[comm] = nsecs;
$temp = arg3;
@call_count[comm,$temp] = count(); // per process, per ioctl number count of ioctl calls
$client = ((FUNC_PARAMS *)arg2)->client;
printf("client: %x \n", $client);
}
kretprobe:is_ioctl /@start[comm]/
{
$delta = nsecs - @start[comm];
delete(@start[comm]);
}
有没有人能提供一些关于如何正确使用这个结构的建议?
发布于 2020-06-24 19:15:30
这是因为就像在C中一样,你不能直接用你给它的名字来调用一个结构:FUNC_PARAMS
是未知的,你需要用到。替换:
$client = ((FUNC_PARAMS *)arg2)->client;
使用
$client = ((struct FUNC_PARAMS *)arg2)->client;
似乎解决了这个问题。在C语言中,人们有时会像您尝试的那样添加一个typedef struct FUNC_PARAMS FUNC_PARAMS
来使用FUNC_PARAMS
,但我不确定bpftrace是否支持typedef
s (我也不推荐使用using it )。
通过上面的更改,bpftrace更进一步,并抱怨:
Attaching 2 probes...
cannot attach kprobe, Invalid argument
Error attaching probe: 'kretprobe:is_ioctl'
在我看来,它似乎找不到您想要附加的is_ioctl
函数(实际上,我在我的系统/proc/kallsyms或内核源代码中也没有看到这样的函数)。
https://stackoverflow.com/questions/62515301
复制相似问题