Skip to content

Commit

Permalink
Fix few things
Browse files Browse the repository at this point in the history
  • Loading branch information
marctc committed Nov 12, 2024
1 parent a4c65bc commit 0dec945
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 40 deletions.
7 changes: 4 additions & 3 deletions bpf/go_nethttp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
46 changes: 23 additions & 23 deletions bpf/headers/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)*/

Expand All @@ -59,5 +59,5 @@
"%0 = %[max]\n" \
: "+r"(VAR) \
: [max] "i"(UMAX))

#endif /* __UTILS_H__ */
9 changes: 7 additions & 2 deletions pkg/internal/discover/attacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package discover

import (
"context"
"debug/gosym"
"log/slog"
"os"

Expand Down Expand Up @@ -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)
Expand Down
Binary file removed pkg/internal/ebpf/common/bpf_bpf.o
Binary file not shown.
2 changes: 1 addition & 1 deletion pkg/internal/ebpf/gotracer/bpf_arm64_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/gotracer/bpf_debug_arm64_bpfel.o
Git LFS file not shown
2 changes: 1 addition & 1 deletion pkg/internal/ebpf/gotracer/bpf_debug_x86_bpfel.o
Git LFS file not shown
2 changes: 1 addition & 1 deletion pkg/internal/ebpf/gotracer/bpf_tp_arm64_bpfel.o
Git LFS file not shown
2 changes: 1 addition & 1 deletion pkg/internal/ebpf/gotracer/bpf_tp_debug_arm64_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/gotracer/bpf_tp_debug_x86_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/gotracer/bpf_tp_x86_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/gotracer/bpf_x86_bpfel.o
Git LFS file not shown

0 comments on commit 0dec945

Please sign in to comment.