Skip to content

Commit d7e45eb

Browse files
laoarAlexei Starovoitov
authored andcommitted
bpftool: Show target_{obj,btf}_id in tracing link info
The target_btf_id can help us understand which kernel function is linked by a tracing prog. The target_btf_id and target_obj_id have already been exposed to userspace, so we just need to show them. The result as follows, $ tools/bpf/bpftool/bpftool link show 2: tracing prog 13 prog_type tracing attach_type trace_fentry target_obj_id 1 target_btf_id 13964 pids trace(10673) $ tools/bpf/bpftool/bpftool link show -j [{"id":2,"type":"tracing","prog_id":13,"prog_type":"tracing","attach_type":"trace_fentry","target_obj_id":1,"target_btf_id":13964,"pids":[{"pid":10673,"comm":"trace"}]}] Signed-off-by: Yafang Shao <laoar.shao@gmail.com> Acked-by: Song Liu <song@kernel.org> Link: https://lore.kernel.org/r/20230517103126.68372-3-laoar.shao@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent e859e42 commit d7e45eb

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

tools/bpf/bpftool/link.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ static int show_link_close_json(int fd, struct bpf_link_info *info)
195195

196196
show_link_attach_type_json(info->tracing.attach_type,
197197
json_wtr);
198+
jsonw_uint_field(json_wtr, "target_obj_id", info->tracing.target_obj_id);
199+
jsonw_uint_field(json_wtr, "target_btf_id", info->tracing.target_btf_id);
198200
break;
199201
case BPF_LINK_TYPE_CGROUP:
200202
jsonw_lluint_field(json_wtr, "cgroup_id",
@@ -375,6 +377,10 @@ static int show_link_close_plain(int fd, struct bpf_link_info *info)
375377
printf("\n\tprog_type %u ", prog_info.type);
376378

377379
show_link_attach_type_plain(info->tracing.attach_type);
380+
if (info->tracing.target_obj_id || info->tracing.target_btf_id)
381+
printf("\n\ttarget_obj_id %u target_btf_id %u ",
382+
info->tracing.target_obj_id,
383+
info->tracing.target_btf_id);
378384
break;
379385
case BPF_LINK_TYPE_CGROUP:
380386
printf("\n\tcgroup_id %zu ", (size_t)info->cgroup.cgroup_id);

0 commit comments

Comments
 (0)