trace.py support for args with Go's gc compiler
- Dominant language
- C
- Stars
- 22.7k
- Forks
- 4.1k
- Avg merge
- 10d 4h
- Merged PRs (30d)
- 3
Description
trace's arg# aliases work with Go when compiled with gccgo ("gccgo -o hello hello.go"). But Go's gc compiler ("go build hello.go") uses a different function calling convention, based on the Plan 9 compiler.
Is it important to fix this? Does everyone run gccgo binaries (where trace already works), because they are expected to be faster, and not Go's compiler? I don't know. I've added a prio:low tag for now.
I wrote some quick docs on the issues here: http://www.brendangregg.com/blog/2017-01-31/golang-bcc-bpf-function-tracing.html
And included a proof of concept:
```
# trace '/home/bgregg/functions:main.add "%d %d" go1, go2'
PID TID COMM FUNC -
17555 17555 functions main.add 42 13
```
The change I made was a dirty hack, and needs to be rewritten properly. I'd done this:
```diff
# diff -u trace.py trace-go.py
--- trace.py 2017-02-01 19:34:01.477727396 +0000
+++ trace-go.py 2017-02-02 09:28:23.796606244 +0000
@@ -209,6 +209,8 @@
aliases = {
"retval": "PT_REGS_RC(ctx)",
+ "go1": "1;bpf_probe_read(&__data.v0,sizeof(__data.v0),(void *)ctx->sp+8)",
+ "go2": "1;bpf_probe_read(&__data.v1,sizeof(__data.v1),(void *)ctx->sp+16)",
"arg1": "PT_REGS_PARM1(ctx)",
"arg2": "PT_REGS_PARM2(ctx)",
"arg3": "PT_REGS_PARM3(ctx)",
```
They should be "goarg1", "goarg1", etc. I suspect this also needs to be done differently so that they can be used in tests, eg, "(goarg1 == 42)". And this should use macros instead of ctx->sp.
I'd also check the following resources to confirm that this approach is valid:
- https://golang.org/doc/asm
- https://9p.io/sys/doc/asm.html
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in trace.py at the aliases handling and compare the proof of concept with the Go assembly and Plan 9 compiler documentation linked in the issue. Validate against a hello.go binary built with go build rather than gccgo, using the shown trace invocation. Done means Go compiler argument aliases work and can be used in conditional expressions and tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, python
- Domain
- devtools, observability-sre
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100