From: Masami Hiramatsu <mhiramat@kernel.org>
To: Thomas-Mich Richter <tmricht@linux.vnet.ibm.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
bhargavb <bhargavaramudu@gmail.com>,
linux-kernel@vger.kernel.org, Paul Clarke <pc@us.ibm.com>,
Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>,
linux-rt-users@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2 4/5] perf-probe: Find versioned symbols from map
Date: Fri, 8 Dec 2017 23:22:49 +0900 [thread overview]
Message-ID: <20171208232249.65cd9951e026c9d9c57740be@kernel.org> (raw)
In-Reply-To: <034765fc-975a-a210-6ed8-bebd3b1ff9b3@linux.vnet.ibm.com>
On Fri, 8 Dec 2017 12:08:41 +0100
Thomas-Mich Richter <tmricht@linux.vnet.ibm.com> wrote:
> On 12/07/2017 08:21 AM, Masami Hiramatsu wrote:
> > Find versioned symbols correctly from map.
> > Commit d80406453ad4 ("perf symbols: Allow user probes on
> > versioned symbols") allows user to find default versioned
> > symbols (with "@@") in map. However, it did not enable
> > normal versioned symbol (with "@") for perf-probe.
> > E.g.
> >
> > =====
> > # ./perf probe -x /lib64/libc-2.25.so malloc_get_state
> > Failed to find symbol malloc_get_state in /usr/lib64/libc-2.25.so
> > Error: Failed to add events.
> > =====
> >
> > This solves above issue by improving perf-probe symbol
> > search function, as below.
> >
> > =====
> > # ./perf probe -x /lib64/libc-2.25.so malloc_get_state
> > Added new event:
> > probe_libc:malloc_get_state (on malloc_get_state in /usr/lib64/libc-2.25.so)
> >
> > You can now use it in all perf tools, such as:
> >
> > perf record -e probe_libc:malloc_get_state -aR sleep 1
> >
> > # ./perf probe -l
> > probe_libc:malloc_get_state (on malloc_get_state@GLIBC_2.2.5 in /usr/lib64/libc-2.25.so)
> > =====
> >
> > Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> > ---
> > tools/perf/arch/powerpc/util/sym-handling.c | 8 ++++++++
> > tools/perf/util/probe-event.c | 16 +++++++++++++++-
> > tools/perf/util/symbol.c | 5 +++++
> > tools/perf/util/symbol.h | 1 +
> > 4 files changed, 29 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/perf/arch/powerpc/util/sym-handling.c b/tools/perf/arch/powerpc/util/sym-handling.c
> > index 9c4e23d8c8ce..a3613c8d97b6 100644
> > --- a/tools/perf/arch/powerpc/util/sym-handling.c
> > +++ b/tools/perf/arch/powerpc/util/sym-handling.c
> > @@ -64,6 +64,14 @@ int arch__compare_symbol_names_n(const char *namea, const char *nameb,
> >
> > return strncmp(namea, nameb, n);
> > }
> > +
> > +const char *arch__normalize_symbol_name(const char *name)
> > +{
> > + /* Skip over initial dot */
> > + if (*name == '.')
> > + name++;
> > + return name;
> > +}
> > #endif
> >
> > #if defined(_CALL_ELF) && _CALL_ELF == 2
> > diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
> > index 959c4d2ef455..94acc5846e2a 100644
> > --- a/tools/perf/util/probe-event.c
> > +++ b/tools/perf/util/probe-event.c
> > @@ -2801,16 +2801,30 @@ static int find_probe_functions(struct map *map, char *name,
> > int found = 0;
> > struct symbol *sym;
> > struct rb_node *tmp;
> > + const char *norm, *ver;
> > + char *buf = NULL;
> >
> > if (map__load(map) < 0)
> > return 0;
> >
> > map__for_each_symbol(map, sym, tmp) {
> > - if (strglobmatch(sym->name, name)) {
> > + norm = arch__normalize_symbol_name(sym->name);
>
> The weak default function arch__normalize_symbol_name() simply returns
> its parameter, so norm can be a NULL ptr when parameter sym->name is a
> NULL pointer.
> However when sym->name is a NULL pointer (or can be one) then the
> Powerpc version of arch__normalize_symbol_name() dereferences a NULL
> ptr (by checking the symbol's first character is a '.').
Oops, right!
Thank you for pointing out. :)
>
> > + if (!norm)
> > + continue;
> > +
> > + /* We don't care about default symbol or not */
> > + ver = strchr(norm, '@');
> > + if (ver) {
> > + buf = strndup(norm, ver - norm);
> > + norm = buf;
>
> if strndup() returns a NULL pointer (due to lack of memory)
> then variable norm is a NULL ptr and strglobmatch() --> __match_glob()
> derefenences that NULL pointer (1. parameter).
Ah, right. easy miss...
OK, I'll update.
Thank you,
>
> > + }
> > + if (strglobmatch(norm, name)) {
> > found++;
> > if (syms && found < probe_conf.max_probes)
> > syms[found - 1] = sym;
> > }
> > + if (buf)
> > + zfree(&buf);
> > }
> >
> > return found;
> > diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
> > index 1b67a8639dfe..cc065d4bfafc 100644
> > --- a/tools/perf/util/symbol.c
> > +++ b/tools/perf/util/symbol.c
> > @@ -94,6 +94,11 @@ static int prefix_underscores_count(const char *str)
> > return tail - str;
> > }
> >
> > +const char * __weak arch__normalize_symbol_name(const char *name)
> > +{
> > + return name;
> > +}
> > +
> > int __weak arch__compare_symbol_names(const char *namea, const char *nameb)
> > {
> > return strcmp(namea, nameb);
> > diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
> > index a4f0075b4e5c..0563f33c1eb3 100644
> > --- a/tools/perf/util/symbol.h
> > +++ b/tools/perf/util/symbol.h
> > @@ -349,6 +349,7 @@ bool elf__needs_adjust_symbols(GElf_Ehdr ehdr);
> > void arch__sym_update(struct symbol *s, GElf_Sym *sym);
> > #endif
> >
> > +const char *arch__normalize_symbol_name(const char *name);
> > #define SYMBOL_A 0
> > #define SYMBOL_B 1
> >
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-perf-users" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
> >
>
>
> --
> Thomas Richter, Dept 3303, IBM LTC Boeblingen Germany
> --
> Vorsitzende des Aufsichtsrats: Martina Koederitz
> Geschäftsführung: Dirk Wittkopp
> Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294
>
--
Masami Hiramatsu <mhiramat@kernel.org>
next prev parent reply other threads:[~2017-12-08 14:22 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-07 7:19 [PATCH v2 0/5] perf-probe: Improve probing on versioned symbols Masami Hiramatsu
2017-12-07 7:19 ` [PATCH v2 1/5] perf-probe: Add warning message if there is unexpected event name Masami Hiramatsu
2017-12-07 15:53 ` Arnaldo Carvalho de Melo
2017-12-08 2:48 ` Masami Hiramatsu
2017-12-07 7:20 ` [PATCH v2 2/5] perf-probe: Cut off the version suffix from " Masami Hiramatsu
2017-12-07 16:34 ` Paul Clarke
2017-12-08 3:01 ` Masami Hiramatsu
2017-12-08 14:49 ` Paul Clarke
2017-12-08 16:12 ` Masami Hiramatsu
2017-12-11 18:25 ` Arnaldo Carvalho de Melo
2017-12-12 15:02 ` Masami Hiramatsu
2017-12-07 16:56 ` Arnaldo Carvalho de Melo
2017-12-07 17:24 ` Paul Clarke
2017-12-07 17:55 ` Arnaldo Carvalho de Melo
2017-12-08 3:15 ` Masami Hiramatsu
2017-12-07 7:20 ` [PATCH v2 3/5] perf-probe: Add __return suffix for return events Masami Hiramatsu
2017-12-07 7:21 ` [PATCH v2 4/5] perf-probe: Find versioned symbols from map Masami Hiramatsu
2017-12-08 11:08 ` Thomas-Mich Richter
2017-12-08 14:22 ` Masami Hiramatsu [this message]
2017-12-07 7:21 ` [PATCH v2 5/5] perf-probe: Support escaped character in parser Masami Hiramatsu
2017-12-08 11:45 ` Thomas-Mich Richter
2017-12-08 15:54 ` Masami Hiramatsu
2017-12-07 12:47 ` [PATCH v2 0/5] perf-probe: Improve probing on versioned symbols Ravi Bangoria
2017-12-08 16:24 ` Masami Hiramatsu
2017-12-08 17:13 ` Ravi Bangoria
2017-12-08 11:56 ` Thomas-Mich Richter
2017-12-08 16:12 ` Masami Hiramatsu
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=20171208232249.65cd9951e026c9d9c57740be@kernel.org \
--to=mhiramat@kernel.org \
--cc=acme@kernel.org \
--cc=bhargavaramudu@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=pc@us.ibm.com \
--cc=ravi.bangoria@linux.vnet.ibm.com \
--cc=tmricht@linux.vnet.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.