From 228427ba5a960d8b47ac345e0e5ca90d17229e24 Mon Sep 17 00:00:00 2001 From: Hengqi Chen Date: Sat, 25 Dec 2021 12:05:54 +0800 Subject: [PATCH] libbpf-tools: Add verbose option to bashreadline Support verbose mode and set custom libbpf print callback in bashreadline. Signed-off-by: Hengqi Chen --- libbpf-tools/bashreadline.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libbpf-tools/bashreadline.c b/libbpf-tools/bashreadline.c index 3fb7fea8..2fcb2e2c 100644 --- a/libbpf-tools/bashreadline.c +++ b/libbpf-tools/bashreadline.c @@ -35,11 +35,13 @@ const char argp_program_doc[] = static const struct argp_option opts[] = { { "shared", 's', "PATH", 0, "the location of libreadline.so library" }, + { "verbose", 'v', NULL, 0, "Verbose debug output" }, { NULL, 'h', NULL, OPTION_HIDDEN, "Show the full help" }, {}, }; static char *libreadline_path = NULL; +static bool verbose = false; static error_t parse_arg(int key, char *arg, struct argp_state *state) { @@ -49,6 +51,9 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state) if (libreadline_path == NULL) return ARGP_ERR_UNKNOWN; break; + case 'v': + verbose = true; + break; case 'h': argp_state_help(state, stderr, ARGP_HELP_STD_HELP); break; @@ -58,6 +63,13 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state) return 0; } +static int libbpf_print_fn(enum libbpf_print_level level, const char *format, va_list args) +{ + if (level == LIBBPF_DEBUG && !verbose) + return 0; + return vfprintf(stderr, format, args); +} + static void handle_event(void *ctx, int cpu, void *data, __u32 data_size) { struct str_t *e = data; @@ -154,6 +166,7 @@ int main(int argc, char **argv) } libbpf_set_strict_mode(LIBBPF_STRICT_ALL); + libbpf_set_print(libbpf_print_fn); obj = bashreadline_bpf__open_and_load(); if (!obj) { -- 2.34.1