Skip to content

Commit a6293f3

Browse files
Stanislav Ivanichkinacmel
authored andcommitted
perf trace: Fix segfault when trying to trace events by cgroup
# ./perf trace -e sched:sched_switch -G test -a sleep 1 perf: Segmentation fault Obtained 11 stack frames. ./perf(sighandler_dump_stack+0x43) [0x55cfdc636db3] /lib/x86_64-linux-gnu/libc.so.6(+0x3efcf) [0x7fd23eecafcf] ./perf(parse_cgroups+0x36) [0x55cfdc673f36] ./perf(+0x3186ed) [0x55cfdc70d6ed] ./perf(parse_options_subcommand+0x629) [0x55cfdc70e999] ./perf(cmd_trace+0x9c2) [0x55cfdc5ad6d2] ./perf(+0x1e8ae0) [0x55cfdc5ddae0] ./perf(+0x1e8ded) [0x55cfdc5ddded] ./perf(main+0x370) [0x55cfdc556f00] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe6) [0x7fd23eeadb96] ./perf(_start+0x29) [0x55cfdc557389] Segmentation fault # It happens because "struct trace" in option->value is passed to the parse_cgroups function instead of "struct evlist". Fixes: 9ea42ba ("perf trace: Support setting cgroups as targets") Signed-off-by: Stanislav Ivanichkin <sivanichkin@yandex-team.ru> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Cc: Dmitry Monakhov <dmtrmonakhov@yandex-team.ru> Link: http://lore.kernel.org/lkml/20201027094357.94881-1-sivanichkin@yandex-team.ru Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent ab8bf5f commit a6293f3

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

‎tools/perf/builtin-trace.c‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4639,9 +4639,9 @@ static int trace__parse_events_option(const struct option *opt, const char *str,
46394639
err = 0;
46404640

46414641
if (lists[0]) {
4642-
struct option o = OPT_CALLBACK('e', "event", &trace->evlist, "event",
4643-
"event selector. use 'perf list' to list available events",
4644-
parse_events_option);
4642+
struct option o = {
4643+
.value = &trace->evlist,
4644+
};
46454645
err = parse_events_option(&o, lists[0], 0);
46464646
}
46474647
out:
@@ -4655,9 +4655,12 @@ static int trace__parse_cgroups(const struct option *opt, const char *str, int u
46554655
{
46564656
struct trace *trace = opt->value;
46574657

4658-
if (!list_empty(&trace->evlist->core.entries))
4659-
return parse_cgroups(opt, str, unset);
4660-
4658+
if (!list_empty(&trace->evlist->core.entries)) {
4659+
struct option o = {
4660+
.value = &trace->evlist,
4661+
};
4662+
return parse_cgroups(&o, str, unset);
4663+
}
46614664
trace->cgroup = evlist__findnew_cgroup(trace->evlist, str);
46624665

46634666
return 0;

0 commit comments

Comments
 (0)