diff mbox series

[bpf-next] bpftool: auto-complete BTF IDs for btf dump

Message ID 20190526000101.112077-1-andriin@fb.com
State Accepted
Delegated to: BPF Maintainers
Headers show
Series [bpf-next] bpftool: auto-complete BTF IDs for btf dump | expand

Commit Message

Andrii Nakryiko May 26, 2019, 12:01 a.m. UTC
Auto-complete BTF IDs for `btf dump id` sub-command. List of possible BTF
IDs is scavenged from loaded BPF programs that have associated BTFs, as
there is currently no API in libbpf to fetch list of all BTFs in the
system.

Suggested-by: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
 tools/bpf/bpftool/bash-completion/bpftool | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Quentin Monnet May 28, 2019, 8:25 a.m. UTC | #1
2019-05-25 17:01 UTC-0700 ~ Andrii Nakryiko <andriin@fb.com>
> Auto-complete BTF IDs for `btf dump id` sub-command. List of possible BTF
> IDs is scavenged from loaded BPF programs that have associated BTFs, as
> there is currently no API in libbpf to fetch list of all BTFs in the
> system.
> 
> Suggested-by: Quentin Monnet <quentin.monnet@netronome.com>
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>

Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>

Thanks!
Daniel Borkmann May 28, 2019, 9:24 a.m. UTC | #2
On 05/26/2019 02:01 AM, Andrii Nakryiko wrote:
> Auto-complete BTF IDs for `btf dump id` sub-command. List of possible BTF
> IDs is scavenged from loaded BPF programs that have associated BTFs, as
> there is currently no API in libbpf to fetch list of all BTFs in the
> system.
> 
> Suggested-by: Quentin Monnet <quentin.monnet@netronome.com>
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>

Applied, thanks!

(Please add versioning in the subject in future, e.g. [PATCH v2 bpf-next])
Andrii Nakryiko May 28, 2019, 4:41 p.m. UTC | #3
On Tue, May 28, 2019 at 2:24 AM Daniel Borkmann <daniel@iogearbox.net> wrote:
>
> On 05/26/2019 02:01 AM, Andrii Nakryiko wrote:
> > Auto-complete BTF IDs for `btf dump id` sub-command. List of possible BTF
> > IDs is scavenged from loaded BPF programs that have associated BTFs, as
> > there is currently no API in libbpf to fetch list of all BTFs in the
> > system.
> >
> > Suggested-by: Quentin Monnet <quentin.monnet@netronome.com>
> > Signed-off-by: Andrii Nakryiko <andriin@fb.com>
>
> Applied, thanks!

Thanks!

>
> (Please add versioning in the subject in future, e.g. [PATCH v2 bpf-next])

Ah yeah, sorry about that, forgot to update --subject-prefix when
generating patch :(
diff mbox series

Patch

diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool
index 75c01eafd3a1..fbbad0ed8e82 100644
--- a/tools/bpf/bpftool/bash-completion/bpftool
+++ b/tools/bpf/bpftool/bash-completion/bpftool
@@ -71,6 +71,12 @@  _bpftool_get_prog_tags()
         command sed -n 's/.*"tag": "\(.*\)",$/\1/p' )" -- "$cur" ) )
 }
 
+_bpftool_get_btf_ids()
+{
+    COMPREPLY+=( $( compgen -W "$( bpftool -jp prog 2>&1 | \
+        command sed -n 's/.*"btf_id": \(.*\),\?$/\1/p' )" -- "$cur" ) )
+}
+
 _bpftool_get_obj_map_names()
 {
     local obj
@@ -635,6 +641,9 @@  _bpftool()
                                 map)
                                     _bpftool_get_map_ids
                                     ;;
+                                dump)
+                                    _bpftool_get_btf_ids
+                                    ;;
                             esac
                             return 0
                             ;;