Re: [PATCH 16/35] perf annotate: Add samples into struct annotation_line

From: Jiri Olsa
Date: Tue Nov 14 2017 - 05:30:08 EST


On Tue, Nov 14, 2017 at 03:45:27PM +0530, Ravi Bangoria wrote:
> Hi Jiri,
>
> On 11/14/2017 03:01 PM, Jiri Olsa wrote:
> > On Mon, Nov 13, 2017 at 09:14:38PM +0100, Jiri Olsa wrote:
> > > On Mon, Nov 13, 2017 at 09:16:20PM +0530, Ravi Bangoria wrote:
> > > > Hi Jiri,
> > > >
> > > > This patch seems to be causing segfault with "perf top --stdio".
> > > >
> > > > Steps to reproduce:
> > > > 1. start "perf top --stdio" in one terminal
> > > > 2. run some simple workload in another terminal, let it get finished.
> > > > 3. annotate function from previous workload in perf top (press 'a' followed
> > > > by 's')
> > > >
> > > > Perf will crash with:
> > > >
> > > >   perf: Segmentation fault
> > > >   Obtained 8 stack frames.
> > > >   ./perf(sighandler_dump_stack+0x3e) [0x4f1b6e]
> > > >   /lib64/libc.so.6(+0x36a7f) [0x7ff3aa7e4a7f]
> > > >   ./perf() [0x4a27fd]
> > > >   ./perf(symbol__annotate+0x199) [0x4a4439]
> > > >   ./perf() [0x44e32d]
> > > >   ./perf() [0x44f098]
> > > >   /lib64/libpthread.so.0(+0x736c) [0x7ff3acee836c]
> > > >   /lib64/libc.so.6(clone+0x3e) [0x7ff3aa8bee1e]
> > > >
> > > > Can you please check.
> > > hum, I'm getting following crash after resizing the terminal window:
> > >
> > > perf: Floating point exception
> > > Obtained 8 stack frames.
> > > ./perf(dump_stack+0x2e) [0x510c89]
> > > ./perf(sighandler_dump_stack+0x2e) [0x510d69]
> > > /lib64/libc.so.6(+0x36a80) [0x7f9419588a80]
> > > ./perf(perf_top__header_snprintf+0x208) [0x4f42c1]
> > > ./perf() [0x453c09]
> > > ./perf() [0x454ddb]
> > > /lib64/libpthread.so.0(+0x736d) [0x7f941bc8c36d]
> > > /lib64/libc.so.6(clone+0x3f) [0x7f9419662e1f]
> > > Floating point exception (core dumped)
> > >
> > > working on fix
> > so my crash is caused by bogus resize code, I have it working with fix for
> > memory corruption happening in SIGWINCH signal handler (attached)
> > could you please check if that fixes the code for you?
>
> Yes, this fixes the crash caused by resize.
>
> But original crash I reported is still there. Issue seems to be with evsel
> being NULL and we are trying to de-reference it somewhere inside
> annotation_line__new().
>
> Will try to spend more time on it.

right, I can see it now.. we are passing NULL as evsel in
the top but does not check on that.. attached patch prevents
the crash for me, but I'll need to double check if that's
correct fix

jirka


---
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 54321b947de8..07bbebfa2fe5 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -916,7 +916,7 @@ annotation_line__new(struct annotate_args *args, size_t privsize)
size_t size = privsize + sizeof(*al);
int nr = 1;

- if (perf_evsel__is_group_event(evsel))
+ if (evsel && perf_evsel__is_group_event(evsel))
nr = evsel->nr_members;

size += sizeof(al->samples[0]) * nr;