From 0dec945d23fe939e9a33e24ec616ecc3db6fed48 Mon Sep 17 00:00:00 2001 From: Marc Tuduri Date: Tue, 12 Nov 2024 10:44:34 +0100 Subject: [PATCH] Fix few things --- bpf/go_nethttp.h | 7 +-- bpf/headers/utils.h | 46 +++++++++--------- pkg/internal/discover/attacher.go | 9 +++- pkg/internal/ebpf/common/bpf_bpf.o | Bin 1968 -> 0 bytes pkg/internal/ebpf/gotracer/bpf_arm64_bpfel.o | 2 +- .../ebpf/gotracer/bpf_debug_arm64_bpfel.o | 4 +- .../ebpf/gotracer/bpf_debug_x86_bpfel.o | 2 +- .../ebpf/gotracer/bpf_tp_arm64_bpfel.o | 2 +- .../ebpf/gotracer/bpf_tp_debug_arm64_bpfel.o | 2 +- .../ebpf/gotracer/bpf_tp_debug_x86_bpfel.o | 4 +- pkg/internal/ebpf/gotracer/bpf_tp_x86_bpfel.o | 4 +- pkg/internal/ebpf/gotracer/bpf_x86_bpfel.o | 4 +- 12 files changed, 46 insertions(+), 40 deletions(-) delete mode 100644 pkg/internal/ebpf/common/bpf_bpf.o diff --git a/bpf/go_nethttp.h b/bpf/go_nethttp.h index 6d3bf468d..357e2fdd4 100644 --- a/bpf/go_nethttp.h +++ b/bpf/go_nethttp.h @@ -267,9 +267,9 @@ int uprobe_ServeHTTPReturns(struct pt_regs *ctx) { trace->type = EVENT_HTTP_REQUEST; trace->start_monotime_ns = invocation->start_monotime_ns; trace->end_monotime_ns = bpf_ktime_get_ns(); - if (error) + if (error) { trace->error = *error; - + } goroutine_metadata *g_metadata = bpf_map_lookup_elem(&ongoing_goroutines, &g_key); if (g_metadata) { trace->go_start_monotime_ns = g_metadata->timestamp; @@ -503,8 +503,9 @@ int uprobe_error(struct pt_regs *ctx) { .cpu_id = cpu_id, }; - if (bpf_get_current_comm(event.comm, sizeof(event.comm))) + if (bpf_get_current_comm(event.comm, sizeof(event.comm))) { event.comm[0] = 0; + } // Read the stack trace event.ustack_sz = bpf_get_stack(ctx, event.ustack, sizeof(event.ustack), BPF_F_USER_STACK); diff --git a/bpf/headers/utils.h b/bpf/headers/utils.h index 217ef671d..7ea2c6b27 100644 --- a/bpf/headers/utils.h +++ b/bpf/headers/utils.h @@ -21,36 +21,36 @@ #if defined(__TARGET_ARCH_x86) -#define GO_PARAM1(x) ((void*)(x)->ax) -#define GO_PARAM2(x) ((void*)(x)->bx) -#define GO_PARAM3(x) ((void*)(x)->cx) -#define GO_PARAM4(x) ((void*)(x)->di) -#define GO_PARAM5(x) ((void*)(x)->si) -#define GO_PARAM6(x) ((void*)(x)->r8) -#define GO_PARAM7(x) ((void*)(x)->r9) -#define GO_PARAM8(x) ((void*)(x)->r10) -#define GO_PARAM9(x) ((void*)(x)->r11) +#define GO_PARAM1(x) ((void *)(x)->ax) +#define GO_PARAM2(x) ((void *)(x)->bx) +#define GO_PARAM3(x) ((void *)(x)->cx) +#define GO_PARAM4(x) ((void *)(x)->di) +#define GO_PARAM5(x) ((void *)(x)->si) +#define GO_PARAM6(x) ((void *)(x)->r8) +#define GO_PARAM7(x) ((void *)(x)->r9) +#define GO_PARAM8(x) ((void *)(x)->r10) +#define GO_PARAM9(x) ((void *)(x)->r11) // In x86, current goroutine is pointed by r14, according to // https://go.googlesource.com/go/+/refs/heads/dev.regabi/src/cmd/compile/internal-abi.md#amd64-architecture -#define GOROUTINE_PTR(x) ((void*)(x)->r14) -#define STACK_PTR(x) ((void*)(x)->sp) +#define GOROUTINE_PTR(x) ((void *)(x)->r14) +#define STACK_PTR(x) ((void *)(x)->sp) #elif defined(__TARGET_ARCH_arm64) -#define GO_PARAM1(x) ((void*)((PT_REGS_ARM64 *)(x))->regs[0]) -#define GO_PARAM2(x) ((void*)((PT_REGS_ARM64 *)(x))->regs[1]) -#define GO_PARAM3(x) ((void*)((PT_REGS_ARM64 *)(x))->regs[2]) -#define GO_PARAM4(x) ((void*)((PT_REGS_ARM64 *)(x))->regs[3]) -#define GO_PARAM5(x) ((void*)((PT_REGS_ARM64 *)(x))->regs[4]) -#define GO_PARAM6(x) ((void*)((PT_REGS_ARM64 *)(x))->regs[5]) -#define GO_PARAM7(x) ((void*)((PT_REGS_ARM64 *)(x))->regs[6]) -#define GO_PARAM8(x) ((void*)((PT_REGS_ARM64 *)(x))->regs[7]) -#define GO_PARAM9(x) ((void*)((PT_REGS_ARM64 *)(x))->regs[8]) +#define GO_PARAM1(x) ((void *)((PT_REGS_ARM64 *)(x))->regs[0]) +#define GO_PARAM2(x) ((void *)((PT_REGS_ARM64 *)(x))->regs[1]) +#define GO_PARAM3(x) ((void *)((PT_REGS_ARM64 *)(x))->regs[2]) +#define GO_PARAM4(x) ((void *)((PT_REGS_ARM64 *)(x))->regs[3]) +#define GO_PARAM5(x) ((void *)((PT_REGS_ARM64 *)(x))->regs[4]) +#define GO_PARAM6(x) ((void *)((PT_REGS_ARM64 *)(x))->regs[5]) +#define GO_PARAM7(x) ((void *)((PT_REGS_ARM64 *)(x))->regs[6]) +#define GO_PARAM8(x) ((void *)((PT_REGS_ARM64 *)(x))->regs[7]) +#define GO_PARAM9(x) ((void *)((PT_REGS_ARM64 *)(x))->regs[8]) // In arm64, current goroutine is pointed by R28 according to // https://github.com/golang/go/blob/master/src/cmd/compile/abi-internal.md#arm64-architecture -#define GOROUTINE_PTR(x) ((void*)((PT_REGS_ARM64 *)(x))->regs[28]) -#define STACK_PTR(x) ((void*)((PT_REGS_ARM64 *)(x))->regs[13]) +#define GOROUTINE_PTR(x) ((void *)((PT_REGS_ARM64 *)(x))->regs[28]) +#define STACK_PTR(x) ((void *)((PT_REGS_ARM64 *)(x))->regs[13]) #endif /*defined(__TARGET_ARCH_arm64)*/ @@ -59,5 +59,5 @@ "%0 = %[max]\n" \ : "+r"(VAR) \ : [max] "i"(UMAX)) - + #endif /* __UTILS_H__ */ diff --git a/pkg/internal/discover/attacher.go b/pkg/internal/discover/attacher.go index bff4bbfdb..6f533be58 100644 --- a/pkg/internal/discover/attacher.go +++ b/pkg/internal/discover/attacher.go @@ -2,6 +2,7 @@ package discover import ( "context" + "debug/gosym" "log/slog" "os" @@ -285,9 +286,13 @@ func (ta *TraceAttacher) monitorPIDs(tracer *ebpf.ProcessTracer, ie *ebpf.Instru ie.FileInfo.Service.SDKLanguage = ie.Type // allowing the tracer to forward traces from the discovered PID and its children processes - tracer.AllowPID(uint32(ie.FileInfo.Pid), ie.FileInfo.Ns, &ie.FileInfo.Service, ie.Offsets.SymTab) + var symTab *gosym.Table + if ie.Offsets != nil && ie.Offsets.SymTab != nil { + symTab = ie.Offsets.SymTab + } + tracer.AllowPID(uint32(ie.FileInfo.Pid), ie.FileInfo.Ns, &ie.FileInfo.Service, symTab) for _, pid := range ie.ChildPids { - tracer.AllowPID(pid, ie.FileInfo.Ns, &ie.FileInfo.Service, ie.Offsets.SymTab) + tracer.AllowPID(pid, ie.FileInfo.Ns, &ie.FileInfo.Service, symTab) } if ta.SpanSignalsShortcut != nil { spans := make([]request.Span, 0, len(ie.ChildPids)+1) diff --git a/pkg/internal/ebpf/common/bpf_bpf.o b/pkg/internal/ebpf/common/bpf_bpf.o deleted file mode 100644 index d175481fa9ef5ee390a17a86dfee9d6a8ed32f71..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1968 zcmb_dJ8u&~5FRH1Oaci3!Ye!+l!7!?5<+A_frI1-q)4EUB7tIY?8RrrcW3VQq6Cnj zKmsZX3Mh~e1rkC+@Cy(H5)}LZL_tM^_yM7VZ}#T=0#PyY?Dy?Fc6Mj)&bJD4vt6ka zC6b~IYR(cX(VI<8p0_klX+%E#k)nO#8to=xebro`tE-vT3s+UU zq(l}xEjl517C0;X9&l0kN1y}k<2ma3!0pf+xB>P<7g6j6a1iQ%-vy?jKT+@za3?gk zndphwb4Yp)z6-hr{u;Ok`WXBza6j}j_(D?d4}(9D963wsq4+ZJ ziP(Pe9ddp~jDWU2vi(_{+t0xI0t0@0Ep(Iz2={^iKP z4vm?r`+=d7?-}hGwpOr`Ud4o>94Un%^1^Dx)8$ObDFzfxPq7(e!(Q{fN`?nGX6EN- zmej>_mkMfO=|Vv%iYBHx0b?T}bhv1Ae3Bg)8;&ZM_v@_GG&*;kgw}s!q4(x{3zHkd%s{) z_UXU_4$jX4WsP1l@sinEZPm4RfZjEVg(fh?Wy*%@uEjvtvS$`%Irl%v2-c7-wXIf{ zkMGGgtL(YO#%EyV?^3JeTPH1?&)q8gedOMB?jbKhN#A4|zbDBAcmits*kWUvm-+XO zf*n)h{}X