mirror of
https://github.com/eunomia-bpf/bpf-developer-tutorial.git
synced 2026-04-05 03:28:50 +08:00
Deploying to gh-pages from @ eunomia-bpf/bpf-developer-tutorial@4671af2739 🚀
This commit is contained in:
4
38-btf-uprobe/examples/.gitignore
vendored
Normal file
4
38-btf-uprobe/examples/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
*.o
|
||||
*.btf
|
||||
btf-base
|
||||
btf-base-new
|
||||
35
38-btf-uprobe/examples/Makefile
Normal file
35
38-btf-uprobe/examples/Makefile
Normal file
@@ -0,0 +1,35 @@
|
||||
# BPF compiler
|
||||
BPF_CC = clang
|
||||
# BPF C flags
|
||||
BPF_CFLAGS = -O2 -target bpf -c -g
|
||||
# BPF source files
|
||||
BPF_SRCS = $(wildcard *.bpf.c)
|
||||
# BPF object files
|
||||
BPF_OBJS = $(BPF_SRCS:.c=.o)
|
||||
|
||||
all: $(BPF_OBJS) base.btf btf-base btf-base-new base-new.btf
|
||||
|
||||
%.bpf.o: %.bpf.c
|
||||
$(BPF_CC) $(BPF_CFLAGS) $< -o $@
|
||||
|
||||
btf-base.o: btf-base.c
|
||||
clang -g -c btf-base.c -o btf-base.o
|
||||
|
||||
btf-base-new.o: btf-base-new.c
|
||||
clang -g -c btf-base-new.c -o btf-base-new.o
|
||||
|
||||
base.btf: btf-base.o
|
||||
pahole --btf_encode_detached base.btf btf-base.o
|
||||
|
||||
base-new.btf: btf-base-new.o
|
||||
pahole --btf_encode_detached base-new.btf btf-base-new.o
|
||||
|
||||
btf-base: btf-base.o
|
||||
clang -g btf-base.o -o btf-base
|
||||
|
||||
btf-base-new: btf-base-new.o
|
||||
clang -g btf-base-new.o -o btf-base-new
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.o *.btf btf-base btf-base-new
|
||||
19
38-btf-uprobe/examples/btf-base-new.c
Normal file
19
38-btf-uprobe/examples/btf-base-new.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <stdio.h>
|
||||
|
||||
struct data {
|
||||
int a;
|
||||
int b;
|
||||
int c;
|
||||
int d;
|
||||
};
|
||||
|
||||
int add_test(struct data *d) {
|
||||
return d->a + d->c;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
struct data d = {1, 2, 3, 4};
|
||||
printf("add_test(&d) = %d\n", add_test(&d));
|
||||
return 0;
|
||||
}
|
||||
|
||||
19
38-btf-uprobe/examples/btf-base.c
Normal file
19
38-btf-uprobe/examples/btf-base.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <stdio.h>
|
||||
|
||||
// use a different struct
|
||||
struct data {
|
||||
int a;
|
||||
int c;
|
||||
int d;
|
||||
};
|
||||
|
||||
int add_test(struct data *d) {
|
||||
return d->a + d->c;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
struct data d = {1, 3, 4};
|
||||
printf("add_test(&d) = %d\n", add_test(&d));
|
||||
return 0;
|
||||
}
|
||||
|
||||
19
38-btf-uprobe/examples/btf-relo.bpf.c
Normal file
19
38-btf-uprobe/examples/btf-relo.bpf.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef BPF_NO_PRESERVE_ACCESS_INDEX
|
||||
#pragma clang attribute push (__attribute__((preserve_access_index)), apply_to = record)
|
||||
#endif
|
||||
|
||||
struct data {
|
||||
int a;
|
||||
int c;
|
||||
int d;
|
||||
};
|
||||
|
||||
#ifndef BPF_NO_PRESERVE_ACCESS_INDEX
|
||||
#pragma clang attribute pop
|
||||
#endif
|
||||
|
||||
|
||||
int add_test(struct data *d) {
|
||||
return d->a + d->c;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user