tools/bpftool: Add BTF_KIND_FLOAT support
authorIlya Leoshkevich <iii@linux.ibm.com>
Fri, 26 Feb 2021 20:22:50 +0000 (21:22 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 5 Mar 2021 01:58:15 +0000 (17:58 -0800)
Only dumping support needs to be adjusted, the code structure follows
that of BTF_KIND_INT. Example plain and JSON outputs:

    [4] FLOAT 'float' size=4
    {"id":4,"kind":"FLOAT","name":"float","size":4}

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20210226202256.116518-5-iii@linux.ibm.com
tools/bpf/bpftool/btf.c
tools/bpf/bpftool/btf_dumper.c

index fe9e7b3a4b5038d9dde6bafd0a0f27d8dabf92d7..985610c3f19335f48d35fd9e6a9c663a8f3f8a6d 100644 (file)
@@ -36,6 +36,7 @@ static const char * const btf_kind_str[NR_BTF_KINDS] = {
        [BTF_KIND_FUNC_PROTO]   = "FUNC_PROTO",
        [BTF_KIND_VAR]          = "VAR",
        [BTF_KIND_DATASEC]      = "DATASEC",
+       [BTF_KIND_FLOAT]        = "FLOAT",
 };
 
 struct btf_attach_table {
@@ -327,6 +328,13 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
                        jsonw_end_array(w);
                break;
        }
+       case BTF_KIND_FLOAT: {
+               if (json_output)
+                       jsonw_uint_field(w, "size", t->size);
+               else
+                       printf(" size=%u", t->size);
+               break;
+       }
        default:
                break;
        }
index 0e9310727281af3f0f8b58d1f6e76f2866548047..7ca54d046362c0ac7b1ce5de3e95a89bac2c2bcc 100644 (file)
@@ -596,6 +596,7 @@ static int __btf_dumper_type_only(const struct btf *btf, __u32 type_id,
        switch (BTF_INFO_KIND(t->info)) {
        case BTF_KIND_INT:
        case BTF_KIND_TYPEDEF:
+       case BTF_KIND_FLOAT:
                BTF_PRINT_ARG("%s ", btf__name_by_offset(btf, t->name_off));
                break;
        case BTF_KIND_STRUCT: