Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Ian 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.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
56d9117c 217b7d41

+56 -13
+2 -2
tools/perf/arch/common.c
··· 130 130 } 131 131 132 132 static int perf_env__lookup_binutils_path(struct perf_env *env, 133 - const char *name, const char **path) 133 + const char *name, char **path) 134 134 { 135 135 int idx; 136 136 const char *arch = perf_env__arch(env), *cross_env; ··· 202 202 return -1; 203 203 } 204 204 205 - int perf_env__lookup_objdump(struct perf_env *env, const char **path) 205 + int perf_env__lookup_objdump(struct perf_env *env, char **path) 206 206 { 207 207 /* 208 208 * For live mode, env->arch will be NULL and we can use
+1 -1
tools/perf/arch/common.h
··· 6 6 7 7 struct perf_env; 8 8 9 - int perf_env__lookup_objdump(struct perf_env *env, const char **path); 9 + int perf_env__lookup_objdump(struct perf_env *env, char **path); 10 10 bool perf_env__single_address_space(struct perf_env *env); 11 11 12 12 #endif /* ARCH_PERF_COMMON_H */
+14 -2
tools/perf/builtin-annotate.c
··· 517 517 struct itrace_synth_opts itrace_synth_opts = { 518 518 .set = 0, 519 519 }; 520 + const char *disassembler_style = NULL, *objdump_path = NULL; 520 521 struct option options[] = { 521 522 OPT_STRING('i', "input", &input_name, "file", 522 523 "input file name"), ··· 562 561 "Interleave source code with assembly code (default)"), 563 562 OPT_BOOLEAN(0, "asm-raw", &annotate.opts.show_asm_raw, 564 563 "Display raw encoding of assembly instructions (default)"), 565 - OPT_STRING('M', "disassembler-style", &annotate.opts.disassembler_style, "disassembler style", 564 + OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style", 566 565 "Specify disassembler style (e.g. -M intel for intel syntax)"), 567 566 OPT_STRING(0, "prefix", &annotate.opts.prefix, "prefix", 568 567 "Add prefix to source file path names in programs (with --prefix-strip)"), 569 568 OPT_STRING(0, "prefix-strip", &annotate.opts.prefix_strip, "N", 570 569 "Strip first N entries of source file path name in programs (with --prefix)"), 571 - OPT_STRING(0, "objdump", &annotate.opts.objdump_path, "path", 570 + OPT_STRING(0, "objdump", &objdump_path, "path", 572 571 "objdump binary to use for disassembly and annotations"), 573 572 OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle, 574 573 "Enable symbol demangling"), ··· 617 616 usage_with_options(annotate_usage, options); 618 617 619 618 annotate.sym_hist_filter = argv[0]; 619 + } 620 + 621 + if (disassembler_style) { 622 + annotate.opts.disassembler_style = strdup(disassembler_style); 623 + if (!annotate.opts.disassembler_style) 624 + return -ENOMEM; 625 + } 626 + if (objdump_path) { 627 + annotate.opts.objdump_path = strdup(objdump_path); 628 + if (!annotate.opts.objdump_path) 629 + return -ENOMEM; 620 630 } 621 631 622 632 if (annotate_check_args(&annotate.opts) < 0)
+14 -2
tools/perf/builtin-report.c
··· 1226 1226 }; 1227 1227 char *sort_order_help = sort_help("sort by key(s):"); 1228 1228 char *field_order_help = sort_help("output field(s): overhead period sample "); 1229 + const char *disassembler_style = NULL, *objdump_path = NULL; 1229 1230 const struct option options[] = { 1230 1231 OPT_STRING('i', "input", &input_name, "file", 1231 1232 "input file name"), ··· 1323 1322 "Interleave source code with assembly code (default)"), 1324 1323 OPT_BOOLEAN(0, "asm-raw", &report.annotation_opts.show_asm_raw, 1325 1324 "Display raw encoding of assembly instructions (default)"), 1326 - OPT_STRING('M', "disassembler-style", &report.annotation_opts.disassembler_style, "disassembler style", 1325 + OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style", 1327 1326 "Specify disassembler style (e.g. -M intel for intel syntax)"), 1328 1327 OPT_STRING(0, "prefix", &report.annotation_opts.prefix, "prefix", 1329 1328 "Add prefix to source file path names in programs (with --prefix-strip)"), ··· 1342 1341 parse_branch_mode), 1343 1342 OPT_BOOLEAN(0, "branch-history", &branch_call_mode, 1344 1343 "add last branch records to call history"), 1345 - OPT_STRING(0, "objdump", &report.annotation_opts.objdump_path, "path", 1344 + OPT_STRING(0, "objdump", &objdump_path, "path", 1346 1345 "objdump binary to use for disassembly and annotations"), 1347 1346 OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle, 1348 1347 "Disable symbol demangling"), ··· 1418 1417 usage_with_options(report_usage, options); 1419 1418 1420 1419 report.symbol_filter_str = argv[0]; 1420 + } 1421 + 1422 + if (disassembler_style) { 1423 + report.annotation_opts.disassembler_style = strdup(disassembler_style); 1424 + if (!report.annotation_opts.disassembler_style) 1425 + return -ENOMEM; 1426 + } 1427 + if (objdump_path) { 1428 + report.annotation_opts.objdump_path = strdup(objdump_path); 1429 + if (!report.annotation_opts.objdump_path) 1430 + return -ENOMEM; 1421 1431 } 1422 1432 1423 1433 if (annotate_check_args(&report.annotation_opts) < 0) {
+15 -2
tools/perf/builtin-top.c
··· 1439 1439 }; 1440 1440 struct record_opts *opts = &top.record_opts; 1441 1441 struct target *target = &opts->target; 1442 + const char *disassembler_style = NULL, *objdump_path = NULL; 1442 1443 const struct option options[] = { 1443 1444 OPT_CALLBACK('e', "event", &top.evlist, "event", 1444 1445 "event selector. use 'perf list' to list available events", ··· 1525 1524 OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel, 1526 1525 "Enable kernel symbol demangling"), 1527 1526 OPT_BOOLEAN(0, "no-bpf-event", &top.record_opts.no_bpf_event, "do not record bpf events"), 1528 - OPT_STRING(0, "objdump", &top.annotation_opts.objdump_path, "path", 1527 + OPT_STRING(0, "objdump", &objdump_path, "path", 1529 1528 "objdump binary to use for disassembly and annotations"), 1530 - OPT_STRING('M', "disassembler-style", &top.annotation_opts.disassembler_style, "disassembler style", 1529 + OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style", 1531 1530 "Specify disassembler style (e.g. -M intel for intel syntax)"), 1532 1531 OPT_STRING(0, "prefix", &top.annotation_opts.prefix, "prefix", 1533 1532 "Add prefix to source file path names in programs (with --prefix-strip)"), ··· 1618 1617 argc = parse_options(argc, argv, options, top_usage, 0); 1619 1618 if (argc) 1620 1619 usage_with_options(top_usage, options); 1620 + 1621 + if (disassembler_style) { 1622 + top.annotation_opts.disassembler_style = strdup(disassembler_style); 1623 + if (!top.annotation_opts.disassembler_style) 1624 + return -ENOMEM; 1625 + } 1626 + if (objdump_path) { 1627 + top.annotation_opts.objdump_path = strdup(objdump_path); 1628 + if (!top.annotation_opts.objdump_path) 1629 + return -ENOMEM; 1630 + } 1631 + 1621 1632 1622 1633 status = symbol__validate_sym_arguments(); 1623 1634 if (status)
+8 -2
tools/perf/util/annotate.c
··· 3206 3206 } else if (!strcmp(var, "annotate.use_offset")) { 3207 3207 opt->use_offset = perf_config_bool("use_offset", value); 3208 3208 } else if (!strcmp(var, "annotate.disassembler_style")) { 3209 - opt->disassembler_style = value; 3209 + opt->disassembler_style = strdup(value); 3210 + if (!opt->disassembler_style) { 3211 + pr_err("Not enough memory for annotate.disassembler_style\n"); 3212 + return -1; 3213 + } 3210 3214 } else if (!strcmp(var, "annotate.demangle")) { 3211 3215 symbol_conf.demangle = perf_config_bool("demangle", value); 3212 3216 } else if (!strcmp(var, "annotate.demangle_kernel")) { ··· 3235 3231 } 3236 3232 3237 3233 3238 - void annotation_options__exit(struct annotation_options *opt __maybe_unused) 3234 + void annotation_options__exit(struct annotation_options *opt) 3239 3235 { 3236 + zfree(&opt->disassembler_style); 3237 + zfree(&opt->objdump_path); 3240 3238 } 3241 3239 3242 3240 void annotation_config__init(struct annotation_options *opt)
+2 -2
tools/perf/util/annotate.h
··· 94 94 int min_pcnt; 95 95 int max_lines; 96 96 int context; 97 - const char *objdump_path; 98 - const char *disassembler_style; 97 + char *objdump_path; 98 + char *disassembler_style; 99 99 const char *prefix; 100 100 const char *prefix_strip; 101 101 unsigned int percent_type;