From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Jiri Olsa <jolsa@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andriin@fb.com>,
Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
Yonghong Song <yhs@fb.com>, Martin KaFai Lau <kafai@fb.com>,
Jakub Kicinski <kuba@kernel.org>, David Miller <davem@redhat.com>,
John Fastabend <john.fastabend@gmail.com>,
Jesper Dangaard Brouer <hawk@kernel.org>
Subject: Re: [RFC] libbpf,selftests: Question on btf_dump__emit_type_decl for BTF_KIND_FUNC
Date: Tue, 3 Mar 2020 09:09:38 -0800 [thread overview]
Message-ID: <CAEf4BzY8_=wcL3N96eS-jcSPBL=ueMgQg+m=Fxiw+o0Tc7F23Q@mail.gmail.com> (raw)
In-Reply-To: <20200303140837.90056-1-jolsa@kernel.org>
On Tue, Mar 3, 2020 at 6:12 AM Jiri Olsa <jolsa@kernel.org> wrote:
>
> hi,
> for bpftrace I'd like to print BTF functions (BTF_KIND_FUNC)
> declarations together with their names.
>
> I saw we have btf_dump__emit_type_decl and added BTF_KIND_FUNC,
> where it seemed to be missing, so it prints out something now
> (not sure it's the right fix though).
>
> Anyway, would you be ok with adding some flag/bool to struct
> btf_dump_emit_type_decl_opts, so I could get output like:
>
> kfunc:ksys_readahead(int fd, long long int offset, long unsigned int count) = ssize_t
> kfunc:ksys_read(unsigned int fd, char buf, long unsigned int count) = size_t
>
> ... to be able to the arguments and return type separated,
> so I could easily get to something like above?
>
> Current interface is just vfprintf callback and I'm not sure
> I can rely that it will allywas be called with same arguments,
> like having separated calls for parsed atoms like 'return type',
> '(', ')', '(', 'arg type', 'arg name', ...
>
> I'm open to any suggestion ;-)
Hey Jiri!
Can you please elaborate on the use case and problem you are trying to solve?
I think we can (and probably even should) add such option and support
to dump functions, but whatever we do it should be a valid C syntax
and should be compilable.
Example above:
kfunc:ksys_read(unsigned int fd, char buf, long unsigned int count) = size_t
Is this really the syntax you need to get? I think btf_dump, when
(optionally) emitting function declaration, will have to emit that
particular one as:
size_t ksys_read(unsigned int fd, char buf, long unsigned int count);
But I'd like to hear the use case before we add this. Thanks!
>
> thanks,
> jirka
>
>
> ---
> tools/lib/bpf/btf_dump.c | 4 ++++
> .../selftests/bpf/prog_tests/btf_dump.c | 21 +++++++++++++++++++
> .../bpf/progs/btf_dump_test_case_bitfields.c | 10 +++++++++
> .../bpf/progs/btf_dump_test_case_multidim.c | 3 +++
> .../progs/btf_dump_test_case_namespacing.c | 19 +++++++++++++++++
> .../bpf/progs/btf_dump_test_case_ordering.c | 3 +++
> .../bpf/progs/btf_dump_test_case_packing.c | 16 ++++++++++++++
> .../bpf/progs/btf_dump_test_case_padding.c | 15 +++++++++++++
> .../bpf/progs/btf_dump_test_case_syntax.c | 3 +++
> 9 files changed, 94 insertions(+)
>
[...]
>
> +/*
> + *int ()(struct {
> + * struct packed_trailing_space _1;
> + * short: 16;
> + * struct non_packed_trailing_space _2;
> + * struct packed_fields _3;
> + * short: 16;
> + * struct non_packed_fields _4;
> + * struct nested_packed _5;
> + * short: 16;
> + * union union_is_never_packed _6;
> + * union union_does_not_need_packing _7;
> + * union jump_code_union _8;
> + * int: 24;
> + *} __attribute__((packed)) *_)
> + */
This clearly isn't compilable, right?
> /*------ END-EXPECTED-OUTPUT ------ */
>
> int f(struct {
> diff --git a/tools/testing/selftests/bpf/progs/btf_dump_test_case_padding.c b/tools/testing/selftests/bpf/progs/btf_dump_test_case_padding.c
> index 35c512818a56..581349bb0c2f 100644
> --- a/tools/testing/selftests/bpf/progs/btf_dump_test_case_padding.c
> +++ b/tools/testing/selftests/bpf/progs/btf_dump_test_case_padding.c
> @@ -102,6 +102,21 @@ struct zone {
> struct zone_padding __pad__;
> };
>
[...]
next prev parent reply other threads:[~2020-03-03 17:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-03 14:08 [RFC] libbpf,selftests: Question on btf_dump__emit_type_decl for BTF_KIND_FUNC Jiri Olsa
2020-03-03 17:09 ` Andrii Nakryiko [this message]
2020-03-03 17:33 ` Jiri Olsa
2020-03-03 18:00 ` Andrii Nakryiko
2020-03-03 20:05 ` Jiri Olsa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAEf4BzY8_=wcL3N96eS-jcSPBL=ueMgQg+m=Fxiw+o0Tc7F23Q@mail.gmail.com' \
--to=andrii.nakryiko@gmail.com \
--cc=andriin@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@redhat.com \
--cc=hawk@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kafai@fb.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).