Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for listing struct/union/enum definitions using BTF #1340

Merged
merged 5 commits into from
May 29, 2020

Conversation

mmisono
Copy link
Collaborator

@mmisono mmisono commented May 19, 2020

'-l' option now can take struct/union/enum name and dump its definition
using BTF. For example:

% sudo ./src/bpftrace -l "enum bpf*"
enum bpf_access_type
enum bpf_adj_room_mode
enum bpf_arg_type
enum bpf_attach_type
enum bpf_cgroup_storage_type
[...]

and

% sudo ./src/bpftrace -lv "struct path"
BTF: using data from /sys/kernel/btf/vmlinux
struct path {
        struct vfsmount *mnt;
        struct dentry *dentry;
};
Checklist
  • Language changes are updated in docs/reference_guide.md
  • User-visible and non-trivial changes updated in CHANGELOG.md

@mmisono
Copy link
Collaborator Author

mmisono commented May 19, 2020

@olsajiri
I think the second commit c5959b6 is harmless, but could you take a look when you can?

src/list.cpp Outdated Show resolved Hide resolved
src/btf.cpp Outdated Show resolved Hide resolved
src/btf.cpp Outdated Show resolved Hide resolved
@mmisono
Copy link
Collaborator Author

mmisono commented May 24, 2020

@danobi
Thanks for the review. I fixed the reviewed points. I also added 8aab8ab to list only usdt and uprobe when a pid is given. For example:

% sudo ./src/bpftrace -lv -p 25655
BTF: using data from /sys/kernel/btf/vmlinux
uprobe:/proc/25655/root/home/ubuntu/work/bpftrace/bpftrace/build-debug/a.out:__do_global_dtors_aux
uprobe:/proc/25655/root/home/ubuntu/work/bpftrace/bpftrace/build-debug/a.out:__libc_csu_fini
uprobe:/proc/25655/root/home/ubuntu/work/bpftrace/bpftrace/build-debug/a.out:__libc_csu_init
[...]
usdt:/proc/25655/root/lib/x86_64-linux-gnu/libc-2.27.so:libc:setjmp
usdt:/proc/25655/root/lib/x86_64-linux-gnu/libc-2.27.so:libc:longjmp
usdt:/proc/25655/root/lib/x86_64-linux-gnu/libc-2.27.so:libc:longjmp_target
[...]

Please let me know if this has a problem.

Copy link
Member

@danobi danobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a "Changed" entry to the changelog for the usdt+uprobe change?

src/list.cpp Outdated Show resolved Hide resolved
@danobi
Copy link
Member

danobi commented May 26, 2020

Please let me know if this has a problem.

Seems like a reasonable change

Split a long function and call functions only when necessary
BTF::c_def() now accepts enum name, such as "enum bpf_prog_type"
'-l' option now can take struct/union/enum name and dump its definition
using BTF. For example:

```
% sudo ./src/bpftrace -l "enum bpf*"
enum bpf_access_type
enum bpf_adj_room_mode
enum bpf_arg_type
enum bpf_attach_type
enum bpf_cgroup_storage_type
[...]
```

and

```
% sudo ./src/bpftrace -lv "struct path"
BTF: using data from /sys/kernel/btf/vmlinux
struct path {
        struct vfsmount *mnt;
        struct dentry *dentry;
};
```
Now `bpftrace -l -p 11234` only lists uprobe and usdt probes.
`bpftrace -l "k:*" -p 11234` lists kprobe, which is the same as before.
@mmisono
Copy link
Collaborator Author

mmisono commented May 27, 2020

  • Updated changelog and fixed nits.

@danobi danobi merged commit 0bad2a3 into bpftrace:master May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants