libbpf-tools: Add verbose option to bashreadline
Support verbose mode and set custom libbpf print callback
in bashreadline.
@@ -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) {
