Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/proc: add support for more types in ebpf tracing backend #3474

Merged
merged 3 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions _fixtures/ebpf_trace3.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"fmt"
"time"
)

func main() {
str := "abcdefghijklmnopqrstuvqxyz"
i := int64(0)
for i = 0; i < 5; i++ {
tracedFunction(i, i%5 == 0, str[i])
}
for i = 5; i < 10; i++ {
tracedFunction(i, i%5 == 0, str[i])
time.Sleep(time.Millisecond)
}
}

//go:noinline
func tracedFunction(x int64, b bool, r byte) {
fmt.Println(x, b, r)
}
52 changes: 50 additions & 2 deletions cmd/dlv/dlv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1098,10 +1098,10 @@ func TestTraceEBPF(t *testing.T) {
output, err := ioutil.ReadAll(rdr)
assertNoError(err, t, "ReadAll")

cmd.Wait()
if !bytes.Contains(output, expected) {
t.Fatalf("expected:\n%s\ngot:\n%s", string(expected), string(output))
}
cmd.Wait()
}

func TestTraceEBPF2(t *testing.T) {
Expand Down Expand Up @@ -1158,10 +1158,10 @@ func TestTraceEBPF2(t *testing.T) {
output, err := ioutil.ReadAll(rdr)
assertNoError(err, t, "ReadAll")

cmd.Wait()
if !bytes.Contains(output, expected) {
t.Fatalf("expected:\n%s\ngot:\n%s", string(expected), string(output))
}
cmd.Wait()
}

func TestTraceEBPF3(t *testing.T) {
Expand Down Expand Up @@ -1206,10 +1206,58 @@ func TestTraceEBPF3(t *testing.T) {
output, err := ioutil.ReadAll(rdr)
assertNoError(err, t, "ReadAll")

cmd.Wait()
if !bytes.Contains(output, expected) {
t.Fatalf("expected:\n%s\ngot:\n%s", string(expected), string(output))
}
}

func TestTraceEBPF4(t *testing.T) {
if os.Getenv("CI") == "true" {
t.Skip("cannot run test in CI, requires kernel compiled with btf support")
}
if runtime.GOOS != "linux" || runtime.GOARCH != "amd64" {
t.Skip("not implemented on non linux/amd64 systems")
}
if !goversion.VersionAfterOrEqual(runtime.Version(), 1, 16) {
t.Skip("requires at least Go 1.16 to run test")
}
usr, err := user.Current()
if err != nil {
t.Fatal(err)
}
if usr.Uid != "0" {
t.Skip("test must be run as root")
}

dlvbin := getDlvBinEBPF(t)

expected := []byte(`> (1) main.tracedFunction(0, true, 97)
> (1) main.tracedFunction(1, false, 98)
> (1) main.tracedFunction(2, false, 99)
> (1) main.tracedFunction(3, false, 100)
> (1) main.tracedFunction(4, false, 101)
> (1) main.tracedFunction(5, true, 102)
> (1) main.tracedFunction(6, false, 103)
> (1) main.tracedFunction(7, false, 104)
> (1) main.tracedFunction(8, false, 105)
> (1) main.tracedFunction(9, false, 106)`)

fixtures := protest.FindFixturesDir()
cmd := exec.Command(dlvbin, "trace", "--ebpf", "--output", filepath.Join(t.TempDir(), "__debug"), filepath.Join(fixtures, "ebpf_trace3.go"), "main.traced")
rdr, err := cmd.StderrPipe()
assertNoError(err, t, "stderr pipe")
defer rdr.Close()

assertNoError(cmd.Start(), t, "running trace")

output, err := ioutil.ReadAll(rdr)
assertNoError(err, t, "ReadAll")

cmd.Wait()
if !bytes.Contains(output, expected) {
t.Fatalf("expected:\n%s\ngot:\n%s", string(expected), string(output))
}
}

func TestDlvTestChdir(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/proc/internal/ebpf/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ func parseFunctionParameterList(rawParamBytes []byte) RawUProbeParams {
iparam.Addr = FakeAddressBase

switch iparam.Kind {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
iparam.RealType = &godwarf.UintType{BasicType: godwarf.BasicType{CommonType: godwarf.CommonType{ByteSize: 8}}}
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Bool:
iparam.RealType = &godwarf.IntType{BasicType: godwarf.BasicType{CommonType: godwarf.CommonType{ByteSize: 8}}}
case reflect.String:
strLen := binary.LittleEndian.Uint64(val[8:])
Expand Down