diff options
author | Yonghong Song <yhs@fb.com> | 2019-02-01 19:14:15 -0500 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2019-02-04 12:40:58 -0500 |
commit | 9d100a19ffa519b17a0e998918337da5386e47fb (patch) | |
tree | 33ba27812e8abc05913c8f57b654e30f1e1e1cd6 /tools/lib/bpf/btf.c | |
parent | 8461ef8b7ef286212ca954d8b82dac3ceecb219d (diff) |
tools/bpf: print out btf log at LIBBPF_WARN level
Currently, the btf log is allocated and printed out in case
of error at LIBBPF_DEBUG level.
Such logs from kernel are very important for debugging.
For example, bpf syscall BPF_PROG_LOAD command can get
verifier logs back to user space. In function load_program()
of libbpf.c, the log buffer is allocated unconditionally
and printed out at pr_warning() level.
Let us do the similar thing here for btf. Allocate buffer
unconditionally and print out error logs at pr_warning() level.
This can reduce one global function and
optimize for common situations where pr_warning()
is activated either by default or by user supplied
debug output function.
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/lib/bpf/btf.c')
-rw-r--r-- | tools/lib/bpf/btf.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index 93e792b82242..51a0db05bf80 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c | |||
@@ -377,16 +377,15 @@ struct btf *btf__new(__u8 *data, __u32 size) | |||
377 | 377 | ||
378 | btf->fd = -1; | 378 | btf->fd = -1; |
379 | 379 | ||
380 | if (libbpf_print_level_available(LIBBPF_DEBUG)) { | 380 | log_buf = malloc(BPF_LOG_BUF_SIZE); |
381 | log_buf = malloc(BPF_LOG_BUF_SIZE); | 381 | if (!log_buf) { |
382 | if (!log_buf) { | 382 | err = -ENOMEM; |
383 | err = -ENOMEM; | 383 | goto done; |
384 | goto done; | ||
385 | } | ||
386 | *log_buf = 0; | ||
387 | log_buf_size = BPF_LOG_BUF_SIZE; | ||
388 | } | 384 | } |
389 | 385 | ||
386 | *log_buf = 0; | ||
387 | log_buf_size = BPF_LOG_BUF_SIZE; | ||
388 | |||
390 | btf->data = malloc(size); | 389 | btf->data = malloc(size); |
391 | if (!btf->data) { | 390 | if (!btf->data) { |
392 | err = -ENOMEM; | 391 | err = -ENOMEM; |
@@ -401,9 +400,9 @@ struct btf *btf__new(__u8 *data, __u32 size) | |||
401 | 400 | ||
402 | if (btf->fd == -1) { | 401 | if (btf->fd == -1) { |
403 | err = -errno; | 402 | err = -errno; |
404 | pr_debug("Error loading BTF: %s(%d)\n", strerror(errno), errno); | 403 | pr_warning("Error loading BTF: %s(%d)\n", strerror(errno), errno); |
405 | if (log_buf && *log_buf) | 404 | if (log_buf && *log_buf) |
406 | pr_debug("%s\n", log_buf); | 405 | pr_warning("%s\n", log_buf); |
407 | goto done; | 406 | goto done; |
408 | } | 407 | } |
409 | 408 | ||