[PATCH 01/13] lib bpf: Add bpf_program__insns function
From: Jiri Olsa
Date: Mon Mar 12 2018 - 05:48:29 EST
Adding bpf_program__insns helper function to retrieve
prog's instructions. It's used later in the patchset.
Link: http://lkml.kernel.org/n/tip-xvpbbusx8gie33kj0et5wx6l@xxxxxxxxxxxxxx
Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
tools/lib/bpf/libbpf.c | 7 +++++++
tools/lib/bpf/libbpf.h | 3 +++
2 files changed, 10 insertions(+)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 5bbbf285af74..6b9df10470e8 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -261,6 +261,13 @@ struct bpf_object {
};
#define obj_elf_valid(o) ((o)->efile.elf)
+struct bpf_insn*
+bpf_program__insns(struct bpf_program *prog, int *insns_cnt)
+{
+ *insns_cnt = prog->insns_cnt;
+ return prog->insns;
+}
+
static void bpf_program__unload(struct bpf_program *prog)
{
int i;
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index f85906533cdd..bfc4d0411ec5 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -180,6 +180,9 @@ int bpf_program__set_prep(struct bpf_program *prog, int nr_instance,
int bpf_program__nth_fd(struct bpf_program *prog, int n);
+struct bpf_insn*
+bpf_program__insns(struct bpf_program *prog, int *insns_cnt);
+
/*
* Adjust type of bpf program. Default is kprobe.
*/
--
2.13.6