[英]How to use a struct for golang fuction args in bpftrace
我有以下代码:
package main
import "fmt"
type foo struct {
bar string
some int
}
//go:noinline
func sum(a int, b int) {
fmt.Printf("Sum: %d\n", (a + b))
}
//go:noinline
func (f *foo) baz(value string) string {
return f.bar
}
//go:noinline
func (f *foo) nested(_f foo) foo {
fmt.Printf("Arg value: %s and %d\n", _f.bar, _f.some)
return _f
}
func main() {
f := foo{
bar: "hello world!",
some: 42,
}
fmt.Println(f.baz(f.bar))
sum(1, 2)
temp := f.nested(f)
fmt.Println(temp.bar)
}
按照脚本或我在使用结构定义时正确取消引用字符串结构时遇到问题:
struct args
{
uint64_t array;
uint64_t length;
uint64_t somevalue;
};
uprobe:/tmp/main:0x49aa00 {
$s = (struct args *)(reg("sp") + 16);
$length = *(reg("sp") + 24);
$array = reg("sp") + 16;
printf("length: %d\n", $s->length);
printf("array: %s\n", str(*($array), $length));
printf("somevalue: %d\n", $s->somevalue);
// this one will be empty
printf("array: %s\n", str($s->array, $s->length));
}
Output:
Attaching 1 probe...
length: 12
array: hello world!
somevalue: 42
array:
然而,删除$s->length
打印 64 字节(默认):
hello world!host is downillegal seekinvalid slotlfstack.pushmad
使用reg("sp")
没有任何问题,但是当使用用户定义的结构时,数组似乎是“空的”。 $s->length
似乎是 12,但是当分配给一个额外的变量时,它变成了 2...有人可以帮忙吗?
我已经在 ubuntu 20.04 中用 bpftrace 0.9.4 测试了你的代码,这似乎是同样的问题。
之后我用最新版本构建 bpftrace,一切正常。 你可以试试看。
Attaching 1 probe...
length: 12
array: hello world!
somevalue: 42
array: hello world!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.