[RFC PATCH v2 16/26] perf bpf: Add method for fetching nth ubpf vm

From: He Kuang
Date: Sun Jun 26 2016 - 07:23:36 EST


Same as bpf_program__fd() and bpf_program__nth_fd(), add methods for
fetching the nth ubpf entry.

Signed-off-by: He Kuang <hekuang@xxxxxxxxxx>
Signed-off-by: Wang Nan <wangnan0@xxxxxxxxxx>
---
tools/lib/bpf/libbpf.c | 14 ++++++++++++++
tools/lib/bpf/libbpf.h | 1 +
2 files changed, 15 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index b738ef2..7e77cc2 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1132,6 +1132,20 @@ int bpf_program__fd(struct bpf_program *prog)
return bpf_program__nth_fd(prog, 0);
}

+static void *bpf_program__nth_vm(struct bpf_program *prog, int n)
+{
+ void *ret;
+
+ prog->engine->get_nth(prog, n, &ret);
+
+ return ret;
+}
+
+void *bpf_program__vm(struct bpf_program *prog)
+{
+ return bpf_program__nth_vm(prog, 0);
+}
+
int bpf_program__set_prep(struct bpf_program *prog, int nr_instances,
bpf_program_prep_t prep)
{
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 996862f..b0e6c68 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -87,6 +87,7 @@ void *bpf_program__priv(struct bpf_program *prog);
const char *bpf_program__title(struct bpf_program *prog, bool needs_copy);

int bpf_program__fd(struct bpf_program *prog);
+void *bpf_program__vm(struct bpf_program *prog);

struct bpf_insn;

--
1.8.5.2