Re: [PATCH] perf probe: support signedness casting

From: Naohiro Aota
Date: Fri Aug 05 2016 - 07:41:11 EST


2016-08-05 (é) ã 18:10 +0900 ã Masami Hiramatsu ãããæãããã:
> On Fri, 5 Aug 2016 14:33:53 +0900
> Naohiro Aota <naohiro.aota@xxxxxxxx> wrote:
>
> >
> > Perf-probe detects a variable's type and use the detected type to
> > add new
> > probe. Then, kprobes prints its variable in hexadecimal format if
> > the
> > variable is unsigned and prints in decimal if it is signed.
> >
> > We sometimes want to see unsigned variable in decimal format (e.g.
> > sector_t or size_t). In that case, we need to investigate
> > variable's
> > size manually to specify just signedness.
> >
> > This patch add signedness casting support. By specifying "s" or "u"
> > as a
> > type, perf-probe will investigate variable size as usual and use
> > the specified signedness.
> OK, I could understand what the patch does from code. Please add an
> example, and update tools/perf/Documentation/perf-probe.txt too.

Thanks for the review. I'm posting updated patch with type
descriptions.

> Thank you,
>
> >
> >
> > Signed-off-by: Naohiro Aota <naohiro.aota@xxxxxxxx>
> > ---
> > Âtools/perf/util/probe-finder.c | 15 ++++++++++++---
> > Â1 file changed, 12 insertions(+), 3 deletions(-)
> >
> > diff --git a/tools/perf/util/probe-finder.c
> > b/tools/perf/util/probe-finder.c
> > index f2d9ff0..5c290c6 100644
> > --- a/tools/perf/util/probe-finder.c
> > +++ b/tools/perf/util/probe-finder.c
> > @@ -297,10 +297,13 @@ static int convert_variable_type(Dwarf_Die
> > *vr_die,
> > Â char sbuf[STRERR_BUFSIZE];
> > Â int bsize, boffs, total;
> > Â int ret;
> > + char sign;
> > Â
> > Â /* TODO: check all types */
> > - if (cast && strcmp(cast, "string") != 0) {
> > + if (cast && strcmp(cast, "string") != 0 &&
> > + ÂÂÂÂstrcmp(cast, "s") != 0 && strcmp(cast, "u") != 0) {
> > Â /* Non string type is OK */
> > + /* and respect signedness cast */
> > Â tvar->type = strdup(cast);
> > Â return (tvar->type == NULL) ? -ENOMEM : 0;
> > Â }
> > @@ -361,6 +364,13 @@ static int convert_variable_type(Dwarf_Die
> > *vr_die,
> > Â return (tvar->type == NULL) ? -ENOMEM : 0;
> > Â }
> > Â
> > + if (cast && (strcmp(cast, "u") == 0))
> > + sign = 'u';
> > + else if (cast && (strcmp(cast, "s") == 0))
> > + sign = 's';
> > + else
> > + sign = die_is_signed_type(&type) ? 's' : 'u';
> > +
> > Â ret = dwarf_bytesize(&type);
> > Â if (ret <= 0)
> > Â /* No size ... try to use default type */
> > @@ -373,8 +383,7 @@ static int convert_variable_type(Dwarf_Die
> > *vr_die,
> > Â dwarf_diename(&type),
> > MAX_BASIC_TYPE_BITS);
> > Â ret = MAX_BASIC_TYPE_BITS;
> > Â }
> > - ret = snprintf(buf, 16, "%c%d",
> > - ÂÂÂÂÂÂÂdie_is_signed_type(&type) ? 's' : 'u',
> > ret);
> > + ret = snprintf(buf, 16, "%c%d", sign, ret);
> > Â
> > Âformatted:
> > Â if (ret < 0 || ret >= 16) {
> > --Â
> > 2.7.3
> >
>
Western Digital Corporation (and its subsidiaries) E-mail Confidentiality Notice & Disclaimer:

This e-mail and any files transmitted with it may contain confidential or legally privileged information of WDC and/or its affiliates, and are intended solely for the use of the individual or entity to which they are addressed. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited. If you have received this e-mail in error, please notify the sender immediately and delete the e-mail in its entirety from your system.