MCPcopy
hub / github.com/cilium/ebpf / DocLoadCollectionSpec

Function DocLoadCollectionSpec

docs/examples/docs_test.go:11–34  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9)
10
11func DocLoadCollectionSpec() {
12 // Parse an ELF into a CollectionSpec.
13 // bpf_prog.o is the result of compiling BPF C code.
14 spec, err := ebpf.LoadCollectionSpec("bpf_prog.o")
15 if err != nil {
16 panic(err)
17 }
18
19 // Look up the MapSpec and ProgramSpec in the CollectionSpec.
20 m := spec.Maps["my_map"]
21 p := spec.Programs["my_prog"]
22 // Note: We've omitted nil checks for brevity, take a look at
23 // LoadAndAssign for an automated way of checking for maps/programs.
24
25 // Inspect the map and program type.
26 fmt.Println(m.Type, p.Type)
27
28 // Print the map's key and value BTF types.
29 fmt.Println(m.Key, m.Value)
30
31 // Print the program's instructions in a human-readable form,
32 // similar to llvm-objdump -S.
33 fmt.Println(p.Instructions)
34}
35
36func DocNewCollection() {
37 spec, err := ebpf.LoadCollectionSpec("bpf_prog.o")

Callers

nothing calls this directly

Calls 1

LoadCollectionSpecFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…