• Martin KaFai Lau's avatar
    bpftool: Translate prog_id to its bpf prog_name · d5ae04da
    Martin KaFai Lau authored
    The kernel struct_ops obj has kernel's func ptrs implemented by bpf_progs.
    The bpf prog_id is stored as the value of the func ptr for introspection
    purpose.  In the latter patch, a struct_ops dump subcmd will be added
    to introspect these func ptrs.  It is desired to print the actual bpf
    prog_name instead of only printing the prog_id.
    
    Since struct_ops is the only usecase storing prog_id in the func ptr,
    this patch adds a prog_id_as_func_ptr bool (default is false) to
    "struct btf_dumper" in order not to mis-interpret the ptr value
    for the other existing use-cases.
    
    While printing a func_ptr as a bpf prog_name,
    this patch also prefix the bpf prog_name with the ptr's func_proto.
    [ Note that it is the ptr's func_proto instead of the bpf prog's
      func_proto ]
    It reuses the current btf_dump_func() to obtain the ptr's func_proto
    string.
    
    Here is an example from the bpf_cubic.c:
    "void (struct sock *, u32, u32) bictcp_cong_avoid/prog_id:140"
    Signed-off-by: default avatarMartin KaFai Lau <kafai@fb.com>
    Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
    Acked-by: default avatarQuentin Monnet <quentin@isovalent.com>
    Link: https://lore.kernel.org/bpf/20200318171650.129252-1-kafai@fb.com
    d5ae04da
main.h 7.38 KB