Re: [PATCH bpf-next 2/6] bpftool: Show probed function in kprobe_multi link info

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Jun 3, 2023 at 4:37 AM Alexei Starovoitov
<alexei.starovoitov@xxxxxxxxx> wrote:
>
> On Fri, Jun 02, 2023 at 08:52:35AM +0000, Yafang Shao wrote:
> > Show the already expose kprobe_multi link info in bpftool. The result as
> > follows,
> > $ tools/bpf/bpftool/bpftool link show
> > 1: kprobe_multi  prog 5
> >         func_cnt 4  addrs            symbols
> >                     ffffffffb4d465b0 schedule_timeout_interruptible
> >                     ffffffffb4d465f0 schedule_timeout_killable
> >                     ffffffffb4d46630 schedule_timeout_uninterruptible
> >                     ffffffffb4d46670 schedule_timeout_idle
> >         pids trace(8729)
> >
> > $ tools/bpf/bpftool/bpftool link show -j
> > [{"id":1,"type":"kprobe_multi","prog_id":5,"func_cnt":4,"addrs":[{"addr":18446744072448402864,"symbol":"schedule_timeout_interruptible"},{"addr":18446744072448402928,"symbol":"schedule_timeout_killable"},{"addr":18446744072448402992,"symbol":"schedule_timeout_uninterruptible"},{"addr":18446744072448403056,"symbol":"schedule_timeout_idle"}],"pids":[{"pid":8729,"comm":"trace"}]}]
> >
> > Signed-off-by: Yafang Shao <laoar.shao@xxxxxxxxx>
> > ---
> >  tools/bpf/bpftool/link.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 94 insertions(+)
> >
> > diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
> > index 2d78607..3b00c07 100644
> > --- a/tools/bpf/bpftool/link.c
> > +++ b/tools/bpf/bpftool/link.c
> > @@ -166,6 +166,57 @@ static int get_prog_info(int prog_id, struct bpf_prog_info *info)
> >       return err;
> >  }
> >
> > +static int cmp_u64(const void *A, const void *B)
> > +{
> > +     const __u64 *a = A, *b = B;
> > +
> > +     return *a - *b;
> > +}
> > +
> > +static void kprobe_multi_print_plain(__u64 addr, char *sym, __u32 indent)
> > +{
> > +     printf("\n\t%*s  %0*llx %s", indent, "", 16, addr, sym);
> > +}
> > +
> > +static void kprobe_multi_print_json(__u64 addr, char *sym)
> > +{
> > +     jsonw_start_object(json_wtr);
> > +     jsonw_uint_field(json_wtr, "addr", addr);
> > +     jsonw_string_field(json_wtr, "symbol", sym);
> > +     jsonw_end_object(json_wtr);
> > +}
> > +
> > +static void kernel_syms_show(const __u64 *addrs, __u32 cnt, __u32 indent)
> > +{
> > +     char buff[256], sym[256];
> > +     __u64 addr;
> > +     int i = 0;
> > +     FILE *fp;
> > +
> > +     fp = fopen("/proc/kallsyms", "r");
> > +     if (!fp)
> > +             return;
> > +
> > +     /* Each address is guaranteed to be unique. */
> > +     qsort((void *)addrs, cnt, sizeof(__u64), cmp_u64);
> > +     /* The addresses in /proc/kallsyms are already sorted. */
> > +     while (fgets(buff, sizeof(buff), fp)) {
> > +             if (sscanf(buff, "%llx %*c %s", &addr, sym) != 2)
> > +                     continue;
> > +             /* The addr probed by kprobe_multi is always in
> > +              * /proc/kallsyms, so we can ignore some edge cases.
> > +              */
> > +             if (addr != addrs[i])
> > +                     continue;
> > +             if (indent)
> > +                     kprobe_multi_print_plain(addr, sym, indent);
> > +             else
> > +                     kprobe_multi_print_json(addr, sym);
> > +             i++;
> > +     }
> > +     fclose(fp);
>
> There is kernel_syms_load().
> Let's reuse it instead of reimplementing kallsysm parsing?

I will think about it. Thanks for your suggestion.

-- 
Regards
Yafang





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux