Skip to content

Commit a779569

Browse files
olsajirianakryiko
authored andcommitted
bpftool: Add support to display uprobe_multi links
Adding support to display details for uprobe_multi links, both plain: # bpftool link -p ... 24: uprobe_multi prog 126 uprobe.multi path /home/jolsa/bpf/test_progs func_cnt 3 pid 4143 offset ref_ctr_offset cookies 0xd1f88 0xf5d5a8 0xdead 0xd1f8f 0xf5d5aa 0xbeef 0xd1f96 0xf5d5ac 0xcafe and json: # bpftool link -p [{ ... },{ "id": 24, "type": "uprobe_multi", "prog_id": 126, "retprobe": false, "path": "/home/jolsa/bpf/test_progs", "func_cnt": 3, "pid": 4143, "funcs": [{ "offset": 860040, "ref_ctr_offset": 16111016, "cookie": 57005 },{ "offset": 860047, "ref_ctr_offset": 16111018, "cookie": 48879 },{ "offset": 860054, "ref_ctr_offset": 16111020, "cookie": 51966 } ] } ] Signed-off-by: Jiri Olsa <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Reviewed-by: Quentin Monnet <[email protected]> Acked-by: Song Liu <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 147c693 commit a779569

File tree

1 file changed

+103
-2
lines changed

1 file changed

+103
-2
lines changed

tools/bpf/bpftool/link.c

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,37 @@ show_kprobe_multi_json(struct bpf_link_info *info, json_writer_t *wtr)
294294
jsonw_end_array(json_wtr);
295295
}
296296

297+
static __u64 *u64_to_arr(__u64 val)
298+
{
299+
return (__u64 *) u64_to_ptr(val);
300+
}
301+
302+
static void
303+
show_uprobe_multi_json(struct bpf_link_info *info, json_writer_t *wtr)
304+
{
305+
__u32 i;
306+
307+
jsonw_bool_field(json_wtr, "retprobe",
308+
info->uprobe_multi.flags & BPF_F_UPROBE_MULTI_RETURN);
309+
jsonw_string_field(json_wtr, "path", (char *) u64_to_ptr(info->uprobe_multi.path));
310+
jsonw_uint_field(json_wtr, "func_cnt", info->uprobe_multi.count);
311+
jsonw_int_field(json_wtr, "pid", (int) info->uprobe_multi.pid);
312+
jsonw_name(json_wtr, "funcs");
313+
jsonw_start_array(json_wtr);
314+
315+
for (i = 0; i < info->uprobe_multi.count; i++) {
316+
jsonw_start_object(json_wtr);
317+
jsonw_uint_field(json_wtr, "offset",
318+
u64_to_arr(info->uprobe_multi.offsets)[i]);
319+
jsonw_uint_field(json_wtr, "ref_ctr_offset",
320+
u64_to_arr(info->uprobe_multi.ref_ctr_offsets)[i]);
321+
jsonw_uint_field(json_wtr, "cookie",
322+
u64_to_arr(info->uprobe_multi.cookies)[i]);
323+
jsonw_end_object(json_wtr);
324+
}
325+
jsonw_end_array(json_wtr);
326+
}
327+
297328
static void
298329
show_perf_event_kprobe_json(struct bpf_link_info *info, json_writer_t *wtr)
299330
{
@@ -465,6 +496,9 @@ static int show_link_close_json(int fd, struct bpf_link_info *info)
465496
case BPF_LINK_TYPE_KPROBE_MULTI:
466497
show_kprobe_multi_json(info, json_wtr);
467498
break;
499+
case BPF_LINK_TYPE_UPROBE_MULTI:
500+
show_uprobe_multi_json(info, json_wtr);
501+
break;
468502
case BPF_LINK_TYPE_PERF_EVENT:
469503
switch (info->perf_event.type) {
470504
case BPF_PERF_EVENT_EVENT:
@@ -674,6 +708,33 @@ static void show_kprobe_multi_plain(struct bpf_link_info *info)
674708
}
675709
}
676710

711+
static void show_uprobe_multi_plain(struct bpf_link_info *info)
712+
{
713+
__u32 i;
714+
715+
if (!info->uprobe_multi.count)
716+
return;
717+
718+
if (info->uprobe_multi.flags & BPF_F_UPROBE_MULTI_RETURN)
719+
printf("\n\turetprobe.multi ");
720+
else
721+
printf("\n\tuprobe.multi ");
722+
723+
printf("path %s ", (char *) u64_to_ptr(info->uprobe_multi.path));
724+
printf("func_cnt %u ", info->uprobe_multi.count);
725+
726+
if (info->uprobe_multi.pid)
727+
printf("pid %d ", info->uprobe_multi.pid);
728+
729+
printf("\n\t%-16s %-16s %-16s", "offset", "ref_ctr_offset", "cookies");
730+
for (i = 0; i < info->uprobe_multi.count; i++) {
731+
printf("\n\t0x%-16llx 0x%-16llx 0x%-16llx",
732+
u64_to_arr(info->uprobe_multi.offsets)[i],
733+
u64_to_arr(info->uprobe_multi.ref_ctr_offsets)[i],
734+
u64_to_arr(info->uprobe_multi.cookies)[i]);
735+
}
736+
}
737+
677738
static void show_perf_event_kprobe_plain(struct bpf_link_info *info)
678739
{
679740
const char *buf;
@@ -807,6 +868,9 @@ static int show_link_close_plain(int fd, struct bpf_link_info *info)
807868
case BPF_LINK_TYPE_KPROBE_MULTI:
808869
show_kprobe_multi_plain(info);
809870
break;
871+
case BPF_LINK_TYPE_UPROBE_MULTI:
872+
show_uprobe_multi_plain(info);
873+
break;
810874
case BPF_LINK_TYPE_PERF_EVENT:
811875
switch (info->perf_event.type) {
812876
case BPF_PERF_EVENT_EVENT:
@@ -846,8 +910,10 @@ static int show_link_close_plain(int fd, struct bpf_link_info *info)
846910

847911
static int do_show_link(int fd)
848912
{
913+
__u64 *ref_ctr_offsets = NULL, *offsets = NULL, *cookies = NULL;
849914
struct bpf_link_info info;
850915
__u32 len = sizeof(info);
916+
char path_buf[PATH_MAX];
851917
__u64 *addrs = NULL;
852918
char buf[PATH_MAX];
853919
int count;
@@ -889,6 +955,39 @@ static int do_show_link(int fd)
889955
goto again;
890956
}
891957
}
958+
if (info.type == BPF_LINK_TYPE_UPROBE_MULTI &&
959+
!info.uprobe_multi.offsets) {
960+
count = info.uprobe_multi.count;
961+
if (count) {
962+
offsets = calloc(count, sizeof(__u64));
963+
if (!offsets) {
964+
p_err("mem alloc failed");
965+
close(fd);
966+
return -ENOMEM;
967+
}
968+
info.uprobe_multi.offsets = ptr_to_u64(offsets);
969+
ref_ctr_offsets = calloc(count, sizeof(__u64));
970+
if (!ref_ctr_offsets) {
971+
p_err("mem alloc failed");
972+
free(offsets);
973+
close(fd);
974+
return -ENOMEM;
975+
}
976+
info.uprobe_multi.ref_ctr_offsets = ptr_to_u64(ref_ctr_offsets);
977+
cookies = calloc(count, sizeof(__u64));
978+
if (!cookies) {
979+
p_err("mem alloc failed");
980+
free(cookies);
981+
free(offsets);
982+
close(fd);
983+
return -ENOMEM;
984+
}
985+
info.uprobe_multi.cookies = ptr_to_u64(cookies);
986+
info.uprobe_multi.path = ptr_to_u64(path_buf);
987+
info.uprobe_multi.path_size = sizeof(path_buf);
988+
goto again;
989+
}
990+
}
892991
if (info.type == BPF_LINK_TYPE_PERF_EVENT) {
893992
switch (info.perf_event.type) {
894993
case BPF_PERF_EVENT_TRACEPOINT:
@@ -924,8 +1023,10 @@ static int do_show_link(int fd)
9241023
else
9251024
show_link_close_plain(fd, &info);
9261025

927-
if (addrs)
928-
free(addrs);
1026+
free(ref_ctr_offsets);
1027+
free(cookies);
1028+
free(offsets);
1029+
free(addrs);
9291030
close(fd);
9301031
return 0;
9311032
}

0 commit comments

Comments
 (0)