Commit 56d9117c authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo

perf annotate: Own objdump_path and disassembler_style strings

Make struct annotation_options own the strings objdump_path and
disassembler_style, freeing them on exit. Add missing strdup for
disassembler_style when read from a config file.

Committer notes:

Converted free(obj->member) to zfree(&obj->member) in
annotation_options__exit()
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: German Gomez <german.gomez@arm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Tom Rix <trix@redhat.com>
Cc: llvm@lists.linux.dev
Link: https://lore.kernel.org/r/20230328235543.1082207-2-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 217b7d41
...@@ -130,7 +130,7 @@ static int lookup_triplets(const char *const *triplets, const char *name) ...@@ -130,7 +130,7 @@ static int lookup_triplets(const char *const *triplets, const char *name)
} }
static int perf_env__lookup_binutils_path(struct perf_env *env, static int perf_env__lookup_binutils_path(struct perf_env *env,
const char *name, const char **path) const char *name, char **path)
{ {
int idx; int idx;
const char *arch = perf_env__arch(env), *cross_env; const char *arch = perf_env__arch(env), *cross_env;
...@@ -202,7 +202,7 @@ static int perf_env__lookup_binutils_path(struct perf_env *env, ...@@ -202,7 +202,7 @@ static int perf_env__lookup_binutils_path(struct perf_env *env,
return -1; return -1;
} }
int perf_env__lookup_objdump(struct perf_env *env, const char **path) int perf_env__lookup_objdump(struct perf_env *env, char **path)
{ {
/* /*
* For live mode, env->arch will be NULL and we can use * For live mode, env->arch will be NULL and we can use
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
struct perf_env; struct perf_env;
int perf_env__lookup_objdump(struct perf_env *env, const char **path); int perf_env__lookup_objdump(struct perf_env *env, char **path);
bool perf_env__single_address_space(struct perf_env *env); bool perf_env__single_address_space(struct perf_env *env);
#endif /* ARCH_PERF_COMMON_H */ #endif /* ARCH_PERF_COMMON_H */
...@@ -517,6 +517,7 @@ int cmd_annotate(int argc, const char **argv) ...@@ -517,6 +517,7 @@ int cmd_annotate(int argc, const char **argv)
struct itrace_synth_opts itrace_synth_opts = { struct itrace_synth_opts itrace_synth_opts = {
.set = 0, .set = 0,
}; };
const char *disassembler_style = NULL, *objdump_path = NULL;
struct option options[] = { struct option options[] = {
OPT_STRING('i', "input", &input_name, "file", OPT_STRING('i', "input", &input_name, "file",
"input file name"), "input file name"),
...@@ -561,13 +562,13 @@ int cmd_annotate(int argc, const char **argv) ...@@ -561,13 +562,13 @@ int cmd_annotate(int argc, const char **argv)
"Interleave source code with assembly code (default)"), "Interleave source code with assembly code (default)"),
OPT_BOOLEAN(0, "asm-raw", &annotate.opts.show_asm_raw, OPT_BOOLEAN(0, "asm-raw", &annotate.opts.show_asm_raw,
"Display raw encoding of assembly instructions (default)"), "Display raw encoding of assembly instructions (default)"),
OPT_STRING('M', "disassembler-style", &annotate.opts.disassembler_style, "disassembler style", OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style",
"Specify disassembler style (e.g. -M intel for intel syntax)"), "Specify disassembler style (e.g. -M intel for intel syntax)"),
OPT_STRING(0, "prefix", &annotate.opts.prefix, "prefix", OPT_STRING(0, "prefix", &annotate.opts.prefix, "prefix",
"Add prefix to source file path names in programs (with --prefix-strip)"), "Add prefix to source file path names in programs (with --prefix-strip)"),
OPT_STRING(0, "prefix-strip", &annotate.opts.prefix_strip, "N", OPT_STRING(0, "prefix-strip", &annotate.opts.prefix_strip, "N",
"Strip first N entries of source file path name in programs (with --prefix)"), "Strip first N entries of source file path name in programs (with --prefix)"),
OPT_STRING(0, "objdump", &annotate.opts.objdump_path, "path", OPT_STRING(0, "objdump", &objdump_path, "path",
"objdump binary to use for disassembly and annotations"), "objdump binary to use for disassembly and annotations"),
OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle, OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle,
"Enable symbol demangling"), "Enable symbol demangling"),
...@@ -618,6 +619,17 @@ int cmd_annotate(int argc, const char **argv) ...@@ -618,6 +619,17 @@ int cmd_annotate(int argc, const char **argv)
annotate.sym_hist_filter = argv[0]; annotate.sym_hist_filter = argv[0];
} }
if (disassembler_style) {
annotate.opts.disassembler_style = strdup(disassembler_style);
if (!annotate.opts.disassembler_style)
return -ENOMEM;
}
if (objdump_path) {
annotate.opts.objdump_path = strdup(objdump_path);
if (!annotate.opts.objdump_path)
return -ENOMEM;
}
if (annotate_check_args(&annotate.opts) < 0) if (annotate_check_args(&annotate.opts) < 0)
return -EINVAL; return -EINVAL;
......
...@@ -1226,6 +1226,7 @@ int cmd_report(int argc, const char **argv) ...@@ -1226,6 +1226,7 @@ int cmd_report(int argc, const char **argv)
}; };
char *sort_order_help = sort_help("sort by key(s):"); char *sort_order_help = sort_help("sort by key(s):");
char *field_order_help = sort_help("output field(s): overhead period sample "); char *field_order_help = sort_help("output field(s): overhead period sample ");
const char *disassembler_style = NULL, *objdump_path = NULL;
const struct option options[] = { const struct option options[] = {
OPT_STRING('i', "input", &input_name, "file", OPT_STRING('i', "input", &input_name, "file",
"input file name"), "input file name"),
...@@ -1322,7 +1323,7 @@ int cmd_report(int argc, const char **argv) ...@@ -1322,7 +1323,7 @@ int cmd_report(int argc, const char **argv)
"Interleave source code with assembly code (default)"), "Interleave source code with assembly code (default)"),
OPT_BOOLEAN(0, "asm-raw", &report.annotation_opts.show_asm_raw, OPT_BOOLEAN(0, "asm-raw", &report.annotation_opts.show_asm_raw,
"Display raw encoding of assembly instructions (default)"), "Display raw encoding of assembly instructions (default)"),
OPT_STRING('M', "disassembler-style", &report.annotation_opts.disassembler_style, "disassembler style", OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style",
"Specify disassembler style (e.g. -M intel for intel syntax)"), "Specify disassembler style (e.g. -M intel for intel syntax)"),
OPT_STRING(0, "prefix", &report.annotation_opts.prefix, "prefix", OPT_STRING(0, "prefix", &report.annotation_opts.prefix, "prefix",
"Add prefix to source file path names in programs (with --prefix-strip)"), "Add prefix to source file path names in programs (with --prefix-strip)"),
...@@ -1341,7 +1342,7 @@ int cmd_report(int argc, const char **argv) ...@@ -1341,7 +1342,7 @@ int cmd_report(int argc, const char **argv)
parse_branch_mode), parse_branch_mode),
OPT_BOOLEAN(0, "branch-history", &branch_call_mode, OPT_BOOLEAN(0, "branch-history", &branch_call_mode,
"add last branch records to call history"), "add last branch records to call history"),
OPT_STRING(0, "objdump", &report.annotation_opts.objdump_path, "path", OPT_STRING(0, "objdump", &objdump_path, "path",
"objdump binary to use for disassembly and annotations"), "objdump binary to use for disassembly and annotations"),
OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle, OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle,
"Disable symbol demangling"), "Disable symbol demangling"),
...@@ -1419,6 +1420,17 @@ int cmd_report(int argc, const char **argv) ...@@ -1419,6 +1420,17 @@ int cmd_report(int argc, const char **argv)
report.symbol_filter_str = argv[0]; report.symbol_filter_str = argv[0];
} }
if (disassembler_style) {
report.annotation_opts.disassembler_style = strdup(disassembler_style);
if (!report.annotation_opts.disassembler_style)
return -ENOMEM;
}
if (objdump_path) {
report.annotation_opts.objdump_path = strdup(objdump_path);
if (!report.annotation_opts.objdump_path)
return -ENOMEM;
}
if (annotate_check_args(&report.annotation_opts) < 0) { if (annotate_check_args(&report.annotation_opts) < 0) {
ret = -EINVAL; ret = -EINVAL;
goto exit; goto exit;
......
...@@ -1439,6 +1439,7 @@ int cmd_top(int argc, const char **argv) ...@@ -1439,6 +1439,7 @@ int cmd_top(int argc, const char **argv)
}; };
struct record_opts *opts = &top.record_opts; struct record_opts *opts = &top.record_opts;
struct target *target = &opts->target; struct target *target = &opts->target;
const char *disassembler_style = NULL, *objdump_path = NULL;
const struct option options[] = { const struct option options[] = {
OPT_CALLBACK('e', "event", &top.evlist, "event", OPT_CALLBACK('e', "event", &top.evlist, "event",
"event selector. use 'perf list' to list available events", "event selector. use 'perf list' to list available events",
...@@ -1524,9 +1525,9 @@ int cmd_top(int argc, const char **argv) ...@@ -1524,9 +1525,9 @@ int cmd_top(int argc, const char **argv)
OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel, OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,
"Enable kernel symbol demangling"), "Enable kernel symbol demangling"),
OPT_BOOLEAN(0, "no-bpf-event", &top.record_opts.no_bpf_event, "do not record bpf events"), OPT_BOOLEAN(0, "no-bpf-event", &top.record_opts.no_bpf_event, "do not record bpf events"),
OPT_STRING(0, "objdump", &top.annotation_opts.objdump_path, "path", OPT_STRING(0, "objdump", &objdump_path, "path",
"objdump binary to use for disassembly and annotations"), "objdump binary to use for disassembly and annotations"),
OPT_STRING('M', "disassembler-style", &top.annotation_opts.disassembler_style, "disassembler style", OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style",
"Specify disassembler style (e.g. -M intel for intel syntax)"), "Specify disassembler style (e.g. -M intel for intel syntax)"),
OPT_STRING(0, "prefix", &top.annotation_opts.prefix, "prefix", OPT_STRING(0, "prefix", &top.annotation_opts.prefix, "prefix",
"Add prefix to source file path names in programs (with --prefix-strip)"), "Add prefix to source file path names in programs (with --prefix-strip)"),
...@@ -1618,6 +1619,18 @@ int cmd_top(int argc, const char **argv) ...@@ -1618,6 +1619,18 @@ int cmd_top(int argc, const char **argv)
if (argc) if (argc)
usage_with_options(top_usage, options); usage_with_options(top_usage, options);
if (disassembler_style) {
top.annotation_opts.disassembler_style = strdup(disassembler_style);
if (!top.annotation_opts.disassembler_style)
return -ENOMEM;
}
if (objdump_path) {
top.annotation_opts.objdump_path = strdup(objdump_path);
if (!top.annotation_opts.objdump_path)
return -ENOMEM;
}
status = symbol__validate_sym_arguments(); status = symbol__validate_sym_arguments();
if (status) if (status)
goto out_delete_evlist; goto out_delete_evlist;
......
...@@ -3206,7 +3206,11 @@ static int annotation__config(const char *var, const char *value, void *data) ...@@ -3206,7 +3206,11 @@ static int annotation__config(const char *var, const char *value, void *data)
} else if (!strcmp(var, "annotate.use_offset")) { } else if (!strcmp(var, "annotate.use_offset")) {
opt->use_offset = perf_config_bool("use_offset", value); opt->use_offset = perf_config_bool("use_offset", value);
} else if (!strcmp(var, "annotate.disassembler_style")) { } else if (!strcmp(var, "annotate.disassembler_style")) {
opt->disassembler_style = value; opt->disassembler_style = strdup(value);
if (!opt->disassembler_style) {
pr_err("Not enough memory for annotate.disassembler_style\n");
return -1;
}
} else if (!strcmp(var, "annotate.demangle")) { } else if (!strcmp(var, "annotate.demangle")) {
symbol_conf.demangle = perf_config_bool("demangle", value); symbol_conf.demangle = perf_config_bool("demangle", value);
} else if (!strcmp(var, "annotate.demangle_kernel")) { } else if (!strcmp(var, "annotate.demangle_kernel")) {
...@@ -3231,8 +3235,10 @@ void annotation_options__init(struct annotation_options *opt) ...@@ -3231,8 +3235,10 @@ void annotation_options__init(struct annotation_options *opt)
} }
void annotation_options__exit(struct annotation_options *opt __maybe_unused) void annotation_options__exit(struct annotation_options *opt)
{ {
zfree(&opt->disassembler_style);
zfree(&opt->objdump_path);
} }
void annotation_config__init(struct annotation_options *opt) void annotation_config__init(struct annotation_options *opt)
......
...@@ -94,8 +94,8 @@ struct annotation_options { ...@@ -94,8 +94,8 @@ struct annotation_options {
int min_pcnt; int min_pcnt;
int max_lines; int max_lines;
int context; int context;
const char *objdump_path; char *objdump_path;
const char *disassembler_style; char *disassembler_style;
const char *prefix; const char *prefix;
const char *prefix_strip; const char *prefix_strip;
unsigned int percent_type; unsigned int percent_type;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment