perf tools: Refactor out kernel symbol argument sanity checking
authorJames Clark <james.clark@arm.com>
Mon, 18 Oct 2021 13:48:41 +0000 (14:48 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Sun, 7 Nov 2021 15:27:38 +0000 (12:27 -0300)
User supplied values for vmlinux and kallsyms are checked before
continuing. Refactor this into a function so that it can be used
elsewhere.

Reviewed-by: Denis Nikitin <denik@chromium.org>
Signed-off-by: James Clark <james.clark@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20211018134844.2627174-2-james.clark@arm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-report.c
tools/perf/util/symbol.c
tools/perf/util/symbol.h

index a0316ce910db61d83afe7f072d77c86e2ab8a6ea..8167ebfe776a790aac12ab9cb01167dd62094a2f 100644 (file)
@@ -1378,18 +1378,9 @@ int cmd_report(int argc, const char **argv)
        if (quiet)
                perf_quiet_option();
 
-       if (symbol_conf.vmlinux_name &&
-           access(symbol_conf.vmlinux_name, R_OK)) {
-               pr_err("Invalid file: %s\n", symbol_conf.vmlinux_name);
-               ret = -EINVAL;
-               goto exit;
-       }
-       if (symbol_conf.kallsyms_name &&
-           access(symbol_conf.kallsyms_name, R_OK)) {
-               pr_err("Invalid file: %s\n", symbol_conf.kallsyms_name);
-               ret = -EINVAL;
+       ret = symbol__validate_sym_arguments();
+       if (ret)
                goto exit;
-       }
 
        if (report.inverted_callchain)
                callchain_param.order = ORDER_CALLER;
index 35116aed74eb8fda560c5232d9b5cf2c612a9ab5..aa1b7c12fd61da335a15335a2a5687d9a5c3ec92 100644 (file)
@@ -2634,3 +2634,25 @@ struct mem_info *mem_info__new(void)
                refcount_set(&mi->refcnt, 1);
        return mi;
 }
+
+/*
+ * Checks that user supplied symbol kernel files are accessible because
+ * the default mechanism for accessing elf files fails silently. i.e. if
+ * debug syms for a build ID aren't found perf carries on normally. When
+ * they are user supplied we should assume that the user doesn't want to
+ * silently fail.
+ */
+int symbol__validate_sym_arguments(void)
+{
+       if (symbol_conf.vmlinux_name &&
+           access(symbol_conf.vmlinux_name, R_OK)) {
+               pr_err("Invalid file: %s\n", symbol_conf.vmlinux_name);
+               return -EINVAL;
+       }
+       if (symbol_conf.kallsyms_name &&
+           access(symbol_conf.kallsyms_name, R_OK)) {
+               pr_err("Invalid file: %s\n", symbol_conf.kallsyms_name);
+               return -EINVAL;
+       }
+       return 0;
+}
index 954d6a049ee2386fba1b648065e01117d6284b3c..166196686f2e632d2de6f046531d1880d0e720b5 100644 (file)
@@ -286,4 +286,6 @@ static inline void __mem_info__zput(struct mem_info **mi)
 
 #define mem_info__zput(mi) __mem_info__zput(&mi)
 
+int symbol__validate_sym_arguments(void);
+
 #endif /* __PERF_SYMBOL */