mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-15 16:53:54 +08:00
tools/bpftool: Add bpftool support for split BTF
Add ability to work with split BTF by providing extra -B flag, which allows to specify the path to the base BTF file. Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Song Liu <songliubraving@fb.com> Link: https://lore.kernel.org/bpf/20201105043402.2530976-12-andrii@kernel.org
This commit is contained in:
parent
232338fa2f
commit
75fa177769
@ -358,8 +358,12 @@ static int dump_btf_raw(const struct btf *btf,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int cnt = btf__get_nr_types(btf);
|
int cnt = btf__get_nr_types(btf);
|
||||||
|
int start_id = 1;
|
||||||
|
|
||||||
for (i = 1; i <= cnt; i++) {
|
if (base_btf)
|
||||||
|
start_id = btf__get_nr_types(base_btf) + 1;
|
||||||
|
|
||||||
|
for (i = start_id; i <= cnt; i++) {
|
||||||
t = btf__type_by_id(btf, i);
|
t = btf__type_by_id(btf, i);
|
||||||
dump_btf_type(btf, i, t);
|
dump_btf_type(btf, i, t);
|
||||||
}
|
}
|
||||||
@ -438,7 +442,6 @@ static int do_dump(int argc, char **argv)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
src = GET_ARG();
|
src = GET_ARG();
|
||||||
|
|
||||||
if (is_prefix(src, "map")) {
|
if (is_prefix(src, "map")) {
|
||||||
struct bpf_map_info info = {};
|
struct bpf_map_info info = {};
|
||||||
__u32 len = sizeof(info);
|
__u32 len = sizeof(info);
|
||||||
@ -499,7 +502,7 @@ static int do_dump(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
} else if (is_prefix(src, "file")) {
|
} else if (is_prefix(src, "file")) {
|
||||||
btf = btf__parse(*argv, NULL);
|
btf = btf__parse_split(*argv, base_btf);
|
||||||
if (IS_ERR(btf)) {
|
if (IS_ERR(btf)) {
|
||||||
err = -PTR_ERR(btf);
|
err = -PTR_ERR(btf);
|
||||||
btf = NULL;
|
btf = NULL;
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include <bpf/bpf.h>
|
#include <bpf/bpf.h>
|
||||||
#include <bpf/libbpf.h>
|
#include <bpf/libbpf.h>
|
||||||
|
#include <bpf/btf.h>
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ bool show_pinned;
|
|||||||
bool block_mount;
|
bool block_mount;
|
||||||
bool verifier_logs;
|
bool verifier_logs;
|
||||||
bool relaxed_maps;
|
bool relaxed_maps;
|
||||||
|
struct btf *base_btf;
|
||||||
struct pinned_obj_table prog_table;
|
struct pinned_obj_table prog_table;
|
||||||
struct pinned_obj_table map_table;
|
struct pinned_obj_table map_table;
|
||||||
struct pinned_obj_table link_table;
|
struct pinned_obj_table link_table;
|
||||||
@ -391,6 +393,7 @@ int main(int argc, char **argv)
|
|||||||
{ "mapcompat", no_argument, NULL, 'm' },
|
{ "mapcompat", no_argument, NULL, 'm' },
|
||||||
{ "nomount", no_argument, NULL, 'n' },
|
{ "nomount", no_argument, NULL, 'n' },
|
||||||
{ "debug", no_argument, NULL, 'd' },
|
{ "debug", no_argument, NULL, 'd' },
|
||||||
|
{ "base-btf", required_argument, NULL, 'B' },
|
||||||
{ 0 }
|
{ 0 }
|
||||||
};
|
};
|
||||||
int opt, ret;
|
int opt, ret;
|
||||||
@ -407,7 +410,7 @@ int main(int argc, char **argv)
|
|||||||
hash_init(link_table.table);
|
hash_init(link_table.table);
|
||||||
|
|
||||||
opterr = 0;
|
opterr = 0;
|
||||||
while ((opt = getopt_long(argc, argv, "Vhpjfmnd",
|
while ((opt = getopt_long(argc, argv, "VhpjfmndB:",
|
||||||
options, NULL)) >= 0) {
|
options, NULL)) >= 0) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'V':
|
case 'V':
|
||||||
@ -441,6 +444,15 @@ int main(int argc, char **argv)
|
|||||||
libbpf_set_print(print_all_levels);
|
libbpf_set_print(print_all_levels);
|
||||||
verifier_logs = true;
|
verifier_logs = true;
|
||||||
break;
|
break;
|
||||||
|
case 'B':
|
||||||
|
base_btf = btf__parse(optarg, NULL);
|
||||||
|
if (libbpf_get_error(base_btf)) {
|
||||||
|
p_err("failed to parse base BTF at '%s': %ld\n",
|
||||||
|
optarg, libbpf_get_error(base_btf));
|
||||||
|
base_btf = NULL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
p_err("unrecognized option '%s'", argv[optind - 1]);
|
p_err("unrecognized option '%s'", argv[optind - 1]);
|
||||||
if (json_output)
|
if (json_output)
|
||||||
@ -465,6 +477,7 @@ int main(int argc, char **argv)
|
|||||||
delete_pinned_obj_table(&map_table);
|
delete_pinned_obj_table(&map_table);
|
||||||
delete_pinned_obj_table(&link_table);
|
delete_pinned_obj_table(&link_table);
|
||||||
}
|
}
|
||||||
|
btf__free(base_btf);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,7 @@ extern bool show_pids;
|
|||||||
extern bool block_mount;
|
extern bool block_mount;
|
||||||
extern bool verifier_logs;
|
extern bool verifier_logs;
|
||||||
extern bool relaxed_maps;
|
extern bool relaxed_maps;
|
||||||
|
extern struct btf *base_btf;
|
||||||
extern struct pinned_obj_table prog_table;
|
extern struct pinned_obj_table prog_table;
|
||||||
extern struct pinned_obj_table map_table;
|
extern struct pinned_obj_table map_table;
|
||||||
extern struct pinned_obj_table link_table;
|
extern struct pinned_obj_table link_table;
|
||||||
|
Loading…
Reference in New Issue
Block a user