我有一些代码(myclient)。它看起来像这样(这里只有 mypackage 是相关的):
package mypackage
import (
...
func (o *Client) CreateUser(ctx context.Context, user *User, ...) (User, error) {
...
if err != nil ...
return nil, err
...
return &user, nil
}
我跑去go build -o build/myclient cmd/myclient/main.go
获取二进制文件。
λ bob [~] → objdump -t ~/go/src/github.com/Corp/myclient/build/myclient | grep CreateUser
....
000000000087d490 l F .text 0000000000000e55 github.com/Corp/myclient.(*Client).CreateUser
现在这个二进制文件被其他一些 go 程序使用并被加载。
不知何故像这样:
bob 745322 0.1 0.1 195556 33172 pts/1 Sl+ 20:18 0:07 some-prog
bob 750774 0.0 0.0 1229316 14188 pts/1 Sl+ 20:22 0:00 /home/bob/go/src/github.com/Corp/myclient/build/myclient
现在我尝试使用 BCC 工具进行跟踪/调试。原因是生产中发生了一些奇怪的错误,查看上面函数的参数和返回值很重要。我受到了启发:http ://www.brendangregg.com/blog/2017-01-31/golang-bcc-bpf-function-tracing.html
使用时,funccount
我在这里看到了这个(在通过调用 some-prog 调用函数之后)
λ bob [~] → sudo funccount '/home/bob/go/src/github.com/Corp/myclient/build/myclient:*.CreateUser'
Tracing 5 functions for "b'/home/bob/go/src/github.com/Corp/myclient/build/myclient:*.CreateUser'"... Hit Ctrl-C to end.
^C
FUNC COUNT
...
b'github.com/Corp/myclient.(*Client).CreateUser' 1
Detaching...
但是当我尝试使用trace
(或gotrace
)时,它看起来像这样:
λ bob [~] → trace '/home/bob/go/src/github.com/Corp/myclient/build/myclient:mypackage.*'
could not determine address of symbol b'mypackage.*'
λ bob [~] → trace '/home/bob/go/src/github.com/Corp/myclient/build/myclient:github.com/Corp/myclient.CreateUser'
could not determine address of symbol b'github.com/Corp/myclient.CreateUser'
λ bob [~] → trace '/home/bob/go/src/github.com/Corp/myclient/build/myclient:github.com/Corp/myclient.(*Client).CreateUser'
error in probe '/home/bob/go/src/github.com/Corp/myclient/build/myclient:github.com/Corp/myclient.(*Client).CreateUser': expected format string in "s
λ bob [~] → trace '/home/bob/go/src/github.com/Corp/myclient/build/myclient:*.CreateUser'
could not determine address of symbol b'*.CreateUser'
是否有可能使用 BCC 工具或 eBPF/(bpftrace?) 跟踪这样的 go-function(特别是检查结构参数和返回值)(不添加任何代码)