Skip to contentSkip to conversation

perf script: Fix segfault using --show-mmap-events

PATCH Applied Adrian Hunter 3 participants 3 messages Aug 20, 2015 – Aug 22, 2015 perf events

lore
Share & tools
lore

Adrian Hunter

author reviewer
#0 lore raw

PATCH 1/1 perf script: Fix segfault using --show-mmap-events

Patch "perf script: Don't assume evsel position of tracking events" changed 'perf script' to use 'perf_evlist__id2evsel()'. That results in a segfault if there is more than 1 event and there are synthesized mmap events e.g.

	$ perf record -e cycles,instructions -p$$ sleep 1
	$ perf script --show-mmap-events
	Segmentation fault (core dumped)

That happens because these synthesized events have an 'id' of zero which does not match any 'evsel'.

Currently, these synthesized events use the sample type of the first evsel.

Change 'perf_evlist__id2evsel()' to reflect that which also makes it consistent with 'perf_evlist__event2evsel()'.

---
 tools/perf/util/evlist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/evlist.c +1 -1
index 373f65b02545..e9a5d432902c 100644
@@ -573,7 +573,7 @@ struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id)
 {
 	struct perf_sample_id *sid;
 
-	if (evlist->nr_entries == 1)
+	if (evlist->nr_entries == 1 || !id)
 		return perf_evlist__first(evlist);
 
 	sid = perf_evlist__id2sid(evlist, id);
Signature · 1 line
1.9.1
maintainer Applied
#1 lore raw

Em Thu, Aug 20, 2015 at 11:26:45AM +0300, Adrian Hunter escreveu:

Quoted 8 lines

Patch "perf script: Don't assume evsel position of tracking events" changed 'perf script' to use 'perf_evlist__id2evsel()'. That results in a segfault if there is more than 1 event and there are synthesized mmap events e.g.

	$ perf record -e cycles,instructions -p$$ sleep 1
	$ perf script --show-mmap-events
	Segmentation fault (core dumped)

Please next time tell what branch this affects, otherwise I'll have to try it on perf/urgent, notice that the problem is not there, then try it again on perf/core, where it is, to then apply...

Applied to perf/core.

Thanks,

- Arnaldo

Quoted 29 lines

That happens because these synthesized events have an 'id' of zero which does not match any 'evsel'.

Currently, these synthesized events use the sample type of the first evsel.

Change 'perf_evlist__id2evsel()' to reflect that which also makes it consistent with 'perf_evlist__event2evsel()'.

---
 tools/perf/util/evlist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/evlist.c +1 -1
index 373f65b02545..e9a5d432902c 100644
@@ -573,7 +573,7 @@ struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id)
 {
 	struct perf_sample_id *sid;
 
-	if (evlist->nr_entries == 1)
+	if (evlist->nr_entries == 1 || !id)
 		return perf_evlist__first(evlist);
 
 	sid = perf_evlist__id2sid(evlist, id);
Signature · 1 line
1.9.1
#2 lore raw
In reply to Adrian Hunter
perf script: Fix segfault using --show-mmap-events
Commit-ID:  05169df5561363ff04ac04d6aad0be3b45c26ac1
Gitweb:     http://git.kernel.org/tip/05169df5561363ff04ac04d6aad0be3b45c26ac1
Author:     Adrian Hunter <[email protected]>
AuthorDate: Thu, 20 Aug 2015 11:26:45 +0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 21 Aug 2015 10:29:22 -0300

perf script: Fix segfault using --show-mmap-events

Patch "perf script: Don't assume evsel position of tracking events" changed 'perf script' to use 'perf_evlist__id2evsel()'. That results in a segfault if there is more than 1 event and there are synthesized mmap events e.g.

	$ perf record -e cycles,instructions -p$$ sleep 1
	$ perf script --show-mmap-events
	Segmentation fault (core dumped)

That happens because these synthesized events have an 'id' of zero which does not match any 'evsel'.

Currently, these synthesized events use the sample type of the first evsel.

Change 'perf_evlist__id2evsel()' to reflect that which also makes it consistent with 'perf_evlist__event2evsel()'.

Fixes 06b234ec26fd ("perf script: Don't assume evsel position of tracking events")
Cc Jiri Olsa <[email protected]>
---
 tools/perf/util/evlist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/evlist.c +1 -1
index 373f65b..e9a5d43 100644
@@ -573,7 +573,7 @@ struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id)
 {
 	struct perf_sample_id *sid;
 
-	if (evlist->nr_entries == 1)
+	if (evlist->nr_entries == 1 || !id)
 		return perf_evlist__first(evlist);
 
 	sid = perf_evlist__id2sid(evlist, id);