libbpf: Add btf__str_by_offset() as a more generic variant of name_by_offset
authorAndrii Nakryiko <andriin@fb.com>
Tue, 29 Sep 2020 02:05:31 +0000 (19:05 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 29 Sep 2020 02:17:13 +0000 (19:17 -0700)
BTF strings are used not just for names, they can be arbitrary strings used
for CO-RE relocations, line/func infos, etc. Thus "name_by_offset" terminology
is too specific and might be misleading. Instead, introduce
btf__str_by_offset() API which uses generic string terminology.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20200929020533.711288-3-andriin@fb.com
tools/lib/bpf/btf.c
tools/lib/bpf/btf.h
tools/lib/bpf/libbpf.map

index 7533088..2d0b1e1 100644 (file)
@@ -1025,7 +1025,7 @@ const void *btf__get_raw_data(const struct btf *btf_ro, __u32 *size)
        return btf->raw_data;
 }
 
-const char *btf__name_by_offset(const struct btf *btf, __u32 offset)
+const char *btf__str_by_offset(const struct btf *btf, __u32 offset)
 {
        if (offset < btf->hdr->str_len)
                return btf->strs_data + offset;
@@ -1033,6 +1033,11 @@ const char *btf__name_by_offset(const struct btf *btf, __u32 offset)
                return NULL;
 }
 
+const char *btf__name_by_offset(const struct btf *btf, __u32 offset)
+{
+       return btf__str_by_offset(btf, offset);
+}
+
 int btf__get_from_id(__u32 id, struct btf **btf)
 {
        struct bpf_btf_info btf_info = { 0 };
index d6629a2..f7dec01 100644 (file)
@@ -49,6 +49,7 @@ LIBBPF_API int btf__fd(const struct btf *btf);
 LIBBPF_API void btf__set_fd(struct btf *btf, int fd);
 LIBBPF_API const void *btf__get_raw_data(const struct btf *btf, __u32 *size);
 LIBBPF_API const char *btf__name_by_offset(const struct btf *btf, __u32 offset);
+LIBBPF_API const char *btf__str_by_offset(const struct btf *btf, __u32 offset);
 LIBBPF_API int btf__get_from_id(__u32 id, struct btf **btf);
 LIBBPF_API int btf__get_map_kv_tids(const struct btf *btf, const char *map_name,
                                    __u32 expected_key_size,
index 0216ee6..6b10eba 100644 (file)
@@ -327,6 +327,7 @@ LIBBPF_0.2.0 {
                btf__add_volatile;
                btf__find_str;
                btf__new_empty;
+               btf__str_by_offset;
                perf_buffer__buffer_cnt;
                perf_buffer__buffer_fd;
                perf_buffer__epoll_fd;