public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Taeung Song <treeze.taeung@gmail.com>
Cc: linux-kernel@vger.kernel.org, Jiri Olsa <jolsa@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Ingo Molnar <mingo@kernel.org>, Wang Nan <wangnan0@huawei.com>
Subject: Re: [PATCH 2/3] perf script: Exception handling when the print fmt is empty
Date: Thu, 25 Feb 2016 12:59:14 -0300	[thread overview]
Message-ID: <20160225155914.GM8720@kernel.org> (raw)
In-Reply-To: <1456413179-12331-1-git-send-email-treeze.taeung@gmail.com>

Em Fri, Feb 26, 2016 at 12:12:59AM +0900, Taeung Song escreveu:
> After collecting samples for events 'syscalls:',
> perf-script with python script doesn't occasionally
> work generating a segmentation fault.

Thanks, applied.

- Arnaldo
 
> The reason is that the print fmt is empty and
> a value of event->print_fmt.args is NULL, so
> dereferencing the null pointer results in
> a segmentation fault i.e.
> 
>     # perf record -e syscalls:*
>     # perf script -g python
>     # perf script -s perf-script.py
> 
>     in trace_begin
>     syscalls__sys_enter_brk  3 79841.832099154  3777 test.sh  syscall_nr=12, brk=0
> 
>     ... (omitted) ...
> 
>     Segmentation fault (core dumped)
> 
> For example, a format of sys_enter_getuid() hasn't
> print fmt as below.
> 
>     # cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_getuid/format
>     name: sys_enter_getuid
>     ID: 188
>     format:
>             field:unsigned short common_type;         offset:0; size:2; signed:0;
>             field:unsigned char common_flags;         offset:2; size:1; signed:0;
>             field:unsigned char common_preempt_count; offset:3; size:1; signed:0;
>             field:int common_pid;                     offset:4; size:4; signed:1;
>             field:int syscall_nr;                     offset:8; size:4; signed:1;
> 
>     print fmt: ""
> 
> So add exception handling to avoid this problem.
> 
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Wang Nan <wangnan0@huawei.com>
> Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
> ---
>  tools/perf/util/scripting-engines/trace-event-perl.c   | 3 +++
>  tools/perf/util/scripting-engines/trace-event-python.c | 3 +++
>  2 files changed, 6 insertions(+)
> 
> diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c
> index 544509c..b3aabc0 100644
> --- a/tools/perf/util/scripting-engines/trace-event-perl.c
> +++ b/tools/perf/util/scripting-engines/trace-event-perl.c
> @@ -187,6 +187,9 @@ static void define_event_symbols(struct event_format *event,
>  				 const char *ev_name,
>  				 struct print_arg *args)
>  {
> +	if (args == NULL)
> +		return;
> +
>  	switch (args->type) {
>  	case PRINT_NULL:
>  		break;
> diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
> index d72fafc..309d90f 100644
> --- a/tools/perf/util/scripting-engines/trace-event-python.c
> +++ b/tools/perf/util/scripting-engines/trace-event-python.c
> @@ -205,6 +205,9 @@ static void define_event_symbols(struct event_format *event,
>  				 const char *ev_name,
>  				 struct print_arg *args)
>  {
> +	if (args == NULL)
> +		return;
> +
>  	switch (args->type) {
>  	case PRINT_NULL:
>  		break;
> -- 
> 2.5.0

  reply	other threads:[~2016-02-25 15:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-25 15:12 [PATCH 2/3] perf script: Exception handling when the print fmt is empty Taeung Song
2016-02-25 15:59 ` Arnaldo Carvalho de Melo [this message]
2016-02-25 16:33   ` Taeung Song
2016-02-27  9:40 ` [tip:perf/core] " tip-bot for Taeung Song

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160225155914.GM8720@kernel.org \
    --to=acme@kernel.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=treeze.taeung@gmail.com \
    --cc=wangnan0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox