OSDN Git Service

bpf: Move to generic BTF show support, apply it to seq files/strings
authorAlan Maguire <alan.maguire@oracle.com>
Mon, 28 Sep 2020 11:31:04 +0000 (12:31 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 29 Sep 2020 01:26:58 +0000 (18:26 -0700)
commit31d0bc81637d8d974a6dad9827b765b4b70c89d7
tree95012b4f5c189b4ae257f45f102c41ea92c519e9
parent76654e67f3a01c50dc13dd6dea75e58943413956
bpf: Move to generic BTF show support, apply it to seq files/strings

generalize the "seq_show" seq file support in btf.c to support
a generic show callback of which we support two instances; the
current seq file show, and a show with snprintf() behaviour which
instead writes the type data to a supplied string.

Both classes of show function call btf_type_show() with different
targets; the seq file or the string to be written.  In the string
case we need to track additional data - length left in string to write
and length to return that we would have written (a la snprintf).

By default show will display type information, field members and
their types and values etc, and the information is indented
based upon structure depth. Zeroed fields are omitted.

Show however supports flags which modify its behaviour:

BTF_SHOW_COMPACT - suppress newline/indent.
BTF_SHOW_NONAME - suppress show of type and member names.
BTF_SHOW_PTR_RAW - do not obfuscate pointer values.
BTF_SHOW_UNSAFE - do not copy data to safe buffer before display.
BTF_SHOW_ZERO - show zeroed values (by default they are not shown).

Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/1601292670-1616-3-git-send-email-alan.maguire@oracle.com
include/linux/btf.h
kernel/bpf/btf.c