Skip to content

Commit

Permalink
fix: Get bpf prog func name from insns
Browse files Browse the repository at this point in the history
It'll get wrong func name of bpf prog when there are multiple bpf progs
in one BTF.

Instead, get the very first symbol name from bpf prog's instructions as
its entry func name.

Signed-off-by: Leon Hwang <[email protected]>
  • Loading branch information
Asphaltt committed May 30, 2024
1 parent d932b39 commit 22deea6
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions internal/vista/bpf_prog.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"

"github.com/cilium/ebpf"
"github.com/cilium/ebpf/btf"
"golang.org/x/sys/unix"
)

Expand Down Expand Up @@ -50,26 +49,15 @@ func getEntryFuncName(prog *ebpf.Program) (string, string, error) {
return "", "", fmt.Errorf("failed to get program info: %w", err)
}

id, ok := info.BTFID()
if !ok {
return "", "", errNotFound
}

handle, err := btf.NewHandleFromID(id)
if err != nil {
return "", "", fmt.Errorf("failed to get BTF handle: %w", err)
}
defer handle.Close()

spec, err := handle.Spec(nil)
insns, err := info.Instructions()
if err != nil {
return "", "", fmt.Errorf("failed to get BTF spec: %w", err)
return "", "", fmt.Errorf("failed to get program instructions: %w", err)
}

iter := spec.Iterate()
for iter.Next() {
if fn, ok := iter.Type.(*btf.Func); ok {
return fn.Name, info.Name, nil
for _, insn := range insns {
sym := insn.Symbol()
if sym != "" {
return sym, info.Name, nil
}
}

Expand Down

0 comments on commit 22deea6

Please sign in to comment.